Beispiel #1
0
def interface_list(device):
    """Retrieve the list of interfaces on a device.

        Returns the port name, status, description, and vlan information.

        Example command:

            ./wlanmgmt.py inteface_list switch1

    """
    click.secho("Retrieving the interfaces for {}.".format(device))

    from dnacsdk.networkDevice import NetworkDevice
    device = NetworkDevice(dnacp, hostname = device)

    headers = ["Port Name", "Status", "Description", "VLAN", "Voice VLAN"]
    table = list()

    for interface in device.interfaces.values():
        tr = [
                interface["portName"],
                "{}/{}".format(interface["adminStatus"], interface["status"]),
                interface["description"],
                interface["vlanId"],
                interface["voiceVlan"]
            ]
        table.append(tr)
    try:
        click.echo(tabulate.tabulate(table, headers, tablefmt="fancy_grid"))
    except UnicodeEncodeError:
        click.echo(tabulate.tabulate(table, headers, tablefmt="grid"))
Beispiel #2
0
def device_list():
    """Retrieve and return network devices list.

        Returns the hostname, management IP, and family of each device.

        Example command:

            ./wlanmgmt.py device_list

    """
    click.secho("Retrieving the devices.")

    from dnacsdk.networkDevice import NetworkDevice
    devices = NetworkDevice.get_all(dnacp)

    headers = ["Hostname", "Management IP", "Family","ID"]
    table = list()

    for device in devices:
        tr = [device.hostname, device.managementIpAddress, device.family, device.id]
        table.append(tr)
    try:
        click.echo(tabulate.tabulate(table, headers, tablefmt="fancy_grid"))
    except UnicodeEncodeError:
        click.echo(tabulate.tabulate(table, headers, tablefmt="grid"))
Beispiel #3
0
def deploy(template, target, parameters):
    """Deploy a template with DNA Center.

        Provide all template parameters and their values as arguements in the format of: "PARAMTER=VALUE"

        You can find the list of parameters using:
          ./wlanmgmt.py template_list

        Example command:

          ./wlanmgmt.py deploy --template VLANSetup --target switch1 \\\n"VLANID=3001" "VLANNAME=Data"
    """
    click.secho("Attempting deployment.")

    from dnacsdk.networkDevice import NetworkDevice
    from dnacsdk.templateProgrammer import Template


    device = NetworkDevice(dnacp, hostname = target)
    template = Template(dnacp, name = template)

    deploy_params = dict([param.split("=", maxsplit=1) for param in parameters])

    # Deploy Template
    deployment = template.deploy(
                                    dnacp,
                                    target_device_ip = device.managementIpAddress,
                                    params = deploy_params
                                )

    print("Deployment Status: {}".format(
        Template.deployment_status(dnacp, deployment)["devices"][0]["status"])
    )
Beispiel #4
0
def unassign_device_site(parameters):
    """Unassign a site to a device

        Provide all parameters and their values as arguements in the format of: "PARAMTER=VALUE"

        You can find the list of parameters using:
          ./wlanmgmt.py device_list

        Example command:

          ./wlanmgmt.py unassign_device_site "deviceid=<deviceid>" "siteid=<siteid>"
    """
    click.secho("Attempting device/site unassignment.")

    from dnacsdk.networkDevice import NetworkDevice

    unassign_params = dict([param.split("=", maxsplit=1) for param in parameters])

    # Create VLAN
    unassignment = NetworkDevice.unassign(dnacp, unassign_params = unassign_params)

    print("Unassignment Status: {}".format(unassignment))