Skip to content

Commit

Permalink
ec2_elb_lb boto3 migration (#377)
Browse files Browse the repository at this point in the history
ec2_elb_lb boto3 migration

SUMMARY
Rewrite ec2_elb_lb using the boto3 SDK
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_elb_lb
ADDITIONAL INFORMATION
Current state

 renamed to elb_classic_lb
 create/delete ELBs
 change schema
 update availability-zones
 update subnets
 manage tags
 manage listeners
 manage health checks
 manage cross-AZ balancing
 manage draining
 manage idle_timeout
 manage backend policies
 manage stickiness
 manage Instance attachment
 manage access logging
 lookup SGs by name
 parameter validation (protocol, mandatory on creation etc)

Depends-On: ansible/ansible-zuul-jobs#1097

Reviewed-by: Jill R <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: None <None>
  • Loading branch information
tremble authored Sep 28, 2021
1 parent 58f486c commit 0d790f6
Show file tree
Hide file tree
Showing 37 changed files with 6,224 additions and 1,675 deletions.
8 changes: 8 additions & 0 deletions changelogs/fragments/377-ec2_elb_lb-boto3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
minor_changes:
- ec2_elb_lb - module renamed to ``elb_classic_lb`` (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - migrated to boto3 SDK (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - added support for check_mode (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - added support for wait during creation (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - added support for wait during instance addition and removal (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - added retries on common AWS temporary API failures (https://github.com/ansible-collections/amazon.aws/pull/377).
- elb_classic_lb - various error messages changed due to refactor (https://github.com/ansible-collections/amazon.aws/pull/377).
3 changes: 3 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ action_groups:
- ec2_vpc_net_info
- ec2_vpc_subnet
- ec2_vpc_subnet_info
- elb_classic_lb
- s3_bucket
- ec2_vpc_endpoint_facts
- ec2_vpc_endpoint
Expand Down Expand Up @@ -98,6 +99,8 @@ plugin_routing:
warning_text: >-
ec2_ami_facts was renamed in Ansible 2.9 to ec2_ami_info.
Please update your tasks.
ec2_elb_lb:
redirect: amazon.aws.elb_classic_lb
ec2_eni_facts:
deprecation:
removal_date: 2021-12-01
Expand Down
157 changes: 157 additions & 0 deletions plugins/module_utils/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@
},
]
},
"NetworkInterfaceDeleted": {
"operation": "DescribeNetworkInterfaces",
"delay": 5,
"maxAttempts": 40,
"acceptors": [
{
"matcher": "path",
"expected": True,
"argument": "length(NetworkInterfaces[]) > `0`",
"state": "retry"
},
{
"matcher": "path",
"expected": True,
"argument": "length(NetworkInterfaces[]) == `0`",
"state": "success"
},
{
"expected": "InvalidNetworkInterfaceID.NotFound",
"matcher": "error",
"state": "success"
},
]
},
"NetworkInterfaceDeleteOnTerminate": {
"operation": "DescribeNetworkInterfaces",
"delay": 5,
Expand Down Expand Up @@ -462,6 +486,98 @@
}


elb_data = {
"version": 2,
"waiters": {
"AnyInstanceInService": {
"acceptors": [
{
"argument": "InstanceStates[].State",
"expected": "InService",
"matcher": "pathAny",
"state": "success"
}
],
"delay": 15,
"maxAttempts": 40,
"operation": "DescribeInstanceHealth"
},
"InstanceDeregistered": {
"delay": 15,
"operation": "DescribeInstanceHealth",
"maxAttempts": 40,
"acceptors": [
{
"expected": "OutOfService",
"matcher": "pathAll",
"state": "success",
"argument": "InstanceStates[].State"
},
{
"matcher": "error",
"expected": "InvalidInstance",
"state": "success"
}
]
},
"InstanceInService": {
"acceptors": [
{
"argument": "InstanceStates[].State",
"expected": "InService",
"matcher": "pathAll",
"state": "success"
},
{
"matcher": "error",
"expected": "InvalidInstance",
"state": "retry"
}
],
"delay": 15,
"maxAttempts": 40,
"operation": "DescribeInstanceHealth"
},
"LoadBalancerCreated": {
"delay": 10,
"maxAttempts": 60,
"operation": "DescribeLoadBalancers",
"acceptors": [
{
"matcher": "path",
"expected": True,
"argument": "length(LoadBalancerDescriptions[]) > `0`",
"state": "success",
},
{
"matcher": "error",
"expected": "LoadBalancerNotFound",
"state": "retry",
},
],
},
"LoadBalancerDeleted": {
"delay": 10,
"maxAttempts": 60,
"operation": "DescribeLoadBalancers",
"acceptors": [
{
"matcher": "path",
"expected": True,
"argument": "length(LoadBalancerDescriptions[]) > `0`",
"state": "retry",
},
{
"matcher": "error",
"expected": "LoadBalancerNotFound",
"state": "success",
},
],
},
}
}


rds_data = {
"version": 2,
"waiters": {
Expand Down Expand Up @@ -572,6 +688,11 @@ def eks_model(name):
return eks_models.get_waiter(name)


def elb_model(name):
elb_models = core_waiter.WaiterModel(waiter_config=_inject_limit_retries(elb_data))
return elb_models.get_waiter(name)


def rds_model(name):
rds_models = core_waiter.WaiterModel(waiter_config=_inject_limit_retries(rds_data))
return rds_models.get_waiter(name)
Expand Down Expand Up @@ -601,6 +722,12 @@ def route53_model(name):
core_waiter.NormalizedOperationMethod(
ec2.describe_network_interfaces
)),
('EC2', 'network_interface_deleted'): lambda ec2: core_waiter.Waiter(
'network_interface_deleted',
ec2_model('NetworkInterfaceDeleted'),
core_waiter.NormalizedOperationMethod(
ec2.describe_network_interfaces
)),
('EC2', 'network_interface_available'): lambda ec2: core_waiter.Waiter(
'network_interface_available',
ec2_model('NetworkInterfaceAvailable'),
Expand Down Expand Up @@ -745,6 +872,36 @@ def route53_model(name):
core_waiter.NormalizedOperationMethod(
eks.describe_cluster
)),
('ElasticLoadBalancing', 'any_instance_in_service'): lambda elb: core_waiter.Waiter(
'any_instance_in_service',
elb_model('AnyInstanceInService'),
core_waiter.NormalizedOperationMethod(
elb.describe_instance_health
)),
('ElasticLoadBalancing', 'instance_deregistered'): lambda elb: core_waiter.Waiter(
'instance_deregistered',
elb_model('InstanceDeregistered'),
core_waiter.NormalizedOperationMethod(
elb.describe_instance_health
)),
('ElasticLoadBalancing', 'instance_in_service'): lambda elb: core_waiter.Waiter(
'load_balancer_created',
elb_model('InstanceInService'),
core_waiter.NormalizedOperationMethod(
elb.describe_instance_health
)),
('ElasticLoadBalancing', 'load_balancer_created'): lambda elb: core_waiter.Waiter(
'load_balancer_created',
elb_model('LoadBalancerCreated'),
core_waiter.NormalizedOperationMethod(
elb.describe_load_balancers
)),
('ElasticLoadBalancing', 'load_balancer_deleted'): lambda elb: core_waiter.Waiter(
'load_balancer_deleted',
elb_model('LoadBalancerDeleted'),
core_waiter.NormalizedOperationMethod(
elb.describe_load_balancers
)),
('RDS', 'db_instance_stopped'): lambda rds: core_waiter.Waiter(
'db_instance_stopped',
rds_model('DBInstanceStopped'),
Expand Down
Loading

0 comments on commit 0d790f6

Please sign in to comment.