Ver código fonte

Made ec2 refresh methods more resilient to missing/deleted objects.

nuwan_ag 10 anos atrás
pai
commit
07d873eda2

+ 12 - 2
cloudbridge/providers/aws/resources.py

@@ -263,7 +263,12 @@ class AWSInstance(BaseInstance):
         Refreshes the state of this instance by re-querying the cloud provider
         Refreshes the state of this instance by re-querying the cloud provider
         for its latest state.
         for its latest state.
         """
         """
-        self._ec2_instance.update()
+        try:
+            self._ec2_instance.update()
+        except EC2ResponseError:
+            # The volume no longer exists and cannot be refreshed.
+            # set the status to unknown
+            self._ec2_instance.status = 'unknown'
 
 
     def __repr__(self):
     def __repr__(self):
         return "<CB-AWSInstance: {0}({1})>".format(self.name, self.instance_id)
         return "<CB-AWSInstance: {0}({1})>".format(self.name, self.instance_id)
@@ -349,7 +354,12 @@ class AWSVolume(BaseVolume):
         Refreshes the state of this volume by re-querying the cloud provider
         Refreshes the state of this volume by re-querying the cloud provider
         for its latest state.
         for its latest state.
         """
         """
-        self._volume.update()
+        try:
+            self._volume.update()
+        except EC2ResponseError:
+            # The volume no longer exists and cannot be refreshed.
+            # set the status to unknown
+            self._volume.status = 'unknown'
 
 
     def __repr__(self):
     def __repr__(self):
         return "<CB-AWSVolume: {0} ({1})>".format(self.volume_id, self.name)
         return "<CB-AWSVolume: {0} ({1})>".format(self.volume_id, self.name)

+ 4 - 2
cloudbridge/providers/aws/services.py

@@ -154,7 +154,8 @@ class AWSSecurityGroupService(SecurityGroupService):
                           returned.
                           returned.
 
 
         :rtype: list of :class:`SecurityGroup`
         :rtype: list of :class:`SecurityGroup`
-        :return: A list of SecurityGroup objects or an empty list if none found.
+        :return: A list of SecurityGroup objects or an empty list if none
+        found.
         """
         """
         try:
         try:
             security_groups = self.provider.ec2_conn.get_all_security_groups(
             security_groups = self.provider.ec2_conn.get_all_security_groups(
@@ -177,7 +178,8 @@ class AWSSecurityGroupService(SecurityGroupService):
                   the first place.
                   the first place.
         """
         """
         try:
         try:
-            for sg in self.provider.ec2_conn.get_all_security_groups(group_ids=[group_id]):
+            for sg in self.provider.ec2_conn.get_all_security_groups(
+                    group_ids=[group_id]):
                 try:
                 try:
                     sg.delete()
                     sg.delete()
                 except EC2ResponseError:
                 except EC2ResponseError: