def dc_access_config(task, tenant): vlans = dc_access_vlans(tenant, task.host['site']) l1 = [] for v in vlans: l1.append(str(v["id"])) x = (',').join(l1) command = "show vlan id {}".format(x) trunks = device_trunks(f'{task.host.name}', "mza-enc") 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_access.j2", path=f"/home/wamer/netops/automation/templates/cisco", vlans=vlans, trunks=trunks) # 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 Configuration on the device", replace=False, configuration=task.host["config"]) else: print("vlans exist")
def dc_access_params(task, tenant): temp = {} vlans = dc_access_vlans(tenant, task.host['site']) trunks = device_trunks(f'{task.host.name}', "mza-enc") temp['vlans'] = vlans temp['trunks'] = trunks data[task.host.name] = temp
def dc_fw_params(task, tenant): trunks = device_trunks(f'{task.host.name}', "agg") interfaces = dc_fw_prefixes(tenant) pat_ip = get_pat_ip(tenant) temp = {} temp['trunks'] = trunks temp['interfaces'] = interfaces temp['pat_ip'] = pat_ip data[task.host.name] = temp
def dc_access_template(task, tenant): # Generate VLANs group from NetBox vlans = dc_access_vlans(tenant, task.host['site']) # Get host trunk interfaces trunks = device_trunks(f'{task.host.name}', "mza-enc") # Transform inventory data to configuration via a template file r = task.run(task=text.template_file, name="Base Configuration", template="dc_access.j2", path=f"/home/wamer/netops/automation/templates/cisco", vlans=vlans, trunks=trunks)
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_fw_rollback(task, tenant): trunks = device_trunks(f'{task.host.name}', "agg") interafces = dc_fw_prefixes(tenant) # Transform inventory data to configuration via a template file r = task.run(task=text.template_file, name="Rollback Configuration", template="dc_fw.j2", path=f"/home/wamer/netops/automation/templates/rollback", interfaces=interafces, trunk=trunks[0]) task.host["config"] = r.result task.run(task=networking.netmiko_send_config, name="Loading Rollback Configuration on the device", config_commands=task.host["config"])
def dc_fw_config(task, tenant): trunks = device_trunks(f'{task.host.name}', "agg") interfaces = dc_fw_prefixes(tenant) pat_ip = get_pat_ip(tenant) r = task.run(task=text.template_file, name="Base Configuration", template="dc_fw.j2", path=f"/home/wamer/netops/automation/templates/cisco", interfaces=interfaces, trunk=trunks[0], cust=tenant, site=task.host['site'], pat_ip=pat_ip) task.host["config"] = r.result task.run(task=networking.netmiko_send_config, name="Loading Configuration on the device", config_commands=task.host["config"])
def dc_access_rollback(task, tenant): # Generate VLANs group from NetBox vlans, vlan_list = dc_access_vlans(tenant, task.host['site']) command = "show vlan id {}".format(vlan_list) # Get host trunk interfaces trunks = device_trunks(f'{task.host.name}', "mza-enc") # Transform inventory data to configuration via a template file r = task.run(task=text.template_file, name="Rollback Configuration", template="dc_access.j2", path=f"/home/wamer/netops/automation/templates/rollback", vlans=vlans, trunks=trunks) # 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_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")