pycloudlib.ec2.instance module
EC2 instance.
- class pycloudlib.ec2.instance.EC2Instance(key_pair, client, instance, *, username: str | None = None)[source]
Bases:
BaseInstanceEC2 backed instance.
- __init__(key_pair, client, instance, *, username: str | None = None)[source]
Set up instance.
- Parameters:
key_pair – SSH key object
client – boto3 client object
instance – created boto3 instance object
username – username to use when connecting via SSH
- add_network_interface(*, ipv4_address_count: int = 1, ipv6_address_count: int = 0, ipv4_public_ip_count: int = 0, **kwargs) str[source]
Add network interface to instance.
Creates an ENI device and attaches it to the running instance. This is effectively a hot-add of a network device. Returns the IP address of the added network interface as a string.
See the AWS documentation for more info: https://boto3.readthedocs.io/en/latest/reference/services/ec2.html?#EC2.Client.create_network_interface https://boto3.readthedocs.io/en/latest/reference/services/ec2.html?#EC2.Client.attach_network_interface
- Parameters:
ipv4_address_count – number of private ipv4s
ipv6_address_count – number of private ipv6s
ipv4_public_ip_count – number of public ips associated to private ips
Returns: private primary ip
- add_volume(size=8, drive_type='gp2')[source]
Add storage volume to instance.
Creates an EBS volume and attaches it to the running instance. This is effectively a hot-add of a storage device.
See AWS documentation for more info: https://boto3.readthedocs.io/en/latest/reference/services/ec2.html?#EC2.Client.create_volume https://boto3.readthedocs.io/en/latest/reference/services/ec2.html?#EC2.Client.attach_volume
- Parameters:
size – Size in GB of the drive to add
drive_type – Type of EBS volume to add
- property availability_zone
Return availability zone.
- console_log()[source]
Collect console log from instance.
The console log is buffered and not always present, therefore may return empty string.
- Returns:
The console log or error message
- property id
Return id of instance.
- property image_id
Return id of instance.
- property ip
Return IP address of instance.
- property name
Return id of instance.
- property public_ips: List[str]
Return public IP addresses of instance.
- ready_timeout = 40
- remove_network_interface(ip_address)[source]
Remove network interface based on IP address.
Find the NIC from the IP, detach from the instance, then delete the NIC.