Exemple #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()
Exemple #2
0
 def share_image_with_accounts(self, image_id, share_account_ids):
     """ Send request to share image with other alibaba
         accounts. Return Alibaba response """
     request = ModifyImageSharePermissionRequest()
     request.set_ImageId(image_id)
     request.set_AddAccounts(share_account_ids)
     return self.__send_request(request)
def delete_image(image_id):
    """Delete image by image id."""
    if image_id is None or not image_id:
        raise Exception('No image id was provided')
    request = DeleteImageRequest()
    request.set_ImageId(image_id)
    return request
Exemple #4
0
 def describe_image_share_permission(self, image_id):
     """Print description of an image's share permissions"""
     if image_id is None or not image_id:
         raise Exception('No image id provided')
     request = DescribeImageSharePermissionRequest()
     if image_id:
         request.set_ImageId(image_id)
     return self.__send_request(request)
def describe_images(image_id, image_name):
    """Print description of an image with matching id or name."""
    request = DescribeImagesRequest()
    if image_id:
        request.set_ImageId(image_id)
    if image_name:
        request.set_ImageName(image_name)
    return request
Exemple #6
0
 def describe_images(self, image_id, image_name):
     """ Send request to get details of images
         Filter by image id and name
         Return Alibaba response """
     request = DescribeImagesRequest()
     if image_id:
         request.set_ImageId(image_id)
     if image_name:
         request.set_ImageName(image_name)
     return self.__send_request(request)
def modify_image_share_permission(image_id, accounts_str):
    """Share image with accounts by image id"""
    if image_id is None or not image_id:
        raise Exception('No image id was provided')
    if accounts_str is None or not accounts_str:
        raise Exception('No accounts string was provided')

    # Transform accounts string to account array
    accounts_array = accounts_str.split(",")

    request = ModifyImageSharePermissionRequest()
    request.set_ImageId(image_id)
    request.set_AddAccounts(accounts_array)
    return request
Exemple #8
0
 def delete_image(self, image_id):
     """ Delete image by image id
         Return Alibaba response """
     request = DeleteImageRequest()
     request.set_ImageId(image_id)
     return self.__send_request(request)