pycloudlib.oci.instance module

OCI instance.

class pycloudlib.oci.instance.OciInstance(key_pair, instance_id, compartment_id, availability_domain, oci_config=None)[source]

Bases: pycloudlib.instance.BaseInstance

OCI backed instance.

__init__(key_pair, instance_id, compartment_id, availability_domain, oci_config=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
add_network_interface() → 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 IP address of the added network interface as a string.

Note: It assumes the associated compartment has at least one subnet and creates the vnic in the first encountered subnet.

clean()

Clean an instance to make it look prestine.

This will clean out specifically the cloud-init files and system logs.

console_log()[source]

Not currently implemented.

delete(wait=True)[source]

Delete the instance.

Parameters:wait – wait for instance to be deleted
execute(command, stdin=None, description=None, *, use_sudo=False, no_log=False, **kwargs)

Execute command in instance, recording output, error and exit code.

Assumes functional networking and execution with the target filesystem being available at /.

Parameters:
  • command – the command to execute as root inside the image. If command is a string, then it will be executed as: [‘sh’, ‘-c’, command]
  • stdin – bytes content for standard in
  • description – purpose of command
  • use_sudo – boolean to run the command as sudo
Returns:

Result object

Raises SSHException if there are any problem with the ssh connection

get_boot_id()

Get the instance boot_id.

Returns:string with the boot UUID
install(packages)

Install specific packages.

Parameters:packages – string or list of package(s) to install
Returns:result from install
instance_data

Return JSON formatted details from OCI about this instance.

ip

Return IP address of instance.

name

Return the instance name.

pull_file(remote_path, local_path)

Copy file at ‘remote_path’, from instance to ‘local_path’.

Parameters:
  • remote_path – path on remote instance
  • local_path – local path

Raises SSHException if there are any problem with the ssh connection

push_file(local_path, remote_path)

Copy file at ‘local_path’ to instance at ‘remote_path’.

Parameters:
  • local_path – local path
  • remote_path – path on remote instance

Raises SSHException if there are any problem with the ssh connection

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.

restart(wait=True, **kwargs)

Restart an instance.

run_script(script, description=None)

Run script in target and return stdout.

Parameters:
  • script – script contents
  • description – purpose of script
Returns:

result from script execution

Raises SSHException if there are any problem with the ssh connection

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.
update()

Run apt-get update/upgrade on instance.

Returns:result from upgrade
wait()

Wait for instance to be up and cloud-init to be complete.

wait_for_delete()[source]

Wait for instance to be deleted.

wait_for_restart(old_boot_id)

Wait for instance to be restarted and cloud-init to be complete.

old_boot_id is the boot id prior to restart

wait_for_stop()[source]

Wait for instance stop.