Skip to content

CML

This guide shows how to use the CiscoModelingLabs client to interact with Cisco Modeling Labs APIs.

The wingpy Cisco Modeling Labs client is designed for seamless interaction with CML's REST API. E.g. advanced device management, credential operations, and task polling.

Wingpy handles authentication, token refresh, logging, concurrency and error management for you.

  • The client raises UnsupportedMethodError for unsupported HTTP methods (e.g., PATCH).
  • You can call cml.authenticate() to force (re-)authentication.

The Basics - Connect and Get Labs

Environment Variables

You can set the environment variables in your shell to avoid hardcoding sensitive information in your code. Check out the FAQ section on Environment Variables for more details.

Connect to Cisco Modeling Labs
import wingpy

cml = wingpy.CiscoModelingLabs(
    base_url="https://cml.example.com", # (1)!
    username="admin", # (2)!
    password="password" # (3)!
)
  1. Environment variable:
    WINGPY_CML_BASE_URL
    
  2. Environment variable:
    WINGPY_CML_USERNAME
    
  3. Environment variable:
    WINGPY_CML_PASSWORD
    

Get all labs
all_labs = cml.get_all("/labs")
for lab_id in all_labs:
    print(lab_id)

Get node details
rsp = cml.get("/labs/{lab_id}/nodes/{node_id}",
        path_params={
            "lab_id": "7cb6906a-503d-4ae0-aebc-056bbaf8fbe3",
            "node_id": "2ff3ccbc-be22-43ba-843e-4a42e88410d8"
        }
    )
print(rsp.json())

Create new lab
rsp = cml.post("/lab", data={"title": "My New Lab"})
print(rsp.status_code())

Start lab
rsp = cml.put("/labs/{lab_id}/start",
        path_params={
            "lab_id": "7cb6906a-503d-4ae0-aebc-056bbaf8fbe3"
        }
    )
print(rsp.status_code())

Update lab setting
rsp = cml.patch("/labs/{lab_id}",
        path_params={
            "lab_id": "7cb6906a-503d-4ae0-aebc-056bbaf8fbe3"
        },
        data={
            "description": "Just testing wingpy with CML"
        }
    )
print(rsp.status_code())

Remove lab
rsp = cml.delete("/labs/{lab_id}",
        path_params={
            "lab_id": "7cb6906a-503d-4ae0-aebc-056bbaf8fbe3"
        }
    )
print(rsp.status_code())