Hyperfabric

This guide shows how to use the CiscoHyperfabric client to interact with Cisco Hyperfabric APIs.

The Hyperfabric client is designed for token-based, high-performance interaction with Cisco Hyperfabric APIs. It supports bulk operations, advanced path parameterization, and robust error handling for unsupported methods and authentication.

Connect to Hyperfabric
from wingpy import CiscoHyperfabric

hyperfabric = CiscoHyperfabric(
    token="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", # (1)!
)
  1. Environment variable:
    WINGPY_HYPERFABRIC_TOKEN
    

Create a fabric
payload = {"fabrics": [{"name": "TestFabric"}]}
rsp = hyperfabric.post("/fabrics", data=payload)
fabric_id = rsp.json()["fabrics"][0]["fabricId"]
print(fabric_id)

Get a fabric by ID
rsp = hyperfabric.get(
    "/fabrics/{fabricId}",
    path_params={"fabricId": fabric_id},
)
print(rsp.json())

Update a fabric
payload = {"name": "TestFabric", "description": "Updated description"}
rsp = hyperfabric.put(
    "/fabrics/{fabricId}",
    data=payload,
    path_params={"fabricId": fabric_id},
)
print(rsp.json()["description"])

Bulk create VRFs
vrfs = [{"name": f"Vrf-{i:03d}", "enabled": True} for i in range(20)]
payload = {"vrfs": vrfs}
rsp = hyperfabric.post(
    f"/fabrics/{fabric_id}/vrfs",
    data=payload,
)
print(rsp.status_code)

Get all VRFs for a fabric
vrfs = hyperfabric.get_all("/fabrics/{fabricId}/vrfs", path_params={"fabricId": fabric_id})
print(len(vrfs))

Delete a fabric
rsp = hyperfabric.delete(
    "/fabrics/{fabricId}",
    path_params={"fabricId": fabric_id},
)
print(rsp.status_code)

  • The client raises UnsupportedMethodError for unsupported HTTP methods (e.g., PATCH).
  • Instantiating without a token or with an invalid token raises a ValueError or returns a 401 response.