Explorar o código

Wait for volume attachment

Nuwan Goonasekera %!s(int64=5) %!d(string=hai) anos
pai
achega
52bc29cd15
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      cloudbridge/providers/aws/resources.py

+ 10 - 0
cloudbridge/providers/aws/resources.py

@@ -495,12 +495,22 @@ class AWSVolume(BaseVolume):
             for a in self._volume.attachments
             for a in self._volume.attachments
         ][0] if self._volume.attachments else None
         ][0] if self._volume.attachments else None
 
 
+    @tenacity.retry(stop=tenacity.stop_after_attempt(5),
+                    retry=tenacity.retry_if_exception_type(Exception),
+                    wait=tenacity.wait_fixed(5),
+                    reraise=True)
+    def _wait_till_volume_attached(self, instance_id):
+        if not self.attachments.instance_id == instance_id:
+            raise Exception(f"Volume {self.id} is not yet attached to"
+                            f"instance {instance_id}")
+
     def attach(self, instance, device):
     def attach(self, instance, device):
         instance_id = instance.id if isinstance(
         instance_id = instance.id if isinstance(
             instance,
             instance,
             AWSInstance) else instance
             AWSInstance) else instance
         self._volume.attach_to_instance(InstanceId=instance_id,
         self._volume.attach_to_instance(InstanceId=instance_id,
                                         Device=device)
                                         Device=device)
+        self._wait_till_volume_attached(instance_id)
 
 
     def detach(self, force=False):
     def detach(self, force=False):
         a = self.attachments
         a = self.attachments