PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 1ms

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

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