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 managment ip address usage

Change-Id: I2b06e5cb512612cd1b99a438568ddd17a1653c84
Closes-Bug: #1524592
This commit is contained in:
Eric Lopez 2016-01-02 00:08:51 -08:00
parent c1344d03dc
commit f24c5a1eee
2 changed files with 19 additions and 19 deletions

View File

@ -24,7 +24,7 @@ import sys
from astara.common.i18n import _LW
from astara import commands
from astara.cli import message
from astara.api import keystone, nova, neutron
from astara.api import keystone, nova
from novaclient import exceptions
from oslo_config import cfg
@ -154,22 +154,18 @@ class RouterSSH(_TenantRouterCmd):
return p
def take_action(self, parsed_args):
n_c = client.Client(
username=self.app.rug_ini.admin_user,
password=self.app.rug_ini.admin_password,
tenant_name=self.app.rug_ini.admin_tenant_name,
auth_url=self.app.rug_ini.auth_url,
auth_strategy=self.app.rug_ini.auth_strategy,
region_name=self.app.rug_ini.auth_region,
)
ks_session = keystone.KeystoneSession()
n_c = client.Client(session=ks_session.session)
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="ASTARA: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", "astara@%s" % mgmt_ip_addr] + parsed_args.remainder
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)

View File

@ -0,0 +1,4 @@
---
fixes:
- Bug `152492 <https://bugs.launchpad.net/astara/+bug/1524592>`_
Fixed astara-ctl ssh command