Fixed astara-ctl ssh command

* Modified 'RouterSSH' class to parse neutron ports for ASTARA:MGT port
* Added Exception Handling in class for key or index error
* Fixed ssh username used for connection
* Generalized variable name for management ip address usage

Change-Id: Ia02c3718796e2c6b59312f5341ced76dd18dd8a2
Partial-Bug: #1524592
This commit is contained in:
Ryan Petrello 2016-02-02 09:51:49 -08:00 committed by Adam Gandelman
parent a14cd260ec
commit d35432a5d3
1 changed files with 13 additions and 11 deletions

View File

@ -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)