Skip to content

Commit

Permalink
Fix for edge case where snapshot doesn't exist on EC2 (since ec2 doesn't
Browse files Browse the repository at this point in the history
have a deleted state for snapshots)
  • Loading branch information
nuwang committed Oct 7, 2015
1 parent c480ca9 commit 1a6ca77
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cloudbridge/providers/aws/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
DataTypes used by this provider
"""

from boto.exception import EC2ResponseError

from cloudbridge.providers.base import BaseInstance
from cloudbridge.providers.base import BaseKeyPair
from cloudbridge.providers.base import BaseMachineImage
Expand Down Expand Up @@ -77,8 +79,12 @@ def refresh(self):
Refreshes the state of this instance by re-querying the cloud provider
for its latest state.
"""
self._ec2_image = self.provider.images.get_image(
self.image_id)._ec2_image
image = self.provider.images.get_image(self.image_id)
if image:
self._ec2_image = image._ec2_image
else:
# image no longer exists
self._ec2_image.state = "unknown"


class AWSPlacementZone(PlacementZone):
Expand Down Expand Up @@ -391,7 +397,12 @@ def refresh(self):
Refreshes the state of this snapshot by re-querying the cloud provider
for its latest state.
"""
self._snapshot.update()
try:
self._snapshot.update()
except EC2ResponseError:
# The snapshot no longer exists and cannot be refreshed.
# set the status to unknown
self._snapshot.status = 'unknown'

def delete(self):
"""
Expand Down

0 comments on commit 1a6ca77

Please sign in to comment.