mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Fix netyang modules and examples
This commit is contained in:
parent
0e0a73fd91
commit
3f6fea2e1a
@ -52,7 +52,7 @@ def __virtual__():
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _get_root_object(*models):
|
||||
def _get_root_object(models):
|
||||
'''
|
||||
Read list of models and returns a Root object with the proper models added.
|
||||
'''
|
||||
@ -69,7 +69,7 @@ def _get_root_object(*models):
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
def diff(candidate, running, *models):
|
||||
def diff(candidate, running, models):
|
||||
'''
|
||||
Returns the difference between two configuration entities structured
|
||||
according to the YANG model.
|
||||
@ -119,15 +119,15 @@ def diff(candidate, running, *models):
|
||||
}
|
||||
}
|
||||
'''
|
||||
first = _get_root_object(*models)
|
||||
first = _get_root_object(models)
|
||||
first.load_dict(candidate)
|
||||
second = _get_root_object(*models)
|
||||
second = _get_root_object(models)
|
||||
second.load_dict(running)
|
||||
return napalm_yang.utils.diff(first, second)
|
||||
|
||||
|
||||
@proxy_napalm_wrap
|
||||
def parse(*models, **kwargs):
|
||||
def parse(models, **kwargs):
|
||||
'''
|
||||
Parse configuration from the device.
|
||||
|
||||
@ -345,7 +345,9 @@ def parse(*models, **kwargs):
|
||||
profiles = kwargs.pop('profiles', [])
|
||||
if not profiles and hasattr(napalm_device, 'profile'): # pylint: disable=undefined-variable
|
||||
profiles = napalm_device.profile # pylint: disable=undefined-variable
|
||||
root = _get_root_object(*models)
|
||||
if not profiles:
|
||||
profiles = [__grains__.get('os')]
|
||||
root = _get_root_object(models)
|
||||
parser_kwargs = {
|
||||
'device': napalm_device, # pylint: disable=undefined-variable
|
||||
'profile': profiles
|
||||
@ -358,7 +360,7 @@ def parse(*models, **kwargs):
|
||||
|
||||
|
||||
@proxy_napalm_wrap
|
||||
def get_config(data, *models, **kwargs):
|
||||
def get_config(data, models, **kwargs):
|
||||
'''
|
||||
Return the native config.
|
||||
|
||||
@ -394,16 +396,21 @@ def get_config(data, *models, **kwargs):
|
||||
profiles = kwargs.pop('profiles', [])
|
||||
if not profiles and hasattr(napalm_device, 'profile'): # pylint: disable=undefined-variable
|
||||
profiles = napalm_device.profile # pylint: disable=undefined-variable
|
||||
if not profiles:
|
||||
profiles = [__grains__.get('os')]
|
||||
parser_kwargs = {
|
||||
'profile': profiles
|
||||
}
|
||||
root = _get_root_object(*models)
|
||||
root = _get_root_object(models)
|
||||
root.load_dict(data)
|
||||
return root.translate_config(**parser_kwargs)
|
||||
native_config = root.translate_config(**parser_kwargs)
|
||||
log.debug('Generated config')
|
||||
log.debug(native_config)
|
||||
return native_config
|
||||
|
||||
|
||||
@proxy_napalm_wrap
|
||||
def load_config(data, *models, **kwargs):
|
||||
def load_config(data, models, **kwargs):
|
||||
'''
|
||||
Generate and load the config on the device using the OpenConfig or IETF
|
||||
models and device profiles.
|
||||
@ -538,7 +545,7 @@ def load_config(data, *models, **kwargs):
|
||||
result:
|
||||
True
|
||||
'''
|
||||
config = get_config(data, *models, **kwargs)
|
||||
config = get_config(data, models, **kwargs)
|
||||
test = kwargs.pop('test', False)
|
||||
debug = kwargs.pop('debug', False)
|
||||
commit = kwargs.pop('commit', True)
|
||||
@ -552,7 +559,7 @@ def load_config(data, *models, **kwargs):
|
||||
|
||||
|
||||
@proxy_napalm_wrap
|
||||
def compliance_report(data, *models, **kwargs):
|
||||
def compliance_report(data, models, **kwargs):
|
||||
'''
|
||||
Return the compliance report using YANG objects.
|
||||
|
||||
@ -592,6 +599,6 @@ def compliance_report(data, *models, **kwargs):
|
||||
}
|
||||
'''
|
||||
filepath = kwargs.pop('filepath', '')
|
||||
root = _get_root_object(*models)
|
||||
root = _get_root_object(models)
|
||||
root.load_dict(data)
|
||||
return root.compliance_report(filepath)
|
||||
|
@ -75,7 +75,7 @@ def __virtual__():
|
||||
|
||||
def managed(name,
|
||||
data,
|
||||
*models,
|
||||
models,
|
||||
**kwargs):
|
||||
'''
|
||||
Manage the device configuration given the input data strucuted
|
||||
@ -131,7 +131,8 @@ def managed(name,
|
||||
config:
|
||||
mtu: 9000
|
||||
Et2:
|
||||
description: "description example"
|
||||
config:
|
||||
description: "description example"
|
||||
'''
|
||||
ret = salt.utils.napalm.default_ret(name)
|
||||
test = kwargs.get('test', False) or __opts__.get('test', False)
|
||||
@ -145,13 +146,13 @@ def managed(name,
|
||||
data = {'to_dict': data}
|
||||
with fopen(temp_file, 'w') as file_handle:
|
||||
yaml.dump(data, file_handle)
|
||||
device_config = __salt__['napalm_yang.parse'](*models,
|
||||
device_config = __salt__['napalm_yang.parse'](models,
|
||||
config=True,
|
||||
profiles=profiles)
|
||||
log.debug('Parsed the config from the device:')
|
||||
log.debug(device_config)
|
||||
compliance_report = __salt__['napalm_yang.compliance_report'](device_config,
|
||||
*models,
|
||||
models,
|
||||
filepath=temp_file)
|
||||
log.debug('Compliance report:')
|
||||
log.debug(compliance_report)
|
||||
@ -167,7 +168,7 @@ def managed(name,
|
||||
if '_kwargs' in data:
|
||||
data.pop('_kwargs')
|
||||
loaded_changes = __salt__['napalm_yang.load_config'](data,
|
||||
*models,
|
||||
models,
|
||||
profiles=profiles,
|
||||
test=test,
|
||||
debug=debug,
|
||||
@ -181,7 +182,7 @@ def managed(name,
|
||||
|
||||
def configured(name,
|
||||
data,
|
||||
*models,
|
||||
models,
|
||||
**kwargs):
|
||||
'''
|
||||
Configure the network device, given the input data strucuted
|
||||
@ -248,7 +249,8 @@ def configured(name,
|
||||
config:
|
||||
mtu: 9000
|
||||
Et2:
|
||||
description: "description example"
|
||||
config:
|
||||
description: "description example"
|
||||
'''
|
||||
ret = salt.utils.napalm.default_ret(name)
|
||||
test = kwargs.get('test', False) or __opts__.get('test', False)
|
||||
@ -259,7 +261,7 @@ def configured(name,
|
||||
if '_kwargs' in data:
|
||||
data.pop('_kwargs')
|
||||
loaded_changes = __salt__['napalm_yang.load_config'](data,
|
||||
*models,
|
||||
models,
|
||||
profiles=profiles,
|
||||
test=test,
|
||||
debug=debug,
|
||||
|
Loading…
Reference in New Issue
Block a user