diff --git a/akanda/rug/cli/router.py b/akanda/rug/cli/router.py index 1998a031..c0d8dc1d 100644 --- a/akanda/rug/cli/router.py +++ b/akanda/rug/cli/router.py @@ -23,7 +23,7 @@ import sys from akanda.rug import commands from akanda.rug.cli import message -from akanda.rug.api import nova, neutron +from akanda.rug.api import nova from novaclient import exceptions from oslo.config import cfg @@ -154,13 +154,15 @@ class RouterSSH(_TenantRouterCmd): region_name=self.app.rug_ini.auth_region, ) router_id = parsed_args.router_id.lower() - ports = n_c.show_router(router_id).get('router', {}).get('ports', {}) - for port in ports: - if port['fixed_ips'] and \ - port['device_owner'] == neutron.DEVICE_OWNER_ROUTER_MGT: - v6_addr = port['fixed_ips'].pop()['ip_address'] - try: - cmd = ["ssh", "root@%s" % v6_addr] + parsed_args.remainder - subprocess.check_call(cmd) - except subprocess.CalledProcessError as e: - sys.exit(e.returncode) + port = n_c.list_ports(name="AKANDA:MGT:%s" % router_id) + try: + mgmt_ip_addr = port['ports'][0]['fixed_ips'].pop()['ip_address'] + except (KeyError, IndexError): + raise ValueError( + "No router management address found for router with id %s" + % router_id) + try: + cmd = ["ssh", "akanda@%s" % mgmt_ip_addr] + parsed_args.remainder + subprocess.check_call(cmd) + except subprocess.CalledProcessError as e: + sys.exit(e.returncode)