コード例 #1
0
ファイル: Ecs.py プロジェクト: 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
コード例 #2
0
ファイル: aliyun_sss.py プロジェクト: Victor88101/tools
def runInstance(client, instance_name, password, template_id):
    request = RunInstancesRequest()
    request.set_accept_format('json')
    request.set_InstanceName(instance_name)
    request.set_Password(password)
    request.set_LaunchTemplateId(template_id)
    response = client.do_action_with_exception(request)
    return response