From 81028e86ad806032add638908a9fc5e894a0331c Mon Sep 17 00:00:00 2001 From: Ryan Lane Date: Fri, 9 Oct 2015 14:25:00 -0700 Subject: [PATCH] Various followup fixes for boto modules --- salt/modules/boto_elb.py | 15 +++--- salt/states/boto_asg.py | 4 +- salt/states/boto_elb.py | 11 ++-- salt/utils/boto_elb_tag.py | 101 ++++++++++++++++++++----------------- 4 files changed, 71 insertions(+), 60 deletions(-) diff --git a/salt/modules/boto_elb.py b/salt/modules/boto_elb.py index 831c772d18..733d6343be 100644 --- a/salt/modules/boto_elb.py +++ b/salt/modules/boto_elb.py @@ -77,7 +77,6 @@ except ImportError: # Import Salt libs from salt.ext.six import string_types -from salt.utils.boto_elb_tag import TagDescriptions as TagDescriptions import salt.utils.odict as odict @@ -165,7 +164,7 @@ def get_elb_config(name, region=None, key=None, keyid=None, profile=None): return [] -def _listener_dict_to_tuple(listener): +def listener_dict_to_tuple(listener): ''' Convert an ELB listener dict into a listener tuple used by certain parts of the AWS ELB API. @@ -206,7 +205,7 @@ def create(name, availability_zones, listeners, subnets=None, _complex_listeners = [] for listener in listeners: - _complex_listeners.append(_listener_dict_to_tuple(listener)) + _complex_listeners.append(listener_dict_to_tuple(listener)) try: lb = conn.create_load_balancer(name, availability_zones, [], subnets, security_groups, scheme, @@ -269,7 +268,7 @@ def create_listeners(name, listeners, region=None, key=None, keyid=None, _complex_listeners = [] for listener in listeners: - _complex_listeners.append(_listener_dict_to_tuple(listener)) + _complex_listeners.append(listener_dict_to_tuple(listener)) try: conn.create_load_balancer_listeners(name, [], _complex_listeners) msg = 'Created ELB listeners on {0}'.format(name) @@ -903,8 +902,12 @@ def _get_all_tags(conn, load_balancer_names=None): conn.build_list_params(params, load_balancer_names, 'LoadBalancerNames.member.%d') - tags = conn.get_object('DescribeTags', params, TagDescriptions, - verb='POST') + tags = conn.get_object( + 'DescribeTags', + params, + __utils__['boto_elb_tag.get_tag_descriptions'](), + verb='POST' + ) if tags[load_balancer_names]: return tags[load_balancer_names] else: diff --git a/salt/states/boto_asg.py b/salt/states/boto_asg.py index 90142f5be9..10ef6d594f 100644 --- a/salt/states/boto_asg.py +++ b/salt/states/boto_asg.py @@ -434,8 +434,8 @@ def present( if sg_index: log.debug('security group associations found in launch config') _group_ids = __salt__['boto_secgroup.convert_to_group_ids']( - launch_config[sg_index]['security_groups'], vpc_id, region, - key, keyid, profile + launch_config[sg_index]['security_groups'], vpc_id=vpc_id, + region=region, key=key, keyid=keyid, profile=profile ) launch_config[sg_index]['security_groups'] = _group_ids diff --git a/salt/states/boto_elb.py b/salt/states/boto_elb.py index f05dd9ff2a..6f2e56aaaf 100644 --- a/salt/states/boto_elb.py +++ b/salt/states/boto_elb.py @@ -548,7 +548,8 @@ def _elb_present( msg = 'Subnets {0} do not map to a valid vpc id.'.format(subnets) raise SaltInvocationError(msg) security_groups = __salt__['boto_secgroup.convert_to_group_ids']( - security_groups, vpc_id, region, key, keyid, profile + security_groups, vpc_id=vpc_id, region=region, key=key, + keyid=keyid, profile=profile ) if not security_groups: msg = 'Security groups {0} do not map to valid security group ids.' @@ -628,11 +629,11 @@ def _listeners_present( expected_listeners_by_tuple = {} for l in listeners: - key = __salt__['boto_elb._listener_dict_to_tuple'](l) + key = __salt__['boto_elb.listener_dict_to_tuple'](l) expected_listeners_by_tuple[key] = l actual_listeners_by_tuple = {} for l in lb['listeners']: - key = __salt__['boto_elb._listener_dict_to_tuple'](l) + key = __salt__['boto_elb.listener_dict_to_tuple'](l) actual_listeners_by_tuple[key] = l to_delete = [] @@ -651,10 +652,10 @@ def _listeners_present( msg.append('ELB {0} set to have listeners modified:'.format(name)) for listener in to_create: msg.append('Listener {0} added.'.format( - __salt__['boto_elb._listener_dict_to_tuple'](listener))) + __salt__['boto_elb.listener_dict_to_tuple'](listener))) for listener in to_delete: msg.append('Listener {0} deleted.'.format( - __salt__['boto_elb._listener_dict_to_tuple'](listener))) + __salt__['boto_elb.listener_dict_to_tuple'](listener))) else: msg.append('Listeners already set on ELB {0}.'.format(name)) ret['comment'] = ' '.join(msg) diff --git a/salt/utils/boto_elb_tag.py b/salt/utils/boto_elb_tag.py index a5dc04f750..0bfb233c24 100644 --- a/salt/utils/boto_elb_tag.py +++ b/salt/utils/boto_elb_tag.py @@ -22,57 +22,64 @@ # IN THE SOFTWARE. -class TagDescriptions(dict): - ''' - A TagDescriptions is used to collect the tags associated with ELB resources. - See :class:`boto.ec2.elb.LoadBalancer` for more details. - ''' - - def __init__(self, connection=None): - dict.__init__(self) - self.connection = connection - self._load_balancer_name = None - self._tags = None - - def startElement(self, name, attrs, connection): - if name == 'member': - self.load_balancer_name = None - self.tags = None - if name == 'Tags': - self._tags = TagSet() - return self._tags - return None - - def endElement(self, name, value, connection): - if name == 'LoadBalancerName': - self._load_balancer_name = value - elif name == 'member': - self[self._load_balancer_name] = self._tags +def __virtual__(): + return True -class TagSet(dict): - ''' - A TagSet is used to collect the tags associated with a particular - ELB resource. See :class:`boto.ec2.elb.LoadBalancer` for more - details. - ''' +def get_tag_descriptions(): + class TagDescriptions(dict): + ''' + A TagDescriptions is used to collect the tags associated with ELB + resources. + See :class:`boto.ec2.elb.LoadBalancer` for more details. + ''' - def __init__(self, connection=None): - dict.__init__(self) - self.connection = connection - self._current_key = None - self._current_value = None + def __init__(self, connection=None): + dict.__init__(self) + self.connection = connection + self._load_balancer_name = None + self._tags = None - def startElement(self, name, attrs, connection): - if name == 'member': + def startElement(self, name, attrs, connection): + if name == 'member': + self.load_balancer_name = None + self.tags = None + if name == 'Tags': + self._tags = TagSet() + return self._tags + return None + + def endElement(self, name, value, connection): + if name == 'LoadBalancerName': + self._load_balancer_name = value + elif name == 'member': + self[self._load_balancer_name] = self._tags + + class TagSet(dict): + ''' + A TagSet is used to collect the tags associated with a particular + ELB resource. See :class:`boto.ec2.elb.LoadBalancer` for more + details. + ''' + + def __init__(self, connection=None): + dict.__init__(self) + self.connection = connection self._current_key = None self._current_value = None - return None - def endElement(self, name, value, connection): - if name == 'Key': - self._current_key = value - elif name == 'Value': - self._current_value = value - elif name == 'member': - self[self._current_key] = self._current_value + def startElement(self, name, attrs, connection): + if name == 'member': + self._current_key = None + self._current_value = None + return None + + def endElement(self, name, value, connection): + if name == 'Key': + self._current_key = value + elif name == 'Value': + self._current_value = value + elif name == 'member': + self[self._current_key] = self._current_value + + return TagDescriptions