Skip to content

Commit ffc6cc0

Browse files
gholmstoastdriven
authored andcommitted
Start moving get_all_instances to get_all_reservations
get_all_instances doesn't actually get all instances, but rather gets all *reservations*, which themselves contain instances. This commit starts the process of making get_all_instances actually return a list of instances by doing a few things: 1. Rename the current get_all_instances to get_all_reservations. 2. Make get_all_instances a stub that warns and then calls get_all_reservations. 3. Add a new get_only_instances method that will eventually become the new behavior of get_all_instances. People can then transition to get_all_reservations and get_only_instances as appropriate until get_all_instances finally switches over in a future release.
1 parent 8ff4a4b commit ffc6cc0

File tree

14 files changed

+78
-19
lines changed

14 files changed

+78
-19
lines changed

bin/elbadmin

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ def get(elb, name):
118118
instances = [state.instance_id for state in instance_health]
119119

120120
names = {}
121-
for r in ec2.get_all_instances(instances):
122-
for i in r.instances:
123-
names[i.id] = i.tags.get('Name', '')
121+
for i in ec2.get_only_instances(instances):
122+
names[i.id] = i.tags.get('Name', '')
124123

125124
name_column_width = max([4] + [len(v) for k,v in names.iteritems()]) + 2
126125

bin/instance_events

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def list(region, headers, order, completed):
5151

5252
ec2 = boto.connect_ec2(region=region)
5353

54-
reservations = ec2.get_all_instances()
54+
reservations = ec2.get_all_reservations()
5555

5656
instanceinfo = {}
5757
events = {}

bin/list_instances

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main():
7676
print format_string % headers
7777
print "-" * len(format_string % headers)
7878

79-
for r in ec2.get_all_instances(filters=filters):
79+
for r in ec2.get_all_reservations(filters=filters):
8080
groups = [g.name for g in r.groups]
8181
for i in r.instances:
8282
i.groups = ','.join(groups)

boto/ec2/connection.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,69 @@ def reset_image_attribute(self, image_id, attribute='launchPermission'):
435435
# Instance methods
436436

437437
def get_all_instances(self, instance_ids=None, filters=None):
438+
"""
439+
Retrieve all the instance reservations associated with your account.
440+
441+
.. note::
442+
This method's current behavior is deprecated in favor of
443+
:meth:`get_all_reservations`. A future major release will change
444+
:meth:`get_all_instances` to return a list of
445+
:class:`boto.ec2.instance.Instance` objects as its name suggests.
446+
To obtain that behavior today, use :meth:`get_only_instances`.
447+
448+
:type instance_ids: list
449+
:param instance_ids: A list of strings of instance IDs
450+
451+
:type filters: dict
452+
:param filters: Optional filters that can be used to limit the
453+
results returned. Filters are provided in the form of a
454+
dictionary consisting of filter names as the key and
455+
filter values as the value. The set of allowable filter
456+
names/values is dependent on the request being performed.
457+
Check the EC2 API guide for details.
458+
459+
:rtype: list
460+
:return: A list of :class:`boto.ec2.instance.Reservation`
461+
462+
"""
463+
warnings.warn(('The current get_all_instances implementation will be '
464+
'replaced with get_all_reservations.'),
465+
PendingDeprecationWarning)
466+
return self.get_all_reservations(instance_ids=instance_ids,
467+
filters=filters)
468+
469+
def get_only_instances(self, instance_ids=None, filters=None):
470+
# A future release should rename this method to get_all_instances
471+
# and make get_only_instances an alias for that.
438472
"""
439473
Retrieve all the instances associated with your account.
440474
441475
:type instance_ids: list
442476
:param instance_ids: A list of strings of instance IDs
443477
478+
:type filters: dict
479+
:param filters: Optional filters that can be used to limit the
480+
results returned. Filters are provided in the form of a
481+
dictionary consisting of filter names as the key and
482+
filter values as the value. The set of allowable filter
483+
names/values is dependent on the request being performed.
484+
Check the EC2 API guide for details.
485+
486+
:rtype: list
487+
:return: A list of :class:`boto.ec2.instance.Instance`
488+
"""
489+
reservations = self.get_all_reservations(instance_ids=instance_ids,
490+
filters=filters)
491+
return [instance for reservation in reservations
492+
for instance in reservation.instances]
493+
494+
def get_all_reservations(self, instance_ids=None, filters=None):
495+
"""
496+
Retrieve all the instance reservations associated with your account.
497+
498+
:type instance_ids: list
499+
:param instance_ids: A list of strings of instance IDs
500+
444501
:type filters: dict
445502
:param filters: Optional filters that can be used to limit the
446503
results returned. Filters are provided in the form of a

boto/ec2/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def update(self, validate=False):
418418
raise a ValueError exception if no data is
419419
returned from EC2.
420420
"""
421-
rs = self.connection.get_all_instances([self.id])
421+
rs = self.connection.get_all_reservations([self.id])
422422
if len(rs) > 0:
423423
r = rs[0]
424424
for i in r.instances:

boto/ec2/securitygroup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,13 @@ def instances(self):
271271
"""
272272
rs = []
273273
if self.vpc_id:
274-
rs.extend(self.connection.get_all_instances(filters={'instance.group-id': self.id}))
274+
rs.extend(self.connection.get_all_reservations(
275+
filters={'instance.group-id': self.id}
276+
))
275277
else:
276-
rs.extend(self.connection.get_all_instances(filters={'group-id': self.id}))
278+
rs.extend(self.connection.get_all_reservations(
279+
filters={'group-id': self.id}
280+
))
277281
instances = [i for r in rs for i in r.instances]
278282
return instances
279283

boto/manage/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def create_from_instance_id(cls, instance_id, name, description=''):
353353
for region in regions:
354354
ec2 = region.connect()
355355
try:
356-
rs = ec2.get_all_instances([instance_id])
356+
rs = ec2.get_all_reservations([instance_id])
357357
except:
358358
rs = []
359359
if len(rs) == 1:
@@ -377,7 +377,7 @@ def create_from_current_instances(cls):
377377
regions = boto.ec2.regions()
378378
for region in regions:
379379
ec2 = region.connect()
380-
rs = ec2.get_all_instances()
380+
rs = ec2.get_all_reservations()
381381
for reservation in rs:
382382
for instance in reservation.instances:
383383
try:
@@ -413,7 +413,7 @@ def _setup_ec2(self):
413413
self.ec2 = region.connect()
414414
if self.instance_id and not self._instance:
415415
try:
416-
rs = self.ec2.get_all_instances([self.instance_id])
416+
rs = self.ec2.get_all_reservations([self.instance_id])
417417
if len(rs) >= 1:
418418
for instance in rs[0].instances:
419419
if instance.id == self.instance_id:

boto/mashups/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def getInstance(self):
114114
if not self._instance:
115115
if self.instance_id:
116116
try:
117-
rs = self.ec2.get_all_instances([self.instance_id])
117+
rs = self.ec2.get_all_reservations([self.instance_id])
118118
except:
119119
return None
120120
if len(rs) > 0:

boto/pyami/installers/ubuntu/ebs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def attach(self):
122122
while volume.update() != 'available':
123123
boto.log.info('Volume %s not yet available. Current status = %s.' % (volume.id, volume.status))
124124
time.sleep(5)
125-
instance = ec2.get_all_instances([self.instance_id])[0].instances[0]
125+
instance = ec2.get_only_instances([self.instance_id])[0]
126126
attempt_attach = True
127127
while attempt_attach:
128128
try:

docs/source/autoscale_tut.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ To retrieve the instances in your autoscale group:
201201
>>> ec2 = boto.ec2.connect_to_region('us-west-2)
202202
>>> conn.get_all_groups(names=['my_group'])[0]
203203
>>> instance_ids = [i.instance_id for i in group.instances]
204-
>>> reservations = ec2.get_all_instances(instance_ids)
205-
>>> instances = [i for r in reservations for i in r.instances]
204+
>>> instances = ec2.get_only_instances(instance_ids)
206205

207206
To delete your autoscale group, we first need to shutdown all the
208207
instances:

0 commit comments

Comments
 (0)