diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-07-12 14:40:29 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-07-12 14:40:29 +0000 |
| commit | 6b80efb42927f5f116545bda584aebfb5ddb8afc (patch) | |
| tree | fd39fee115f15cc709e2adbb8d39b3c62076b549 /openstackclient/compute | |
| parent | d96f8b532aa462a684ccfdeae86b75c170a1dc24 (diff) | |
| parent | f89fc1ef3288fb432fe6f76268a92f6f1111a1eb (diff) | |
| download | python-openstackclient-6b80efb42927f5f116545bda584aebfb5ddb8afc.tar.gz | |
Merge "Fix address parsing for server ssh command"
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/server.py | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 5007b072..4efef975 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -55,6 +55,39 @@ def _format_servers_list_networks(networks): return '; '.join(output) +def _get_ip_address(addresses, address_type, ip_address_family): + # Old style addresses + if address_type in addresses: + for addy in addresses[address_type]: + if int(addy['version']) in ip_address_family: + return addy['addr'] + + # New style addresses + new_address_type = address_type + if address_type == 'public': + new_address_type = 'floating' + if address_type == 'private': + new_address_type = 'fixed' + for network in addresses: + for addy in addresses[network]: + # Case where it is list of strings + if isinstance(addy, six.string_types): + if new_address_type == 'fixed': + return addresses[network][0] + else: + return addresses[network][-1] + # Case where it is a dict + if 'OS-EXT-IPS:type' not in addy: + continue + if addy['OS-EXT-IPS:type'] == new_address_type: + if int(addy['version']) in ip_address_family: + return addy['addr'] + raise exceptions.CommandError( + "ERROR: No %s IP version %s address found" % + (address_type, ip_address_family) + ) + + def _prep_server_detail(compute_client, server): """Prepare the detailed server dict for printing @@ -1283,6 +1316,7 @@ class SshServer(command.Command): ) parser.add_argument( '-l', + dest='login', metavar='<login-name>', help=argparse.SUPPRESS, ) @@ -1381,13 +1415,6 @@ class SshServer(command.Command): # Build the command cmd = "ssh" - # Look for address type - if parsed_args.address_type: - address_type = parsed_args.address_type - if address_type not in server.addresses: - raise SystemExit("ERROR: No %s IP address found" % address_type) - - # Set up desired address family ip_address_family = [4, 6] if parsed_args.ipv4: ip_address_family = [4] @@ -1396,14 +1423,6 @@ class SshServer(command.Command): ip_address_family = [6] cmd += " -6" - # Grab the first matching IP address - ip_address = None - for addr in server.addresses[address_type]: - if int(addr['version']) in ip_address_family: - ip_address = addr['addr'] - if not ip_address: - raise SystemExit("ERROR: No IP address found") - if parsed_args.port: cmd += " -p %d" % parsed_args.port if parsed_args.identity: @@ -1418,6 +1437,9 @@ class SshServer(command.Command): cmd += " -v" cmd += " %s@%s" + ip_address = _get_ip_address(server.addresses, + parsed_args.address_type, + ip_address_family) self.log.debug("ssh command: %s", (cmd % (login, ip_address))) os.system(cmd % (login, ip_address)) |
