pycloudlib.oci.instance module

OCI instance.

class pycloudlib.oci.instance.OciInstance(key_pair, instance_id, compartment_id, availability_domain, oci_config=None, *, username: str | None = None)[source]

Bases: BaseInstance

OCI backed instance.

__init__(key_pair, instance_id, compartment_id, availability_domain, oci_config=None, *, username: str | None = None)[source]

Set up the instance.

Parameters:
  • key_pair – A KeyPair for SSH interactions

  • instance_id – The instance id representing the cloud instance

  • 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’

  • oci_config – OCI configuration dictionary

  • username – username to use when connecting via SSH

add_network_interface(nic_index: int = 0, use_private_subnet: bool = False, subnet_name: str | None = None, **kwargs: Any) str[source]

Add network interface to running instance.

Creates a nic and attaches it to the instance. This is effectively a hot-add of a network device. Returns the private IP address of the added network interface as a string.

Parameters:
  • nic_index – The index of the NIC to add

  • subnet_name – Name of the subnet to add the NIC to. If not provided, will use use_private_subnet to select first available subnet.

  • use_private_subnet – If True, will select the first available private subnet. If False, will select the first available public subnet. This is only used if subnet_name is not provided.

configure_secondary_vnic() str[source]

Configure the secondary VNIC using information from the Oracle Cloud metadata service.

This method fetches the secondary VNIC data from the Oracle Cloud metadata service, extracts the MAC address and private IP, and assigns the IP address to the corresponding network interface on the instance.

Returns:

The private IP address assigned to the secondary VNIC.

Return type:

str

Raises:
  • ValueError – If no secondary VNIC is attached, if no interface is found for the MAC address, or if the IP address was not successfully assigned to the interface.

  • PycloudlibError – If failed to fetch secondary VNIC data from the Oracle Cloud metadata service.

console_log()[source]

Not currently implemented.

delete(wait=True) List[Exception][source]

Delete the instance.

Parameters:

wait – wait for instance to be deleted

property fault_domain

Obtain the fault domain the instance resides in.

get_secondary_vnic_ip() str[source]

Check if the instance has a secondary VNIC.

property id: str

Return instance id.

property instance_data

Return JSON formatted details from OCI about this instance.

property ip

Return IP address of instance.

property ips

Return IP address of instance.

property name

Return the instance name.

property private_ip

Return private IP address of instance.

remove_network_interface(ip_address: str)[source]

Remove network interface based on IP address.

Find the NIC from the IP, detach from the instance.

Note: In OCI, detaching triggers deletion.

property secondary_vnic_private_ip: str | None

Return private IP address of secondary vnic.

shutdown(wait=True, **kwargs)[source]

Shutdown the instance.

Parameters:

wait – wait for the instance to shutdown

start(wait=True)[source]

Start the instance.

Parameters:

wait – wait for the instance to start.

wait_for_delete(*, func_kwargs: Dict[str, str] | None = None, **kwargs)[source]

Wait for instance to be deleted.

wait_for_stop(*, func_kwargs: Dict[str, str] | None = None, **kwargs)[source]

Wait for instance stop.