Basic Create Policy Example

This sample creates a Cisco Adaptive Network Control (ANC) policy.

Prerequisites

Running

To run this sample execute the sample/basic/basic_anc_create_policy_example.py script as follows:

python sample/basic/basic_anc_create_policy_example.py

If the policy can be created successfully, the output should appear similar to the following:

{
    "actions": [
        "SHUT_DOWN"
    ],
    "name": "ANC_Shut_2"
}

The received results are displayed.

If the policy already exists:

Error: 500 (0)

Details

The majority of the sample code is shown below:

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 'create policy'
        resp_dict = client.anc.create_policy("ANC_Shut_2",["SHUT_DOWN"])

        # 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:
        print(str(ex))

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

Next, the dxlciscopxgridclient.client.AncClientCategory.create_policy() method is invoked with the policy name and list of actions to perform.

The final step is to display the contents of the returned dictionary (dict) which contains the created policy.