lib/sles4sap/aws_cli.pm

SYNOPSIS

Library to compose and run AWS cli commands.

aws_import_key_pair

aws_import_key_pair($ssh_key, $pub_key_path);

Import an SSH public key pair into AWS EC2 for instance authentication

$ssh_key - name to assign to the imported key pair in AWS
$pub_key_path - filesystem path to the public key file

aws_create_vpc

my $vpc_id = aws_create_vpc($region, $cidr, $job_id);

Create a new AWS VPC with a specified CIDR block and tag it with the OpenQA job ID

$region - AWS region where to create the VPC
$cidr - CIDR block for the VPC (e.g., '10.0.0.0/16')
$job_id - OpenQA job identifier for tagging

Returns the VPC ID

aws_get_vpc_id

my $vpc_id = aws_get_vpc_id($region, $job_id);

Retrieve the VPC ID associated with a specific OpenQA job

$region - AWS region where the VPC is located
$job_id - OpenQA job identifier used to tag the VPC

Returns the VPC ID

aws_create_security_group

my $sg_id = aws_create_security_group($region, $group_name, $description, $vpc_id);

Create an AWS security group within a VPC and tag it with the OpenQA job ID

$region - AWS region where to create the security group
$group_name - name for the security group
$description - description of the security group purpose
$vpc_id - ID of the VPC where the security group will be created
$job_id - OpenQA job identifier used to tag the VPC

Returns the security group ID

aws_get_security_group_id

my $sg_id = aws_get_security_group_id($region, $job_id);

Retrieve the security group ID associated with a specific OpenQA job

$region - AWS region where the security group is located
$job_id - OpenQA job identifier used to tag the security group

Returns the security group ID

aws_create_subnet

my $subnet_id = aws_create_subnet($region, $cidr, $vpc_id);

Create a subnet within a VPC with a specified CIDR block and tag it with the OpenQA job ID

$region - AWS region where to create the subnet
$cidr - CIDR block for the subnet (e.g., '10.0.1.0/24')
$vpc_id - ID of the VPC where the subnet will be created
$job_id - OpenQA job identifier used to tag the security group

Returns the subnet ID

aws_get_subnet_id

my $subnet_id = aws_get_subnet_id($region, $job_id);

Retrieve the subnet ID associated with a specific OpenQA job

$region - AWS region where the subnet is located
$job_id - OpenQA job identifier used to tag the subnet

Returns the subnet ID

aws_create_internet_gateway

my $igw_id = aws_create_internet_gateway($region);

Create an internet gateway and tag it with the OpenQA job ID

$region - AWS region where to create the internet gateway
$job_id - OpenQA job identifier used to tag the security group

Returns the internet gateway ID

aws_get_internet_gateway_id

my $igw_id = aws_get_internet_gateway_id($region, $job_id);

Retrieve the internet gateway ID associated with a specific OpenQA job

$region - AWS region where the internet gateway is located
$job_id - OpenQA job identifier used to tag the internet gateway

Returns the internet gateway ID

aws_attach_internet_gateway

aws_attach_internet_gateway($vpc_id, $igw_id, $region);

Attach an internet gateway to a VPC

$vpc_id - ID of the VPC to attach the gateway to
$igw_id - ID of the internet gateway to attach
$region - AWS region where the resources are located

aws_create_route_table

my $route_table_id = aws_create_route_table($region, $vpc_id);

Create a route table within a VPC

$region - AWS region where to create the route table
$vpc_id - ID of the VPC where the route table will be created

Returns the route table ID

aws_associate_route_table

aws_associate_route_table($subnet_id, $route_table_id, $region);

Associate a route table with a subnet

$subnet_id - ID of the subnet to associate
$route_table_id - ID of the route table to associate
$region - AWS region where the resources are located

aws_create_route

aws_create_route($route_table_id, $destination_cidr_block, $igw_id, $region);

Create a route in a route table pointing to an internet gateway

$route_table_id - ID of the route table where to create the route
$destination_cidr_block - destination CIDR block for the route (e.g., '0.0.0.0/0' for default route)
$igw_id - ID of the internet gateway as the route target
$region - AWS region where the resources are located

aws_authorize_security_group_ingress

aws_authorize_security_group_ingress($sg_id, $protocol, $port, $cidr, $region);

Add an ingress rule to a security group allowing traffic from a specific CIDR block

$sg_id - ID of the security group to modify
$protocol - protocol for the rule (e.g., 'tcp', 'udp', 'icmp')
$port - port number or port range for the rule
$cidr - CIDR block allowed to access (e.g., '0.0.0.0/0' for all)
$region - AWS region where the security group is located

aws_create_vm

my $instance_id = aws_create_vm($instance_type, $image_id, $subnet_id, $sg_id, $ssh_key, $region);

Launch an EC2 instance with specified configuration and tag it with the OpenQA job ID

$instance_type - EC2 instance type (e.g., 't2.micro', 'm5.large')
$image_id - AMI ID to use for the instance
$subnet_id - ID of the subnet where to launch the instance
$sg_id - ID of the security group to assign to the instance
$ssh_key - name of the SSH key pair for instance access
$region - AWS region where to launch the instance
$job_id - OpenQA job identifier used to tag the internet gateway

Returns the instance ID

aws_get_vm_id

my $instance_id = aws_get_vm_id($region, $job_id);

Retrieve the EC2 instance ID associated with a specific OpenQA job

$region - AWS region where the instance is located
$job_id - OpenQA job identifier used to tag the instance

Returns the instance ID

aws_wait_instance_status_ok

aws_wait_instance_status_ok($instance_id);

Wait for an EC2 instance to reach 'running' state with a timeout of 600 seconds

$instance_id - ID of the instance to monitor

aws_get_ip_address

my $ip = aws_get_ip_address($instance_id);

Retrieve the public IP address of an EC2 instance

$instance_id - ID of the instance

Returns the public IP address