Переглянути джерело

Fix mount points

In GCE, when attaching a disk to an instance, the mount point is
/dev/disk/by-id/google-{DEVICE-NAME}, where DEVICE-NAME is a string matching
\w[\w.-]{0,254}. So, when something like '/dev/sda2' is passed as the device
name, we eliminate '/dev/' and just use 'sda2' to mount the dist to
'/dev/disk/by-id/google-sda2'.

Test stats after this CL
========================
Ran 58 tests in 1596.950s

FAILED (SKIP=1, errors=23, failures=7)
Ehsan Chiniforooshan 8 роки тому
батько
коміт
9eeb52c878
1 змінених файлів з 6 додано та 6 видалено
  1. 6 6
      cloudbridge/cloud/providers/gce/resources.py

+ 6 - 6
cloudbridge/cloud/providers/gce/resources.py

@@ -1717,17 +1717,17 @@ class GCEVolume(BaseVolume):
         """
         """
         attach_disk_body = {
         attach_disk_body = {
             "source": self.id,
             "source": self.id,
-            "deviceName": device,
+            "deviceName": device.split('/')[-1],
         }
         }
-        instance_name = instance.name if isinstance(
-            instance,
-            GCEInstance) else instance
+        if not isinstance(instance, GCEInstance):
+            instance = self._provider.get_resource('instances', instance)
+        parsed_zone_url = self._provider.parse_url(instance.zone_id)
         (self._provider
         (self._provider
              .gce_compute
              .gce_compute
              .instances()
              .instances()
              .attachDisk(project=self._provider.project_name,
              .attachDisk(project=self._provider.project_name,
-                         zone=self._provider.default_zone,
-                         instance=instance_name,
+                         zone=parsed_zone_url.parameters['zone'],
+                         instance=instance.name,
                          body=attach_disk_body)
                          body=attach_disk_body)
              .execute())
              .execute())