Skip to content

Basic Retrieve ANC Policy by Name

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

This sample retrieves information for a named Cisco Adaptive Network Control (ANC) policy via DXL and Cisco pxGrid.

The majority of the sample code is shown below.

Sample Code

# 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 'retrieve policy by name' method on service
        resp_dict = client.anc.retrieve_policy_by_name("quarantine_policy")

        # 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 the 'quarantine_policy' has not
        # already been created.
        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 retrieve_policy_by_name() method is invoked with the name of the policy for which to retrieve information, quarantine_policy.

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

Output

The output should appear similar to the following:

{
    "ancStatus": "success",
    "ancpolicy": [
        {
            "action": [
                "Quarantine"
            ],
            "name": "quarantine_policy"
        }
    ]
}

If the quarantine_policy has not been defined before the example is run, an Exception should be raised and output similar to the following should appear:

Error: Policy not configured (0)

Clone this wiki locally