mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[cloud] ECS Service load balancer modification graceful fail (#32876)
It is not possible to modify the load balancer configuration for ECS Service. As it is possible to detect this, it's nicer to fail gracefully than return AWS's less meaningful failure message. Fix PEP8 compliance
This commit is contained in:
parent
b24d502682
commit
142cacfec3
1 changed files with 10 additions and 26 deletions
|
@ -334,32 +334,17 @@ class EcsServiceManager:
|
||||||
deploymentConfiguration=deployment_configuration,
|
deploymentConfiguration=deployment_configuration,
|
||||||
placementConstraints=placement_constraints,
|
placementConstraints=placement_constraints,
|
||||||
placementStrategy=placement_strategy)
|
placementStrategy=placement_strategy)
|
||||||
return self.jsonize(response['service'])
|
return response['service']
|
||||||
|
|
||||||
def update_service(self, service_name, cluster_name, task_definition,
|
def update_service(self, service_name, cluster_name, task_definition,
|
||||||
load_balancers, desired_count, client_token, role, deployment_configuration):
|
desired_count, deployment_configuration):
|
||||||
response = self.ecs.update_service(
|
response = self.ecs.update_service(
|
||||||
cluster=cluster_name,
|
cluster=cluster_name,
|
||||||
service=service_name,
|
service=service_name,
|
||||||
taskDefinition=task_definition,
|
taskDefinition=task_definition,
|
||||||
desiredCount=desired_count,
|
desiredCount=desired_count,
|
||||||
deploymentConfiguration=deployment_configuration)
|
deploymentConfiguration=deployment_configuration)
|
||||||
return self.jsonize(response['service'])
|
return response['service']
|
||||||
|
|
||||||
def jsonize(self, service):
|
|
||||||
# some fields are datetime which is not JSON serializable
|
|
||||||
# make them strings
|
|
||||||
if 'deployments' in service:
|
|
||||||
for d in service['deployments']:
|
|
||||||
if 'createdAt' in d:
|
|
||||||
d['createdAt'] = str(d['createdAt'])
|
|
||||||
if 'updatedAt' in d:
|
|
||||||
d['updatedAt'] = str(d['updatedAt'])
|
|
||||||
if 'events' in service:
|
|
||||||
for e in service['events']:
|
|
||||||
if 'createdAt' in e:
|
|
||||||
e['createdAt'] = str(e['createdAt'])
|
|
||||||
return service
|
|
||||||
|
|
||||||
def delete_service(self, service, cluster=None):
|
def delete_service(self, service, cluster=None):
|
||||||
return self.ecs.delete_service(cluster=cluster, service=service)
|
return self.ecs.delete_service(cluster=cluster, service=service)
|
||||||
|
@ -414,31 +399,30 @@ def main():
|
||||||
if existing and 'status' in existing and existing['status'] == "ACTIVE":
|
if existing and 'status' in existing and existing['status'] == "ACTIVE":
|
||||||
if service_mgr.is_matching_service(module.params, existing):
|
if service_mgr.is_matching_service(module.params, existing):
|
||||||
matching = True
|
matching = True
|
||||||
results['service'] = service_mgr.jsonize(existing)
|
results['service'] = existing
|
||||||
else:
|
else:
|
||||||
update = True
|
update = True
|
||||||
|
|
||||||
if not matching:
|
if not matching:
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
loadBalancers = module.params['load_balancers']
|
|
||||||
for loadBalancer in loadBalancers:
|
|
||||||
if 'containerPort' in loadBalancer:
|
|
||||||
loadBalancer['containerPort'] = int(loadBalancer['containerPort'])
|
|
||||||
|
|
||||||
role = module.params['role']
|
role = module.params['role']
|
||||||
clientToken = module.params['client_token']
|
clientToken = module.params['client_token']
|
||||||
|
loadBalancers = module.params['load_balancers']
|
||||||
|
|
||||||
if update:
|
if update:
|
||||||
|
if (existing['loadBalancers'] or []) != loadBalancers:
|
||||||
|
module.fail_json(msg="It is not possible to update the load balancers of an existing service")
|
||||||
# update required
|
# update required
|
||||||
response = service_mgr.update_service(module.params['name'],
|
response = service_mgr.update_service(module.params['name'],
|
||||||
module.params['cluster'],
|
module.params['cluster'],
|
||||||
module.params['task_definition'],
|
module.params['task_definition'],
|
||||||
loadBalancers,
|
|
||||||
module.params['desired_count'],
|
module.params['desired_count'],
|
||||||
clientToken,
|
|
||||||
role,
|
|
||||||
deploymentConfiguration)
|
deploymentConfiguration)
|
||||||
else:
|
else:
|
||||||
|
for loadBalancer in loadBalancers:
|
||||||
|
if 'containerPort' in loadBalancer:
|
||||||
|
loadBalancer['containerPort'] = int(loadBalancer['containerPort'])
|
||||||
# doesn't exist. create it.
|
# doesn't exist. create it.
|
||||||
response = service_mgr.create_service(module.params['name'],
|
response = service_mgr.create_service(module.params['name'],
|
||||||
module.params['cluster'],
|
module.params['cluster'],
|
||||||
|
|
Loading…
Reference in a new issue