The following page documents the Azure cloud integration in pycloudlib.
To access Azure requires users to have four different keys:
- client id
- client secret id
- tenant id
- subscription id
These should be set in pycloudlib.toml.
Azure login (Deprecated)¶
By using the Azure CLI, you can login into your Azure account through it. Once you logged in, the CLI will create folder in your home directory which will contain all of the necessary information to use the API. To login into you Azure using the CLI, just run the following command:
Passed Directly (Deprecated)¶
All of these four credentials can also be provided directly when initializing the Azure object:
azure = pycloudlib.Azure( client_id='ID_VALUE', client_secret_id='ID_VALUE', tenant_id='ID_VALUE', subscription_id='ID_VALUE', )
This way we can create different Azure instances with different configurations.
Azure requires an SSH key to be uploaded before using it. See the SSH Key page for more details.
To find latest daily Azure image for a release of Ubuntu:
The return Azure image can then be used for launching instances.
Launching an instance requires at a minimum an Azure image.
inst_0 = azure.launch('Canonical:UbuntuServer:14.04.0-LTS') inst_1 = azure.launch('Canonical:UbuntuServer:18.04-DAILY-LTS')
If further customization of an instance is required, a user can pass additional arguments to the launch command and have them passed on.
inst = azure.launch( image_id='Canonical:UbuntuServer:14.04.0-LTS', user_data='#cloud-config\nfinal_message: "system up!"', )
By default, the launch method will wait for cloud-init to finish initializing before completing. When launching multiple instances a user may not wish to wait for each instance to come up by passing the
instances =  for inst in range(num_instances): instances.append( azure.launch('Canonical:UbuntuServer:18.04-DAILY-LTS', wait=False)) for instance in instances: instance.wait()
Similarly, when deleting an instance, the default action will wait for the instance to complete termination. Otherwise, the
wait=False option can be used to start the termination of a number of instances:
inst.delete() for instance in instances: instance.delete(wait=False)
An existing instance can get used by providing an instance-id.
instance = azure.get_instance('my-azure-vm')
A snapshot of an instance is used to generate a new backing Azure image. The generated image can in turn get used to launch new instances. This allows for customization of an image and then re-use of that image.
inst = azure.launch('Canonical:UbuntuServer:14.04.0-LTS') inst.execute('touch /etc/foobar') image_id_snapshot = azure.snapshot(inst) inst_prime = azure.launch(image_id_snapshot)
The snapshot function returns a string of the created AMI ID.
To delete the image when the snapshot is no longer required: