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 from boto.ec2.instancestatus import Status, Details |
| 25 |
| 26 class Event(object): |
| 27 """ |
| 28 A status event for an instance. |
| 29 |
| 30 :ivar type: The type of the event. |
| 31 :ivar id: The ID of the event. |
| 32 :ivar description: A string describing the reason for the event. |
| 33 :ivar not_before: A datestring describing the earliest time for |
| 34 the event. |
| 35 :ivar not_after: A datestring describing the latest time for |
| 36 the event. |
| 37 """ |
| 38 |
| 39 def __init__(self, type=None, id=None, description=None, |
| 40 not_before=None, not_after=None): |
| 41 self.type = type |
| 42 self.id = id |
| 43 self.description = description |
| 44 self.not_before = not_before |
| 45 self.not_after = not_after |
| 46 |
| 47 def __repr__(self): |
| 48 return 'Event:%s' % self.type |
| 49 |
| 50 def startElement(self, name, attrs, connection): |
| 51 return None |
| 52 |
| 53 def endElement(self, name, value, connection): |
| 54 if name == 'eventType': |
| 55 self.type = value |
| 56 elif name == 'eventId': |
| 57 self.id = value |
| 58 elif name == 'description': |
| 59 self.description = value |
| 60 elif name == 'notBefore': |
| 61 self.not_before = value |
| 62 elif name == 'notAfter': |
| 63 self.not_after = value |
| 64 else: |
| 65 setattr(self, name, value) |
| 66 |
| 67 class EventSet(list): |
| 68 |
| 69 def startElement(self, name, attrs, connection): |
| 70 if name == 'item': |
| 71 event = Event() |
| 72 self.append(event) |
| 73 return event |
| 74 else: |
| 75 return None |
| 76 |
| 77 def endElement(self, name, value, connection): |
| 78 setattr(self, name, value) |
| 79 |
| 80 class Action(object): |
| 81 """ |
| 82 An action for an instance. |
| 83 |
| 84 :ivar code: The code for the type of the action. |
| 85 :ivar id: The ID of the event. |
| 86 :ivar type: The type of the event. |
| 87 :ivar description: A description of the action. |
| 88 """ |
| 89 |
| 90 def __init__(self, code=None, id=None, description=None, type=None): |
| 91 self.code = code |
| 92 self.id = id |
| 93 self.type = type |
| 94 self.description = description |
| 95 |
| 96 def __repr__(self): |
| 97 return 'Action:%s' % self.code |
| 98 |
| 99 def startElement(self, name, attrs, connection): |
| 100 return None |
| 101 |
| 102 def endElement(self, name, value, connection): |
| 103 if name == 'eventType': |
| 104 self.type = value |
| 105 elif name == 'eventId': |
| 106 self.id = value |
| 107 elif name == 'description': |
| 108 self.description = value |
| 109 elif name == 'code': |
| 110 self.code = value |
| 111 else: |
| 112 setattr(self, name, value) |
| 113 |
| 114 class ActionSet(list): |
| 115 |
| 116 def startElement(self, name, attrs, connection): |
| 117 if name == 'item': |
| 118 action = Action() |
| 119 self.append(action) |
| 120 return action |
| 121 else: |
| 122 return None |
| 123 |
| 124 def endElement(self, name, value, connection): |
| 125 setattr(self, name, value) |
| 126 |
| 127 class VolumeStatus(object): |
| 128 """ |
| 129 Represents an EC2 Volume status as reported by |
| 130 DescribeVolumeStatus request. |
| 131 |
| 132 :ivar id: The volume identifier. |
| 133 :ivar zone: The availability zone of the volume |
| 134 :ivar volume_status: A Status object that reports impaired |
| 135 functionality that arises from problems internal to the instance. |
| 136 :ivar events: A list of events relevant to the instance. |
| 137 :ivar actions: A list of events relevant to the instance. |
| 138 """ |
| 139 |
| 140 def __init__(self, id=None, zone=None): |
| 141 self.id = id |
| 142 self.zone = zone |
| 143 self.volume_status = Status() |
| 144 self.events = None |
| 145 self.actions = None |
| 146 |
| 147 def __repr__(self): |
| 148 return 'VolumeStatus:%s' % self.id |
| 149 |
| 150 def startElement(self, name, attrs, connection): |
| 151 if name == 'eventsSet': |
| 152 self.events = EventSet() |
| 153 return self.events |
| 154 elif name == 'actionsSet': |
| 155 self.actions = ActionSet() |
| 156 return self.actions |
| 157 elif name == 'volumeStatus': |
| 158 return self.volume_status |
| 159 else: |
| 160 return None |
| 161 |
| 162 def endElement(self, name, value, connection): |
| 163 if name == 'volumeId': |
| 164 self.id = value |
| 165 elif name == 'availabilityZone': |
| 166 self.zone = value |
| 167 else: |
| 168 setattr(self, name, value) |
| 169 |
| 170 class VolumeStatusSet(list): |
| 171 """ |
| 172 A list object that contains the results of a call to |
| 173 DescribeVolumeStatus request. Each element of the |
| 174 list will be an VolumeStatus object. |
| 175 |
| 176 :ivar next_token: If the response was truncated by |
| 177 the EC2 service, the next_token attribute of the |
| 178 object will contain the string that needs to be |
| 179 passed in to the next request to retrieve the next |
| 180 set of results. |
| 181 """ |
| 182 |
| 183 def __init__(self, connection=None): |
| 184 list.__init__(self) |
| 185 self.connection = connection |
| 186 self.next_token = None |
| 187 |
| 188 def startElement(self, name, attrs, connection): |
| 189 if name == 'item': |
| 190 status = VolumeStatus() |
| 191 self.append(status) |
| 192 return status |
| 193 else: |
| 194 return None |
| 195 |
| 196 def endElement(self, name, value, connection): |
| 197 if name == 'NextToken': |
| 198 self.next_token = value |
| 199 setattr(self, name, value) |
| 200 |
OLD | NEW |