Auto-generated documentation for ocs_ci.utility.aws module.
- Ocs-ci / Modules / Ocs Ci / Utility / AWS
- AWS
- AWS().append_security_group
- AWS().attach_volume
- AWS().block_instances_access
- AWS().create_security_group
- AWS().create_volume
- AWS().create_volume_and_attach
- AWS().delete_security_group
- AWS().delete_volume
- AWS().detach_and_delete_volume
- AWS().detach_volume
- AWS().ec2_client
- AWS().ec2_resource
- AWS().get_all_security_groups
- AWS().get_availability_zone_id_by_instance_id
- AWS().get_ec2_instance
- AWS().get_ec2_instance_volumes
- AWS().get_instances_by_name_pattern
- AWS().get_instances_status_by_id
- AWS().get_security_groups_by_instance_id
- AWS().get_volumes_by_name_pattern
- AWS().get_vpc_id_by_instance_id
- AWS().remove_security_group
- AWS().restart_ec2_instances
- AWS().restore_instances_access
- AWS().start_ec2_instances
- AWS().stop_ec2_instances
- AWS().store_security_groups_for_instances
- AWSTimeoutException
- get_data_volumes
- get_instances_ids_and_names
- get_vpc_id_by_node_obj
- AWS
class AWS(object):
def __init__(region_name=None):
This is wrapper class for AWS
def append_security_group(security_group_id, instance_id):
Append security group to selected ec2 nodes
-
instance_id
str - Instances to attach security group -
security_group_id(str)
- Security group to attach -
print
out - security group added to selected nodes
def attach_volume(volume, instance_id, device='/dev/sdx'):
Attach volume to an ec2 instance
volume
Volume - Volume instanceinstance_id
str - id of instance where to attach the volumedevice
str - The name of the device where to attach (default: /dev/sdx)
def block_instances_access(security_group_id, instances_id):
Block ec2 instances by:
- Append security group without access permissions
- Remove original security groups
security_group_id
str - security group without access permissionsinstances_id
list - list of ec2 instances ids
def create_security_group(group_name, dict_permissions, vpc_id):
Create security group with predefined group name and permissions
group_name
str - Group name (aws tag: "Group Name")dict_permissions
dict - The security group's inbound/outbound permissionsvpc_id(str)
- For group to be attached
str
- newly created security group id
def create_volume(
availability_zone,
name,
encrypted=False,
size=100,
timeout=20,
volume_type='gp2',
):
Create volume
availability_zone
str - The availability zone e.g.: us-west-1bname
str - The name of the volumeencrypted
boolean - True if encrypted, False otherwise(default
- False)
size
int - The size in GB (default: 100)timeout
int - The timeout in seconds for volume creation (default: 20)volume_type
str - 'standard'|'io1'|'gp2'|'sc1'|'st1'(default
- gp2)
Volume
- AWS Resource instance of the newly created volume
def create_volume_and_attach(
availability_zone,
instance_id,
name,
device='/dev/sdx',
encrypted=False,
size=100,
timeout=20,
volume_type='gp2',
):
Create volume and attach to instance
availability_zone
str - The availability zone e.g.: us-west-1binstance_id
str - The id of the instance where to attach the volumename
str - The name of volumedevice
str - The name of device where to attach (default: /dev/sdx)encrypted
boolean - True if encrypted, False otherwise(default
- False)
size
int - The size in GB (default: 100)timeout
int - The timeout in seconds for volume creation (default: 20)volume_type
str - 'standard'|'io1'|'gp2'|'sc1'|'st1'(default
- gp2)
def delete_security_group(security_group_id):
Delete selected security group print out: Security group deleted
security_group_id
str - Id of selected security group
def delete_volume(volume):
Delete an ec2 volume from AWS
volume
Volume - The volume to delete
def detach_and_delete_volume(volume, timeout=120):
Detach volume if attached and then delete it from AWS
volume
Volume - The volume to deletetimeout
int - Timeout in seconds for API calls
def detach_volume(volume, timeout=120):
Detach volume if attached
volume
Volume - The volume to deletetimeout
int - Timeout in seconds for API calls
Volume
- ec2 Volume instance
@property
def ec2_client():
Property for ec2 client
boto3.client
- instance of ec2
@property
def ec2_resource():
Property for ec2 resource
boto3.resource instance of ec2 resource
def get_all_security_groups():
Get all security groups in AWS region
list
- All security groups
def get_availability_zone_id_by_instance_id(instance_id):
Fetch availability zone out of ec2 node (EC2.Instances.placement)
instance_id
str - ID of the instance - to get availability zone info from ec2 node
str
- availability_zone: The availability zone name
def get_ec2_instance(instance_id):
Get instance of ec2 Instance
instance_id
str - The ID of the instance to get
boto3.Instance
- instance of ec2 instance resource
def get_ec2_instance_volumes(instance_id):
Get all volumes attached to an ec2 instance
instance_id
str - The ec2 instance ID
list
- ec2 Volume instances
def get_instances_by_name_pattern(pattern):
Get instances by Name tag pattern
The instance details do not contain all the values but just those we are consuming.
Those parameters we are storing for instance are:
- id: id of instance
- avz: Availability Zone
- name: The value of Tag Name if define otherwise None
- vpc_id: VPC ID
- security_groups: Security groups of the instance
pattern
str - Pattern of tag name like: pbalogh-testing-cluster-55jx2-worker*
list
- contains dictionaries with instance details mentioned above
def get_instances_status_by_id(instance_id):
Get instances by ID
instance_id
str - ID of the instance
str
- The instance status
def get_security_groups_by_instance_id(instance_id):
Get all attached security groups of ec2 instance
instance_id
str - Required instance to get security groups from it
list
- all_sg_ids: all attached security groups id.
def get_volumes_by_name_pattern(pattern):
Get volumes by pattern
pattern
str - Pattern of volume name (e.g. 'cl-vol-')
list
- Volume information like id and attachments
def get_vpc_id_by_instance_id(instance_id):
Fetch vpc id out of ec2 node (EC2.Instances.vpc_id)
instance_id
str - ID of the instance - to get vpc id info from ec2 node
str
- vpc_id: The vpc id
def remove_security_group(security_group_id, instance_id):
Remove security group from selected ec2 instance (by instance id) print out: security group removed from selected nodes
security_group_id
str - Security group to be removedinstance_id
str - Instance attached with selected security group
def restart_ec2_instances(instances, wait=False, force=True):
Stop and start ec2 instances
instances
dict - A dictionary of instance IDs and names to restartwait
bool - True in case wait for status is needed, False otherwiseforce
bool - True for force instance stop, False otherwise
def restore_instances_access(
security_group_id_to_remove,
original_security_group_dict,
):
Restore access to instances by removing blocking security group and append original security group
security_group_id_to_remove (str):
original_security_group_dict
dict - keys: blocked instances: ec2 instances idvalues
- list of original security groups
def start_ec2_instances(instances, wait=False):
Starting an instance
instances
dict - A dictionary of instance IDs and names to startwait
bool - True in case wait for status is needed, False otherwise
def stop_ec2_instances(instances, wait=False, force=True):
Stopping an instance
instances
dict - A dictionary of instance IDs and names to stopwait
bool - True in case wait for status is needed, False otherwiseforce
bool - True for force instance stop, False otherwise
def store_security_groups_for_instances(instances_id):
Stored all security groups attached to selected ec2 instances
instances_id
list - ec2 instance_id
dict
- security_group_dict: keys: blocked instances: ec2_instances idsvalues
- list of original security groups of each instance
class AWSTimeoutException(Exception):
def get_data_volumes(deviceset_pvs):
Get the instance data volumes (which doesn't include root FS)
deviceset_pvs
list - PVC objects of the deviceset PVs
list
- ec2 Volume instances
def get_instances_ids_and_names(instances):
Get the instances IDs and names according to nodes dictionary
instances
list - Nodes dictionaries, returned by 'oc get node -o yaml'
dict
- The ID keys and the name values of the instances
def get_vpc_id_by_node_obj(aws_obj, instances):
This function getting vpc id by randomly selecting instances out of user aws deployment
aws_obj
obj - AWS() objectinstances
dict - cluster ec2 instances objects
str
- vpc_id: The vpc id