Skip to content

Commit

Permalink
[SQUASHME] More filters
Browse files Browse the repository at this point in the history
  • Loading branch information
aske committed Oct 30, 2017
1 parent dad0ccf commit af76af6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion nixops/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,15 @@ def _get_spot_instance_request_by_id(self, request_id, allow_missing=False):
"""Get spot instance request object by id."""
self.connect()
result = self._conn.get_all_spot_instance_requests([request_id])

request_id_filter = {'Name': 'spot-instance-request-id', 'Values': [request_id]}
result = [req for req in self._conn.describe_spot_instance_requests(Filters=[request_id_filter])]
if len(result) == 0:
if allow_missing:
return None
raise EC2InstanceDisappeared("Spot instance request ‘{0}’ disappeared!".format(request_id))
return result[0]


def _get_instance(self, instance_id=None, allow_missing=False, update=False):
"""Get instance object for this machine, with caching"""
if not instance_id: instance_id = self.vm_id
Expand Down
3 changes: 2 additions & 1 deletion nixops/ec2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def handle_exception(e):
def get_volume_by_id(conn, volume_id, allow_missing=False):
"""Get volume object by volume id."""
try:
volumes = conn.get_all_volumes([volume_id])
volumes = [vol for vol in conn.volumes.filter(Filters=[{'Name': 'volume-id',
'Values': [volume_id]}])]
if len(volumes) != 1:
raise Exception("unable to find volume ‘{0}’".format(volume_id))
return volumes[0]
Expand Down

0 comments on commit af76af6

Please sign in to comment.