Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: boto/ec2/instance.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « boto/ec2/image.py ('k') | boto/ec2/keypair.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/
2 # Copyright (c) 2010, Eucalyptus Systems, Inc. 2 # Copyright (c) 2010, Eucalyptus Systems, Inc.
3 # 3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a 4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the 5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including 6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis- 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 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- 9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions: 10 # lowing conditions:
(...skipping 14 matching lines...) Expand all
25 """ 25 """
26 import boto 26 import boto
27 from boto.ec2.ec2object import EC2Object, TaggedEC2Object 27 from boto.ec2.ec2object import EC2Object, TaggedEC2Object
28 from boto.resultset import ResultSet 28 from boto.resultset import ResultSet
29 from boto.ec2.address import Address 29 from boto.ec2.address import Address
30 from boto.ec2.blockdevicemapping import BlockDeviceMapping 30 from boto.ec2.blockdevicemapping import BlockDeviceMapping
31 from boto.ec2.image import ProductCodes 31 from boto.ec2.image import ProductCodes
32 import base64 32 import base64
33 33
34 class Reservation(EC2Object): 34 class Reservation(EC2Object):
35 """
36 Represents a Reservation response object.
37
38 :ivar id: The unique ID of the Reservation.
39 :ivar owner_id: The unique ID of the owner of the Reservation.
40 :ivar groups: A list of Group objects representing the security
41 groups associated with launched instances.
42 :ivar instances: A list of Instance objects launched in this
43 Reservation.
44 """
35 45
36 def __init__(self, connection=None): 46 def __init__(self, connection=None):
37 EC2Object.__init__(self, connection) 47 EC2Object.__init__(self, connection)
38 self.id = None 48 self.id = None
39 self.owner_id = None 49 self.owner_id = None
40 self.groups = [] 50 self.groups = []
41 self.instances = [] 51 self.instances = []
42 52
43 def __repr__(self): 53 def __repr__(self):
44 return 'Reservation:%s' % self.id 54 return 'Reservation:%s' % self.id
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 self.ip_address = None 106 self.ip_address = None
97 self.requester_id = None 107 self.requester_id = None
98 self._in_monitoring_element = False 108 self._in_monitoring_element = False
99 self.persistent = False 109 self.persistent = False
100 self.root_device_name = None 110 self.root_device_name = None
101 self.root_device_type = None 111 self.root_device_type = None
102 self.block_device_mapping = None 112 self.block_device_mapping = None
103 self.state_reason = None 113 self.state_reason = None
104 self.group_name = None 114 self.group_name = None
105 self.client_token = None 115 self.client_token = None
116 self.groups = []
106 117
107 def __repr__(self): 118 def __repr__(self):
108 return 'Instance:%s' % self.id 119 return 'Instance:%s' % self.id
109 120
110 def startElement(self, name, attrs, connection): 121 def startElement(self, name, attrs, connection):
111 retval = TaggedEC2Object.startElement(self, name, attrs, connection) 122 retval = TaggedEC2Object.startElement(self, name, attrs, connection)
112 if retval is not None: 123 if retval is not None:
113 return retval 124 return retval
114 if name == 'monitoring': 125 if name == 'monitoring':
115 self._in_monitoring_element = True 126 self._in_monitoring_element = True
116 elif name == 'blockDeviceMapping': 127 elif name == 'blockDeviceMapping':
117 self.block_device_mapping = BlockDeviceMapping() 128 self.block_device_mapping = BlockDeviceMapping()
118 return self.block_device_mapping 129 return self.block_device_mapping
119 elif name == 'productCodes': 130 elif name == 'productCodes':
120 return self.product_codes 131 return self.product_codes
121 elif name == 'stateReason': 132 elif name == 'stateReason':
122 self.state_reason = StateReason() 133 self.state_reason = StateReason()
123 return self.state_reason 134 return self.state_reason
135 elif name == 'groupSet':
136 self.groups = ResultSet([('item', Group)])
137 return self.groups
124 return None 138 return None
125 139
126 def endElement(self, name, value, connection): 140 def endElement(self, name, value, connection):
127 if name == 'instanceId': 141 if name == 'instanceId':
128 self.id = value 142 self.id = value
129 elif name == 'imageId': 143 elif name == 'imageId':
130 self.image_id = value 144 self.image_id = value
131 elif name == 'dnsName' or name == 'publicDnsName': 145 elif name == 'dnsName' or name == 'publicDnsName':
132 self.dns_name = value # backwards compatibility 146 self.dns_name = value # backwards compatibility
133 self.public_dns_name = value 147 self.public_dns_name = value
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 self._update(i) 236 self._update(i)
223 elif validate: 237 elif validate:
224 raise ValueError('%s is not a valid Instance ID' % self.id) 238 raise ValueError('%s is not a valid Instance ID' % self.id)
225 return self.state 239 return self.state
226 240
227 def terminate(self): 241 def terminate(self):
228 """ 242 """
229 Terminate the instance 243 Terminate the instance
230 """ 244 """
231 rs = self.connection.terminate_instances([self.id]) 245 rs = self.connection.terminate_instances([self.id])
232 self._update(rs[0]) 246 if len(rs) > 0:
247 self._update(rs[0])
233 248
234 def stop(self, force=False): 249 def stop(self, force=False):
235 """ 250 """
236 Stop the instance 251 Stop the instance
237 252
238 :type force: bool 253 :type force: bool
239 :param force: Forces the instance to stop 254 :param force: Forces the instance to stop
240 255
241 :rtype: list 256 :rtype: list
242 :return: A list of the instances stopped 257 :return: A list of the instances stopped
243 """ 258 """
244 rs = self.connection.stop_instances([self.id]) 259 rs = self.connection.stop_instances([self.id])
245 self._update(rs[0]) 260 if len(rs) > 0:
261 self._update(rs[0])
246 262
247 def start(self): 263 def start(self):
248 """ 264 """
249 Start the instance. 265 Start the instance.
250 """ 266 """
251 rs = self.connection.start_instances([self.id]) 267 rs = self.connection.start_instances([self.id])
252 self._update(rs[0]) 268 if len(rs) > 0:
269 self._update(rs[0])
253 270
254 def reboot(self): 271 def reboot(self):
255 return self.connection.reboot_instances([self.id]) 272 return self.connection.reboot_instances([self.id])
256 273
257 def get_console_output(self): 274 def get_console_output(self):
258 """ 275 """
259 Retrieves the console output for the instance. 276 Retrieves the console output for the instance.
260 277
261 :rtype: :class:`boto.ec2.instance.ConsoleOutput` 278 :rtype: :class:`boto.ec2.instance.ConsoleOutput`
262 :return: The console output as a ConsoleOutput object 279 :return: The console output as a ConsoleOutput object
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 346
330 :rtype: bool 347 :rtype: bool
331 :return: Whether the operation succeeded or not 348 :return: Whether the operation succeeded or not
332 """ 349 """
333 return self.connection.reset_instance_attribute(self.id, attribute) 350 return self.connection.reset_instance_attribute(self.id, attribute)
334 351
335 class Group: 352 class Group:
336 353
337 def __init__(self, parent=None): 354 def __init__(self, parent=None):
338 self.id = None 355 self.id = None
356 self.name = None
339 357
340 def startElement(self, name, attrs, connection): 358 def startElement(self, name, attrs, connection):
341 return None 359 return None
342 360
343 def endElement(self, name, value, connection): 361 def endElement(self, name, value, connection):
344 if name == 'groupId': 362 if name == 'groupId':
345 self.id = value 363 self.id = value
364 elif name == 'groupName':
365 self.name = value
346 else: 366 else:
347 setattr(self, name, value) 367 setattr(self, name, value)
348 368
349 class ConsoleOutput: 369 class ConsoleOutput:
350 370
351 def __init__(self, parent=None): 371 def __init__(self, parent=None):
352 self.parent = parent 372 self.parent = parent
353 self.instance_id = None 373 self.instance_id = None
354 self.timestamp = None 374 self.timestamp = None
355 self.comment = None 375 self.output = None
356 376
357 def startElement(self, name, attrs, connection): 377 def startElement(self, name, attrs, connection):
358 return None 378 return None
359 379
360 def endElement(self, name, value, connection): 380 def endElement(self, name, value, connection):
361 if name == 'instanceId': 381 if name == 'instanceId':
362 self.instance_id = value 382 self.instance_id = value
383 elif name == 'timestamp':
384 self.timestamp = value
363 elif name == 'output': 385 elif name == 'output':
364 self.output = base64.b64decode(value) 386 self.output = base64.b64decode(value)
365 else: 387 else:
366 setattr(self, name, value) 388 setattr(self, name, value)
367 389
368 class InstanceAttribute(dict): 390 class InstanceAttribute(dict):
369 391
392 ValidValues = ['instanceType', 'kernel', 'ramdisk', 'userData',
393 'disableApiTermination', 'instanceInitiatedShutdownBehavior',
394 'rootDeviceName', 'blockDeviceMapping', 'sourceDestCheck',
395 'groupSet']
396
370 def __init__(self, parent=None): 397 def __init__(self, parent=None):
371 dict.__init__(self) 398 dict.__init__(self)
399 self.instance_id = None
400 self.request_id = None
372 self._current_value = None 401 self._current_value = None
373 402
374 def startElement(self, name, attrs, connection): 403 def startElement(self, name, attrs, connection):
375 return None 404 if name == 'blockDeviceMapping':
405 self[name] = BlockDeviceMapping()
406 return self[name]
407 elif name == 'groupSet':
408 self[name] = ResultSet([('item', Group)])
409 return self[name]
410 else:
411 return None
376 412
377 def endElement(self, name, value, connection): 413 def endElement(self, name, value, connection):
378 if name == 'value': 414 if name == 'instanceId':
415 self.instance_id = value
416 elif name == 'requestId':
417 self.request_id = value
418 elif name == 'value':
379 self._current_value = value 419 self._current_value = value
380 else: 420 elif name in self.ValidValues:
381 self[name] = self._current_value 421 self[name] = self._current_value
382 422
383 class StateReason(dict): 423 class StateReason(dict):
384 424
385 def __init__(self, parent=None): 425 def __init__(self, parent=None):
386 dict.__init__(self) 426 dict.__init__(self)
387 427
388 def startElement(self, name, attrs, connection): 428 def startElement(self, name, attrs, connection):
389 return None 429 return None
390 430
391 def endElement(self, name, value, connection): 431 def endElement(self, name, value, connection):
392 if name != 'stateReason': 432 if name != 'stateReason':
393 self[name] = value 433 self[name] = value
394 434
OLDNEW
« no previous file with comments | « boto/ec2/image.py ('k') | boto/ec2/keypair.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698