libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [09/20] libcloud git commit: FAM-690 WIP
Date Fri, 11 Aug 2017 05:00:51 GMT
FAM-690 WIP


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

Branch: refs/heads/trunk
Commit: 5352e710350939539878aae879c2bd687f401c3d
Parents: 432145f
Author: mermoldy <s.babak@scalr.com>
Authored: Thu Mar 9 14:19:59 2017 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Aug 11 14:59:31 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py | 74 +++++++++++++++++-------------
 1 file changed, 41 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5352e710/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py
index 375d432..3326a74 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -169,7 +169,6 @@ class AzureNodeDriver(NodeDriver):
     type = Provider.AZURE_ARM
     features = {'create_node': ['ssh_key', 'password']}
 
-
     # The API doesn't provide state or country information, so fill it in.
     # Information from https://azure.microsoft.com/en-us/regions/
     _location_to_country = {
@@ -397,7 +396,8 @@ class AzureNodeDriver(NodeDriver):
                     ex_nic=None,
                     ex_tags={},
                     ex_customdata="",
-                    ex_use_managed_disks=False):
+                    ex_use_managed_disks=False,
+                    ex_storage_account_type="Standard_LRS"):
         """Create a new node instance. This instance will be started
         automatically.
 
@@ -495,6 +495,10 @@ class AzureNodeDriver(NodeDriver):
             in all regions.
         :type ex_use_managed_disks: ``bool``
 
+        :param ex_storage_account_type: The Storage Account type,
+            ``Standard_LRS``(HDD disks) or ``Premium_LRS``(SSD disks).
+        :type ex_storage_account_type: str
+
         :return: The newly created node.
         :rtype: :class:`.Node`
         """
@@ -523,25 +527,25 @@ class AzureNodeDriver(NodeDriver):
                  "/Microsoft.Compute/virtualMachines/%s" % \
                  (self.subscription_id, ex_resource_group, name)
 
-        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)
-                break
-            except LibcloudError:
-                n += 1
+        def _get_instance_vhd():
+            n = 0
+            while True:
+                try:
+                    instance_vhd = "https://%s.blob.core.windows.net" \
+                                   "/%s/%s-os_%i.vhd" \
+                                   % (ex_storage_account,
+                                      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):
             storage_profile = {
                 "osDisk": {
-                    "name": "virtualmachine-osDisk",
+                    "name": name,
                     "osType": "linux",
                     "caching": "ReadWrite",
                     "createOption": "FromImage",
@@ -549,10 +553,14 @@ class AzureNodeDriver(NodeDriver):
                         "uri": image.id
                     },
                     "vhd": {
-                        "uri": instance_vhd
+                        "uri": _get_instance_vhd(),
                     }
                 }
             }
+            if ex_use_managed_disks:
+                raise LibcloudError(
+                    "Creating managed OS disk from %s image "
+                    "type is not supported." % type(image))
         elif isinstance(image, AzureImage):
             storage_profile = {
                 "imageReference": {
@@ -562,25 +570,24 @@ class AzureNodeDriver(NodeDriver):
                     "version": image.version
                 },
                 "osDisk": {
-                    "name": "virtualmachine-osDisk",
-                    "vhd": {
-                        "uri": instance_vhd
-                    },
+                    "name": name,
+                    "osType": "linux",
                     "caching": "ReadWrite",
                     "createOption": "FromImage"
                 }
             }
             if ex_use_managed_disks:
-                storage_profile["osDisk"] = {
-                    "name": name,
-                    "createOption": "FromImage",
-                    "caching": "ReadWrite",
+                storage_profile["osDisk"]["managedDisk"] = {
+                    "storageAccountType": ex_storage_account_type
+                }
+            else:
+                storage_profile["osDisk"]["vhd"] = {
+                    "uri": _get_instance_vhd()
                 }
         else:
             raise LibcloudError(
-                "Unknown image type %s,"
-                "expected one of AzureImage, AzureVhdImage",
-                type(image))
+                "Unknown image type %s, expected one of AzureImage, "
+                "AzureVhdImage." % type(image))
 
         data = {
             "id": target,
@@ -636,10 +643,11 @@ class AzureNodeDriver(NodeDriver):
             raise ValueError(
                 "Must provide NodeAuthSSHKey or NodeAuthPassword in auth")
 
-        r = self.connection.request(target,
-                                    params={"api-version": RESOURCE_API_VERSION},
-                                    data=data,
-                                    method="PUT")
+        r = self.connection.request(
+            target,
+            params={"api-version": RESOURCE_API_VERSION},
+            data=data,
+            method="PUT")
 
         node = self._to_node(r.object)
         node.size = size


Mime
View raw message