Package: aliyun-img-utils
Overviewaliyun-img-utilsprovides a command line utility and API for publishing
images in the Aliyun Cloud. This includes helper functions for uploading
image blobs, creating compute images and replicating/publishing/deprecating/
images across all available regions.See theAlibaba docsto get
more info on the Aliyun cloud.Requirementsoss2ClickPyYAMLaliyun-python-sdk-corealiyun-python-sdk-ecsInstallationTo install the package on openSUSE and SLES use the following commands as root:$zypperarhttp://download.opensuse.org/repositories/Cloud:/Tools/<distribution>
$zypperrefresh
$zypperinpython3-aliyun-img-utilsTo install from PyPI:$pipinstallaliyun-img-utilsConfigurationaliyun-img-utilscan be configured with yaml based profiles. The configuration
directory is~/.config/aliyun_img_utilsand the default profile is default.yaml
(~/.config/aliyun_img_utils/default.yaml).The following configration options are available in a configuration profile:no_colorlog_levelregionaccess_keyaccess_secretbucket_nameAn example configuration profile may look like:region:cn-beijingaccess_key:FakeKEYaccess_secret:FAKESecretbucket_name:smarlow-testingWhen running any command the profile can be chosen via the--profileoption.
For example,aliyun-img-utils image upload --profile productionwould pull
configuration from ~/.config/aliyun_img_utils/production.yaml.CLIThe CLI is broken into multiple distinct subcommands that handle different
steps of creating and publishing images in the Aliyun cloud framework.Image blob uploadThe first step is to upload a qcow2 image to a storage bucket. For thisaliyun-img-utils image uploadis available.Example:$aliyun-img-utilsimageupload--image-file~/Documents/test.qcow2In this example the qcow2 file will be uploaded to the storage bucket configured
for the given profile and the blob will be named test.qcow2. If you want to
override the name of the blob there is a--blob-nameoption.For more information about the image upload function see the help message:$aliyun-img-utilsimageupload--helpCompute image createThe next step is to create a compute image from the qcow2 blob. For thisaliyun-img-utils image createis available.Example:$aliyun-img-utilsimagecreate--image-nameSLES15-SP2-BYOS--image-description"Test image"--platformSUSE--blob-nameSLES15-SP2-BYOS.qcow2In this example the qcow2 blob will be used to create the compute image.
for the given profile and the blob will be named test.qcow2. If you want to
override the default (20GB) root disk size there is a--disk-sizeoption.For more information about the image create function see the help message:$aliyun-img-utilsimagecreate--helpReplicate (copy) imageOnce an image is created in a single region it can be replicated or copied to any other region:aliyun-img-utils image replicate.Example:$aliyun-img-utilsimagereplicate--image-nametest-image-v20210303--regionscn-shanghaiIn this example the image will be replicated to the cn-shanghai region. If
no regions are provided the image will be replicated to all available regions.For more information about the image replicate function see the help message:$aliyun-img-utilsimagereplicate--helpPublish imageThe image can then be published or shared to other accounts withaliyun-img-utils image publish.Example:$aliyun-img-utilsimagepublish--image-nametest-image-v20210303--launch-permissionEXAMPLEIn this example the launch permission for the image will be set toEXAMPLE. If
no regions are provided the image will be published in all available regions.For more information about the image publish function see the help message:$aliyun-img-utilsimagepublish--helpDeprecate imageAn image can be set to the deprecated state withaliyun-img-utils image deprecate.Example:$aliyun-img-utilsimagedeprecate--image-nametest-image-v20210303As with the other commands, if no regions are provided the image will be deprecated
in all available regions.For more information about the image deprecate function see the help message:$aliyun-img-utilsimagedeprecate--helpActivate imageAn image can be set back to the active state withaliyun-img-utils image activate.Example:$aliyun-img-utilsimageactivate--image-nametest-image-v20210303As with the other commands, if no regions are provided the image will be activated
in all available regions.For more information about the image activate function see the help message:$aliyun-img-utilsimageactivate--helpGet image infoInfo about a specific compute image can be retrieved withaliyun-img-utils image info.Example:$aliyun-img-utilsimageinfo--image-nametest-image-v20210303The image can be searched by the--image-nameor--image-id. By
default only active images will be searched. To filter deprecated images
there is a--deprecatedoption.For more information about the image info function see the help message:$aliyun-img-utilsimageinfo--helpDelete imageA compute image can be deleted withaliyun-img-utils image delete.Example:$aliyun-img-utilsimagedelete--image-nametest-image-v20210303As with the other commands, if no regions are provided the image will be
deleted in all available regions.For more information about the image delete function see the help message:$aliyun-img-utilsimagedelete--helpAPIThe AliyunImage class can be instantiated and used as an API from code.
This provides all the same functions as the CLI with a few additional
helpers. For example there are waiter functions which will wait for
a compute image to be created and/or deleted.To create an instance of AliyunImage you need anaccess_key,access_secret,regionandbucket_name. optionally you can pass
in a Python log object and/or alog_level.aliyun_image=AliyunImage(access_key,access_secret,region,bucket_name,log_level=log_level,log_callback=logger)Code examplesWith an instance of AliyunImage you can perform any of the image functions
which are available through the CLI.aliyun_image=AliyunImage('accessKEY','superSECRET','cn-beijing','images)# Upload image blobblob_name=aliyun_image.upload_image_tarball('/path/to/image.qcow2')# Create compute imageimage_id=aliyun_image.create_compute_image('test-image-v20220202','A great image to use.','test_image.qcow2','SUSE')# Delete compute image# Deletes the image from the current regiondeleted=aliyun_image.delete_compute_image('test-image-v20220202')# Delete compute image in all available regionsaliyun_image.delete_compute_image_in_regions('test-image-v20220202')# Delete storage blob from current bucketdeleted=aliyun_image.delete_storage_blob('test_image.qcow2')# Copy image to a single regionimage_id=aliyun_image.copy_compute_image('test-image-v20220202','cn-shanghai')# Replicate (copy) image to all available regions# A dictionary mapping region names to image ids is returned.images=aliyun_image.replicate_image('test-image-v20220202')# Publish image in current regionaliyun_image.publish_image('test-image-v20220202','EXAMPLE_PERMISSION')# Publish image in all available regionsaliyun_image.publish_image_to_regions('test-image-v20220202','EXAMPLE_PERMISSION')# Deprecate image in current regionaliyun_image.deprecate_image('test-image-v20220202')# Deprecate image in all available regionsaliyun_image.deprecate_image_in_regions('test-image-v20220202')# Activate image in current regionaliyun_image.activate_image('test-image-v20220202')# Activate image in all available regionsaliyun_image.activate_image_in_regions('test-image-v20220202')# Wait for image to become available based on image idaliyun_image.wait_on_compute_image('i-123456789')# Wait for image to be deleted based on image idaliyun_image.wait_on_compute_image_delete('i-123456789')# Return True if the image exists based on image nameexists=aliyun_image.image_exists('test-image-v20220202')#exists=aliyun_image.image_tarball_exists('test_image.qcow2')# Get image info as a dictionaryimage_info=aliyun_image.get_compute_image(image_name='test_image.qcow2')# Get a list of available regionsregions=aliyun_image.get_regions()The currentregionorbucket_namecan be changed at any time.When thebucket_nameis changed the currentbucket_clientsession
is closed. The session will reconnect in a lazy fashion on the next
storage operation.aliyun_image=AliyunImage('accessKEY','superSECRET','cn-beijing','images)exists=aliyun_image.image_tarball_exists('test_image.qcow2')# Resets the storage bucket clientaliyun_image.bucket_name='old-images'# Storage bucket client connects to the new bucket lazilyexists=aliyun_image.image_tarball_exists('test_image.qcow2')Similarly when theregionis changed both thebucket_clientand
thecompute_clientsessions are closed.aliyun_image=AliyunImage('accessKEY','superSECRET','cn-beijing','images)image_info=aliyun_image.get_compute_image(image_name='test_image.qcow2')# Resets the compute clientaliyun_image.region='cn-shanghai'# Compute client connects to the new region lazilyimage_info=aliyun_image.get_compute_image(image_name='test_image.qcow2')Issues/EnhancementsPlease submit issues and requests toGithub.ContributingContributions toaliyun-img-utilsare welcome and encouraged. SeeCONTRIBUTINGfor info on getting started.LicenseCopyright (c) 2021 SUSE LLC.Distributed under the terms of GPL-3.0+ license, seeLICENSEfor details.