You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2017/09/19 21:01:07 UTC

[09/11] libcloud git commit: Refactor get_instance_vhd from a closure method to instance method so it can be tested more easily.

Refactor get_instance_vhd from a closure method to instance method so it
can be tested more easily.


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

Branch: refs/heads/trunk
Commit: 2a8764b1d4dffaf2217a670323b31cef953d1679
Parents: 91d14ea
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 22:48:52 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 22:48:52 2017 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py | 47 ++++++++++++++++++------------
 1 file changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2a8764b1/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py
index f7e8a1b..8950c2a 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -534,23 +534,12 @@ class AzureNodeDriver(NodeDriver):
                  "/Microsoft.Compute/virtualMachines/%s" % \
                  (self.subscription_id, ex_resource_group, name)
 
-        def _get_instance_vhd():
-            n = 0
-            while True:
-                try:
-                    instance_vhd = "https://%s.blob%s" \
-                                   "/%s/%s-os_%i.vhd" \
-                                   % (ex_storage_account,
-                                      self.connection.storage_suffix,
-                                      ex_blob_container,
-                                      name,
-                                      n)
-                    self._ex_delete_old_vhd(ex_resource_group, instance_vhd)
-                    return instance_vhd
-                except LibcloudError:
-                    n += 1
-
         if isinstance(image, AzureVhdImage):
+            instance_vhd = self._get_instance_vhd(
+                name=name,
+                ex_resource_group=ex_resource_group,
+                ex_storage_account=ex_storage_account,
+                ex_blob_container=ex_blob_container)
             storage_profile = {
                 "osDisk": {
                     "name": name,
@@ -561,7 +550,7 @@ class AzureNodeDriver(NodeDriver):
                         "uri": image.id
                     },
                     "vhd": {
-                        "uri": _get_instance_vhd(),
+                        "uri": instance_vhd,
                     }
                 }
             }
@@ -589,8 +578,13 @@ class AzureNodeDriver(NodeDriver):
                     "storageAccountType": ex_storage_account_type
                 }
             else:
+                instance_vhd = self._get_instance_vhd(
+                    name=name,
+                    ex_resource_group=ex_resource_group,
+                    ex_storage_account=ex_storage_account,
+                    ex_blob_container=ex_blob_container)
                 storage_profile["osDisk"]["vhd"] = {
-                    "uri": _get_instance_vhd()
+                    "uri": instance_vhd
                 }
         else:
             raise LibcloudError(
@@ -2014,6 +2008,23 @@ class AzureNodeDriver(NodeDriver):
         return NodeLocation(loc_id, loc, self._location_to_country.get(loc_id),
                             self.connection.driver)
 
+    def _get_instance_vhd(self, name, ex_resource_group, ex_storage_account,
+                          ex_blob_container="vhds"):
+        n = 0
+        while True:
+            try:
+                instance_vhd = "https://%s.blob%s" \
+                               "/%s/%s-os_%i.vhd" \
+                               % (ex_storage_account,
+                                  self.connection.storage_suffix,
+                                  ex_blob_container,
+                                  name,
+                                  n)
+                self._ex_delete_old_vhd(ex_resource_group, instance_vhd)
+                return instance_vhd
+            except LibcloudError:
+                n += 1
+
 
 def _split_blob_uri(uri):
     uri = uri.split('/')