pycloudlib.azure.util module

Azure Util Functions.

pycloudlib.azure.util.get_client(resource, config_dict)[source]

Get azure client based on the give resource.

This method will first verify if we can get the client by using the information provided on the login account of the user machine. If the user is not logged into Azure, we will try to get the client from the ids given by the user to this class.

Parameters:
  • resource – Azure Resource, An Azure resource that we want to get a client for.
  • config_dict – dict, Id parameters passed by the user to this class.
Returns:

The client for the resource passed as parameter.

pycloudlib.azure.util.get_image_reference_params(image_id)[source]

Return the correct parameter for image reference based on image id.

Verify if the image id is associated with a current image found on Azure Marketplace or a custom image, for example, created through a snapshot process. Depending on the image id format, we can differentiate if we should create image parameters for a Marketplace image or a custom image.

Parameters:image_id – string, Represents a image to be used when provisioning a virtual machine
Returns:A dict representing the image reference parameters that will be used to provision a virtual machine
pycloudlib.azure.util.get_plan_params(image_id, registered_image)[source]

Return the correct parameter for plan based on pro image id.

Parameters:
  • image_id – string, Represents a image to be used when provisioning a virtual machine
  • registered_image – dict, Represents the base image used for creating the image referenced by image_id. This will only happen for snapshot images.
Returns:

A dict representing the plan parameters that will be used to provision a virtual machine

pycloudlib.azure.util.get_resource_group_name_from_id(resource_id)[source]

Retrive the resource group name of a resource.

Parameters:resource_id – string, the resource id
Returns:A string represeting the resource group
pycloudlib.azure.util.get_resource_name_from_id(resource_id)[source]

Retrive the name of a resource.

Parameters:resource_id – string, the resource id
Returns:A string represeting the resource name
pycloudlib.azure.util.is_pro_image(image_id, registered_image)[source]

Verify if the image id represents a pro image.

Check the image id string for patterns found only on pro images. However, snapshot images do not have pro information on ther image id. We are enconding that information on the registed_image dict, which represents the base image that created the snapshot. Therefore, we fail at looking in the image id string, we look it up at the registered_image dict.

Parameters:
  • image_id – string, Represents a image to be used when provisioning a virtual machine
  • registered_image – dict, Represents the base image used for creating the image referenced by image_id. This will only happen for snapshot images.
Returns:

A boolean indicating if the image is pro image

pycloudlib.azure.util.parse_image_id(image_id)[source]

Extract publisher, offer, sku and optional version from image_id.

The image_id is expected to be a string in the following format: Canonical:UbuntuServer:19.10-DAILY[:latest]

Parameters:image_id – string, The image id
Returns
Dict with publisher, offer and sku and optional version keys.