pycloudlib.oci.cloud module

OCI Cloud type.

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