PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/launchspecification.py

#
Python | 96 lines | 61 code | 12 blank | 23 comment | 17 complexity | fec2126cc129a247881757fd701e6846 MD5 | raw file
  1. # Copyright (c) 2006-2009 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 launch specification for Spot instances.
  23. """
  24. from boto.ec2.ec2object import EC2Object
  25. from boto.resultset import ResultSet
  26. from boto.ec2.blockdevicemapping import BlockDeviceMapping
  27. from boto.ec2.group import Group
  28. class GroupList(list):
  29. def startElement(self, name, attrs, connection):
  30. pass
  31. def endElement(self, name, value, connection):
  32. if name == 'groupId':
  33. self.append(value)
  34. class LaunchSpecification(EC2Object):
  35. def __init__(self, connection=None):
  36. EC2Object.__init__(self, connection)
  37. self.key_name = None
  38. self.instance_type = None
  39. self.image_id = None
  40. self.groups = []
  41. self.placement = None
  42. self.kernel = None
  43. self.ramdisk = None
  44. self.monitored = False
  45. self.subnet_id = None
  46. self._in_monitoring_element = False
  47. self.block_device_mapping = None
  48. def __repr__(self):
  49. return 'LaunchSpecification(%s)' % self.image_id
  50. def startElement(self, name, attrs, connection):
  51. if name == 'groupSet':
  52. self.groups = ResultSet([('item', Group)])
  53. return self.groups
  54. elif name == 'monitoring':
  55. self._in_monitoring_element = True
  56. elif name == 'blockDeviceMapping':
  57. self.block_device_mapping = BlockDeviceMapping()
  58. return self.block_device_mapping
  59. else:
  60. return None
  61. def endElement(self, name, value, connection):
  62. if name == 'imageId':
  63. self.image_id = value
  64. elif name == 'keyName':
  65. self.key_name = value
  66. elif name == 'instanceType':
  67. self.instance_type = value
  68. elif name == 'availabilityZone':
  69. self.placement = value
  70. elif name == 'placement':
  71. pass
  72. elif name == 'kernelId':
  73. self.kernel = value
  74. elif name == 'ramdiskId':
  75. self.ramdisk = value
  76. elif name == 'subnetId':
  77. self.subnet_id = value
  78. elif name == 'state':
  79. if self._in_monitoring_element:
  80. if value == 'enabled':
  81. self.monitored = True
  82. self._in_monitoring_element = False
  83. else:
  84. setattr(self, name, value)