pycloudlib.oci.cloud module¶
OCI Cloud type.
-
class
pycloudlib.oci.cloud.
OCI
(tag: str, timestamp_suffix: bool = True, config_file: Union[pathlib.Path, _io.StringIO, None] = None, *, availability_domain: Optional[str] = None, compartment_id: Optional[str] = None, config_path: Optional[str] = None, config_dict: Optional[str] = None)[source]¶ Bases:
pycloudlib.cloud.BaseCloud
OCI (Oracle) cloud class.
-
__init__
(tag: str, timestamp_suffix: bool = True, config_file: Union[pathlib.Path, _io.StringIO, None] = None, *, availability_domain: Optional[str] = None, compartment_id: Optional[str] = None, config_path: Optional[str] = None, config_dict: Optional[str] = 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
-
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: 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_instance
(instance_id, **kwargs) → pycloudlib.oci.instance.OciInstance[source]¶ Get an instance by id.
Parameters: - instance_id – ocid of the instance
- **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, wait=True, *, retry_strategy=None, **kwargs) → pycloudlib.oci.instance.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
- wait – wait for instance to be live
- retry_strategy – a retry strategy from oci.retry module to apply for this operation
- **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
-
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
-