Cisco Crosswork Planning Design 7.2.x User Guide

PDF

Cisco Crosswork Planning Design 7.2.x User Guide

Run external scripts

Want to summarize with AI?

Log in

Outlines how to configure external scripts to automate network model operations using the OPM and Design RPC Python libraries. This enables you to run customized scripts and CLI tools efficiently in your environment.


In Cisco Crosswork Planning, OPM Python library (previously known as OPM API) and Design RPC Python libraries (previously known as Design RPC APIs) are supported via scripts. You can upload customized scripts that are created using these APIs. You can also use the scripts to run the CLI tools.

OPM Python libraries provide a powerful Python API to manipulate network models. It lets you operate on the network without having to worry about device-specific properties. Even if the underlying routers are replaced by routers from a different vendor, the API calls remain exactly the same.

For a sample Python script, refer to Example: Run external scripts.

Complete these steps to run the external scripts.

Procedure

1.

From the main menu, choose Job Manager.

The Job Manager page opens, displaying the list of all jobs submitted as background jobs.

2.

Click Add icon > Using script.

A list of scripts available in the user space appears.

3.

Select the required script and click Next to continue.

If the required script is not available in the list, use the Upload script option to upload the script. The script name appears under Available Scripts. You can also find the script file under the Network Models > My user space > All files section.

4.

Select the network models on which you want to run the script, and click Next.

5.

Enter the input configuration options in the text field using this format and click Next.

script_name arg1 arg2

Use the Edit button to change the script file, if required.

6.

On the Run Settings page, choose whether to execute the task immediately or schedule it for a later time. You can also set priority for the jobs. Choose from these Execute options:

  • Now: Choose this option to run the script immediately.

  • As a scheduled job: Choose this option to execute the task as an asynchronous job. If you choose this option, set the time at which you want to run the script. The script runs at the scheduled time.

7.

Track the status of the job on the Job Manager page. The Job column displays "User-Script" for the script jobs. Once the job completes, import the output plan file into user space to visualize it. For more information, refer to Access output plan files from job manager.


Example: Run external scripts

This topic explains how to use an external Python script with Cisco Crosswork Planning to append a description to every interface in the network, demonstrating the process and command usage.

The sample Python script (ext_exe_eg.py) appends a description to every interface in the network with "My IGP metric is <value>."

Contents of ext_exe_eg.py:

import sys
from com.cisco.wae.opm.network import Network

src  = sys.argv[1]
dest = sys.argv[2]

srcNet =  Network(src)

for node in srcNet.model.nodes:
    cnt = 1
    for iface in node.interfaces:
        iface.description = 'My IGP metric is ' + str(iface.igp_metric)
        cnt = cnt + 1    

srcNet.write(dest)

Upload this script and run it from Job Manager using the steps mentioned in Run external scripts. Use this command:

ext_exe_eg.py input-plan.pln out-plan.pln

Once the job is completed successfully, download the output file (.tar file) from the Job Manager page, extract it, and import the updated plan file into the user space to access it.