Skip to content

Commit 35c0ed2

Browse files
authored
Merge pull request Juniper#429 from dineshbaburam91/open_config_junos_config
Openconfig and yang supports in juniper_junos_config module
2 parents bab6077 + 65b180c commit 35c0ed2

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

library/juniper_junos_config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ def main():
748748
juniper_junos_common.CONFIG_DATABASE_CHOICES
749749
config_action_choices = [None] + juniper_junos_common.CONFIG_ACTION_CHOICES
750750
config_mode_choices = juniper_junos_common.CONFIG_MODE_CHOICES
751+
config_model_choices = juniper_junos_common.CONFIG_MODEL_CHOICES
751752

752753
# Create the module instance.
753754
junos_module = juniper_junos_common.JuniperJunosModule(
@@ -790,6 +791,16 @@ def main():
790791
type='str',
791792
required=False,
792793
default=None),
794+
model=dict(required=False,
795+
choices=config_model_choices,
796+
type='str',
797+
default=None),
798+
remove_ns=dict(required=False,
799+
type='bool',
800+
default=None),
801+
namespace=dict(required=False,
802+
type='str',
803+
default=None),
793804
check=dict(required=False,
794805
type='bool',
795806
aliases=['check_commit', 'commit_check'],
@@ -885,6 +896,10 @@ def main():
885896
confirmed = junos_module.params.get('confirmed')
886897
comment = junos_module.params.get('comment')
887898
check_commit_wait = junos_module.params.get('check_commit_wait')
899+
model = junos_module.params.get('model')
900+
remove_ns = junos_module.params.get('remove_ns')
901+
namespace = junos_module.params.get('namespace')
902+
888903

889904
# If retrieve is set and load and rollback are not set, then
890905
# check, diff, and commit default to False.
@@ -1076,7 +1091,10 @@ def main():
10761091
database=retrieve,
10771092
format=format,
10781093
options=options,
1079-
filter=filter)
1094+
filter=filter,
1095+
model=model,
1096+
namespace=namespace,
1097+
remove_ns=remove_ns)
10801098
if return_output is True:
10811099
if config is not None:
10821100
results['config'] = config

module_utils/juniper_junos_common.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ class ModuleDocFragment(object):
419419
- INFO
420420
- DEBUG
421421
422+
422423
'''
423424

424425
# _SUB_CONNECT_DOCUMENTATION is just _CONNECT_DOCUMENTATION with each
@@ -582,6 +583,8 @@ class ModuleDocFragment(object):
582583
'replace', 'override', 'overwrite']
583584
# Supported configuration modes
584585
CONFIG_MODE_CHOICES = ['exclusive', 'private']
586+
# Supported configuration models
587+
CONFIG_MODEL_CHOICES = ['openconfig', 'custom', 'ietf', 'True']
585588

586589

587590
def convert_to_bool_func(arg):
@@ -1409,7 +1412,8 @@ def close_configuration(self):
14091412
(str(ex)))
14101413

14111414
def get_configuration(self, database='committed', format='text',
1412-
options={}, filter=None):
1415+
options={}, filter=None, model=None,
1416+
namespace=None, remove_ns=True):
14131417
"""Return the device configuration in the specified format.
14141418
14151419
Return the database device configuration database in the format format.
@@ -1457,7 +1461,10 @@ def get_configuration(self, database='committed', format='text',
14571461
config = None
14581462
try:
14591463
config = self.dev.rpc.get_config(options=options,
1460-
filter_xml=filter)
1464+
filter_xml=filter,
1465+
model=model,
1466+
remove_ns=remove_ns,
1467+
namespace=namespace)
14611468
self.logger.debug("Configuration retrieved.")
14621469
except (self.pyez_exception.RpcError,
14631470
self.pyez_exception.ConnectError) as ex:
@@ -1469,7 +1476,7 @@ def get_configuration(self, database='committed', format='text',
14691476
if not isinstance(config, self.etree._Element):
14701477
self.fail_json(msg='Unexpected configuration type returned. '
14711478
'Configuration is: %s' % (str(config)))
1472-
if config.tag != 'configuration-text':
1479+
if model is None and config.tag != 'configuration-text':
14731480
self.fail_json(msg='Unexpected XML tag returned. '
14741481
'Configuration is: %s' %
14751482
(etree.tostring(config, pretty_print=True)))
@@ -1478,7 +1485,7 @@ def get_configuration(self, database='committed', format='text',
14781485
if not isinstance(config, self.etree._Element):
14791486
self.fail_json(msg='Unexpected configuration type returned. '
14801487
'Configuration is: %s' % (str(config)))
1481-
if config.tag != 'configuration-set':
1488+
if model is None and config.tag != 'configuration-set':
14821489
self.fail_json(msg='Unexpected XML tag returned. '
14831490
'Configuration is: %s' %
14841491
(etree.tostring(config, pretty_print=True)))
@@ -1487,7 +1494,7 @@ def get_configuration(self, database='committed', format='text',
14871494
if not isinstance(config, self.etree._Element):
14881495
self.fail_json(msg='Unexpected configuration type returned. '
14891496
'Configuration is: %s' % (str(config)))
1490-
if config.tag != 'configuration':
1497+
if model is None and config.tag != 'configuration':
14911498
self.fail_json(msg='Unexpected XML tag returned. '
14921499
'Configuration is: %s' %
14931500
(etree.tostring(config, pretty_print=True)))

0 commit comments

Comments
 (0)