Esempio n. 1
0
File: Ecs.py Progetto: lingh0205/ecs
 def create(self, template_id, template_name):
     """
     :argument template_id ***************
     :argument template_name ***************
     :return:
     """
     request = RunInstancesRequest()
     request.set_accept_format('json')
     request.set_LaunchTemplateName(template_name)
     request.set_LaunchTemplateId(template_id)
     try:
         logging.info("Start to create ecs instance for template %s." %
                      template_name)
         response = self.client.do_action_with_exception(request)
         if ResponseUtil.success(response):
             instance_id = get_instance_id(str(response, encoding='utf-8'))
             if not instance_id:
                 raise ValueError("Instance ID NullPointException")
             logging.info(
                 "Successfully create instance %s with template %s." %
                 (instance_id, template_name))
             return True, instance_id
         else:
             return False, str(response, encoding='utf-8')
     except Exception as e:
         logging.error("Failed to create ecs, cause by exception : ", e)
         return False, e
Esempio n. 2
0
File: ALI.py Progetto: y1xiaoc/dpgen
 def create_machine(self):
     AccessKey_ID = self.adata["AccessKey_ID"]
     AccessKey_Secret = self.adata["AccessKey_Secret"]
     strategy = self.adata["pay_strategy"]
     pwd = self.adata["password"]
     regionID = self.mdata_machine['regionID']
     template_name = '%s_%s_%s' % (self.mdata_resources['partition'], self.mdata_resources['numb_gpu'], strategy)
     instance_name = self.adata["instance_name"]
     client = AcsClient(AccessKey_ID,AccessKey_Secret, regionID)
     request = RunInstancesRequest()
     request.set_accept_format('json')
     request.set_UniqueSuffix(True)
     request.set_Password(pwd)
     request.set_InstanceName(instance_name)
     request.set_Amount(self.nchunks)
     request.set_LaunchTemplateName(template_name)
     response = client.do_action_with_exception(request)
     response = json.loads(response)
     self.instance_list = response["InstanceIdSets"]["InstanceIdSet"]
     time.sleep(50)
     request = DescribeInstancesRequest()
     request.set_accept_format('json')
     request.set_InstanceIds(self.instance_list)
     response = client.do_action_with_exception(request)
     response = json.loads(response)
     ip = []
     for i in range(len(response["Instances"]["Instance"])):
         ip.append(response["Instances"]["Instance"][i]["PublicIpAddress"]['IpAddress'][0])
     self.ip_list = ip