diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py index 15330ff..9086747 100644 --- a/libcloud/compute/base.py +++ b/libcloud/compute/base.py @@ -591,6 +591,11 @@ class NodeDriver(BaseDriver): when connecting to SSH server (default is root) @type ssh_username: C{str} + + @keyword ssh_alternate_usernames: Optional list of ssh usernames to + try to connect with if using the + default one fails + @type ssh_alternate_usernames: C{list} @keyword ssh_port: Optional SSH server port (default is 22) @type ssh_port: C{int} @@ -675,10 +680,33 @@ class NodeDriver(BaseDriver): timeout=timeout) # Execute the deployment task - self._run_deployment_script(task=kwargs['deploy'], - node=node, - ssh_client=ssh_client, - max_tries=max_tries) + try: + self._run_deployment_script(task=kwargs['deploy'], + node=node, + ssh_client=ssh_client, + max_tries=max_tries) + except Exception: + # If the user provided alternate usernames try them one by one + ssh_alternate_usernames = kwargs.get('ssh_alternate_usernames', []) + while ssh_alternate_usernames: + ssh_username = ssh_alternate_usernames.pop() + ssh_client = SSHClient(hostname=ip_addresses[0], + port=ssh_port, username=ssh_username, + password=password, + key=ssh_key_file, + timeout=ssh_timeout) + try: + # Connect to the SSH server running on the node + ssh_client = self._ssh_client_connect(ssh_client=ssh_client, + timeout=timeout) + self._run_deployment_script(task=kwargs['deploy'], + node=node, + ssh_client=ssh_client, + max_tries=max_tries) + return node + except Exception: + continue + raise except Exception: e = sys.exc_info()[1] raise DeploymentError(node=node, original_exception=e, driver=self)