OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. |
| 3 # All Rights Reserved |
| 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. |
| 23 |
| 24 class Details(dict): |
| 25 """ |
| 26 A dict object that contains name/value pairs which provide |
| 27 more detailed information about the status of the system |
| 28 or the instance. |
| 29 """ |
| 30 |
| 31 def startElement(self, name, attrs, connection): |
| 32 return None |
| 33 |
| 34 def endElement(self, name, value, connection): |
| 35 if name == 'name': |
| 36 self._name = value |
| 37 elif name == 'status': |
| 38 self[self._name] = value |
| 39 else: |
| 40 setattr(self, name, value) |
| 41 |
| 42 class Event(object): |
| 43 """ |
| 44 A status event for an instance. |
| 45 |
| 46 :ivar code: A string indicating the event type. |
| 47 :ivar description: A string describing the reason for the event. |
| 48 :ivar not_before: A datestring describing the earliest time for |
| 49 the event. |
| 50 :ivar not_after: A datestring describing the latest time for |
| 51 the event. |
| 52 """ |
| 53 |
| 54 def __init__(self, code=None, description=None, |
| 55 not_before=None, not_after=None): |
| 56 self.code = code |
| 57 self.description = description |
| 58 self.not_before = not_before |
| 59 self.not_after = not_after |
| 60 |
| 61 def __repr__(self): |
| 62 return 'Event:%s' % self.code |
| 63 |
| 64 def startElement(self, name, attrs, connection): |
| 65 return None |
| 66 |
| 67 def endElement(self, name, value, connection): |
| 68 if name == 'code': |
| 69 self.code = value |
| 70 elif name == 'description': |
| 71 self.description = value |
| 72 elif name == 'notBefore': |
| 73 self.not_before = value |
| 74 elif name == 'notAfter': |
| 75 self.not_after = value |
| 76 else: |
| 77 setattr(self, name, value) |
| 78 |
| 79 class Status(object): |
| 80 """ |
| 81 A generic Status object used for system status and instance status. |
| 82 |
| 83 :ivar status: A string indicating overall status. |
| 84 :ivar details: A dict containing name-value pairs which provide |
| 85 more details about the current status. |
| 86 """ |
| 87 |
| 88 def __init__(self, status=None, details=None): |
| 89 self.status = status |
| 90 if not details: |
| 91 details = Details() |
| 92 self.details = details |
| 93 |
| 94 def __repr__(self): |
| 95 return 'Status:%s' % self.status |
| 96 |
| 97 def startElement(self, name, attrs, connection): |
| 98 if name == 'details': |
| 99 return self.details |
| 100 return None |
| 101 |
| 102 def endElement(self, name, value, connection): |
| 103 if name == 'status': |
| 104 self.status = value |
| 105 else: |
| 106 setattr(self, name, value) |
| 107 |
| 108 class EventSet(list): |
| 109 |
| 110 def startElement(self, name, attrs, connection): |
| 111 if name == 'item': |
| 112 event = Event() |
| 113 self.append(event) |
| 114 return event |
| 115 else: |
| 116 return None |
| 117 |
| 118 def endElement(self, name, value, connection): |
| 119 setattr(self, name, value) |
| 120 |
| 121 class InstanceStatus(object): |
| 122 """ |
| 123 Represents an EC2 Instance status as reported by |
| 124 DescribeInstanceStatus request. |
| 125 |
| 126 :ivar id: The instance identifier. |
| 127 :ivar zone: The availability zone of the instance. |
| 128 :ivar events: A list of events relevant to the instance. |
| 129 :ivar state_code: An integer representing the current state |
| 130 of the instance. |
| 131 :ivar state_name: A string describing the current state |
| 132 of the instance. |
| 133 :ivar system_status: A Status object that reports impaired |
| 134 functionality that stems from issues related to the systems |
| 135 that support an instance, such as such as hardware failures |
| 136 and network connectivity problems. |
| 137 :ivar instance_status: A Status object that reports impaired |
| 138 functionality that arises from problems internal to the instance. |
| 139 """ |
| 140 |
| 141 def __init__(self, id=None, zone=None, events=None, |
| 142 state_code=None, state_name=None): |
| 143 self.id = id |
| 144 self.zone = zone |
| 145 self.events = events |
| 146 self.state_code = state_code |
| 147 self.state_name = state_name |
| 148 self.system_status = Status() |
| 149 self.instance_status = Status() |
| 150 |
| 151 def __repr__(self): |
| 152 return 'InstanceStatus:%s' % self.id |
| 153 |
| 154 def startElement(self, name, attrs, connection): |
| 155 if name == 'eventsSet': |
| 156 self.events = EventSet() |
| 157 return self.events |
| 158 elif name == 'systemStatus': |
| 159 return self.system_status |
| 160 elif name == 'instanceStatus': |
| 161 return self.instance_status |
| 162 else: |
| 163 return None |
| 164 |
| 165 def endElement(self, name, value, connection): |
| 166 if name == 'instanceId': |
| 167 self.id = value |
| 168 elif name == 'availabilityZone': |
| 169 self.zone = value |
| 170 elif name == 'code': |
| 171 self.state_code = int(value) |
| 172 elif name == 'name': |
| 173 self.state_name = value |
| 174 else: |
| 175 setattr(self, name, value) |
| 176 |
| 177 class InstanceStatusSet(list): |
| 178 """ |
| 179 A list object that contains the results of a call to |
| 180 DescribeInstanceStatus request. Each element of the |
| 181 list will be an InstanceStatus object. |
| 182 |
| 183 :ivar next_token: If the response was truncated by |
| 184 the EC2 service, the next_token attribute of the |
| 185 object will contain the string that needs to be |
| 186 passed in to the next request to retrieve the next |
| 187 set of results. |
| 188 """ |
| 189 |
| 190 def __init__(self, connection=None): |
| 191 list.__init__(self) |
| 192 self.connection = connection |
| 193 self.next_token = None |
| 194 |
| 195 def startElement(self, name, attrs, connection): |
| 196 if name == 'item': |
| 197 status = InstanceStatus() |
| 198 self.append(status) |
| 199 return status |
| 200 else: |
| 201 return None |
| 202 |
| 203 def endElement(self, name, value, connection): |
| 204 if name == 'NextToken': |
| 205 self.next_token = value |
| 206 setattr(self, name, value) |
| 207 |
OLD | NEW |