Skip to content

Commit

Permalink
Find ELB to change by Name when changing traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcs committed Aug 25, 2016
1 parent e40ceba commit ad14b92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
exclude_lines =
pragma: no cover
def __repr__
def __str__
omit =
senza/__main__.py
12 changes: 10 additions & 2 deletions senza/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from clickclick import Action, action, ok, print_table, warning

from .aws import StackReference, get_stacks, get_tag
from .manaus.cloudformation import CloudFormationStack
from .manaus.cloudformation import CloudFormationStack, ResourceType
from .manaus.exceptions import StackNotFound, StackNotUpdated
from .manaus.route53 import (RecordType, Route53, Route53HostedZone,
convert_domain_records_to_alias)
Expand Down Expand Up @@ -150,7 +150,15 @@ def set_new_weights(dns_names: list, identifier, lb_dns_name: str,
"because traffic for it is 0".format(stack_name))
changed = True
continue
load_balancer = stack.template['Resources']['AppLoadBalancerMainDomain']

for key, resource in stack.template['Resources'].items():
if (resource['Type'] == ResourceType.route53_record_set and
resource['Properties']['Name'] == dns_name):
load_balancer = stack.template['Resources'][key]
break

# TODO error handling

load_balancer['Properties']['Weight'] = percentage
try:
stack.update()
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,13 @@ def get_stack(name, region):
assert region == 'aa-fakeregion-1'
if name not in m_stacks:
stack = m_stacks[name]
resources = {'AppLoadBalancerMainDomain': {'Properties': {'Weight': 20}}}
resources = {
'AppLoadBalancerMainDomain': {
'Type': 'AWS::Route53::RecordSet',
'Properties': {'Weight': 20,
'Name': 'myapp.zo.ne.'}
}
}
stack.template = {'Resources': resources}
return m_stacks[name]
m_cfs.get_by_stack_name = get_stack
Expand Down

0 comments on commit ad14b92

Please sign in to comment.