pycloudlib.ibm.instance module

Base class for all instances to provide consistent set of functions.

class pycloudlib.ibm.instance.IBMInstance(key_pair, *, client: VpcV1, instance: dict, floating_ip: dict | None = None, username: str | None = None)[source]

Bases: BaseInstance

Base instance object.

__init__(key_pair, *, client: VpcV1, instance: dict, floating_ip: dict | None = None, username: str | None = None)[source]

Set up an IBMInstance object.

attach_floating_ip(floating_ip_substring: str | None) str | None[source]

Attach a floating IP to this instance.

If floating_ip_substring is given, it will try to attach an existing floating IP that contains the substring in its name. If not, it will create a new floating IP and attach it.

Parameters:

floating_ip_substring – optional substring to find existing floating IPs by. If not given, a new floating IP will be created and attached.

Returns:

ID of the floating IP attached if successful, otherwise None

Raises:
property boot_volume_id: str

Boot volume ID.

static create_raw_instance(client: VpcV1, *, name: str, image_id: str, vpc: VPC, instance_type: str, resource_group_id: str, zone: str, user_data=None, key_id: str) dict[source]

Create and return a raw IBM instance.

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

Delete the instance.

Parameters:

wait – wait for instance to be deleted

classmethod find_existing(*args, client: VpcV1, instance_id: str, username: str | None = None, **kwargs) IBMInstance[source]

Find an instance by ID.

classmethod from_existing(*args, client: VpcV1, instance: dict, username: str | None = None, **kwargs) IBMInstance[source]

Instantiate self from instance.

If floating_ip is not given, it will try to discover an associated Floating Ip.

classmethod from_raw_instance(*args, client: VpcV1, instance: dict, username: str | None = None, **kwargs) IBMInstance[source]

Instantiate IBMInstance object from raw instance dict.

Parameters:
  • args – positional arguments

  • client – IBM VPC client

  • instance – raw instance dict

  • username – username to use for SSH

  • kwargs – other keyword arguments

property id: str

Instance ID.

property ip

Return IP address of instance.

property name: str

Return instance name.

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(sleep_seconds=300, raise_on_fail=False)[source]

Wait for instance to be deleted.

wait_for_stop(**kwargs)[source]

Wait for instance stop.

class pycloudlib.ibm.instance.VPC(key_pair, *, client: VpcV1, vpc: dict, resource_group_id: str, subnet: _Subnet | None = None, **_kwargs)[source]

Bases: object

Virtual Private Cloud class proxy for IBM VPC resource.

__init__(key_pair, *, client: VpcV1, vpc: dict, resource_group_id: str, subnet: _Subnet | None = None, **_kwargs)[source]

Init a VPC.

classmethod create(*args, client: VpcV1, name: str, resource_group_id: str, zone: str, **kwargs) VPC[source]

Create a VPC.

Creates a Subnet and adds inbound rule to accept SSH connections to the default Security Group.

delete() None[source]

Delete VPC.

Note: This will delete all instances and subnets living in the VPC.

classmethod from_default(*args, client: VpcV1, resource_group_id: str, region: str, zone: str, **kwargs) VPC[source]

Find the default VPC and Subnet.

classmethod from_existing(*args, client: VpcV1, name: str, resource_group_id: str, zone: str, **kwargs) VPC[source]

Find a VPC by name.

Try to discover a Subnet within it or create it if not found.

property id: str

VPC ID.

property name: str

VPC name.

property subnet_id: str

Subnet ID.