/src/boto/boto/vpc/vpngateway.py

http://gsutil.googlecode.com/ · Python · 83 lines · 47 code · 13 blank · 23 comment · 11 complexity · 59d53dbc9a4da5c1b0e1ebb7fffcc54c MD5 · raw file

  1. # Copyright (c) 2009-2010 Mitch Garnaat http://garnaat.org/
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a
  4. # copy of this software and associated documentation files (the
  5. # "Software"), to deal in the Software without restriction, including
  6. # without limitation the rights to use, copy, modify, merge, publish, dis-
  7. # tribute, sublicense, and/or sell copies of the Software, and to permit
  8. # persons to whom the Software is furnished to do so, subject to the fol-
  9. # lowing conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included
  12. # in all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  16. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  17. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. # IN THE SOFTWARE.
  21. """
  22. Represents a Vpn Gateway
  23. """
  24. from boto.ec2.ec2object import TaggedEC2Object
  25. class Attachment(object):
  26. def __init__(self, connection=None):
  27. self.vpc_id = None
  28. self.state = None
  29. def startElement(self, name, attrs, connection):
  30. pass
  31. def endElement(self, name, value, connection):
  32. if name == 'vpcId':
  33. self.vpc_id = value
  34. elif name == 'state':
  35. self.state = value
  36. else:
  37. setattr(self, name, value)
  38. class VpnGateway(TaggedEC2Object):
  39. def __init__(self, connection=None):
  40. TaggedEC2Object.__init__(self, connection)
  41. self.id = None
  42. self.type = None
  43. self.state = None
  44. self.availability_zone = None
  45. self.attachments = []
  46. def __repr__(self):
  47. return 'VpnGateway:%s' % self.id
  48. def startElement(self, name, attrs, connection):
  49. retval = TaggedEC2Object.startElement(self, name, attrs, connection)
  50. if retval is not None:
  51. return retval
  52. if name == 'item':
  53. att = Attachment()
  54. self.attachments.append(att)
  55. return att
  56. def endElement(self, name, value, connection):
  57. if name == 'vpnGatewayId':
  58. self.id = value
  59. elif name == 'type':
  60. self.type = value
  61. elif name == 'state':
  62. self.state = value
  63. elif name == 'availabilityZone':
  64. self.availability_zone = value
  65. elif name == 'attachments':
  66. pass
  67. else:
  68. setattr(self, name, value)
  69. def attach(self, vpc_id):
  70. return self.connection.attach_vpn_gateway(self.id, vpc_id)