Skip to content

Latest commit

 

History

History
612 lines (389 loc) · 15.4 KB

aws.md

File metadata and controls

612 lines (389 loc) · 15.4 KB

AWS

Auto-generated documentation for ocs_ci.utility.aws module.

AWS

[find in source code]

class AWS(object):
    def __init__(region_name=None):

This is wrapper class for AWS

AWS().append_security_group

[find in source code]

def append_security_group(security_group_id, instance_id):

Append security group to selected ec2 nodes

Arguments

  • instance_id str - Instances to attach security group

  • security_group_id(str) - Security group to attach

  • print out - security group added to selected nodes

AWS().attach_volume

[find in source code]

def attach_volume(volume, instance_id, device='/dev/sdx'):

Attach volume to an ec2 instance

Arguments

  • volume Volume - Volume instance
  • instance_id str - id of instance where to attach the volume
  • device str - The name of the device where to attach (default: /dev/sdx)

AWS().block_instances_access

[find in source code]

def block_instances_access(security_group_id, instances_id):

Block ec2 instances by:

  • Append security group without access permissions
  • Remove original security groups

Arguments

  • security_group_id str - security group without access permissions
  • instances_id list - list of ec2 instances ids

AWS().create_security_group

[find in source code]

def create_security_group(group_name, dict_permissions, vpc_id):

Create security group with predefined group name and permissions

Arguments

  • group_name str - Group name (aws tag: "Group Name")
  • dict_permissions dict - The security group's inbound/outbound permissions
  • vpc_id(str) - For group to be attached

Returns

  • str - newly created security group id

AWS().create_volume

[find in source code]

def create_volume(
    availability_zone,
    name,
    encrypted=False,
    size=100,
    timeout=20,
    volume_type='gp2',
):

Create volume

Arguments

  • availability_zone str - The availability zone e.g.: us-west-1b
  • name str - The name of the volume
  • 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)

Returns

  • Volume - AWS Resource instance of the newly created volume

AWS().create_volume_and_attach

[find in source code]

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

Arguments

  • availability_zone str - The availability zone e.g.: us-west-1b
  • instance_id str - The id of the instance where to attach the volume
  • name str - The name of volume
  • device 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)

AWS().delete_security_group

[find in source code]

def delete_security_group(security_group_id):

Delete selected security group print out: Security group deleted

Arguments

  • security_group_id str - Id of selected security group

AWS().delete_volume

[find in source code]

def delete_volume(volume):

Delete an ec2 volume from AWS

Arguments

  • volume Volume - The volume to delete

AWS().detach_and_delete_volume

[find in source code]

def detach_and_delete_volume(volume, timeout=120):

Detach volume if attached and then delete it from AWS

Arguments

  • volume Volume - The volume to delete
  • timeout int - Timeout in seconds for API calls

AWS().detach_volume

[find in source code]

def detach_volume(volume, timeout=120):

Detach volume if attached

Arguments

  • volume Volume - The volume to delete
  • timeout int - Timeout in seconds for API calls

Returns

  • Volume - ec2 Volume instance

AWS().ec2_client

[find in source code]

@property
def ec2_client():

Property for ec2 client

Returns

  • boto3.client - instance of ec2

AWS().ec2_resource

[find in source code]

@property
def ec2_resource():

Property for ec2 resource

Returns

boto3.resource instance of ec2 resource

AWS().get_all_security_groups

[find in source code]

def get_all_security_groups():

Get all security groups in AWS region

Returns

  • list - All security groups

AWS().get_availability_zone_id_by_instance_id

[find in source code]

def get_availability_zone_id_by_instance_id(instance_id):

Fetch availability zone out of ec2 node (EC2.Instances.placement)

Arguments

  • instance_id str - ID of the instance - to get availability zone info from ec2 node

Returns

  • str - availability_zone: The availability zone name

AWS().get_ec2_instance

[find in source code]

def get_ec2_instance(instance_id):

Get instance of ec2 Instance

Arguments

  • instance_id str - The ID of the instance to get

Returns

  • boto3.Instance - instance of ec2 instance resource

AWS().get_ec2_instance_volumes

[find in source code]

def get_ec2_instance_volumes(instance_id):

Get all volumes attached to an ec2 instance

Arguments

  • instance_id str - The ec2 instance ID

Returns

  • list - ec2 Volume instances

AWS().get_instances_by_name_pattern

[find in source code]

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

Arguments

  • pattern str - Pattern of tag name like: pbalogh-testing-cluster-55jx2-worker*

Returns

  • list - contains dictionaries with instance details mentioned above

AWS().get_instances_status_by_id

[find in source code]

def get_instances_status_by_id(instance_id):

Get instances by ID

Arguments

  • instance_id str - ID of the instance

Returns

  • str - The instance status

AWS().get_security_groups_by_instance_id

[find in source code]

def get_security_groups_by_instance_id(instance_id):

Get all attached security groups of ec2 instance

Arguments

  • instance_id str - Required instance to get security groups from it

Returns

  • list - all_sg_ids: all attached security groups id.

AWS().get_volumes_by_name_pattern

[find in source code]

def get_volumes_by_name_pattern(pattern):

Get volumes by pattern

Arguments

  • pattern str - Pattern of volume name (e.g. 'cl-vol-')

Returns

  • list - Volume information like id and attachments

AWS().get_vpc_id_by_instance_id

[find in source code]

def get_vpc_id_by_instance_id(instance_id):

Fetch vpc id out of ec2 node (EC2.Instances.vpc_id)

Arguments

  • instance_id str - ID of the instance - to get vpc id info from ec2 node

Returns

  • str - vpc_id: The vpc id

AWS().remove_security_group

[find in source code]

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

Arguments

  • security_group_id str - Security group to be removed
  • instance_id str - Instance attached with selected security group

AWS().restart_ec2_instances

[find in source code]

def restart_ec2_instances(instances, wait=False, force=True):

Stop and start ec2 instances

Arguments

  • instances dict - A dictionary of instance IDs and names to restart
  • wait bool - True in case wait for status is needed, False otherwise
  • force bool - True for force instance stop, False otherwise

AWS().restore_instances_access

[find in source code]

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

Arguments

security_group_id_to_remove (str):

  • original_security_group_dict dict - keys: blocked instances: ec2 instances id
    • values - list of original security groups

AWS().start_ec2_instances

[find in source code]

def start_ec2_instances(instances, wait=False):

Starting an instance

Arguments

  • instances dict - A dictionary of instance IDs and names to start
  • wait bool - True in case wait for status is needed, False otherwise

AWS().stop_ec2_instances

[find in source code]

def stop_ec2_instances(instances, wait=False, force=True):

Stopping an instance

Arguments

  • instances dict - A dictionary of instance IDs and names to stop
  • wait bool - True in case wait for status is needed, False otherwise
  • force bool - True for force instance stop, False otherwise

AWS().store_security_groups_for_instances

[find in source code]

def store_security_groups_for_instances(instances_id):

Stored all security groups attached to selected ec2 instances

Arguments

  • instances_id list - ec2 instance_id

Returns

  • dict - security_group_dict: keys: blocked instances: ec2_instances ids
    • values - list of original security groups of each instance

AWSTimeoutException

[find in source code]

class AWSTimeoutException(Exception):

get_data_volumes

[find in source code]

def get_data_volumes(deviceset_pvs):

Get the instance data volumes (which doesn't include root FS)

Arguments

  • deviceset_pvs list - PVC objects of the deviceset PVs

Returns

  • list - ec2 Volume instances

get_instances_ids_and_names

[find in source code]

def get_instances_ids_and_names(instances):

Get the instances IDs and names according to nodes dictionary

Arguments

  • instances list - Nodes dictionaries, returned by 'oc get node -o yaml'

Returns

  • dict - The ID keys and the name values of the instances

get_vpc_id_by_node_obj

[find in source code]

def get_vpc_id_by_node_obj(aws_obj, instances):

This function getting vpc id by randomly selecting instances out of user aws deployment

Arguments

  • aws_obj obj - AWS() object
  • instances dict - cluster ec2 instances objects

Returns

  • str - vpc_id: The vpc id