Created
September 24, 2020 14:56
-
-
Save h4ndzdatm0ld/f9942cf65ba73c99b49c91d9c8a9609a to your computer and use it in GitHub Desktop.
nornir-netconf-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iac_render(task): | |
''' Load the YAML vars and render the Jinja2 Templates. Deploy L3VPN/VPRN via NETCONF. | |
''' | |
# Load Yaml Files by Hostname | |
vars_yaml = f"vars/{task.host}.yml" | |
vars_data = task.run(task=load_yaml, file=vars_yaml) | |
# With the YAML variables loaded, render the Jinja2 Template with the previous function: iac_render. | |
template= f"{task.host.platform}-vrf.j2" | |
vprn = task.run(task=template_file, path='templates/', template=template, data=vars_data.result['VRF']) | |
# Convert the generated template into a string. | |
payload = str(vprn.result) | |
# Extract the custom data.target attribute passed into the group of hosts to specifcy 'candidate' target | |
# configuration store to run the edit_config rpc against on our task.device. | |
# IOSXR/Nokia take advantage of candidate/lock via netconf. | |
deploy_config = task.run(task=netconf_edit_config, target=task.host['target'], config=payload) | |
# # Extract the new Service ID Created: | |
if task.host.platform == 'alcatel_sros': | |
for vrf in vars_data.result['VRF']: | |
serviceid = vrf['SERVICE_ID'] | |
servicename = vrf['SERVICE_NAME'] | |
# Ensure the customer - id is always interpreted as a string: | |
customer = vrf['CUSTOMER_ID'] | |
customerid = str(customer) | |
if task.host.platform == 'iosxr': | |
for vrf in vars_data.result['VRF']: | |
servicename = vrf['SERVICE_NAME'] | |
serviceid = None | |
rpcreply = deploy_config.result | |
# if 'ok' in result: | |
if rpcreply.ok: | |
print(f"NETCONF RPC = OK. Committing Changes:: {task.host.platform}") | |
task.run(task=netconf_commit) | |
# Validate service on the 7750. | |
if task.host.platform == 'alcatel_sros': | |
nc_getvprn(task, serviceid=serviceid, servicename=servicename, customerid=customerid) | |
elif task.host.platform =='iosxr': | |
pass | |
# Duplicate the getvprn function but for iosxr | |
elif rpcreply != rpcreply.ok: | |
print(rpcreply) | |
else: | |
print(f"NETCONF Error. {rpcreply}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment