diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py index 00880e0..1443a6c 100644 --- a/libcloud/compute/base.py +++ b/libcloud/compute/base.py @@ -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,7 +627,12 @@ 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') + @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 @@ -640,8 +646,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 \ + hasattr(nodes[0], ssh_interface) and getattr(nodes[0], ssh_interface)): + return (nodes[0], getattr(nodes[0], ssh_interface)) else: time.sleep(wait_period) continue diff --git a/test/compute/test_deployment.py b/test/compute/test_deployment.py index f059150..8355350 100644 --- a/test/compute/test_deployment.py +++ b/test/compute/test_deployment.py @@ -139,15 +139,24 @@ 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_timeout(self): RackspaceMockHttp.type = 'TIMEOUT'