Exemplo n.º 1
0
 def create_template(self, image_id, sg_id, vpc_id):
     request = CreateLaunchTemplateRequest()
     request.set_accept_format('json')
     request.set_LaunchTemplateName(''.join(
         random.choice(string.ascii_uppercase) for _ in range(20)))
     request.set_ImageId(image_id)
     request.set_ImageOwnerAlias("self")
     request.set_PasswordInherit(True)
     if "address" in self.cloud_resources and self.cloud_resources[
             'address'] == "public":
         request.set_InternetMaxBandwidthIn(100)
         request.set_InternetMaxBandwidthOut(100)
     request.set_InstanceType("ecs.c6.large")
     request.set_InstanceName(self.cloud_resources["instance_name"])
     request.set_SecurityGroupId(sg_id)
     request.set_VpcId(vpc_id)
     request.set_SystemDiskCategory("cloud_efficiency")
     request.set_SystemDiskSize(70)
     request.set_IoOptimized("optimized")
     request.set_InstanceChargeType("PostPaid")
     request.set_NetworkType("vpc")
     request.set_SpotStrategy("SpotWithPriceLimit")
     request.set_SpotPriceLimit(100)
     try:
         response = self.client.do_action_with_exception(request)
         response = json.loads(response)
         return response["LaunchTemplateId"]
     except ServerException as e:
         dlog.info(e)
         sys.exit()
     except ClientException as e:
         dlog.info(e)
         sys.exit()
Exemplo n.º 2
0
    def get_image_id(self, img_name):
        request = DescribeImagesRequest()
        request.set_accept_format('json')
        request.set_ImageOwnerAlias("self")
        request.set_PageSize(20)
        response = self.client.do_action_with_exception(request)
        response = json.loads(response)
        totalcount = response["TotalCount"]

        iteration = totalcount // 20
        if iteration * 20 < totalcount:
            iteration += 1

        for ii in range(1, iteration + 1):
            count = 0
            flag = 0
            request.set_PageNumber(ii)
            while count < 10:
                try:
                    response = self.client.do_action_with_exception(request)
                    response = json.loads(response)
                    for img in response["Images"]["Image"]:
                        if img["ImageName"] == img_name:
                            return img["ImageId"]
                    flag = 1
                    break
                except:
                    count += 1
                    time.sleep(10)
        if not flag:
            dlog.info("get image failed, exit")
            sys.exit()
Exemplo n.º 3
0
 def get_image_id(self, img_name):
     request = DescribeImagesRequest()
     request.set_accept_format('json')
     request.set_ImageOwnerAlias("self")
     request.set_PageSize(100)
     count = 0
     flag = 0
     while count < 10:
         try:
             response = self.client.do_action_with_exception(request)
             response = json.loads(response)
             for img in response["Images"]["Image"]:
                 if img["ImageName"] == img_name:
                     return img["ImageId"]
             flag = 1
             break
         except:
             count += 1
             time.sleep(10)
     if not flag:
         dlog.info("get image failed, exit")
         sys.exit()