mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
Add nso_show module for Cisco NSO (#34142)
* update version parsing and move requirements to nso_* modules prepare for introduction of nso_show module that has other version requirements than the existing nso_* modules. * Add nso_show module for retreiving config from Cisco NSO New module that supports getting configuration and operational data from Cisco NSO.
This commit is contained in:
parent
0f32f01644
commit
d6fd9703f1
8 changed files with 290 additions and 9 deletions
|
@ -159,6 +159,17 @@ class JsonRpc(object):
|
|||
resp, resp_json = self._write_call(payload)
|
||||
return resp_json['result']
|
||||
|
||||
def show_config(self, path, operational=False):
|
||||
payload = {
|
||||
'method': 'show_config',
|
||||
'params': {
|
||||
'path': path,
|
||||
'result_as': 'json',
|
||||
'with_oper': operational}
|
||||
}
|
||||
resp, resp_json = self._read_call(payload)
|
||||
return resp_json['result']
|
||||
|
||||
def run_action(self, th, path, params=None):
|
||||
if params is None:
|
||||
params = {}
|
||||
|
@ -481,16 +492,40 @@ def connect(params):
|
|||
return client
|
||||
|
||||
|
||||
def verify_version(client):
|
||||
def verify_version(client, required_versions=None):
|
||||
if required_versions is None:
|
||||
required_versions = [(4, 5), (4, 4, 3)]
|
||||
|
||||
version_str = client.get_system_setting('version')
|
||||
if not verify_version_str(version_str, required_versions):
|
||||
supported_versions = ', '.join(
|
||||
['.'.join([str(p) for p in required_version])
|
||||
for required_version in required_versions])
|
||||
raise ModuleFailException(
|
||||
'unsupported NSO version {0}. {1} or later supported'.format(
|
||||
version_str, supported_versions))
|
||||
|
||||
|
||||
def verify_version_str(version_str, required_versions):
|
||||
version = [int(p) for p in version_str.split('.')]
|
||||
if len(version) < 2:
|
||||
raise ModuleFailException(
|
||||
'unsupported NSO version format {0}'.format(version_str))
|
||||
if (version[0] < 4 or version[1] < 4 or
|
||||
(version[1] == 4 and (len(version) < 3 or version[2] < 3))):
|
||||
raise ModuleFailException(
|
||||
'unsupported NSO version {0}, only 4.4.3 or later is supported'.format(version_str))
|
||||
|
||||
def check_version(required_version, version):
|
||||
for pos in range(len(required_version)):
|
||||
if pos >= len(version):
|
||||
return False
|
||||
if version[pos] > required_version[pos]:
|
||||
return True
|
||||
if version[pos] < required_version[pos]:
|
||||
return False
|
||||
return True
|
||||
|
||||
for required_version in required_versions:
|
||||
if check_version(required_version, version):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def normalize_value(expected_value, value, key):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue