Get Capabilities Support (#49880)

Signed-off-by: Anas Badaha <anasb@mellanox.com>
This commit is contained in:
anasbadaha 2018-12-14 06:15:31 +02:00 committed by Ganesh Nalawade
parent 4019d4f6d1
commit fb8b59fcc6
2 changed files with 22 additions and 9 deletions

View file

@ -139,15 +139,27 @@ def get_interfaces_config(module, interface_type, flags=None, json_fmt=True):
return show_cmd(module, cmd, json_fmt) return show_cmd(module, cmd, json_fmt)
def show_version(module):
return show_cmd(module, "show version")
def get_bgp_summary(module): def get_bgp_summary(module):
cmd = "show running-config protocol bgp" cmd = "show running-config protocol bgp"
return show_cmd(module, cmd, json_fmt=False, fail_on_error=False) return show_cmd(module, cmd, json_fmt=False, fail_on_error=False)
def get_capabilities(module):
"""Returns platform info of the remove device
"""
if hasattr(module, '_capabilities'):
return module._capabilities
connection = get_connection(module)
try:
capabilities = connection.get_capabilities()
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
module._capabilities = json.loads(capabilities)
return module._capabilities
class BaseOnyxModule(object): class BaseOnyxModule(object):
ONYX_API_VERSION = "3.6.6000" ONYX_API_VERSION = "3.6.6000"
@ -168,9 +180,9 @@ class BaseOnyxModule(object):
pass pass
def _get_os_version(self): def _get_os_version(self):
version_data = show_version(self._module) capabilities = get_capabilities(self._module)
return self.get_config_attr( device_info = capabilities['device_info']
version_data, "Product release") return device_info['network_os_version']
# pylint: disable=unused-argument # pylint: disable=unused-argument
def check_declarative_intent_params(self, result): def check_declarative_intent_params(self, result):

View file

@ -36,10 +36,11 @@ class Cliconf(CliconfBase):
reply = self.get(b'show version | json-print') reply = self.get(b'show version | json-print')
data = json.loads(reply) data = json.loads(reply)
device_info['network_os'] = data['Product name'] device_info['network_os'] = data['Product name']
device_info['network_os_version'] = data['Version summary'] device_info['network_os_version'] = data['Product release']
device_info['network_os_version_summary'] = data['Version summary']
device_info['network_os_model'] = data['Product model'] device_info['network_os_model'] = data['Product model']
reply = self.get(b'show version | include Hostname') reply = self.get(b'show hosts | include Hostname')
data = to_text(reply, errors='surrogate_or_strict').strip() data = to_text(reply, errors='surrogate_or_strict').strip()
hostname = data.split(':')[1] hostname = data.split(':')[1]
hostname = hostname.strip() hostname = hostname.strip()