Author: tomaz
Date: Fri May 18 05:07:14 2012
New Revision: 1339974
URL: http://svn.apache.org/viewvc?rev=1339974&view=rev
Log:
Allow user to specify which IP to use when calling _wait_until_running
(defaults to 'public_ips'). Previously it only worked with public IPs, now
user can pass 'private_ips' as an argument and SSH client will try to
connect to the node first private IP address. This patch has been contributed
by Jay Doane and is part of LIBCLOUD-198.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/compute/base.py
libcloud/trunk/test/compute/test_deployment.py
Modified: libcloud/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1339974&r1=1339973&r2=1339974&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri May 18 05:07:14 2012
@@ -5,10 +5,16 @@ Changes with Apache Libcloud in developm
*) Compute:
- Update IBM SBC driver so it works with IBM Smart Cloud Enterprise.
; LIBCLOUD-195
- [Sengor Kusturica]
+ [Sengor Kusturica]
- Add ex_register_iso method to the CloudStack driver. ; LIBCLOUD-196
- [Daemian Mack]
+ [Daemian Mack]
+
+ - Allow user to specify which IP to use when calling _wait_until_running.
+ (defaults to 'public_ips'). Previously it only worked with public IP, now
+ user can pass 'private_ips' as an argument and SSH client will try to
+ connect to the node first private IP address.
+ [Jay Doane]
Changes with Apache Libcloud 0.10.0:
Modified: libcloud/trunk/libcloud/compute/base.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/base.py?rev=1339974&r1=1339973&r2=1339974&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/base.py (original)
+++ libcloud/trunk/libcloud/compute/base.py Fri May 18 05:07:14 2012
@@ -578,9 +578,9 @@ class NodeDriver(BaseDriver):
password = node.extra.get('password')
try:
- # Wait until node is up and running and has public IP assigned
- node = self._wait_until_running(node=node, wait_period=3,
- timeout=NODE_ONLINE_WAIT_TIMEOUT)
+ # Wait until node is up and running and has IP assigned
+ node, ip_addresses = self._wait_until_running(
+ node=node, wait_period=3, timeout=NODE_ONLINE_WAIT_TIMEOUT)
if password:
node.extra['password'] = password
@@ -590,7 +590,7 @@ class NodeDriver(BaseDriver):
ssh_timeout = kwargs.get('ssh_timeout', 10)
ssh_key_file = kwargs.get('ssh_key', None)
- ssh_client = SSHClient(hostname=node.public_ips[0],
+ ssh_client = SSHClient(hostname=ip_addresses[0],
port=ssh_port, username=ssh_username,
password=password,
key=ssh_key_file,
@@ -611,7 +611,8 @@ class NodeDriver(BaseDriver):
return node
- def _wait_until_running(self, node, wait_period=3, timeout=600):
+ def _wait_until_running(self, node, wait_period=3, timeout=600,
+ ssh_interface='public_ips'):
"""
Block until node is fully booted and has an IP address assigned.
@@ -626,11 +627,21 @@ class NodeDriver(BaseDriver):
(default is 600)
@type timeout: C{int}
- @return: C{Node} Node instance on success.
+ @keyword ssh_interface: The interface to wait for.
+ Default is 'public_ips', other option is
+ 'private_ips'.
+ @type ssh_interface: C{str}
+
+ @return: C{(Node, ip_addresses)} tuple of Node instance and
+ list of ip_address on success.
"""
start = time.time()
end = start + timeout
+ if ssh_interface not in ['public_ips', 'private_ips']:
+ raise ValueError('ssh_interface argument must either be' +
+ 'public_ips or private_ips')
+
while time.time() < end:
nodes = self.list_nodes()
nodes = list([n for n in nodes if n.uuid == node.uuid])
@@ -640,8 +651,9 @@ class NodeDriver(BaseDriver):
+ 'but multiple nodes have same UUID'),
driver=self)
- if (len(nodes) == 1 and nodes[0].public_ips and nodes[0].state ==
NodeState.RUNNING):
- return nodes[0]
+ if (len(nodes) == 1 and nodes[0].state == NodeState.RUNNING and \
+ getattr(nodes[0], ssh_interface)):
+ return (nodes[0], getattr(nodes[0], ssh_interface))
else:
time.sleep(wait_period)
continue
Modified: libcloud/trunk/test/compute/test_deployment.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_deployment.py?rev=1339974&r1=1339973&r2=1339974&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_deployment.py (original)
+++ libcloud/trunk/test/compute/test_deployment.py Fri May 18 05:07:14 2012
@@ -139,15 +139,33 @@ class DeploymentTests(unittest.TestCase)
self.fail('TypeError was not thrown')
def test_wait_until_running_running_instantly(self):
- node2 = self.driver._wait_until_running(node=self.node, wait_period=1,
- timeout=10)
+ node2, ips = self.driver._wait_until_running(node=self.node,
wait_period=1,
+ timeout=10)
self.assertEqual(self.node.uuid, node2.uuid)
+ self.assertEqual(['67.23.21.33'], ips)
def test_wait_until_running_running_after_1_second(self):
RackspaceMockHttp.type = '1_SECOND_DELAY'
- node2 = self.driver._wait_until_running(node=self.node, wait_period=1,
- timeout=10)
+ node2, ips = self.driver._wait_until_running(node=self.node,
wait_period=1,
+ timeout=10)
+ self.assertEqual(self.node.uuid, node2.uuid)
+ self.assertEqual(['67.23.21.33'], ips)
+
+ def test_wait_until_running_running_after_1_second_private_ips(self):
+ RackspaceMockHttp.type = '1_SECOND_DELAY'
+ node2, ips = self.driver._wait_until_running(node=self.node,
wait_period=1,
+ timeout=10,
ssh_interface='private_ips')
self.assertEqual(self.node.uuid, node2.uuid)
+ self.assertEqual(['10.176.168.218'], ips)
+
+ def test_wait_until_running_invalid_ssh_interface_argument(self):
+ try:
+ self.driver._wait_until_running(node=self.node, wait_period=1,
+ ssh_interface='invalid')
+ except ValueError:
+ pass
+ else:
+ self.fail('Exception was not thrown')
def test_wait_until_running_timeout(self):
RackspaceMockHttp.type = 'TIMEOUT'