PageRenderTime 93ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/spotinstancerequest.py

#
Python | 115 lines | 76 code | 15 blank | 24 comment | 19 complexity | 26e92200be4ab3db3090d702f90e7e35 MD5 | raw file
  1. # Copyright (c) 2006-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. Represents an EC2 Spot Instance Request
  24. """
  25. from boto.ec2.ec2object import TaggedEC2Object
  26. from boto.ec2.launchspecification import LaunchSpecification
  27. class SpotInstanceStateFault(object):
  28. def __init__(self, code=None, message=None):
  29. self.code = code
  30. self.message = message
  31. def __repr__(self):
  32. return '(%s, %s)' % (self.code, self.message)
  33. def startElement(self, name, attrs, connection):
  34. return None
  35. def endElement(self, name, value, connection):
  36. if name == 'code':
  37. self.code = value
  38. elif name == 'message':
  39. self.message = value
  40. setattr(self, name, value)
  41. class SpotInstanceRequest(TaggedEC2Object):
  42. def __init__(self, connection=None):
  43. TaggedEC2Object.__init__(self, connection)
  44. self.id = None
  45. self.price = None
  46. self.type = None
  47. self.state = None
  48. self.fault = None
  49. self.valid_from = None
  50. self.valid_until = None
  51. self.launch_group = None
  52. self.launched_availability_zone = None
  53. self.product_description = None
  54. self.availability_zone_group = None
  55. self.create_time = None
  56. self.launch_specification = None
  57. self.instance_id = None
  58. def __repr__(self):
  59. return 'SpotInstanceRequest:%s' % self.id
  60. def startElement(self, name, attrs, connection):
  61. retval = TaggedEC2Object.startElement(self, name, attrs, connection)
  62. if retval is not None:
  63. return retval
  64. if name == 'launchSpecification':
  65. self.launch_specification = LaunchSpecification(connection)
  66. return self.launch_specification
  67. elif name == 'fault':
  68. self.fault = SpotInstanceStateFault()
  69. return self.fault
  70. else:
  71. return None
  72. def endElement(self, name, value, connection):
  73. if name == 'spotInstanceRequestId':
  74. self.id = value
  75. elif name == 'spotPrice':
  76. self.price = float(value)
  77. elif name == 'type':
  78. self.type = value
  79. elif name == 'state':
  80. self.state = value
  81. elif name == 'validFrom':
  82. self.valid_from = value
  83. elif name == 'validUntil':
  84. self.valid_until = value
  85. elif name == 'launchGroup':
  86. self.launch_group = value
  87. elif name == 'availabilityZoneGroup':
  88. self.availability_zone_group = value
  89. elif name == 'launchedAvailabilityZone':
  90. self.launched_availability_zone = value
  91. elif name == 'instanceId':
  92. self.instance_id = value
  93. elif name == 'createTime':
  94. self.create_time = value
  95. elif name == 'productDescription':
  96. self.product_description = value
  97. else:
  98. setattr(self, name, value)
  99. def cancel(self):
  100. self.connection.cancel_spot_instance_requests([self.id])