libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/6] libcloud git commit: Add ex_fetch_status option to list_nodes().
Date Fri, 13 Oct 2017 04:21:48 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 3ffac42c2 -> 8d7cf639b


Add ex_fetch_status option to list_nodes().

Allows caller to skip (potentially expensive) requests for extended node
status.

Also set timeout on connection object used to fetch token.

Signed-off-by: Quentin Pradet <quentinp@apache.org>


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

Branch: refs/heads/trunk
Commit: 419352ca427e8234143ff04e587979138beadedf
Parents: 3ffac42
Author: Peter Amstutz <peter.amstutz@curoverse.com>
Authored: Mon Oct 9 15:39:12 2017 -0400
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Oct 13 08:13:31 2017 +0400

----------------------------------------------------------------------
 libcloud/common/azure_arm.py          |  2 +-
 libcloud/compute/drivers/azure_arm.py | 74 ++++++++++++++++--------------
 2 files changed, 40 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/419352ca/libcloud/common/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/common/azure_arm.py b/libcloud/common/azure_arm.py
index 064e07e..3d9cab0 100644
--- a/libcloud/common/azure_arm.py
+++ b/libcloud/common/azure_arm.py
@@ -195,7 +195,7 @@ class AzureResourceManagementConnection(ConnectionUserAndKey):
         Log in and get bearer token used to authorize API requests.
         """
 
-        conn = self.conn_class(self.login_host, 443)
+        conn = self.conn_class(self.login_host, 443, timeout=self.timeout)
         conn.connect()
         params = urlencode({
             "grant_type": "client_credentials",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/419352ca/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py
index 78b97b4..23d1532 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -360,7 +360,7 @@ class AzureNodeDriver(NodeDriver):
                                  ex_offer, ex_sku, ex_version)
             return i[0] if i else None
 
-    def list_nodes(self, ex_resource_group=None, ex_fetch_nic=True):
+    def list_nodes(self, ex_resource_group=None, ex_fetch_nic=True, ex_fetch_status=True):
         """
         List all nodes.
 
@@ -371,6 +371,9 @@ class AzureNodeDriver(NodeDriver):
         IP address information for nodes (requires extra API calls).
         :type ex_urn: ``bool``
 
+        :param ex_fetch_status: Fetch node instance status (requires extra API calls).
+        :type ex_urn: ``bool``
+
         :return:  list of node objects
         :rtype: ``list`` of :class:`.Node`
         """
@@ -385,7 +388,7 @@ class AzureNodeDriver(NodeDriver):
                      % (self.subscription_id)
         r = self.connection.request(action,
                                     params={"api-version": "2015-06-15"})
-        return [self._to_node(n, fetch_nic=ex_fetch_nic)
+        return [self._to_node(n, fetch_nic=ex_fetch_nic, fetch_status=ex_fetch_status)
                 for n in r.object["value"]]
 
     def create_node(self,
@@ -1950,7 +1953,7 @@ class AzureNodeDriver(NodeDriver):
         kwargs["cloud_environment"] = self.cloud_environment
         return kwargs
 
-    def _to_node(self, data, fetch_nic=True):
+    def _to_node(self, data, fetch_nic=True, fetch_status=True):
         private_ips = []
         public_ips = []
         nics = data["properties"]["networkProfile"]["networkInterfaces"]
@@ -1973,39 +1976,40 @@ class AzureNodeDriver(NodeDriver):
                     pass
 
         state = NodeState.UNKNOWN
-        try:
-            action = "%s/InstanceView" % (data["id"])
-            r = self.connection.request(action,
-                                        params={"api-version": "2015-06-15"})
-            for status in r.object["statuses"]:
-                if status["code"] in ["ProvisioningState/creating"]:
-                    state = NodeState.PENDING
-                    break
-                elif status["code"] == "ProvisioningState/deleting":
-                    state = NodeState.TERMINATED
-                    break
-                elif status["code"].startswith("ProvisioningState/failed"):
-                    state = NodeState.ERROR
-                    break
-                elif status["code"] == "ProvisioningState/updating":
-                    state = NodeState.UPDATING
-                    break
-                elif status["code"] == "ProvisioningState/succeeded":
-                    pass
+        if fetch_status:
+            try:
+                action = "%s/InstanceView" % (data["id"])
+                r = self.connection.request(action,
+                                            params={"api-version": "2015-06-15"})
+                for status in r.object["statuses"]:
+                    if status["code"] in ["ProvisioningState/creating"]:
+                        state = NodeState.PENDING
+                        break
+                    elif status["code"] == "ProvisioningState/deleting":
+                        state = NodeState.TERMINATED
+                        break
+                    elif status["code"].startswith("ProvisioningState/failed"):
+                        state = NodeState.ERROR
+                        break
+                    elif status["code"] == "ProvisioningState/updating":
+                        state = NodeState.UPDATING
+                        break
+                    elif status["code"] == "ProvisioningState/succeeded":
+                        pass
 
-                if status["code"] == "PowerState/deallocated":
-                    state = NodeState.STOPPED
-                    break
-                elif status["code"] == "PowerState/stopped":
-                    state = NodeState.PAUSED
-                    break
-                elif status["code"] == "PowerState/deallocating":
-                    state = NodeState.PENDING
-                    break
-                elif status["code"] == "PowerState/running":
-                    state = NodeState.RUNNING
-        except BaseHTTPError:
-            pass
+                    if status["code"] == "PowerState/deallocated":
+                        state = NodeState.STOPPED
+                        break
+                    elif status["code"] == "PowerState/stopped":
+                        state = NodeState.PAUSED
+                        break
+                    elif status["code"] == "PowerState/deallocating":
+                        state = NodeState.PENDING
+                        break
+                    elif status["code"] == "PowerState/running":
+                        state = NodeState.RUNNING
+            except BaseHTTPError:
+                pass
 
         node = Node(data["id"],
                     data["name"],


Mime
View raw message