libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [02/20] libcloud git commit: FAM-902 Added vhd_resource_group parameter to 'attach_volume'
Date Fri, 11 Aug 2017 05:00:44 GMT
FAM-902 Added vhd_resource_group parameter to 'attach_volume'


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9866138a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9866138a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9866138a

Branch: refs/heads/trunk
Commit: 9866138af52eb2da8047bf8dc3e395ed0a355a45
Parents: 439e4dc
Author: mermoldy <s.babak@scalr.com>
Authored: Wed May 24 13:03:58 2017 +0300
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Aug 11 14:59:31 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py | 52 ++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9866138a/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py
index eed44d0..a225429 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -886,9 +886,10 @@ class AzureNodeDriver(NodeDriver):
         )
         return [self._to_volume(volume) for volume in response.object['value']]
 
-    def attach_volume(self, node, volume, ex_lun=None, ex_vhd_uri=None, **ex_kwargs):
+    def attach_volume(self, node, volume, ex_lun=None,
+                      ex_vhd_uri=None, ex_vhd_resource_group=None, **ex_kwargs):
         """
-        Attach a managed volume to node.
+        Attach a volume to node.
 
         :param node: A node to attach volume.
         :type node: :class:`Node`
@@ -905,6 +906,10 @@ class AzureNodeDriver(NodeDriver):
             blob. (optional)
         :type ex_vhd_uri: ``str``
 
+        :param ex_vhd_resource_group: Storage account resource group name.
+            (required for ``ex_vhd_uri``)
+        :type ex_vhd_resource_group: ``str``
+
         :rtype: ``bool``
         """
         action = node.extra['id']
@@ -921,23 +926,26 @@ class AzureNodeDriver(NodeDriver):
                 raise LibcloudError("No LUN available to attach new disk.")
 
         if ex_vhd_uri is not None:
+            if ex_vhd_resource_group is None:
+                raise AttributeError(
+                    "'ex_vhd_resource_group' of the VHD blob is not specified.")
+
             # attach new or existing unmanaged disk
-            resource_group = node.id.split('/')[4]
-            is_vhd_exists = self._ex_is_vhd_exists(resource_group, ex_vhd_uri)
+            is_vhd_exists = self._ex_is_vhd_exists(
+                ex_vhd_resource_group,
+                ex_vhd_uri)
             new_disk = {
                 'lun': ex_lun,
                 'name': 'unmanaged-vol-{}'.format(str(uuid.uuid4())[0:8]),
                 'createOption': 'attach' if is_vhd_exists else 'empty',
                 'vhd': {'uri': ex_vhd_uri},
-                'diskSizeGB': volume.size
-            }
+                'diskSizeGB': volume.size}
         else:
             # attach existing managed disk
             new_disk = {
                 'lun': ex_lun,
                 'createOption': 'attach',
-                'managedDisk': {'id': volume.id}
-            }
+                'managedDisk': {'id': volume.id}}
 
         disks.append(new_disk)
         self.connection.request(
@@ -953,8 +961,7 @@ class AzureNodeDriver(NodeDriver):
                     }
                 },
                 'location': location
-            }
-        )
+            })
         return True
 
     def detach_volume(self, volume, ex_node=None):
@@ -1905,9 +1912,20 @@ class AzureNodeDriver(NodeDriver):
         except ObjectDoesNotExistError:
             return True
 
-    def _ex_is_vhd_exists(self, resource_group, uri):
+    def _ex_is_vhd_exists(self, resource_group, vhd_uri):
+        """
+        Check if VHD by given ``vhd_uri`` exists
+
+        :param resource_group: Storage account resource group name.
+        :type: ``str``
+
+        :param vhd_uri: Virtual hard disk's uri.
+        :type: ``str``
+
+        :rtype: ``bool``
+        """
         try:
-            storage_account, blob_container, blob = _split_blob_uri(uri)
+            storage_account, blob_container, blob = _split_blob_uri(vhd_uri)
             keys = self.ex_get_storage_account_keys(
                 resource_group, storage_account)
             blob_driver = AzureBlobsStorageDriver(
@@ -2018,8 +2036,8 @@ class AzureNodeDriver(NodeDriver):
 
 
 def _split_blob_uri(uri):
-    uri = uri.split("/")
-    storageAccount = uri[2].split(".")[0]
-    blobContainer = uri[3]
-    blob = '/'.join(uri[4:])
-    return (storageAccount, blobContainer, blob)
+    uri = uri.split('/')
+    storage_account = uri[2].split('.')[0]
+    blob_container = uri[3]
+    blob_name = '/'.join(uri[4:])
+    return storage_account, blob_container, blob_name


Mime
View raw message