Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions library/junos_install_config
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ options:
required: false
default: no
choices: ['true','false','yes','no']
update:
description:
- If set to ``True`` Compare a complete loaded configuration against
the candidate configuration. For each hierarchy level or
configuration object that is different in the two configurations,
the version in the loaded configuration replaces the version in the
candidate configuration. When the configuration is later committed,
only system processes that are affected by the changed configuration
elements parse the new configuration. This action is supported from
PyEZ 2.1
required: false
default: no
choices: ['true','false','yes','no']
replace:
description:
- Specify whether the configuration I(file) uses "replace:" statements.
Expand Down Expand Up @@ -202,13 +215,13 @@ import os
from distutils.version import LooseVersion



def _load_via_netconf(module):
args = module.params

try:
from jnpr.junos import Device
from jnpr.junos.exception import *
from jnpr.junos.exception import LockError, UnlockError, \
ConfigLoadError, CommitError
from jnpr.junos.utils.config import Config
from jnpr.junos.version import VERSION
if not LooseVersion(VERSION) >= LooseVersion('1.2.2'):
Expand All @@ -228,9 +241,12 @@ def _load_via_netconf(module):
in_check_mode = module.check_mode
overwrite = module.boolean(module.params['overwrite'])
replace = module.boolean(module.params['replace'])
update = module.boolean(module.params['update'])

if all([overwrite, replace]):
msg = "Overwrite and Replace cannot both be True!"
actions = filter(lambda item: module.params.get(item, False),
('overwrite', 'replace', 'update'))
if len(list(actions)) >= 2:
msg = 'action can be only one among %s' % ', '.join(actions)
logging.error(msg)
module.fail_json(msg=msg)

Expand Down Expand Up @@ -281,6 +297,8 @@ def _load_via_netconf(module):
load_args['merge'] = False
elif overwrite is True:
load_args['overwrite'] = True
elif update is True:
load_args['update'] = True
elif overwrite is False:
load_args['merge'] = True
cu.load(**load_args)
Expand Down Expand Up @@ -433,6 +451,7 @@ def main():
console=dict(required=False, default=None),
file=dict(required=True),
overwrite=dict(required=False, type='bool', choices=BOOLEANS, default=False),
update=dict(required=False, type='bool', choices=BOOLEANS, default=False),
replace=dict(required=False, type='bool', choices=BOOLEANS, default=False),
logfile=dict(required=False, default=None),
diffs_file=dict(required=False, default=None),
Expand Down