pycloudlib.ibm.cloud module

IBM Cloud type.

class pycloudlib.ibm.cloud.IBM(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, resource_group: str | None = None, vpc: str | None = None, api_key: str | None = None, region: str | None = None, zone: str | None = None)[source]

Bases: BaseCloud

IBM Virtual Private Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, resource_group: str | None = None, vpc: str | None = None, api_key: str | None = None, region: str | None = None, zone: str | None = None)[source]

Initialize the connection to IBM VPC.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – Append a timestamped suffix to the tag string.

  • config_file – path to pycloudlib configuration file

clean() List[Exception][source]

Cleanup ALL artifacts associated with this Cloud instance.

Cleanup any cloud artifacts created at any time during this class’s existence. This includes all instances, snapshots, resources, etc.

daily_image(release: str, **kwargs) str[source]

ID of the latest daily image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest daily image ID for the specified release.

delete_image(image_id: str, **kwargs)[source]

Delete an image.

Parameters:
  • image_id – string, id of the image to delete

  • **kwargs – dictionary of other arguments to pass to delete_image

delete_key(name: str)[source]

Delete SSH key by name.

get_image_id_from_name(name: str) str[source]

Get the id of the first image whose name contains the given name.

The name does not need to be an exact match, just a substring of the image name.

Returns:

string, image ID

get_instance(instance_id: str, *, username: str | None = None, **kwargs) BaseInstance[source]

Get an instance by id.

Parameters:
  • instance_id – ID used identify the instance

  • username – username to use when connecting via SSH

Returns:

An instance object to use to manipulate the instance further.

get_or_create_vpc(name: str) VPC[source]

Get a VPC by name or create it if not found.

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: str, instance_type: str = 'bx2-2x8', user_data=None, *, name: str | None = None, vpc: VPC | None = None, username: str | None = None, floating_ip_substring: str | None = None, **kwargs) BaseInstance[source]

Launch an instance.

Parameters:
  • image_id – string, image ID to use for the instance

  • instance_type – string, type of instance to create

  • user_data – used by cloud-init to run custom scripts/configuration

  • name – instance name

  • vpc – VPC to allocate the instance in. If not given, the instance

  • username – username to use when connecting via SSH

  • VPC. (will be allocated in the zone's default)

  • floating_ip_substring – use existing floating IP whose name

  • deleted (contains this substring. This floating IP will not be)

  • deleted. (when the instance is)

  • **kwargs – dictionary of other arguments to pass to launch

Returns:

An instance object to use to manipulate the instance further.

list_keys() List[str][source]

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, *, arch: str = 'amd64', **kwargs)[source]

ID of the latest released image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

property resource_group_id: str

Resource Group ID used to create new things under.

snapshot(instance: IBMInstance, clean: bool = True, **kwargs) str[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

Returns:

An image id

property vpc: VPC

Virtual Private Cloud.