pycloudlib.oci.utils module

Utilities for OCI images and instances.

pycloudlib.oci.utils.get_subnet_id(network_client: oci.core.VirtualNetworkClient, compartment_id: str, availability_domain: str, vcn_name: str | None = None, private: bool = False, *, retry_strategy=<oci.retry.retry.ExponentialBackOffWithDecorrelatedJitterRetryStrategy object>) str[source]

Get a subnet id linked to availability_domain.

From specified compartment select the first subnet linked to availability_domain or the first one.

Parameters:
  • network_client – Instance of VirtualNetworkClient.

  • compartment_id – Compartment where the subnet has to belong

  • availability_domain – Domain to look for subnet id in.

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

  • retry_strategy – A retry strategy to apply to the API calls

Returns:

id of the subnet selected

Raises:
  • Exception

  • availability_domain

pycloudlib.oci.utils.get_subnet_id_by_name(network_client: oci.core.VirtualNetworkClient, compartment_id: str, subnet_name: str, *, retry_strategy=<oci.retry.retry.ExponentialBackOffWithDecorrelatedJitterRetryStrategy object>) str[source]

Get a subnet id by name.

Parameters:
  • network_client – Instance of VirtualNetworkClient.

  • compartment_id – Compartment where the subnet has to belong

  • subnet_name – Name of the subnet to find

  • retry_strategy – A retry strategy to apply to the API calls

Returns:

id of the subnet selected

Raises:
  • Exception

  • availability_domain

pycloudlib.oci.utils.parse_oci_config_from_env_vars() Dict[str, str] | None[source]

Read in OCI config file from environment variables and return as a config dict.

If $PYCLOUDLIB_OCI_CONFIG_FILE_PATH is set, reads in the OCI config file from this path. If $PYCLOUDLIB_OCI_KEY_FILE_PATH is set, replaces or adds the key_file path to the config dict.

Returns:

A dictionary containing the OCI config file, or None if the environment

variable $PYCLOUDLIB_OCI_CONFIG_FILE_PATH is not set.

Return type:

oci_config

Raises:

PycloudlibError – If the OCI config file cannot be loaded from the path given by the $PYCLOUDLIB_OCI_CONFIG_FILE_PATH environment variable.

pycloudlib.oci.utils.wait_till_ready(func, current_data, desired_state, sleep_seconds=1000, func_kwargs: Dict[str, str] | None = None)[source]

Wait until the results of function call reach a desired lifecycle state.

Parameters:
  • func – The function to call

  • current_data – Structure containing the initial id and lifecycle state

  • desired_state – Desired value of “lifecycle_state”

  • sleep_seconds – How long to wait in seconds

  • func_kwargs – Dictionary with keyword arguments to pass to the function

Returns:

The updated version of the current_data

Raises:

PycloudlibTimeoutError – If the desired state is not reached in time