def dc_agg_params(task, tenant): vlans = dc_vlans(tenant, task.host['site']) trunks = device_trunks(f'{task.host.name}', "dc-fw") vrfs, interfaces = get_prefixes(tenant, f'{task.host["asset_tag"]}') outside_vrf = get_outside_vrf(tenant) print(vlans, trunks, vrfs, interfaces) temp = {} temp['vlans'] = vlans temp['trunks'] = trunks temp['vrfs'] = vrfs temp['interfaces'] = interfaces temp['outside_vrf'] = outside_vrf data[task.host.name] = temp
def dc_agg_template(task, tenant): # Generate VLANs group from NetBox vlans = dc_vlans(tenant, task.host['site']) # Get host trunk interfaces trunks = device_trunks(f'{task.host.name}', "dc-fw") # Get VRFs and Interfaces vrfs, interfaces = get_prefixes(tenant, f'{task.host["asset_tag"]}') print(f'{task.host["asset_tag"]}') # Transform inventory data to configuration via a template file r = task.run(task=text.template_file, name="Base Configuration", template="dc_agg.j2", path=f"/home/wamer/netops/automation/templates/cisco", cust=tenant, vlans=vlans, trunks=trunks, vrfs=vrfs, interfaces=interfaces)
def dc_agg_rollback(task, tenant): # Generate VLANs group from NetBox vlans = dc_vlans(tenant, task.host['site']) # Get host trunk interfaces trunks = device_trunks(f'{task.host.name}', "dc-fw") # Get VRFs and Interfaces vrfs, interfaces = get_prefixes(tenant, f'{task.host["asset_tag"]}') # Transform inventory data to configuration via a template file r = task.run(task=text.template_file, name="Rollback Configuration", template="dc_agg.j2", path=f"/home/wamer/netops/automation/templates/rollback", vlans=vlans, trunks=trunks, vrfs=vrfs, interfaces=interfaces) # Save the compiled configuration into a host variable task.host["config"] = r.result # Deploy that configuration to the device using NAPALM task.run(task=networking.napalm_configure, name="Loading Rollback Configuration on the device", replace=False, configuration=task.host["config"])
def dc_agg_config(task, tenant): vlans = dc_vlans(tenant, task.host['site']) trunks = device_trunks(f'{task.host.name}', "dc-fw") vrfs, interfaces = get_prefixes(tenant, f'{task.host["asset_tag"]}') vlan_list = dc_join_vlans(tenant) command = "show vlan id {}".format(vlan_list) r1 = task.run(task=networking.netmiko_send_command, command_string=command) if "not found" in r1.result: r = task.run(task=text.template_file, name="Base Configuration", template="dc_agg.j2", path=f"/home/wamer/netops/automation/templates/cisco", cust=tenant, vlans=vlans, trunks=trunks, vrfs=vrfs, interfaces=interfaces) task.host["config"] = r.result task.run(task=networking.napalm_configure, name="Loading Configuration on the device", replace=False, configuration=task.host["config"]) else: print("vlans exist")