pycloudlib.ec2.cloud module¶
AWS EC2 Cloud type.
-
class
pycloudlib.ec2.cloud.
EC2
(tag: str, timestamp_suffix: bool = True, config_file: Union[pathlib.Path, _io.StringIO, None] = None, *, access_key_id: Optional[str] = None, secret_access_key: Optional[str] = None, region: Optional[str] = None)[source]¶ Bases:
pycloudlib.cloud.BaseCloud
EC2 Cloud Class.
-
__init__
(tag: str, timestamp_suffix: bool = True, config_file: Union[pathlib.Path, _io.StringIO, None] = None, *, access_key_id: Optional[str] = None, secret_access_key: Optional[str] = None, region: Optional[str] = None)[source]¶ Initialize the connection to EC2.
boto3 will read a users /home/$USER/.aws/* files if no arguments are provided here to find values.
Parameters: - tag – string used to name and tag resources with
- timestamp_suffix – bool set True to append a timestamp suffix to the tag
- config_file – path to pycloudlib configuration file
- access_key_id – user’s access key ID
- secret_access_key – user’s secret access key
- region – region to login to
-
create_key_pair
()¶ Create and set a ssh key pair for a cloud instance.
Returns: A tuple containing the public and private key created
-
daily_image
(release: str, *, arch: str = 'x86_64', image_type: pycloudlib.cloud.ImageType = <ImageType.GENERIC: 'generic'>, **kwargs)[source]¶ Find the id of the latest daily image for a particular release.
Parameters: - release – string, Ubuntu release to look for
- arch – string, architecture to use
Returns: string, id of latest image
-
delete_image
(image_id, **kwargs)[source]¶ Delete an image.
Parameters: image_id – string, id of the image to delete
-
get_instance
(instance_id)[source]¶ Get an instance by id.
Parameters: instance_id – Returns: An instance object to use to manipulate the instance further.
-
get_or_create_vpc
(name, ipv4_cidr='192.168.1.0/20')[source]¶ Create a or return matching VPC.
This can be used instead of using the default VPC to create a custom VPC for usage.
Parameters: - name – name of the VPC
- ipv4_cidr – CIDR of IPV4 subnet
Returns: VPC object
-
image_serial
(image_id, image_type: pycloudlib.cloud.ImageType = <ImageType.GENERIC: 'generic'>)[source]¶ Find the image serial of a given EC2 image ID.
Parameters: image_id – string, Ubuntu image id Returns: string, serial of latest image
-
launch
(image_id, instance_type='t3.micro', user_data=None, wait=True, vpc=None, username=None, **kwargs)[source]¶ Launch instance on EC2.
Parameters: - image_id – string, AMI ID to use default: latest Ubuntu LTS
- instance_type – string, instance type to launch
- user_data – string, user-data to pass to instance
- wait – boolean, wait for instance to come up
- vpc – optional vpc object to create instance under
- kwargs – other named arguments to add to instance JSON
Returns: EC2 Instance object
Raises: ValueError on invalid image_id
-
released_image
(release: str, *, arch: str = 'x86_64', image_type: pycloudlib.cloud.ImageType = <ImageType.GENERIC: 'generic'>, **kwargs)[source]¶ Find the id of the latest released image for a particular release.
Parameters: - release – string, Ubuntu release to look for
- arch – string, architecture to use
- root_store – string, root store to use
Returns: string, id of latest image
-
snapshot
(instance, clean=True)[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
-