11from __future__ import annotations
22
3+ from typing import Annotated , TypedDict
4+
35from fastapi import FastAPI
46from pydantic import BaseModel , Field
57
@@ -12,6 +14,115 @@ class MyDTO(BaseModel):
1214 a : int = Field (description = "This is the docstring for a single field" )
1315
1416
17+ class CiscoAccessSwitchVLAN (TypedDict ):
18+ vlan_id : int
19+
20+
21+ class CiscoAccessSwitchVLANInterface (TypedDict ):
22+ name : str
23+
24+
25+ class CiscoAccessSwitchInterface (TypedDict ):
26+ name : str
27+
28+
29+ class ISEProfile (TypedDict ):
30+ name : str
31+
32+
33+ class CiscoAccessSwitchTemplateParams (TypedDict ):
34+ hostname : Annotated [str , Field (description = "The hostname of the switch" )]
35+ vlans : Annotated [
36+ list [CiscoAccessSwitchVLAN ],
37+ Field (
38+ description = (
39+ "All the VLANs that should be configured on the switch. These are "
40+ "all the VLANs associated with the location in Nautobot."
41+ )
42+ ),
43+ ]
44+ vlan_interfaces : Annotated [
45+ list [CiscoAccessSwitchVLANInterface ],
46+ Field (
47+ description = "All the virtual interfaces on the switch with the tag 'VLAN'."
48+ ),
49+ ]
50+ client_interfaces : Annotated [
51+ list [CiscoAccessSwitchInterface ],
52+ Field (description = "All the client interfaces on the switch." ),
53+ ]
54+ downlink_interfaces : Annotated [
55+ list [CiscoAccessSwitchInterface ],
56+ Field (description = "All the downlink interfaces on the switch." ),
57+ ]
58+ uplink_interfaces : Annotated [
59+ list [CiscoAccessSwitchInterface ],
60+ Field (description = "All the uplink interfaces on the switch." ),
61+ ]
62+ device_mgmt_ip : Annotated [
63+ str ,
64+ Field (
65+ description = "The IP address assigned to the switch for management purposes."
66+ ),
67+ ]
68+ management_vlan_id : Annotated [
69+ int ,
70+ Field (
71+ description = (
72+ "The VLAN ID of the management VLAN. This is used for the "
73+ "management interface and default gateway."
74+ )
75+ ),
76+ ]
77+ management_interface : Annotated [
78+ str ,
79+ Field (
80+ description = (
81+ "The interface on which the management IP is configured. This is "
82+ "used to determine which interface should be used for out-of-band "
83+ "management access to the switch."
84+ )
85+ ),
86+ ]
87+ default_gateway : Annotated [
88+ str ,
89+ Field (description = "The default gateway for the management VLAN." ),
90+ ]
91+ snmp_contact : Annotated [
92+ str ,
93+ Field (description = "The SNMP contact information for the switch." ),
94+ ]
95+ snmp_location : Annotated [
96+ str ,
97+ Field (description = "The SNMP location information for the switch." ),
98+ ]
99+ ise_profile : Annotated [
100+ ISEProfile ,
101+ Field (description = "The ISE profile to use for this switch." ),
102+ ]
103+
104+
15105@app .get ("/dto" , response_model = MyDTO )
16106def get_dto () -> MyDTO :
17107 return MyDTO (a = 1 )
108+
109+
110+ @app .get ("/switch-template" , response_model = CiscoAccessSwitchTemplateParams )
111+ def get_switch_template () -> CiscoAccessSwitchTemplateParams :
112+ switch_vlan : CiscoAccessSwitchVLAN = {"vlan_id" : 10 }
113+ switch_interface : CiscoAccessSwitchInterface = {"name" : "GigabitEthernet1/0/1" }
114+ return {
115+ "hostname" : "switch-01" ,
116+ "vlans" : [switch_vlan ],
117+ "vlan_interfaces" : [{"name" : "Vlan10" }],
118+ "client_interfaces" : [switch_interface ],
119+ "downlink_interfaces" : [switch_interface ],
120+ "uplink_interfaces" : [switch_interface ],
121+ "device_mgmt_ip" : "192.0.2.10" ,
122+ "management_vlan_id" : 10 ,
123+ "management_interface" : "Vlan10" ,
124+ "default_gateway" : "192.0.2.1" ,
125+ "snmp_contact" : "Network Operations" ,
126+ "snmp_location" : "DC1" ,
127+ "ise_profile" : {"name" : "default" },
128+ }
0 commit comments