pycloudlib package

Main pycloud module __init__.

class pycloudlib.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

list_keys()[source]

List all ssh keys in the class resource group.

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

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

class pycloudlib.EC2(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, access_key_id: str | None = None, secret_access_key: str | None = None, region: str | None = None, profile: str | None = None)[source]

Bases: BaseCloud

EC2 Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, access_key_id: str | None = None, secret_access_key: str | None = None, region: str | None = None, profile: str | None = None)[source]

Initialize the connection to EC2.

boto3 will read a users /home/$USER/.aws/* files if no arguments are provided here to find values.

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

  • access_key_id – user’s access key ID

  • secret_access_key – user’s secret access key

  • region – region to login to

  • profile – profile to use from ~/.aws/config

clean() List[Exception][source]

Cleanup ALL artifacts associated with this Cloud instance.

Cleanup any cloud artifacts created at any time during this class’s existence. This includes all instances, snapshots, resources, etc.

daily_image(release: str, *, arch: str = 'x86_64', image_type: ImageType = ImageType.GENERIC, include_deprecated: bool = False, **kwargs)[source]

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

Parameters:
  • release – string, Ubuntu release to look for

  • arch – string, architecture to use

Returns:

string, id of latest image

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

delete_key(name)[source]

Delete an uploaded key.

Parameters:

name – The key name to delete.

get_instance(instance_id, *, username: str | None = None, **kwargs)[source]

Get an instance by id.

Parameters:
  • instance_id – ID used to identify the 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.

get_or_create_vpc(name, ipv4_cidr='192.168.1.0/20')[source]

Create a or return matching VPC.

This can be used instead of using the default VPC to create a custom VPC for usage.

Parameters:
  • name – name of the VPC

  • ipv4_cidr – CIDR of IPV4 subnet

Returns:

VPC object

image_serial(image_id, image_type: ImageType = ImageType.GENERIC)[source]

Find the image serial of a given EC2 image ID.

Parameters:

image_id – string, Ubuntu image id

Returns:

string, serial of latest image

launch(image_id, instance_type='t3.micro', user_data=None, vpc=None, *, disk_size_gb: int = 15, username: str | None = None, enable_ipv6: bool = False, **kwargs)[source]

Launch instance on EC2.

Parameters:
  • image_id – string, AMI ID to use default: latest Ubuntu LTS

  • instance_type – string, instance type to launch

  • user_data – string, user-data to pass to instance

  • vpc – optional vpc object to create instance under

  • disk_size_gb – size of instance disk in GB

  • username – username to use when connecting via SSH

  • enable_ipv6 – indicates if ipv6 IMDS support must be added to the instance

  • kwargs – other named arguments to add to instance JSON

Returns:

EC2 Instance object

Raises: ValueError on invalid image_id

list_keys()[source]

List all ssh key pair names loaded on this EC2 region.

released_image(release: str, *, arch: str = 'x86_64', image_type: ImageType = ImageType.GENERIC, include_deprecated: bool = False, **kwargs)[source]

Find the id of the latest released image for a particular release.

Parameters:
  • release – string, Ubuntu release to look for

  • arch – string, architecture to use

  • root_store – string, root store to use

Returns:

string, id of latest image

snapshot(instance, clean=True)[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

Returns:

An image id

upload_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

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

class pycloudlib.GCE(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, credentials_path: str | None = None, project: str | None = None, region: str | None = None, zone: str | None = None, service_account_email: str | None = None)[source]

Bases: BaseCloud

GCE Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, credentials_path: str | None = None, project: str | None = None, region: str | None = None, zone: str | None = None, service_account_email: str | None = None)[source]

Initialize the connection to GCE.

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

  • credentials_path – path to credentials file for GCE

  • project – GCE project

  • region – GCE region

  • zone – GCE zone

  • service_account_email – service account to bind launched instances to

daily_image(release: str, *, arch: str = 'x86_64', image_type: ImageType = ImageType.GENERIC, **kwargs)[source]

Find the id of the latest image for a particular release.

Parameters:

release – string, Ubuntu release to look for

Returns:

string, path to latest daily image

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

get_instance(instance_id, name=None, *, username: str | None = None, **kwargs)[source]

Get an instance by id.

Parameters:
  • instance_id – The instance ID returned upon creation

  • username – username to use when connecting via SSH

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='n1-standard-1', user_data=None, *, username: str | None = None, **kwargs)[source]

Launch instance on GCE and print the IP address.

Parameters:
  • image_id – string, image ID for instance to use

  • instance_type – string, instance type to launch

  • user_data – string, user-data to pass to instance

  • username – username to use when connecting via SSH

  • kwargs – other named arguments to add to instance JSON

Raises: ValueError on invalid image_id

released_image(release, *, image_type: ImageType = ImageType.GENERIC, **kwargs)[source]

ID of the latest released image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

snapshot(instance: GceInstance, clean=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

Returns:

An image id

class pycloudlib.IBM(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, resource_group: str | None = None, vpc: str | None = None, api_key: str | None = None, region: str | None = None, zone: str | None = None)[source]

Bases: BaseCloud

IBM Virtual Private Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, resource_group: str | None = None, vpc: str | None = None, api_key: str | None = None, region: str | None = None, zone: str | None = None)[source]

Initialize the connection to IBM VPC.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – Append a timestamped suffix to the tag string.

  • config_file – path to pycloudlib configuration file

clean() List[Exception][source]

Cleanup ALL artifacts associated with this Cloud instance.

Cleanup any cloud artifacts created at any time during this class’s existence. This includes all instances, snapshots, resources, etc.

daily_image(release: str, **kwargs) str[source]

ID of the latest daily image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest daily image ID for the specified release.

delete_image(image_id: str, **kwargs)[source]

Delete an image.

Parameters:
  • image_id – string, id of the image to delete

  • **kwargs – dictionary of other arguments to pass to delete_image

delete_key(name: str)[source]

Delete SSH key by name.

get_image_id_from_name(name: str) str[source]

Get the id of the first image whose name contains the given name.

The name does not need to be an exact match, just a substring of the image name.

Returns:

string, image ID

get_instance(instance_id: str, *, username: str | None = None, **kwargs) BaseInstance[source]

Get an instance by id.

Parameters:
  • instance_id – ID used identify the instance

  • username – username to use when connecting via SSH

Returns:

An instance object to use to manipulate the instance further.

get_or_create_vpc(name: str) VPC[source]

Get a VPC by name or create it if not found.

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: str, instance_type: str = 'bx2-2x8', user_data=None, *, name: str | None = None, vpc: VPC | None = None, username: str | None = None, floating_ip_substring: str | None = None, **kwargs) BaseInstance[source]

Launch an instance.

Parameters:
  • image_id – string, image ID to use for the instance

  • instance_type – string, type of instance to create

  • user_data – used by cloud-init to run custom scripts/configuration

  • name – instance name

  • vpc – VPC to allocate the instance in. If not given, the instance

  • username – username to use when connecting via SSH

  • VPC. (will be allocated in the zone's default)

  • floating_ip_substring – use existing floating IP whose name

  • deleted (contains this substring. This floating IP will not be)

  • deleted. (when the instance is)

  • **kwargs – dictionary of other arguments to pass to launch

Returns:

An instance object to use to manipulate the instance further.

list_keys() List[str][source]

List ssh key names present on the cloud for accessing instances.

Returns:

A list of strings of key pair names accessible to the cloud.

released_image(release, *, arch: str = 'amd64', **kwargs)[source]

ID of the latest released image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

property resource_group_id: str

Resource Group ID used to create new things under.

snapshot(instance: IBMInstance, clean: bool = True, **kwargs) str[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

Returns:

An image id

property vpc: VPC

Virtual Private Cloud.

class pycloudlib.IBMClassic(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, username: str | None = None, api_key: str | None = None, domain_name: str | None = None)[source]

Bases: BaseCloud

IBM Classic Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, username: str | None = None, api_key: str | None = None, domain_name: str | None = None)[source]

Initialize base cloud class.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – Append a timestamped suffix to the tag string.

  • config_file – path to pycloudlib configuration file

  • username – IBM Classic specific username for API

  • api_key – IBM Classic specific API key

  • domain_name – Domain name to use for creating instance FQDNs

clean() List[Exception][source]

Cleanup ALL artifacts associated with this Cloud instance.

Cleanup any cloud artifacts created at any time during this class’s existence. This includes all instances, snapshots, resources, etc.

Returns:

A list of exceptions that occurred during cleanup.

create_default_security_groups() Tuple[int, int][source]

Create default security groups.

To make this extensible for all users, security groups and rules are created on the fly. A unique security group is created for each instance so that it can be torn down later without affecting other instances. The security group is named after the instance tag. The public security group allows inbound ssh traffic and all outbound traffic. The private security group allows all inbound and outbound traffic.

Returns:

A Tuple containing the IDs of the two created security groups in the order (public, private).

daily_image(release: str, **kwargs)[source]

ID of the latest daily image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest daily image ID for the specified release.

delete_image(image_id: str, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, ID (not GID) of the image to delete.

delete_key(name: str)[source]

Delete SSH key by name.

get_image_id_from_name(name: str) str[source]

Get the id of the first image whose name contains the given name.

The name does not need to be an exact match, just a substring of the image name.

Parameters:

name – string, name of the image to search for

Returns:

string, image ID

get_instance(instance_id, **kwargs) BaseInstance[source]

Get an instance by id.

Parameters:

instance_id – ID identifying the 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: str = 'B1_2X4', user_data=None, *, name: str | None = None, disk_size: Literal['25G', '100G'] = '25G', datacenter_region: str = 'dal', datacenter: str | None = None, **kwargs) BaseInstance[source]

Launch an instance.

Parameters:
  • name – name of the instance

  • image_id – image ID to use for the instance. Can accept either an ID or a GID.

  • instance_type – type of instance to create. This value is

  • For (combined with the disk_size to create the instance flavor.)

  • example

  • "B1_2X4X25". (B1_2X4 with disk_size of 25G would result in)

  • user_data – cloud-init user data to pass to the instance

  • datacenter_region – region to launch the instance in. This will automatically select a datacenter in the region if “datacenter” is not provided.

  • datacenter – datacenter to launch the instance in. If not provided, “datacenter_region” will be used. If both are provided, “datacenter” will be used.

  • **kwargs – dictionary of other arguments to pass to launch

Returns:

An instance object to use to manipulate the instance further.

list_keys()[source]

List ssh key names present on the cloud for accessing instances.

Returns:

A list of strings of key pair names accessible to the cloud.

released_image(release, *, disk_size: str = '25G', **kwargs)[source]

ID (globalIdentifier) of the latest released image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

snapshot(instance, clean=True, note: str | None = None, **kwargs)[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

  • note – optional note to add to the snapshot

Returns:

An image id

class pycloudlib.LXD(*args, **kwargs)[source]

Bases: LXDContainer

Old LXD Container Cloud Class (Kept for compatibility issues).

__init__(*args, **kwargs)[source]

Run LXDContainer constructor.

class pycloudlib.LXDContainer(*args, **kwargs)[source]

Bases: _BaseLXD

LXD Containers Cloud Class.

__init__(*args, **kwargs)[source]

Run LXDContainer constructor.

class pycloudlib.LXDVirtualMachine(*args, **kwargs)[source]

Bases: _BaseLXD

LXD Virtual Machine Cloud Class.

__init__(*args, **kwargs)[source]

Run LXDVirtualMachine constructor.

build_necessary_profiles(image_id)[source]

Build necessary profiles to launch the LXD instance.

Parameters:

image_id – string, [<remote>:]<release>, the image to build profiles for

Returns:

A list containing the profiles created

class pycloudlib.OCI(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, availability_domain: str | None = None, compartment_id: str | None = None, config_path: str | None = None, config_dict: dict | None = None, vcn_name: str | None = None, fault_domain: str | None = None, profile: str | None = None, region: str | None = None)[source]

Bases: BaseCloud

OCI (Oracle) cloud class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, availability_domain: str | None = None, compartment_id: str | None = None, config_path: str | None = None, config_dict: dict | None = None, vcn_name: str | None = None, fault_domain: str | None = None, profile: str | None = None, region: str | None = None)[source]

Initialize the connection to OCI.

OCI must be initialized on the CLI first: https://github.com/cloud-init/qa-scripts/blob/master/doc/launching-oracle.md

Parameters:
  • tag – Name of instance

  • timestamp_suffix – bool set True to append a timestamp suffix to the tag

  • config_file – path to pycloudlib configuration file

  • compartment_id – A compartment found at https://console.us-phoenix-1.oraclecloud.com/a/identity/compartments

  • availability_domain – One of the availability domains from: ‘oci iam availability-domain list’

  • config_path – Path of OCI config file

  • config_dict – A dictionary containing the OCI config. Overrides the values from config_path

  • vcn_name – Exact name of the VCN to use. If not provided, the newest VCN in the given compartment will be used.

create_compute_cluster(image_id: str, instance_count: int = 2, instance_type: str = 'BM.Optimized3.36', optional_launch_kwargs: dict | None = None, wait: bool = True) List[OciInstance][source]

Create a compute cluster with a specified number of instances.

Parameters:
  • instance_count – Number of instances to create

  • launch_kwargs – Additional arguments to pass to the launch method

Returns:

List of OciInstance objects that were created

daily_image(release: str, operating_system: str = 'Canonical Ubuntu', **kwargs)[source]

Get the daily image.

OCI just has periodic builds, so “released” and “daily” don’t really make sense here. Just call the same code for both.

Should be equivalent to the cli call: oci compute image list –operating-system=”Canonical Ubuntu” –operating-system-version=”<xx.xx>” –sort-by=’TIMECREATED’ –sort-order=’DESC’

Parameters:
  • release – string, Ubuntu release to look for

  • operating_system – string, Operating system to use

  • **kwargs – dictionary of other arguments to pass to list_images

Returns:

string, id of latest image

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

get_image_id_from_name(name: str) str[source]

Get the image id from the name.

Parameters:

name – string, name of the image to get the id for

Returns:

string, id of the image

get_instance(instance_id, *, username: str | None = None, **kwargs) OciInstance[source]

Get an instance by id.

Parameters:
  • instance_id – ocid of the instance

  • username – username to use when connecting via SSH

  • **kwargs – dictionary of other arguments to pass to get_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='VM.Standard2.1', user_data=None, *, retry_strategy=None, username: str | None = None, cluster_id: str | None = None, subnet_id: str | None = None, subnet_name: str | None = None, metadata: Dict = {}, **kwargs) OciInstance[source]

Launch an instance.

Parameters:
  • image_id – string, image ID to use for the instance

  • instance_type – string, type of instance to create. https://docs.cloud.oracle.com/en-us/iaas/Content/Compute/References/computeshapes.htm

  • user_data – used by Cloud-Init to run custom scripts or provide custom Cloud-Init configuration

  • subnet_id – string, OCID of subnet to use for instance. Takes precedence over subnet_name if both are provided.

  • subnet_name – string, name of subnet to use for instance. Only used if subnet_id is not provided.

  • metadata – Dict, key-value pairs provided to the launch details for the instance.

  • retry_strategy – a retry strategy from oci.retry module to apply for this operation

  • username – username to use when connecting via SSH

  • vcn_name – Name of the VCN to use. If not provided, the first VCN found will be used

  • **kwargs – dictionary of other arguments to pass as LaunchInstanceDetails

Returns:

An instance object to use to manipulate the instance further.

Raises: ValueError on invalid image_id

released_image(release, operating_system='Canonical Ubuntu')[source]

Get the released image.

OCI just has periodic builds, so “released” and “daily” don’t really make sense here. Just call the same code for both

Parameters:
  • release – string, Ubuntu release to look for

  • operating_system – string, operating system to use

Returns:

string, id of latest image

snapshot(instance, clean=True, name=None)[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

  • name – (Optional) Name of created image

Returns:

An image object

class pycloudlib.Openstack(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, network: str | None = None)[source]

Bases: BaseCloud

Openstack cloud class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, network: str | None = None)[source]

Initialize the connection to openstack.

Requires valid pre-configured environment variables or clouds.yaml. See https://docs.openstack.org/python-openstackclient/pike/configuration/index.html

Parameters:
  • tag – Name of instance

  • timestamp_suffix – bool set True to append a timestamp suffix to the tag

  • config_file – path to pycloudlib configuration file

  • network – Name of the network to use (from openstack network list)

daily_image(release: str, **kwargs)[source]

Not supported for openstack.

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

get_instance(instance_id, *, username: str | None = None, **kwargs) OpenstackInstance[source]

Get an instance by id.

Parameters:

instance_id – ID of instance to get

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='m1.small', user_data='', *, username: str | None = None, **kwargs) OpenstackInstance[source]

Launch an instance.

Parameters:
  • image_id – string, image ID to use for the instance

  • instance_type – string, type (flavor) of instance to create

  • user_data – used by cloud-init to run custom scripts/configuration

  • username – username to use when connecting via SSH

  • **kwargs – dictionary of other arguments to pass to launch

Returns:

An instance object to use to manipulate the instance further.

Raises: ValueError on invalid image_id

released_image(release, **kwargs)[source]

Not supported for openstack.

snapshot(instance, clean=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

Returns:

An image id

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

Use an existing key.

Parameters:
  • public_key_path – path to the public key to upload

  • private_key_path – path to the private key

  • name – name to reference key by

class pycloudlib.Qemu(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None)[source]

Bases: BaseCloud

QEMU Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None)[source]

Initialize QemuCloud cloud class.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – Append a timestamped suffix to the tag string.

  • config_file – path to pycloudlib configuration file

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.

daily_image(release: str, **kwargs)[source]

ID of the latest daily image for a particular release.

Download the latest daily image unless it already exists.

Parameters:

release – The release to look for

Returns:

A single string with the latest daily image ID for the specified release.

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:
  • image_id – string, id of the image to delete

  • **kwargs – dictionary of other arguments to pass to delete_image

get_instance(instance_id, **kwargs) QemuInstance[source]

Get an instance by id.

Parameters:

instance_id – The id for this instance. For QEMU this takes the form of <instance_path>::<ssh_port>::<telnet_port>

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 release.

Parameters:

image_id – string, Ubuntu image id

Returns:

string, serial of latest image

launch(image_id: str, instance_type='c1m1500', user_data=None, meta_data=None, vendor_data=None, network_config=None, kernel_cmdline='', kernel_path=None, no_seed_iso=False, username: str | None = None, launch_args: List[str] | None = None, **kwargs) QemuInstance[source]

Launch an instance.

If user_data is passed, a seed iso will be created to be used as a NoCloud datasource. If user_data is not provided, a seed iso will not be created. User data can also be passed within the kernel_cmdline parameter.

Parameters:
  • image_id – image ID to use for the instance. Can be either an absolute path to an image, or a path relative to the image_dir.

  • instance_type – Type of instance to create. For QEMU, this is in the form of c#m#, where # is the number of cpus and memory in MB.

  • user_data – used by cloud-init to run custom scripts/configuration

  • meta_data – used by cloud-init for custom metadata

  • vendor_data – used by cloud-init for custom vendor data

  • network_config – used by cloud-init for custom network data

  • kernel_cmdline – kernel command line arguments

  • kernel_path – path to kernel to use

  • no_seed_iso – if True, do not create a seed iso

  • username – username to use for ssh connection

  • launch_args – list of additional arguments to pass to qemu

Returns:

An instance object to use to manipulate the instance further.

list_keys()[source]

List ssh key names present on the cloud for accessing instances.

Returns:

A list of strings of key pair names accessible to the cloud.

released_image(release, **kwargs)[source]

ID of the latest released image for a particular release.

If an image for this series from any date has been downloaded, it will be used.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

snapshot(instance: QemuInstance, clean=True, **kwargs) str[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

Returns:

An image id

class pycloudlib.VMWare(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, server=None, username=None, password=None, datacenter=None, datastore=None, folder=None, insecure_transport=None)[source]

Bases: BaseCloud

VMWare Cloud class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, server=None, username=None, password=None, datacenter=None, datastore=None, folder=None, insecure_transport=None)[source]

Initialize VMWare cloud class.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – Append a timestamped suffix to the tag string.

  • config_file – path to pycloudlib configuration file

daily_image(release: str, **kwargs)[source]

Return released_image for VMWare.

We’re relying on whatever has been created/uploaded, so the distinction between daily and released doesn’t make sense.

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

get_instance(instance_id, **kwargs) VMWareInstance[source]

Get an instance by id.

Parameters:

instance_id

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 release.

Parameters:

image_id – string, Ubuntu image id

Returns:

string, serial of latest image

launch(image_id: str, instance_type=None, user_data=None, **kwargs) VMWareInstance[source]

Launch an instance.

Parameters:
  • image_id – string, image ID to use for the instance

  • instance_type – string, type of instance to create

  • user_data – used by cloud-init to run custom scripts/configuration

  • wait – wait for instance to be live

  • **kwargs – dictionary of other arguments to pass to launch

Returns:

An instance object to use to manipulate the instance further.

released_image(release, **kwargs)[source]

ID of the uploaded image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest image ID for the specified release.

snapshot(instance, clean=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

Returns:

An image id

Subpackages

Submodules