FAM-928 CR fixes

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

Branch: refs/heads/trunk
Commit: 2ade41d85e3666bf94892f9c72b6067aa86ddb02
Parents: 23ec91f
Author: mermoldy <s.ba...@scalr.com>
Authored: Mon May 29 18:43:03 2017 +0300
Committer: Anthony Shaw <anthonys...@apache.org>
Committed: Fri Aug 11 14:59:31 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py | 45 +++++-------------------------
 1 file changed, 7 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2ade41d8/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py 
b/libcloud/compute/drivers/azure_arm.py
index 37c8815..d0de32f 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -887,7 +887,7 @@ 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_vhd_resource_group=None, 
**ex_kwargs):
+                      ex_vhd_uri=None, ex_vhd_new=False, **ex_kwargs):
         """
         Attach a volume to node.
 
@@ -906,9 +906,9 @@ 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``
+        :param ex_vhd_new: Create a new VHD blob for unmanaged disk.
+            (optional)
+        :type ex_vhd_new: ``bool``
 
         :rtype: ``bool``
         """
@@ -926,20 +926,12 @@ 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
-            vhd_exists = self._ex_vhd_exists(
-                ex_vhd_resource_group,
-                ex_vhd_uri)
             new_disk = {
+                'name': volume.name,
+                'diskSizeGB': volume.size,
                 'lun': ex_lun,
-                'name': 'unmanaged-vol-{}'.format(str(uuid.uuid4())[0:8]),
-                'createOption': 'attach' if vhd_exists else 'empty',
+                'createOption': 'empty' if ex_vhd_new else 'attach',
                 'vhd': {'uri': ex_vhd_uri},
-                'diskSizeGB': volume.size
             }
         else:
             # attach existing managed disk
@@ -1913,29 +1905,6 @@ class AzureNodeDriver(NodeDriver):
         except ObjectDoesNotExistError:
             return True
 
-    def _ex_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(vhd_uri)
-            keys = self.ex_get_storage_account_keys(
-                resource_group, storage_account)
-            blob_driver = AzureBlobsStorageDriver(
-                storage_account, keys['key1'])
-            blob_driver.get_object(blob_container, blob)
-            return True
-        except ObjectDoesNotExistError:
-            return False
-
     def _ex_connection_class_kwargs(self):
         kwargs = super(AzureNodeDriver, self)._ex_connection_class_kwargs()
         kwargs['tenant_id'] = self.tenant_id

Reply via email to