pycloudlib.ibm.instance module¶
Base class for all instances to provide consistent set of functions.
-
class
pycloudlib.ibm.instance.
IBMInstance
(key_pair, *, client: ibm_vpc.vpc_v1.VpcV1, instance: dict, floating_ip: Optional[dict] = None)[source]¶ Bases:
pycloudlib.instance.BaseInstance
Base instance object.
-
__init__
(key_pair, *, client: ibm_vpc.vpc_v1.VpcV1, instance: dict, floating_ip: Optional[dict] = None)[source]¶ Set up instance.
-
add_network_interface
() → str¶ Add nic to running instance.
-
boot_volume_id
¶ Boot volume ID.
-
clean
()¶ Clean an instance to make it look prestine.
This will clean out specifically the cloud-init files and system logs.
-
console_log
()¶ Return the instance console log.
Raises NotImplementedError if the cloud does not support fetching the console log for this instance.
-
static
create_raw_instance
(client: ibm_vpc.vpc_v1.VpcV1, *, name: str, image_id: str, vpc: pycloudlib.ibm.instance.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.
-
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
-
classmethod
find_existing
(*args, client: ibm_vpc.vpc_v1.VpcV1, instance_id: str, **kwargs) → pycloudlib.ibm.instance.IBMInstance[source]¶ Find an instance by ID.
-
classmethod
from_existing
(*args, client: ibm_vpc.vpc_v1.VpcV1, instance: dict, **kwargs) → pycloudlib.ibm.instance.IBMInstance[source]¶ Instantiate self from instance.
If floating_ip is not given, it will try to discover an associated Floating Ip.
-
get_boot_id
()¶ Get the instance boot_id.
Returns: string with the boot UUID
-
id
¶ Instance ID.
-
install
(packages)¶ Install specific packages.
Parameters: packages – string or list of package(s) to install Returns: result from install
-
ip
¶ Return IP address of instance.
-
name
¶ Return 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)¶ Remove nic from running instance.
-
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
-
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_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
-
-
class
pycloudlib.ibm.instance.
VPC
(key_pair, *, client: ibm_vpc.vpc_v1.VpcV1, vpc: dict, resource_group_id: str, subnet: Optional[pycloudlib.ibm.instance._Subnet] = None, **_kwargs)[source]¶ Bases:
object
Virtual Private Cloud class proxy for IBM VPC resource.
-
__init__
(key_pair, *, client: ibm_vpc.vpc_v1.VpcV1, vpc: dict, resource_group_id: str, subnet: Optional[pycloudlib.ibm.instance._Subnet] = None, **_kwargs)[source]¶ Init a VPC.
-
classmethod
create
(*args, client: ibm_vpc.vpc_v1.VpcV1, name: str, resource_group_id: str, zone: str, **kwargs) → pycloudlib.ibm.instance.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: ibm_vpc.vpc_v1.VpcV1, resource_group_id: str, region: str, zone: str, **kwargs) → pycloudlib.ibm.instance.VPC[source]¶ Find the default VPC and Subnet.
-
classmethod
from_existing
(*args, client: ibm_vpc.vpc_v1.VpcV1, name: str, resource_group_id: str, zone: str, **kwargs) → pycloudlib.ibm.instance.VPC[source]¶ Find a VPC by name.
Try to discover a Subnet within it or create it if not found.
-
id
¶ VPC ID.
-
name
¶ VPC name.
-
subnet_id
¶ Subnet ID.
-