本文整理汇总了Python中infrastructure_manager.InfrastructureManager.prepare_instances方法的典型用法代码示例。如果您正苦于以下问题:Python InfrastructureManager.prepare_instances方法的具体用法?Python InfrastructureManager.prepare_instances怎么用?Python InfrastructureManager.prepare_instances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类infrastructure_manager.InfrastructureManager
的用法示例。
在下文中一共展示了InfrastructureManager.prepare_instances方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_flex_cloud_machines
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import prepare_instances [as 别名]
def prepare_flex_cloud_machines(self, params, blocking=False):
logging.debug("prepare_flex_cloud_machines : params : \n%s", pprint.pformat(params))
try:
# NOTE: We are forcing blocking mode within the InfrastructureManager class
# for the launching of VMs because of how GAE joins on all threads before
# returning a response from a request.
i = InfrastructureManager(blocking=blocking)
res = {}
# 4. Prepare Instances
res = i.prepare_instances(params)
logging.debug("prepare_flex_cloud_machines : exiting method with result : %s", str(res))
return True, ''
except Exception, e:
traceback.print_exc()
logging.error("prepare_flex_cloud_machines : exiting method with error : {0}".format(str(e)))
return False, 'Errors occur in preparing machines:' + str(e)
示例2: start_ec2_vms
# 需要导入模块: from infrastructure_manager import InfrastructureManager [as 别名]
# 或者: from infrastructure_manager.InfrastructureManager import prepare_instances [as 别名]
def start_ec2_vms(self, params, blocking=False):
'''
This method instantiates EC2 vm instances
'''
logging.debug("start_ec2_vms : inside method with params : \n%s", pprint.pformat(params))
try:
# make sure that any keynames we use are prefixed with stochss so that
#we can do a terminate all based on keyname prefix
key_prefix = AgentConfig.get_agent_key_prefix(agent_type=AgentTypes.EC2,
key_prefix=params.get('key_prefix', ''))
key_name = params["keyname"]
if not key_name.startswith(key_prefix):
params['keyname'] = key_prefix + key_name
# NOTE: We are forcing blocking mode within the InfrastructureManager class
# for the launching of VMs because of how GAE joins on all threads before
# returning a response from a request.
i = InfrastructureManager(blocking=blocking)
res = {}
# 1. change the status of 'failed' in the previous launch in db to 'terminated'
# NOTE: We need to make sure that the RabbitMQ server is running if any compute
# nodes are running as we are using the AMQP broker option for Celery.
ins_ids = VMStateModel.terminate_not_active(params)
# 2. get user_id, infra, ec2 credentials
user_id = self.__get_required_parameter(parameter_key='user_id', params=params)
infrastructure = self.__get_required_parameter(parameter_key='infrastructure', params=params)
reservation_id = self.__get_required_parameter(parameter_key='reservation_id', params=params)
logging.debug('ec2: reservation_id = {0}'.format(reservation_id))
if 'credentials' in params:
if 'EC2_ACCESS_KEY' in params['credentials'] and 'EC2_SECRET_KEY' in params['credentials']:
ec2_access_key = params['credentials']['EC2_ACCESS_KEY']
ec2_secret_key = params['credentials']['EC2_SECRET_KEY']
else:
raise Exception('VMStateModel ERROR: Cannot get access key or secret.')
else:
raise Exception('VMStateModel ERROR: No credentials are provided.')
if ec2_access_key is None or ec2_secret_key is None:
raise Exception('VMStateModel ERROR: ec2 credentials are not valid.')
# 3. create exact number of entities in db for this launch, and set the status to 'creating'
num_vms = 0
if 'vms' in params:
for vm in params['vms']:
logging.debug('vm: {0}, num: {1}'.format(vm['instance_type'], vm['num_vms']))
num_vms += vm['num_vms']
if 'head_node' in params:
num_vms += 1
logging.debug('num = {0}'.format(num_vms))
ids = self.__create_vm_state_model_entries(ec2_access_key=ec2_access_key, ec2_secret_key=ec2_secret_key,
infrastructure=infrastructure, num_vms=num_vms, user_id=user_id,
reservation_id=reservation_id)
# 4. Prepare Instances
params[VMStateModel.IDS] = ids
res = i.prepare_instances(params)
# 5, check and create stochss table exists if it does not exist
self.__create_dynamodb_stochss_table(ec2_access_key=ec2_access_key, ec2_secret_key=ec2_secret_key)
logging.debug("start_ec2_vms : exiting method with result : %s", str(res))
return True, None
except Exception as e:
logging.exception("start_ec2_vms : exiting method with error : {0}".format(str(e)))
return False, 'Errors occur in starting machines:' + str(e)