pycloudlib package

Main pycloud module __init__.

class pycloudlib.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
class pycloudlib.EC2(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, access_key_id=None, secret_access_key=None, region=None)[source]

Bases: pycloudlib.cloud.BaseCloud

EC2 Cloud Class.

__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, access_key_id=None, secret_access_key=None, region=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
create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
daily_image(release, arch='amd64', root_store='ssd')[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
  • root_store – string, root store to use
Returns:

string, id of latest image

delete_image(image_id)[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)[source]

Get an instance by id.

Parameters:instance_id
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)[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='t2.micro', user_data=None, wait=True, vpc=None, **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
  • wait – boolean, wait for instance to come up
  • vpc – optional vpc object to create instance under
  • kwargs – other named arguments to add to instance JSON
Returns:

EC2 Instance object

list_keys()[source]

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

released_image(release, arch='amd64', root_store='ssd')[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, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, credentials_path=None, project=None, region=None, zone=None, service_account_email=None)[source]

Bases: pycloudlib.cloud.BaseCloud

GCE Cloud Class.

__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, credentials_path=None, project=None, region=None, zone=None, service_account_email=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
create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
daily_image(release, arch='amd64')[source]

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

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, path to latest daily image

delete_image(image_id)[source]

Delete an image.

Parameters:image_id – string, id of the image to delete
get_instance(instance_id, name=None)[source]

Get an instance by id.

Parameters:instance_id – The instance ID returned upon creation
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, wait=True, **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
  • wait – boolean, wait for instance to come up
  • kwargs – other named arguments to add to instance JSON
list_keys()

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='amd64')[source]

ID of the latest released image for a particular release.

Parameters:
  • release – The release to look for
  • arch – string, architecture to use
Returns:

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

snapshot(instance: pycloudlib.gce.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

use_key(public_key_path, private_key_path=None, name=None)

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.LXD(*args, **kwargs)[source]

Bases: pycloudlib.lxd.cloud.LXDContainer

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

CONTAINER_HASH_KEY = 'combined_squashfs_sha256'
__init__(*args, **kwargs)[source]

Run LXDContainer constructor.

clone(base, new_instance_name)

Create copy of an existing instance or snapshot.

Uses the lxc copy command to create a copy of an existing instance or a snapshot. To clone a snapshot then the base is instance_name/snapshot_name otherwise if base is only an existing instance it will clone an instance.

Parameters:
  • base – base instance or instance/snapshot
  • new_instance_name – name of new instance
Returns:

The created LXD instance object

create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
create_profile(profile_name, profile_config, force=False)

Create a lxd profile.

Create a lxd profile and populate it with the given profile config. If the profile already exists, we will not recreate it, unless the force parameter is set to True.

Parameters:
  • profile_name – Name of the profile to be created
  • profile_config – Config to be added to the new profile
  • force – Force the profile creation if it already exists
daily_image(release, arch='amd64')

Find the LXD fingerprint of the latest daily image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

delete_image(image_id)

Delete the image.

Parameters:image_id – string, LXD image fingerprint
delete_instance(instance_name, wait=True)

Delete an instance.

Parameters:
  • instance_name – instance name to delete
  • wait – wait for delete to complete
get_instance(instance_id)

Get an existing instance.

Parameters:instance_id – instance name to get
Returns:The existing instance as a LXD instance object
image_serial(image_id)

Find the image serial of a given LXD image.

Parameters:image_id – string, LXD image fingerprint
Returns:string, serial of latest image
init(name, image_id, ephemeral=False, network=None, storage=None, inst_type=None, profile_list=None, user_data=None, config_dict=None, execute_via_ssh=True)

Init a container.

This will initialize a container, but not launch or start it. If no remote is specified pycloudlib default to daily images.

Parameters:
  • name – string, what to call the instance
  • image_id – string, [<remote>:]<image identifier>, the image to launch
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, optional, network name to use
  • storage – string, optional, storage name to use
  • inst_type – string, optional, type to use
  • profile_list – list, optional, profile(s) to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • config_dict – dict, optional, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

launch(image_id, instance_type=None, user_data=None, wait=True, name=None, ephemeral=False, network=None, storage=None, profile_list=None, config_dict=None, execute_via_ssh=True, **kwargs)

Set up and launch a container.

This will init and start a container with the provided settings. If no remote is specified pycloudlib defaults to daily images.

Parameters:
  • image_id – string, [<remote>:]<image>, the image to launch
  • instance_type – string, type to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • wait – boolean, wait for instance to start
  • name – string, what to call the instance
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, network name to use
  • storage – string, storage name to use
  • profile_list – list, profile(s) to use
  • config_dict – dict, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

list_keys()

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='amd64')

Find the LXD fingerprint of the latest released image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

snapshot(instance, clean=True, name=None)

Take a snapshot of the passed in instance for use as image.

Parameters:
  • instance (LXDInstance) – The instance to create an image from
  • clean – Whether to call cloud-init clean before creation
  • wait – Whether to wait until before image is created before returning
  • name – Name of the new image
  • stateful – Whether to use an LXD stateful snapshot
use_key(public_key_path, private_key_path=None, name=None)

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.LXDContainer(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None)[source]

Bases: pycloudlib.lxd.cloud._BaseLXD

LXD Containers Cloud Class.

CONTAINER_HASH_KEY = 'combined_squashfs_sha256'
__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None)

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
clone(base, new_instance_name)

Create copy of an existing instance or snapshot.

Uses the lxc copy command to create a copy of an existing instance or a snapshot. To clone a snapshot then the base is instance_name/snapshot_name otherwise if base is only an existing instance it will clone an instance.

Parameters:
  • base – base instance or instance/snapshot
  • new_instance_name – name of new instance
Returns:

The created LXD instance object

create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
create_profile(profile_name, profile_config, force=False)

Create a lxd profile.

Create a lxd profile and populate it with the given profile config. If the profile already exists, we will not recreate it, unless the force parameter is set to True.

Parameters:
  • profile_name – Name of the profile to be created
  • profile_config – Config to be added to the new profile
  • force – Force the profile creation if it already exists
daily_image(release, arch='amd64')

Find the LXD fingerprint of the latest daily image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

delete_image(image_id)

Delete the image.

Parameters:image_id – string, LXD image fingerprint
delete_instance(instance_name, wait=True)

Delete an instance.

Parameters:
  • instance_name – instance name to delete
  • wait – wait for delete to complete
get_instance(instance_id)

Get an existing instance.

Parameters:instance_id – instance name to get
Returns:The existing instance as a LXD instance object
image_serial(image_id)

Find the image serial of a given LXD image.

Parameters:image_id – string, LXD image fingerprint
Returns:string, serial of latest image
init(name, image_id, ephemeral=False, network=None, storage=None, inst_type=None, profile_list=None, user_data=None, config_dict=None, execute_via_ssh=True)

Init a container.

This will initialize a container, but not launch or start it. If no remote is specified pycloudlib default to daily images.

Parameters:
  • name – string, what to call the instance
  • image_id – string, [<remote>:]<image identifier>, the image to launch
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, optional, network name to use
  • storage – string, optional, storage name to use
  • inst_type – string, optional, type to use
  • profile_list – list, optional, profile(s) to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • config_dict – dict, optional, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

launch(image_id, instance_type=None, user_data=None, wait=True, name=None, ephemeral=False, network=None, storage=None, profile_list=None, config_dict=None, execute_via_ssh=True, **kwargs)

Set up and launch a container.

This will init and start a container with the provided settings. If no remote is specified pycloudlib defaults to daily images.

Parameters:
  • image_id – string, [<remote>:]<image>, the image to launch
  • instance_type – string, type to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • wait – boolean, wait for instance to start
  • name – string, what to call the instance
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, network name to use
  • storage – string, storage name to use
  • profile_list – list, profile(s) to use
  • config_dict – dict, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

list_keys()

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='amd64')

Find the LXD fingerprint of the latest released image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

snapshot(instance, clean=True, name=None)

Take a snapshot of the passed in instance for use as image.

Parameters:
  • instance (LXDInstance) – The instance to create an image from
  • clean – Whether to call cloud-init clean before creation
  • wait – Whether to wait until before image is created before returning
  • name – Name of the new image
  • stateful – Whether to use an LXD stateful snapshot
use_key(public_key_path, private_key_path=None, name=None)

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.LXDVirtualMachine(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None)[source]

Bases: pycloudlib.lxd.cloud._BaseLXD

LXD Virtual Machine Cloud Class.

DISK1_HASH_KEY = 'combined_disk1-img_sha256'
DISK_KVM_HASH_KEY = 'combined_disk-kvm-img_sha256'
DISK_UEFI1_KEY = 'combined_uefi1-img_sha256'
__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None)

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
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
clone(base, new_instance_name)

Create copy of an existing instance or snapshot.

Uses the lxc copy command to create a copy of an existing instance or a snapshot. To clone a snapshot then the base is instance_name/snapshot_name otherwise if base is only an existing instance it will clone an instance.

Parameters:
  • base – base instance or instance/snapshot
  • new_instance_name – name of new instance
Returns:

The created LXD instance object

create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
create_profile(profile_name, profile_config, force=False)

Create a lxd profile.

Create a lxd profile and populate it with the given profile config. If the profile already exists, we will not recreate it, unless the force parameter is set to True.

Parameters:
  • profile_name – Name of the profile to be created
  • profile_config – Config to be added to the new profile
  • force – Force the profile creation if it already exists
daily_image(release, arch='amd64')

Find the LXD fingerprint of the latest daily image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

delete_image(image_id)

Delete the image.

Parameters:image_id – string, LXD image fingerprint
delete_instance(instance_name, wait=True)

Delete an instance.

Parameters:
  • instance_name – instance name to delete
  • wait – wait for delete to complete
get_instance(instance_id)

Get an existing instance.

Parameters:instance_id – instance name to get
Returns:The existing instance as a LXD instance object
image_serial(image_id)

Find the image serial of a given LXD image.

Parameters:image_id – string, LXD image fingerprint
Returns:string, serial of latest image
init(name, image_id, ephemeral=False, network=None, storage=None, inst_type=None, profile_list=None, user_data=None, config_dict=None, execute_via_ssh=True)

Init a container.

This will initialize a container, but not launch or start it. If no remote is specified pycloudlib default to daily images.

Parameters:
  • name – string, what to call the instance
  • image_id – string, [<remote>:]<image identifier>, the image to launch
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, optional, network name to use
  • storage – string, optional, storage name to use
  • inst_type – string, optional, type to use
  • profile_list – list, optional, profile(s) to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • config_dict – dict, optional, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

launch(image_id, instance_type=None, user_data=None, wait=True, name=None, ephemeral=False, network=None, storage=None, profile_list=None, config_dict=None, execute_via_ssh=True, **kwargs)

Set up and launch a container.

This will init and start a container with the provided settings. If no remote is specified pycloudlib defaults to daily images.

Parameters:
  • image_id – string, [<remote>:]<image>, the image to launch
  • instance_type – string, type to use
  • user_data – used by cloud-init to run custom scripts/configuration
  • wait – boolean, wait for instance to start
  • name – string, what to call the instance
  • ephemeral – boolean, ephemeral, otherwise persistent
  • network – string, network name to use
  • storage – string, storage name to use
  • profile_list – list, profile(s) to use
  • config_dict – dict, configuration values to pass
  • execute_via_ssh – bool, optional, execute commands on the instance via SSH if True (the default)
Returns:

The created LXD instance object

list_keys()

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='amd64')

Find the LXD fingerprint of the latest released image.

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, LXD fingerprint of latest image

snapshot(instance, clean=True, name=None)

Take a snapshot of the passed in instance for use as image.

Parameters:
  • instance (LXDInstance) – The instance to create an image from
  • clean – Whether to call cloud-init clean before creation
  • wait – Whether to wait until before image is created before returning
  • name – Name of the new image
  • stateful – Whether to use an LXD stateful snapshot
use_key(public_key_path, private_key_path=None, name=None)

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.OCI(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, availability_domain=None, compartment_id=None, config_path=None)[source]

Bases: pycloudlib.cloud.BaseCloud

OCI (Oracle) cloud class.

__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, availability_domain=None, compartment_id=None, config_path=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
create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
daily_image(release, operating_system='Canonical Ubuntu')[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
Returns:

string, id of latest image

delete_image(image_id)[source]

Delete an image.

Parameters:image_id – string, id of the image to delete
get_instance(instance_id)[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 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, wait=True, **kwargs)[source]

Launch an instance.

Parameters:
Returns:

An instance object to use to manipulate the instance further.

list_keys()

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, 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

use_key(public_key_path, private_key_path=None, name=None)

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.Openstack(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, network=None)[source]

Bases: pycloudlib.cloud.BaseCloud

Openstack cloud class.

__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, network=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)
create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
daily_image(release, **kwargs)[source]

Not supported for openstack.

delete_image(image_id)[source]

Delete an image.

Parameters:image_id – string, id of the image to delete
get_instance(instance_id) → pycloudlib.openstack.instance.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='', wait=True, **kwargs) → pycloudlib.openstack.instance.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
  • 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.

list_keys()

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]

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