Package: azure-img-utils
Overviewazure-img-utilsprovides a command line utility and API for publishing
images in the Azure Cloud. This includes helper functions for uploading
image blobs, creating compute images and publish/share images across
all available regions.See theAzure docsto get
more info on the Azure cloud.RequirementsThe requirements for the project can be found in the following repo files:requirementsrequirements for testingrequirements for developmentInstallationTo install the package on openSUSE and SLES use the following commands as root:# zypper ar https://download.opensuse.org/repositories/Cloud:Tools:CI/<distribution># zypper refresh# zypper in python3-azure-img-utilsTo install from PyPI:$pipinstallazure-img-utilsConfigurationazure-img-utilscan be configured with yaml based profiles. The configuration
directory is~/.config/azure_img_utilsand the default profile is default.yaml
(~/.config/azure_img_utils/default.yaml).The following configration options are available in a configuration profile:no_colorlog_levelcredentials_fileresource_groupregioncontainerstorage_accountAn example configuration profile may look like:region:westusno_color:Truecredentials_file:mycredentials.jsoncontainer:my_containerWhen running any command the profile can be chosen via the--profileoption.
For example,azure-img-utils image blobexists --profile productionwould pull
configuration from ~/.config/azure_img_utils/production.yaml.CLIThe CLI is broken into multiple distinct subcommands that handle different
steps of creating and publishing images in the Azure cloud framework.AuthenticationThis cli tool expects the user to provide a json file containing the
credentials of a service principal to access his/her Azure services.Per Azure documentation:An Azure service principal is an identity created for use with applications,
hosted services, and automated tools to access Azure resources.Hereyou can find how to create a service principal with the azure cli.With your subscriptionId, the resourceGroupId and the required permissions, you can
create the service principal with the following command:azadspcreate-for-rbac\--sdk-auth\--roleContributor\--scopes/subscriptions/{YOUR_SUSCRI_ID}/resourceGroups/{YOUR_RES_GROUP_ID}\--name"YOUR_SP_NAME">mycredentials.jsonThe expected format for the json file is the output for thatcreate-for-rbacaz
command. Note that the API this repo provides allows additional methods of
authentication, but these are not supported in this CLI tool.blob commandGroup of commands for blob management.exists subcommandThis subcommand allows the user to check if a blob exists in the storage
container specified. The subcommand isazure-img-utils blob exists.Therequiredparameters for the execution of the command (authentication
aside):--storage-account--blob-name--containerExample:$azure-img-utilsblobexists--storage-accountmyStorageAccount\--blob-namemyBlobName\--containermyContainerNameThis command will outputtrueorfalsedepending on the existence of the
blob.For more information about the blob exists command see the help message:$azure-img-utilsblobexists--helpupload subcommandThis subcommand allows the user to upload a file as a blob to the storage
container specified. The subcommand isazure-img-utils blob upload.Therequiredparameters for the execution of the command (authentication
aside):--storage-account--blob-name--container--image-fileSomeoptionalparameters for the execution of the command include:--force-replace-image  (defaults to False)--page-blob            (defaults to False)--expand-image         (defaults to False)--max-workers          (defaults to 5(no limit))--max-attempts   (defaults to 5(no limit))Example:$azure-img-utilsblobupload--storage-accountmyStorageAccount\--blob-namemyBlobName\--containermyContainerName\--image-filemyImageFile.qcow2This command will output if the upload has been successful or not.For more information about the blob upload command see the help message:$azure-img-utilsblobupload--helpdelete subcommandThis subcommand allows the user to delete a blob file from the storage
container specified. The subcommand isazure-img-utils blob delete.Therequiredparameters for the execution of the command (authentication
aside):--storage-account--blob-name--containerSomeoptionalparameters for the execution of the command:--yes  (avoids interactive confirmation for the deletion)Example:$azure-img-utilsblobdelete--storage-accountmyStorageAccount\--blob-namemyBlobName\--containermyContainerName\--yesThis command will output if the deletion has been successful or not.For more information about the blob delete command see the help message:$azure-img-utilsblobdelete--helpimage commandGroup of commands for image management.exists subcommandThis subcommand allows the user to check if an image exists.
The subcommand isazure-img-utils image exists.Therequiredparameters for the execution of the command (authentication
aside):--image-nameExample:$azure-img-utilsimageexists--image-namemyImageNameThis command will outputtrueorfalsedepending on the existence of the
image.For more information about the image exists command see the help message:$azure-img-utilsimageexists--helpcreate subcommandThis subcommand allows the user to create an image based in one blob.
The subcommand isazure-img-utils image create.Therequiredparameters for the execution of the command (authentication
aside):--blob-name--image-name--container--resource-group--storage-accountSomeoptionalparameters for the execution of the command include:--force-replace-image  (defaults to False)--hyper-v-generation   (defaults to 'V1'(legacy bios).)
(Use 'V2' for uefi boot.)Example:$azure-img-utilsimagecreate--blob-namemyBlobName\--image-namemyImageNameFor more information about the image create command see the help message:$azure-img-utilsimagecreate--helpdelete subcommandThis subcommand allows the user to delete an existing image.
The subcommand isazure-img-utils image delete.Therequiredparameters for the execution of the command (authentication
aside):--image-nameExample:$azure-img-utilsimagedelete--image-namemyImageNameFor more information about the image delete command see the help message:$azure-img-utilsimagedelete--helpgallery-image-version commandGroup of commands for gallery image version management.exists subcommandThis subcommand allows the user to check if a gallery image version exists in a
gallery.
The subcommand isazure-img-utils gallery-image-version exists.Therequiredparameters for the execution of the command (authentication
aside):--gallery-image-name--gallery-name--gallery-image-versionExample:$azure-img-utilsgallery-image-versionexists\--gallery-image-namemyImageName\--gallery-namemyGalleryName\--gallery-image-version0.0.1This command will outputtrueorfalsedepending on the existence of the
gallery image version in the gallery.For more information about the gallery image version exists command see the
help message:$azure-img-utilsgallery-image-versionexists--helpcreate subcommandThis subcommand allows the user to create a gallery image version in a gallery based
on a blob.
The subcommand isazure-img-utils gallery-image-version create.Therequiredparameters for the execution of the command (authentication
aside):--blob-name--gallery-name--gallery-image-name--gallery-image-version--resource-groupSomeoptionalparameters for the execution of the command include:--force-replace-image  (defaults to False)Example:$azure-img-utilsgallery-image-versioncreate\--blob-namemyBlobName\--gallery-image-namemyImageName\--gallery-namemyGalleryName\--image-version0.0.1\--resource-groupmyResourceGroupFor more information about the gallery image version create command see the help
message:$azure-img-utilsgallery-image-versioncreate--helpdelete subcommandThis subcommand allows the user to delete an existing gallery image version of
a gallery image.The subcommand isazure-img-utils gallery-image-version delete.Therequiredparameters for the execution of the command (authentication
aside):--gallery-name--gallery-image-name--gallery-image-versionExample:$azure-img-utilsgallery-image-versiondelete\--gallery-image-namemyImageName\--gallery-namemyGalleryName\--gallery-image-version0.0.1For more information about the gallery image version delete command see the
help message:$azure-img-utilsgallery-image-versiondelete--helpcloud-partner-offer commandGroup of commands for cloud partner offer management.publish subcommandThis subcommand allows the user to publish a cloud partner offer.The subcommand isazure-img-utils cloud-partner-offer publish.Therequiredparameters for the execution of the command (authentication
aside):--offer-idExample:$azure-img-utilscloud-partner-offerpublish\--offer-idmyOfferIdThis command will output the job id for the published cloud partner offer
operation if successful.For more information about the cloud partner offer publish command see the
help message:$azure-img-utilscloud-partner-offerpublish--help### go-live subcommandThissubcommandallowstheusertosetacloudpartnerofferasgo-live.

Thesubcommandis*azure-img-utilscloud-partner-offergo-live*.

The*required*parametersfortheexecutionofthecommand(authenticationaside):
---offer-id

Theresultofthesubcommandisthatallnewchangesmadetotheofferarepubliclyvisible.

Example:```shell
$azure-img-utilscloud-partner-offergo-live\--offer-idmyOfferIdThis command will output the URI for the cloud partner offer go-live operation
if successful.For more information about the cloud partner offer go-live command see the
help message:$azure-img-utilscloud-partner-offergo-live--helpupload-offer-document subcommandThis subcommand allows the user to upload an offer document to a cloud
partner offer.The subcommand isazure-img-utils cloud-partner-offer upload-offer-document.Therequiredparameters for the execution of the command (authentication
aside):--offer-id--offer-document-fileThe '--offer-document-file' parameter has to contain the path for a text file
containing the json document for the offer.Example:$azure-img-utilscloud-partner-offerupload-offer-document\--offer-idmyOfferId\--offer-document-file/path/to/my/documentfile.jsonThis command will output only if there's any problem uploading the document for
the offer.For more information about the cloud partner offer upload-offer-document
command see the help message:$azure-img-utilscloud-partner-offerupload-offer-document--helpadd-image-to-offer subcommandThis subcommand allows the user to add an image to a cloud partner offer.The subcommand isazure-img-utils cloud-partner-offer add-image-to-offer.Therequiredparameters for the execution of the command (authentication
aside):--blob-name--image-name--offer-id--skuSomeoptionalparameters for the execution of the command include:--blob-url  (A blob-url is generated if not provided)--generation-idExample:$azure-img-utilscloud-partner-offeradd-image-to-offer\--blob-namemyBlobName\--image-namemyImageName\--offer-idmyOfferId\--skumySKUThis command will output only if there's any problem adding the image
to the offer.For more information about the cloud partner offer add-image-to-offer
command see the help message:$azure-img-utilscloud-partner-offeradd-image-to-offer--helpremove-image-from-offer subcommandThis subcommand allows the user to remove an image from a cloud partner offer.The subcommand isazure-img-utils cloud-partner-offer remove-image-from-offer.Therequiredparameters for the execution of the command (authentication
aside):--image-urnExample:$azure-img-utilscloud-partner-offerremove-image-to-offer\--image-urnmyImageUrnThis command will output only if there's any problem removing the image
from the offer.For more information about the cloud partner offer remove-image-from-offer
command see the help message:$azure-img-utilscloud-partner-offerremove-image-from-offer--helpAPIThe AzureImage 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 AzureImage you need astorage_account,credentials dictionary objectorcredentials fileorsas tokencontainerandresource group. Optionally you can pass
in a Python log object and/or alog_leveland/or atimeoutvalue.Note that you can provide authentication credentials in 3 different ways:with a sas_tokenwith a dictionary of credentials containing the required key valueswith the credentials file name
Providing just one of these options is enough to perform the authentication
in the Azure API.azure_image=AzureImage(container="my_container_name",storage_account="my_storage_account",credentials=my_credentials_dict,credentials_file="my_credentials_file.json",resource_group="my_resource_group",sas_token="my_sas_token",log_level=my_log_level,log_callback=loggertimeout=myTimeout)Code examplesWith an instance of AzureImage you can perform any of the image functions
which are available through the CLI.azure_image=AzureImage(container="my_container",storage_account="my_storage_account",credentials_file="my_credentials.json",resource_gropu="my_resource_group",sas_token="my_sas_token")Check if image blob existsblob_exists=azure_image.image_blob_exists("my_blob_name")Delete storage blobblob_deleted=azure_image.delete_storage_blob("my_blob_name")Upload image blobblob_name=azure_image.upload_image_blob("my_image_file.qcow2",blob_name="my_blob_name")Check if image existsimage_exists=azure_image.image_exists("my_image_name")Check if gallery image version existsgallery_image_version_exists=azure_image.gallery_image_version_exists("my_gallery_name","my_gallery_image_name","my_image_version",gallery_resource_group="my_gallery_resource_group")Delete compute imageazure_image.delete_compute_image("my_image_name")Delete gallery image versionazure_image.delete_gallery_image_version("my_gallery_name","my_gallery_image_name","my_image_version",gallery_resource_group="my_gallery_resource_group")Get compute image dictionaryimage_dict=azure_image.get_compute_image("my_image_name")Get gallery image versionimage_dict=azure_image.get_gallery_image_version("my_gallery_name","my_gallery_image_name","my_image_version",gallery_resource_group="my_gallery_resource_group")Create compute imageimage_name=azure_image.create_compute_image("my_blob_name","my_image_name","my_region",force_replace_image=True,hyper_v_generation='V1')Create gallery image versionimage_name=azure_image.create_gallery_image_version("my_blob_name","my_gallery_name","my_gallery_image_name","my_image_version","my_region",force_replace_image=True,gallery_resource_group="my_gallery_resource_group")Get offer doc dictionaryoffer_doc=azure_image.get_offer_doc("my_offer_id")Upload offer docazure_image.upload_offer_doc("my_offer_id",my_offer_doc_dict)Add image to offerazure_image.add_image_to_offer("my_blob_name","my_image_name","my_offer_id","my_sku",blob_url="https://my.blob.url",generation_id="my_generation_id")Remove image from offerazure_image.remove_image_from_offer("my_image_urn")Publish offeroperation_uri=azure_image.publish_offer("my_offer_id")Go live with offeroperation_uri=azure_image.go_live_with_offer("my_offer_id")Get offer statusoffer_status=azure_image.get_offer_status("my_offer_id")Get operationoperation_status=azure_image.get_operation("my_operation")Issues/EnhancementsPlease submit issues and requests toGithub.ContributingContributions toazure-img-utilsare welcome and encouraged. SeeCONTRIBUTINGfor info on getting started.LicenseCopyright (c) 2022 SUSE LLC.Distributed under the terms of GPL-3.0+ license, seeLICENSEfor details.