1# Copyright (c) 2010 Mitch Garnaat http://garnaat.org/ 2# Copyright (c) 2010, Eucalyptus Systems, Inc. 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the 6# "Software"), to deal in the Software without restriction, including 7# without limitation the rights to use, copy, modify, merge, publish, dis- 8# tribute, sublicense, and/or sell copies of the Software, and to permit 9# persons to whom the Software is furnished to do so, subject to the fol- 10# lowing conditions: 11# 12# The above copyright notice and this permission notice shall be included 13# in all copies or substantial portions of the Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 17# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 18# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21# IN THE SOFTWARE. 22 23 24def __virtual__(): 25 return True 26 27 28def get_tag_descriptions(): 29 class TagDescriptions(dict): 30 """ 31 A TagDescriptions is used to collect the tags associated with ELB 32 resources. 33 See :class:`boto.ec2.elb.LoadBalancer` for more details. 34 """ 35 36 def __init__(self, connection=None): 37 dict.__init__(self) 38 self.connection = connection 39 self._load_balancer_name = None 40 self._tags = None 41 42 def startElement(self, name, attrs, connection): 43 if name == "member": 44 self.load_balancer_name = None 45 self.tags = None 46 if name == "Tags": 47 self._tags = TagSet() 48 return self._tags 49 return None 50 51 def endElement(self, name, value, connection): 52 if name == "LoadBalancerName": 53 self._load_balancer_name = value 54 elif name == "member": 55 self[self._load_balancer_name] = self._tags 56 57 class TagSet(dict): 58 """ 59 A TagSet is used to collect the tags associated with a particular 60 ELB resource. See :class:`boto.ec2.elb.LoadBalancer` for more 61 details. 62 """ 63 64 def __init__(self, connection=None): 65 dict.__init__(self) 66 self.connection = connection 67 self._current_key = None 68 self._current_value = None 69 70 def startElement(self, name, attrs, connection): 71 if name == "member": 72 self._current_key = None 73 self._current_value = None 74 return None 75 76 def endElement(self, name, value, connection): 77 if name == "Key": 78 self._current_key = value 79 elif name == "Value": 80 self._current_value = value 81 elif name == "member": 82 self[self._current_key] = self._current_value 83 84 return TagDescriptions 85