Exemplo n.º 1
0
    def create_apg(self):
        request = CreateAutoProvisioningGroupRequest()
        request.set_accept_format('json')
        request.set_TotalTargetCapacity(str(self.nchunks_limit))
        request.set_LaunchTemplateId(self.cloud_resources["template_id"])
        request.set_AutoProvisioningGroupName(
            self.cloud_resources["instance_name"] +
            ''.join(random.choice(string.ascii_uppercase) for _ in range(20)))
        request.set_AutoProvisioningGroupType("maintain")
        request.set_SpotAllocationStrategy("lowest-price")
        request.set_SpotInstanceInterruptionBehavior("terminate")
        request.set_SpotInstancePoolsToUseCount(1)
        request.set_ExcessCapacityTerminationPolicy("termination")
        request.set_TerminateInstances(True)
        request.set_PayAsYouGoTargetCapacity("0")
        request.set_SpotTargetCapacity(str(self.nchunks_limit))
        config = self.generate_config()
        request.set_LaunchTemplateConfigs(config)

        try:
            response = self.client.do_action_with_exception(request)
            response = json.loads(response)
            with open('apg_id.json', 'w') as fp:
                json.dump({'apg_id': response["AutoProvisioningGroupId"]},
                          fp,
                          indent=4)
            return response["AutoProvisioningGroupId"]
        except ServerException as e:
            dlog.info("create apg failed, err msg: %s" % e)
            sys.exit()
        except ClientException as e:
            dlog.info("create apg failed, err msg: %s" % e)
            sys.exit()
Exemplo n.º 2
0
 def delete_template(self):
     request = DeleteLaunchTemplateRequest()
     request.set_accept_format('json')
     count = 0
     flag = 0
     while count < 10:
         try:
             request.set_LaunchTemplateId(
                 self.cloud_resources["template_id"])
             response = self.client.do_action_with_exception(request)
             flag = 1
             break
         except:
             count += 1