libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/8] libcloud git commit: [LIBCLOUD-770] Provide a way for users to wait for an MCP 2 asset to reach a desired state.
Date Thu, 12 Nov 2015 23:05:08 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 800189eac -> 4a7424367


[LIBCLOUD-770] Provide a way for users to wait for an MCP 2 asset to reach a desired state.

Closes #631

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


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

Branch: refs/heads/trunk
Commit: 84501da7f016900c7526041a636f62e59df9493c
Parents: 800189e
Author: Anthony Shaw <anthony.p.shaw@gmail.com>
Authored: Thu Nov 12 13:15:14 2015 +1100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Nov 12 23:44:55 2015 +0100

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py               | 24 ++++++++++++++++++
 libcloud/compute/drivers/dimensiondata.py      | 28 +++++++++++++++++----
 libcloud/loadbalancer/drivers/dimensiondata.py | 18 +++++++++++++
 3 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/84501da7/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index d6792d9..817ae7a 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -16,6 +16,7 @@
 Dimension Data Common Components
 """
 from base64 import b64encode
+from time import sleep
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import b
 
@@ -217,6 +218,29 @@ class DimensionDataConnection(ConnectionUserAndKey):
         return ("%s/%s/%s" % (self.api_path_version_2, self.api_version_2,
                               self._get_orgId()))
 
+    def wait_for_state(self, state, func, **kwargs):
+        """
+        Wait for the function which returns a instance
+        with field status to match
+
+        Keep polling func until one of the desired states is matched
+
+        :param state: Either the desired state (`str`) or a `list` of states
+        :type  state: ``str`` or ``list``
+
+        :param  func: The function to call, e.g. ex_get_vlan
+        :type   func: ``function``
+
+        :param  kwargs: The arguments for func
+        :type   kwargs: Keyword arguments
+        """
+        response = func(kwargs)
+        while(True):
+            response = func(kwargs)
+            if response.status is state or response.status in state:
+                break
+            sleep(2)
+
     def _get_orgId(self):
         """
         Send the /myaccount API request to DimensionData cloud and parse the

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84501da7/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index ee76daf..6161f7a 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -815,6 +815,24 @@ class DimensionDataNodeDriver(NodeDriver):
                 filter(lambda x: x.id == id, self.list_locations()))[0]
         return location
 
+    def ex_wait_for_state(self, state, func, **kwargs):
+        """
+        Wait for the function which returns a instance
+        with field status to match
+
+        Keep polling func until one of the desired states is matched
+
+        :param state: Either the desired state (`str`) or a `list` of states
+        :type  state: ``str`` or ``list``
+
+        :param  func: The function to call, e.g. ex_get_vlan
+        :type   func: ``function``
+
+        :param  kwargs: The arguments for func
+        :type   kwargs: Keyword arguments
+        """
+        self.connection.wait_for_state(state, func, kwargs)
+
     def _to_nat_rules(self, object, network_domain):
         rules = []
         for element in findall(object, 'natRule', TYPES_URN):
@@ -824,7 +842,7 @@ class DimensionDataNodeDriver(NodeDriver):
         return rules
 
     def _to_nat_rule(self, element, network_domain):
-        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))
+        status = element.find(fixxpath('state', TYPES_URN))
 
         return DimensionDataNatRule(
             id=element.get('id'),
@@ -843,7 +861,7 @@ class DimensionDataNodeDriver(NodeDriver):
         return rules
 
     def _to_firewall_rule(self, element, locations, network_domain):
-        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))
+        status = element.find(fixxpath('state', TYPES_URN))
 
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
@@ -884,7 +902,7 @@ class DimensionDataNodeDriver(NodeDriver):
         return blocks
 
     def _to_ip_block(self, element, locations):
-        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))
+        status = element.find(fixxpath('state', TYPES_URN))
 
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
@@ -939,7 +957,7 @@ class DimensionDataNodeDriver(NodeDriver):
         return network_domains
 
     def _to_network_domain(self, element, locations):
-        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))
+        status = element.find(fixxpath('state', TYPES_URN))
 
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
@@ -966,7 +984,7 @@ class DimensionDataNodeDriver(NodeDriver):
         return vlans
 
     def _to_vlan(self, element, locations):
-        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))
+        status = element.find(fixxpath('state', TYPES_URN))
 
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84501da7/libcloud/loadbalancer/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/dimensiondata.py b/libcloud/loadbalancer/drivers/dimensiondata.py
index da5b45e..5d0fbf7 100644
--- a/libcloud/loadbalancer/drivers/dimensiondata.py
+++ b/libcloud/loadbalancer/drivers/dimensiondata.py
@@ -823,6 +823,24 @@ class DimensionDataLBDriver(Driver):
         response_code = findtext(result, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'OK']
 
+    def ex_wait_for_state(self, state, func, **kwargs):
+        """
+        Wait for the function which returns a instance with
+        field status to match
+
+        Keep polling func until one of the desired states is matched
+
+        :param state: Either the desired state (`str`) or a `list` of states
+        :type  state: ``str`` or ``list``
+
+        :param  func: The function to call, e.g. ex_get_vlan
+        :type   func: ``function``
+
+        :param  kwargs: The arguments for func
+        :type   kwargs: Keyword arguments
+        """
+        self.connection.wait_for_state(state, func, kwargs)
+
     def _to_nodes(self, object):
         nodes = []
         for element in object.findall(fixxpath("node", TYPES_URN)):


Mime
View raw message