pycloudlib.azure.cloud module

Azure Cloud type.

class pycloudlib.azure.cloud.Azure(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, client_id=None, client_secret=None, subscription_id=None, tenant_id=None, region=None)[source]

Bases: pycloudlib.cloud.BaseCloud

Azure Cloud Class.

UBUNTU_RELEASE = {'bionic': 'Canonical:UbuntuServer:18.04-DAILY-LTS', 'focal': 'Canonical:0001-com-ubuntu-server-focal-daily:20_04-daily-lts', 'groovy': 'Canonical:0001-com-ubuntu-server-groovy-daily:20_10-daily', 'hirsute': 'Canonical:0001-com-ubuntu-server-hirsute-daily:21_04-daily', 'xenial': 'Canonical:UbuntuServer:16.04-DAILY-LTS'}
__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, client_id=None, client_secret=None, subscription_id=None, tenant_id=None, region=None)[source]

Initialize the connection to Azure.

Azure will try to read user credentials form the /home/$USER/.azure folder. However, we can overwrite those credentials with the provided id parameters.

Parameters:
  • tag – string used to name and tag resources with
  • timestamp_suffix – bool set True to append a timestamp suffix to the tag
  • config_file – path to pycloudlib configuration file
  • client_id – user’s client id
  • client_secret – user’s client secret access key
  • subscription_id – user’s subscription id key
  • tenant_id – user’s tenant id key
  • region – The region where the instance will be created
create_key_pair(key_name)[source]

Create a pair of ssh keys.

This method creates an a pair of ssh keys in the class resource group.

Parameters:key_name – string, The name of the ssh resource.
daily_image(release)[source]

Find the image info for the latest daily image for a given release.

Parameters:release – string, Ubuntu release to look for.
Returns:A string representing an Ubuntu image
delete_image(image_id)[source]

Delete an image from Azure.

Parameters:image_id – string, The id of the image to be deleted
delete_key(key_name)[source]

Delete a ssh key from the class resource group.

Parameters:key_name – string, The name of the ssh resource.
delete_resource_group()[source]

Delete a resource group.

get_instance(instance_id, search_all=False)[source]

Get an instance by id.

Parameters:
  • instance_id – string, The instance name to search by
  • search_all – boolean, Flag that indicates that if we should search for the instance in the entire reach of the subsctription id. If false, we will search only in the resource group created by this instance.
Returns:

An instance object to use to manipulate the instance further.

image_serial(image_id)[source]

Find the image serial of the latest daily image for a particular release.

Parameters:image_id – string, Ubuntu image id
Returns:string, serial of latest image
launch(image_id, instance_type='Standard_DS1_v2', user_data=None, wait=True, name=None, inbound_ports=None, **kwargs)[source]

Launch virtual machine on Azure.

Parameters:
  • image_id – string, Ubuntu image to use
  • user_data – string, user-data to pass to virtual machine
  • wait – boolean, wait for instance to come up
  • name – string, optional name to give the vm when launching. Default results in a name of <tag>-vm
  • inbound_ports – List of strings, optional inbound ports to enable in the instance.
  • kwargs – dict, other named arguments to provide to virtual_machines.create_or_update
Returns:

Azure Instance object

list_keys()[source]

List all ssh keys in the class resource group.

released_image(release)[source]

Get the released image.

With the way we are indexing our images, it is hard to differentiate between daily and released images, since we would need to have the version of the image to properly provision it. Due to that limitation we are just calling the daily images method here.

Parameters:release – string, Ubuntu release to look for
Returns:string, id of latest image
snapshot(instance, clean=True, delete_provisioned_user=True, **kwargs)[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot
  • clean – Run instance clean method before taking snapshot
  • delete_provisioned_user – Deletes the last provisioned user
  • kwargs – Other named arguments specific to this implementation
Returns:

An image id string

use_key(public_key_path, private_key_path=None, name=None)[source]

Use an existing already uploaded key.

Parameters:
  • public_key_path – path to the public key to upload
  • private_key_path – path to the private key to upload
  • name – name to reference key by