add support for nova ssh user@host
the nova ssh command is convenient, but it is lacking some basic niceties that everyone is used to with ssh, for instance actually doing user@host to connect to an environment. This adds support for "nova ssh user@host" to work as one would expect. The functionality is added to both v1.1 and v3 clients. Tests for this, and other ssh behavior are added to the v1.1 tree (the v3 test_shell.py has not synced over yet). Change-Id: Ic4081f85c848507ebdc5e228ac345faf19127168
This commit is contained in:
parent
7e50eae5ac
commit
6ea070d62e
novaclient
@ -1832,6 +1832,25 @@ class ShellTest(utils.TestCase):
|
||||
'/os-migrations?cell_name=child1&host=host1'
|
||||
'&status=finished')
|
||||
|
||||
@mock.patch('novaclient.v1_1.shell._find_server')
|
||||
@mock.patch('os.system')
|
||||
def test_ssh(self, mock_system, mock_find_server):
|
||||
class FakeResources(object):
|
||||
addresses = {
|
||||
"private": [{'version': 4, 'addr': "1.1.1.1"}],
|
||||
"public": [{'version': 4, 'addr': "2.2.2.2"}]
|
||||
}
|
||||
mock_find_server.return_value = FakeResources()
|
||||
|
||||
self.run_command("ssh --login bob server")
|
||||
mock_system.assert_any_call("ssh -4 -p22 bob@2.2.2.2 ")
|
||||
self.run_command("ssh alice@server")
|
||||
mock_system.assert_any_call("ssh -4 -p22 alice@2.2.2.2 ")
|
||||
self.run_command("ssh --port 202 server")
|
||||
mock_system.assert_any_call("ssh -4 -p202 root@2.2.2.2 ")
|
||||
self.run_command("ssh --private server")
|
||||
mock_system.assert_any_call("ssh -4 -p22 root@1.1.1.1 ")
|
||||
|
||||
|
||||
class GetSecgroupTest(utils.TestCase):
|
||||
def test_with_integer(self):
|
||||
|
@ -3034,6 +3034,11 @@ def do_credentials(cs, _args):
|
||||
default='')
|
||||
def do_ssh(cs, args):
|
||||
"""SSH into a server."""
|
||||
if '@' in args.server:
|
||||
user, server = args.server.split('@', 1)
|
||||
args.login = user
|
||||
args.server = server
|
||||
|
||||
addresses = _find_server(cs, args.server).addresses
|
||||
address_type = "private" if args.private else "public"
|
||||
version = 6 if args.ipv6 else 4
|
||||
|
@ -2801,6 +2801,11 @@ def do_credentials(cs, _args):
|
||||
default='')
|
||||
def do_ssh(cs, args):
|
||||
"""SSH into a server."""
|
||||
if '@' in args.server:
|
||||
user, server = args.server.split('@', 1)
|
||||
args.login = user
|
||||
args.server = server
|
||||
|
||||
addresses = _find_server(cs, args.server).addresses
|
||||
address_type = "private" if args.private else "public"
|
||||
version = 6 if args.ipv6 else 4
|
||||
|
Loading…
x
Reference in New Issue
Block a user