pycloudlib.azure.cloud module
Azure Cloud type.
- class pycloudlib.azure.cloud.Azure(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, client_id: str | None = None, client_secret: str | None = None, subscription_id: str | None = None, tenant_id: str | None = None, region: str | None = None, resource_group_params: AzureParams | None = None, username: str | None = None, enable_boot_diagnostics: bool = False)[source]
Bases:
BaseCloud
Azure Cloud Class.
- __init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, client_id: str | None = None, client_secret: str | None = None, subscription_id: str | None = None, tenant_id: str | None = None, region: str | None = None, resource_group_params: AzureParams | None = None, username: str | None = None, enable_boot_diagnostics: bool = False)[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
resource_group_params – The resource group override parameters.
enable_boot_diagnostics – flag to configure if boot diagnostics logs will be enabled and obtained for instances created.
- clean() List[Exception] [source]
Cleanup ALL artifacts associated with this Cloud instance.
This includes all instances, snapshots, resources, etc. To ensure cleanup isn’t interrupted, any exceptions raised during cleanup operations will be collected and returned.
- confidential_vm_image(release)[source]
Get the confidential computing vm image.
- Parameters:
release – string, Ubuntu release to look for
- Returns:
string, id of latest image
- 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: str, *, image_type: ImageType = ImageType.GENERIC, **kwargs)[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, **kwargs)[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(resource_group_name: str | None = None)[source]
Delete a resource group.
If no resource group is provided, delete self.resource_group
- get_instance(instance_id, search_all=False, *, username: str | None = None, **kwargs)[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.
username – username to use when connecting via SSH
**kwargs – dictionary of other arguments to be used by this method. Currently unused but provided for base class compatibility.
- 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, name=None, inbound_ports=None, username: str | None = None, resource_group_params: AzureParams | None = None, network_security_group_params: AzureCreateParams | None = None, virtual_network_params: AzureCreateParams | None = None, subnet_params: AzureCreateParams | None = None, ip_addresses_params: List[AzureCreateParams | None] | None = None, network_interfaces_params: List[AzureCreateParams | None] | None = None, security_type=AzureSecurityType.STANDARD, provisioning_timeout: int | None = 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
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.
security_type – AzureSecurityType, security on vm image. Defaults to STANDARD
username – username to use when connecting via SSH
resource_group_params – AzureParams, options containing the resource group details to use.
network_security_group_params – AzureParams, options containing the network security group to use.
virtual_network_params – AzureCreateParams, options to override and create vnet options.
subnet_params – AzureCreateParams, options to override and create subnet options.
ip_addresses_params – list[AzureCreateParams], options to override and create ip_address.
network_interfaces_params – list[AzureCreateParams], options to override and create NICs.
provisioning_timeout – int, timeout in seconds for provisioning the VM, defaults to None i.e. use Azure’s default.
kwargs –
vm_params: dict to override configuration for virtual_machines.begin_create_or_update
security_type_params: dict to configure security_types
- Returns:
Azure Instance object
Raises: ValueError on invalid image_id
- released_image(release)[source]
Get the released image.
- 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