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")
Exemple #2
0
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_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)
Exemple #4
0
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"])