Skip to content

Basic Get ANC Endpoint Policy by IP Address

Jeremy Barlow edited this page Oct 26, 2017 · 4 revisions

This sample gets information for a Cisco Adaptive Network Control (ANC) endpoint via DXL and Cisco pxGrid. The sample identifies the endpoint by its IP address.

The majority of the sample code is shown below.

Sample Code

# IP address of the endpoint for which to get information
HOST_IP = "<SPECIFY_IP_ADDRESS>"

# Create the client
with DxlClient(config) as dxl_client:

    # Connect to the fabric
    dxl_client.connect()

    logger.info("Connected to DXL fabric.")

    # Create client wrapper
    client = CiscoPxGridClient(dxl_client)

    try:
        # Invoke 'get endpoint by IP' method on service
        resp_dict = client.anc.get_endpoint_by_ip(HOST_IP)

        # Print out the response (convert dictionary to JSON for pretty
        # printing)
        print("Response:\n{0}".format(
            MessageUtils.dict_to_json(resp_dict, pretty_print=True)))
    except Exception as ex:
        # An exception should be raised if a policy has not already been
        # associated with the endpoint.
        print(str(ex))

Once a connection is established to the DXL fabric, a CiscoPxGridClient instance is created which will be used to communicate with Cisco pxGrid.

Next, the get_endpoint_by_ip() method is invoked with the IP address of the endpoint for which to retrieve information.

The final step is to display the contents of the returned dictionary (dict) which contains the results of the attempt to retrieve the endpoint information.

Output

If information can be retrieved successfully for the endpoint, the output should appear similar to the following:

{
    "ancEndpoint": [
        {
            "macAddress": "00:11:22:33:44:55",
            "policyName": "quarantine_policy"
        }
    ],
    "ancStatus": "success"
}

If no policy has already been associated with the endpoint but an active session exists for the endpoint before the example is run, an Exception should be raised and output similar to the following should appear:

Error: No policy applied to specified IP (0)

If no session has been established for an endpoint which corresponds to the IP address, an Exception should be raised and output similar to the following should appear:

Error: No active session found for this IP address (0)

Clone this wiki locally