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 2011/06/18 11:25:11 UTC
svn commit: r1137147 - /libcloud/trunk/libcloud/compute/base.py
Author: tomaz
Date: Sat Jun 18 09:25:10 2011
New Revision: 1137147
URL: http://svn.apache.org/viewvc?rev=1137147&view=rev
Log:
Reorder methods.
Modified:
libcloud/trunk/libcloud/compute/base.py
Modified: libcloud/trunk/libcloud/compute/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/base.py?rev=1137147&r1=1137146&r2=1137147&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/base.py (original)
+++ libcloud/trunk/libcloud/compute/base.py Sat Jun 18 09:25:10 2011
@@ -554,38 +554,52 @@ class NodeDriver(object):
raise DeploymentError(node, e)
return node
- def _run_deployment_script(self, task, node, ssh_client, max_tries=3):
+ def _wait_until_running(self, node, wait_period=3, timeout=600):
"""
- Run the deployment script on the provided node. At this point it is
- assumed that SSH connection has already been established.
-
- @keyword task: Deployment task to run on the node.
- @type task: C{Deployment}
+ Block until node is fully booted and has an IP address assigned.
- @keyword node: Node to operate one
+ @keyword node: Node instance.
@type node: C{Node}
- @keyword ssh_client: A configured and connected SSHClient instance
- @type ssh_client: C{SSHClient}
+ @keyword wait_period: How many seconds to between each loop iteration
+ (default is 3)
+ @type wait_period: C{int}
- @keyword max_tries: How many times to retry if a deployment fails
- before giving up (default is 3)
- @type max_tries: C{int}
+ @keyword timeout: How many seconds to wait before timing out
+ (default is 600)
+ @type timeout: C{int}
@return: C{Node} Node instance on success.
"""
- tries = 0
- while tries < max_tries:
- try:
- node = task.run(node, ssh_client)
- except Exception:
- tries += 1
- if tries >= max_tries:
- raise LibcloudError(value='Failed after %d tries'
- % (max_tries), driver=self)
- else:
- ssh_client.close()
+ start = time.time()
+ end = start + timeout
+
+ while time.time() < end:
+ nodes = self.list_nodes()
+ nodes = filter(lambda n: n.uuid == node.uuid, nodes)
+
+ if len(nodes) == 0:
+ raise LibcloudError(value=('Booted node[%s] ' % node
+ + 'is missing from list_nodes.'),
+ driver=self)
+
+ if len(nodes) > 1:
+ raise LibcloudError(value=('Booted single node[%s], ' % node
+ + 'but multiple nodes have same UUID'),
+ driver=self)
+
+ node = nodes[0]
+
+ if (node.public_ip is not None
+ and node.public_ip != ""
+ and node.state == NodeState.RUNNING):
return node
+ else:
+ time.sleep(wait_period)
+ continue
+
+ raise LibcloudError(value='Timed out after %s seconds' % (timeout),
+ driver=self)
def _ssh_client_connect(self, ssh_client, timeout=300):
"""
@@ -618,52 +632,38 @@ class NodeDriver(object):
raise LibcloudError(value='Could not connect to the remote SSH ' +
'server. Giving up.', driver=self)
- def _wait_until_running(self, node, wait_period=3, timeout=600):
+ def _run_deployment_script(self, task, node, ssh_client, max_tries=3):
"""
- Block until node is fully booted and has an IP address assigned.
+ Run the deployment script on the provided node. At this point it is
+ assumed that SSH connection has already been established.
- @keyword node: Node instance.
+ @keyword task: Deployment task to run on the node.
+ @type task: C{Deployment}
+
+ @keyword node: Node to operate one
@type node: C{Node}
- @keyword wait_period: How many seconds to between each loop iteration
- (default is 3)
- @type wait_period: C{int}
+ @keyword ssh_client: A configured and connected SSHClient instance
+ @type ssh_client: C{SSHClient}
- @keyword timeout: How many seconds to wait before timing out
- (default is 600)
- @type timeout: C{int}
+ @keyword max_tries: How many times to retry if a deployment fails
+ before giving up (default is 3)
+ @type max_tries: C{int}
@return: C{Node} Node instance on success.
"""
- start = time.time()
- end = start + timeout
-
- while time.time() < end:
- nodes = self.list_nodes()
- nodes = filter(lambda n: n.uuid == node.uuid, nodes)
-
- if len(nodes) == 0:
- raise LibcloudError(value=('Booted node[%s] ' % node
- + 'is missing from list_nodes.'),
- driver=self)
-
- if len(nodes) > 1:
- raise LibcloudError(value=('Booted single node[%s], ' % node
- + 'but multiple nodes have same UUID'),
- driver=self)
-
- node = nodes[0]
-
- if (node.public_ip is not None
- and node.public_ip != ""
- and node.state == NodeState.RUNNING):
- return node
+ tries = 0
+ while tries < max_tries:
+ try:
+ node = task.run(node, ssh_client)
+ except Exception:
+ tries += 1
+ if tries >= max_tries:
+ raise LibcloudError(value='Failed after %d tries'
+ % (max_tries), driver=self)
else:
- time.sleep(wait_period)
- continue
-
- raise LibcloudError(value='Timed out after %s seconds' % (timeout),
- driver=self)
+ ssh_client.close()
+ return node
def _get_size_price(self, size_id):
return get_size_price(driver_type='compute',