use crate::Client;
use crate::error::Result;
use crate::pagination::Page;
use crate::query::QueryBuilder;
use crate::resource::Resource;
use serde::Serialize;
pub type Cable = crate::models::Cable;
pub type CablePath = crate::models::CablePath;
pub type Device = crate::models::Device;
pub type DeviceNapalm = crate::models::DeviceNapalm;
pub type ConsolePort = crate::models::ConsolePort;
pub type ConsolePortTemplate = crate::models::ConsolePortTemplate;
pub type ConsoleServerPortTemplate = crate::models::ConsoleServerPortTemplate;
pub type ConsoleServerPort = crate::models::ConsoleServerPort;
pub type ControllerManagedDeviceGroup = crate::models::ControllerManagedDeviceGroup;
pub type Controller = crate::models::Controller;
pub type DeviceBayTemplate = crate::models::DeviceBayTemplate;
pub type DeviceBay = crate::models::DeviceBay;
pub type DeviceFamily = crate::models::DeviceFamily;
pub type DeviceRedundancyGroup = crate::models::DeviceRedundancyGroup;
pub type DeviceTypeToSoftwareImageFile = crate::models::DeviceTypeToSoftwareImageFile;
pub type DeviceType = crate::models::DeviceType;
pub type FrontPortTemplate = crate::models::FrontPortTemplate;
pub type FrontPort = crate::models::FrontPort;
pub type InterfaceConnection = crate::models::InterfaceConnection;
pub type InterfaceRedundancyGroupAssociation = crate::models::InterfaceRedundancyGroupAssociation;
pub type InterfaceRedundancyGroup = crate::models::InterfaceRedundancyGroup;
pub type InterfaceTemplate = crate::models::InterfaceTemplate;
pub type InterfaceVdcAssignment = crate::models::InterfaceVdcAssignment;
pub type Interface = crate::models::Interface;
pub type InventoryItem = crate::models::InventoryItem;
pub type LocationType = crate::models::LocationType;
pub type Location = crate::models::Location;
pub type Stats = crate::models::Stats;
pub type Manufacturer = crate::models::Manufacturer;
pub type ModuleBayTemplate = crate::models::ModuleBayTemplate;
pub type ModuleBay = crate::models::ModuleBay;
pub type ModuleFamily = crate::models::ModuleFamily;
pub type ModuleType = crate::models::ModuleType;
pub type Module = crate::models::Module;
pub type Platform = crate::models::Platform;
pub type PowerPort = crate::models::PowerPort;
pub type PowerFeed = crate::models::PowerFeed;
pub type PowerOutletTemplate = crate::models::PowerOutletTemplate;
pub type PowerOutlet = crate::models::PowerOutlet;
pub type PowerPanel = crate::models::PowerPanel;
pub type PowerPortTemplate = crate::models::PowerPortTemplate;
pub type RackGroup = crate::models::RackGroup;
pub type RackReservation = crate::models::RackReservation;
pub type Rack = crate::models::Rack;
pub type RackUnit = crate::models::RackUnit;
pub type RearPortTemplate = crate::models::RearPortTemplate;
pub type RearPort = crate::models::RearPort;
pub type SoftwareImageFile = crate::models::SoftwareImageFile;
pub type SoftwareVersion = crate::models::SoftwareVersion;
pub type VirtualChassis = crate::models::VirtualChassis;
pub type VirtualDeviceContext = crate::models::VirtualDeviceContext;
#[derive(Serialize)]
struct ConnectedDeviceQuery<'a> {
peer_device: &'a str,
peer_interface: &'a str,
#[serde(flatten)]
extra: Option<QueryBuilder>,
}
pub type CablesApi = Resource<crate::models::Cable>;
pub type ConsoleConnectionsApi = Resource<crate::models::ConsolePort>;
pub type ConsolePortTemplatesApi = Resource<crate::models::ConsolePortTemplate>;
pub type ConsolePortsApi = Resource<crate::models::ConsolePort>;
pub type ConsoleServerPortTemplatesApi = Resource<crate::models::ConsoleServerPortTemplate>;
pub type ConsoleServerPortsApi = Resource<crate::models::ConsoleServerPort>;
pub type ControllerManagedDeviceGroupsApi = Resource<crate::models::ControllerManagedDeviceGroup>;
pub type ControllersApi = Resource<crate::models::Controller>;
pub type DeviceBayTemplatesApi = Resource<crate::models::DeviceBayTemplate>;
pub type DeviceBaysApi = Resource<crate::models::DeviceBay>;
pub type DeviceFamiliesApi = Resource<crate::models::DeviceFamily>;
pub type DeviceRedundancyGroupsApi = Resource<crate::models::DeviceRedundancyGroup>;
pub type DeviceTypesToSoftwareImageFilesApi =
Resource<crate::models::DeviceTypeToSoftwareImageFile>;
pub type DeviceTypesApi = Resource<crate::models::DeviceType>;
pub type DevicesApi = Resource<crate::models::Device>;
pub type FrontPortTemplatesApi = Resource<crate::models::FrontPortTemplate>;
pub type FrontPortsApi = Resource<crate::models::FrontPort>;
pub type InterfaceConnectionsApi = Resource<crate::models::InterfaceConnection>;
pub type InterfaceRedundancyGroupAssociationsApi =
Resource<crate::models::InterfaceRedundancyGroupAssociation>;
pub type InterfaceRedundancyGroupsApi = Resource<crate::models::InterfaceRedundancyGroup>;
pub type InterfaceTemplatesApi = Resource<crate::models::InterfaceTemplate>;
pub type InterfaceVdcAssignmentsApi = Resource<crate::models::InterfaceVdcAssignment>;
pub type InterfacesApi = Resource<crate::models::Interface>;
pub type InventoryItemsApi = Resource<crate::models::InventoryItem>;
pub type LocationTypesApi = Resource<crate::models::LocationType>;
pub type LocationsApi = Resource<crate::models::Location>;
pub type ManufacturersApi = Resource<crate::models::Manufacturer>;
pub type ModuleBayTemplatesApi = Resource<crate::models::ModuleBayTemplate>;
pub type ModuleBaysApi = Resource<crate::models::ModuleBay>;
pub type ModuleFamiliesApi = Resource<crate::models::ModuleFamily>;
pub type ModuleTypesApi = Resource<crate::models::ModuleType>;
pub type ModulesApi = Resource<crate::models::Module>;
pub type PlatformsApi = Resource<crate::models::Platform>;
pub type PowerConnectionsApi = Resource<crate::models::PowerPort>;
pub type PowerFeedsApi = Resource<crate::models::PowerFeed>;
pub type PowerOutletTemplatesApi = Resource<crate::models::PowerOutletTemplate>;
pub type PowerOutletsApi = Resource<crate::models::PowerOutlet>;
pub type PowerPanelsApi = Resource<crate::models::PowerPanel>;
pub type PowerPortTemplatesApi = Resource<crate::models::PowerPortTemplate>;
pub type PowerPortsApi = Resource<crate::models::PowerPort>;
pub type RackGroupsApi = Resource<crate::models::RackGroup>;
pub type RackReservationsApi = Resource<crate::models::RackReservation>;
pub type RacksApi = Resource<crate::models::Rack>;
pub type RearPortTemplatesApi = Resource<crate::models::RearPortTemplate>;
pub type RearPortsApi = Resource<crate::models::RearPort>;
pub type SoftwareImageFilesApi = Resource<crate::models::SoftwareImageFile>;
pub type SoftwareVersionsApi = Resource<crate::models::SoftwareVersion>;
pub type VirtualChassisApi = Resource<crate::models::VirtualChassis>;
pub type VirtualDeviceContextsApi = Resource<crate::models::VirtualDeviceContext>;
#[derive(Clone)]
pub struct DcimApi {
client: Client,
}
impl DcimApi {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub fn cables(&self) -> CablesApi {
Resource::new(self.client.clone(), "dcim/cables/")
}
pub async fn connected_device(
&self,
peer_device: &str,
peer_interface: &str,
query: Option<QueryBuilder>,
) -> Result<Vec<crate::models::Device>> {
let params = ConnectedDeviceQuery {
peer_device,
peer_interface,
extra: query,
};
self.client
.get_with_params("dcim/connected-device/", ¶ms)
.await
}
pub async fn device_napalm(&self, id: &str) -> Result<DeviceNapalm> {
self.client
.get(&format!("dcim/devices/{}/napalm/", id))
.await
}
pub async fn front_port_paths(
&self,
id: &str,
query: Option<QueryBuilder>,
) -> Result<Page<CablePath>> {
let query = query.unwrap_or_default();
self.client
.get_with_params(&format!("dcim/front-ports/{}/paths/", id), &query)
.await
}
pub async fn rear_port_paths(
&self,
id: &str,
query: Option<QueryBuilder>,
) -> Result<Page<CablePath>> {
let query = query.unwrap_or_default();
self.client
.get_with_params(&format!("dcim/rear-ports/{}/paths/", id), &query)
.await
}
pub async fn rack_elevation(
&self,
id: &str,
query: Option<QueryBuilder>,
) -> Result<Page<RackUnit>> {
let query = query.unwrap_or_default();
self.client
.get_with_params(&format!("dcim/racks/{}/elevation/", id), &query)
.await
}
pub fn console_connections(&self) -> ConsoleConnectionsApi {
Resource::new(self.client.clone(), "dcim/console-connections/")
}
pub fn console_port_templates(&self) -> ConsolePortTemplatesApi {
Resource::new(self.client.clone(), "dcim/console-port-templates/")
}
pub fn console_ports(&self) -> ConsolePortsApi {
Resource::new(self.client.clone(), "dcim/console-ports/")
}
pub async fn console_port_trace(&self, id: &str) -> Result<crate::models::ConsolePort> {
self.client
.get(&format!("dcim/console-ports/{}/trace/", id))
.await
}
pub fn console_server_port_templates(&self) -> ConsoleServerPortTemplatesApi {
Resource::new(self.client.clone(), "dcim/console-server-port-templates/")
}
pub fn console_server_ports(&self) -> ConsoleServerPortsApi {
Resource::new(self.client.clone(), "dcim/console-server-ports/")
}
pub async fn console_server_port_trace(
&self,
id: &str,
) -> Result<crate::models::ConsoleServerPort> {
self.client
.get(&format!("dcim/console-server-ports/{}/trace/", id))
.await
}
pub fn controller_managed_device_groups(&self) -> ControllerManagedDeviceGroupsApi {
Resource::new(
self.client.clone(),
"dcim/controller-managed-device-groups/",
)
}
pub fn controllers(&self) -> ControllersApi {
Resource::new(self.client.clone(), "dcim/controllers/")
}
pub fn device_bay_templates(&self) -> DeviceBayTemplatesApi {
Resource::new(self.client.clone(), "dcim/device-bay-templates/")
}
pub fn device_bays(&self) -> DeviceBaysApi {
Resource::new(self.client.clone(), "dcim/device-bays/")
}
pub fn device_families(&self) -> DeviceFamiliesApi {
Resource::new(self.client.clone(), "dcim/device-families/")
}
pub fn device_redundancy_groups(&self) -> DeviceRedundancyGroupsApi {
Resource::new(self.client.clone(), "dcim/device-redundancy-groups/")
}
pub fn device_types_to_software_image_files(&self) -> DeviceTypesToSoftwareImageFilesApi {
Resource::new(
self.client.clone(),
"dcim/device-types-to-software-image-files/",
)
}
pub fn device_types(&self) -> DeviceTypesApi {
Resource::new(self.client.clone(), "dcim/device-types/")
}
pub fn devices(&self) -> DevicesApi {
Resource::new(self.client.clone(), "dcim/devices/")
}
pub fn front_port_templates(&self) -> FrontPortTemplatesApi {
Resource::new(self.client.clone(), "dcim/front-port-templates/")
}
pub fn front_ports(&self) -> FrontPortsApi {
Resource::new(self.client.clone(), "dcim/front-ports/")
}
pub fn interface_connections(&self) -> InterfaceConnectionsApi {
Resource::new(self.client.clone(), "dcim/interface-connections/")
}
pub fn interface_redundancy_group_associations(
&self,
) -> InterfaceRedundancyGroupAssociationsApi {
Resource::new(
self.client.clone(),
"dcim/interface-redundancy-group-associations/",
)
}
pub fn interface_redundancy_groups(&self) -> InterfaceRedundancyGroupsApi {
Resource::new(self.client.clone(), "dcim/interface-redundancy-groups/")
}
pub fn interface_templates(&self) -> InterfaceTemplatesApi {
Resource::new(self.client.clone(), "dcim/interface-templates/")
}
pub fn interface_vdc_assignments(&self) -> InterfaceVdcAssignmentsApi {
Resource::new(self.client.clone(), "dcim/interface-vdc-assignments/")
}
pub fn interfaces(&self) -> InterfacesApi {
Resource::new(self.client.clone(), "dcim/interfaces/")
}
pub async fn interface_trace(&self, id: &str) -> Result<crate::models::Interface> {
self.client
.get(&format!("dcim/interfaces/{}/trace/", id))
.await
}
pub fn inventory_items(&self) -> InventoryItemsApi {
Resource::new(self.client.clone(), "dcim/inventory-items/")
}
pub fn location_types(&self) -> LocationTypesApi {
Resource::new(self.client.clone(), "dcim/location-types/")
}
pub fn locations(&self) -> LocationsApi {
Resource::new(self.client.clone(), "dcim/locations/")
}
pub async fn location_stats(
&self,
id: &str,
query: Option<QueryBuilder>,
) -> Result<Page<Stats>> {
let query = query.unwrap_or_default();
self.client
.get_with_params(&format!("dcim/locations/{}/stats/", id), &query)
.await
}
pub fn manufacturers(&self) -> ManufacturersApi {
Resource::new(self.client.clone(), "dcim/manufacturers/")
}
pub fn module_bay_templates(&self) -> ModuleBayTemplatesApi {
Resource::new(self.client.clone(), "dcim/module-bay-templates/")
}
pub fn module_bays(&self) -> ModuleBaysApi {
Resource::new(self.client.clone(), "dcim/module-bays/")
}
pub fn module_families(&self) -> ModuleFamiliesApi {
Resource::new(self.client.clone(), "dcim/module-families/")
}
pub fn module_types(&self) -> ModuleTypesApi {
Resource::new(self.client.clone(), "dcim/module-types/")
}
pub fn modules(&self) -> ModulesApi {
Resource::new(self.client.clone(), "dcim/modules/")
}
pub fn platforms(&self) -> PlatformsApi {
Resource::new(self.client.clone(), "dcim/platforms/")
}
pub fn power_connections(&self) -> PowerConnectionsApi {
Resource::new(self.client.clone(), "dcim/power-connections/")
}
pub fn power_feeds(&self) -> PowerFeedsApi {
Resource::new(self.client.clone(), "dcim/power-feeds/")
}
pub async fn power_feed_trace(&self, id: &str) -> Result<crate::models::PowerFeed> {
self.client
.get(&format!("dcim/power-feeds/{}/trace/", id))
.await
}
pub fn power_outlet_templates(&self) -> PowerOutletTemplatesApi {
Resource::new(self.client.clone(), "dcim/power-outlet-templates/")
}
pub fn power_outlets(&self) -> PowerOutletsApi {
Resource::new(self.client.clone(), "dcim/power-outlets/")
}
pub async fn power_outlet_trace(&self, id: &str) -> Result<crate::models::PowerOutlet> {
self.client
.get(&format!("dcim/power-outlets/{}/trace/", id))
.await
}
pub fn power_panels(&self) -> PowerPanelsApi {
Resource::new(self.client.clone(), "dcim/power-panels/")
}
pub fn power_port_templates(&self) -> PowerPortTemplatesApi {
Resource::new(self.client.clone(), "dcim/power-port-templates/")
}
pub fn power_ports(&self) -> PowerPortsApi {
Resource::new(self.client.clone(), "dcim/power-ports/")
}
pub async fn power_port_trace(&self, id: &str) -> Result<crate::models::PowerPort> {
self.client
.get(&format!("dcim/power-ports/{}/trace/", id))
.await
}
pub fn rack_groups(&self) -> RackGroupsApi {
Resource::new(self.client.clone(), "dcim/rack-groups/")
}
pub fn rack_reservations(&self) -> RackReservationsApi {
Resource::new(self.client.clone(), "dcim/rack-reservations/")
}
pub fn racks(&self) -> RacksApi {
Resource::new(self.client.clone(), "dcim/racks/")
}
pub fn rear_port_templates(&self) -> RearPortTemplatesApi {
Resource::new(self.client.clone(), "dcim/rear-port-templates/")
}
pub fn rear_ports(&self) -> RearPortsApi {
Resource::new(self.client.clone(), "dcim/rear-ports/")
}
pub fn software_image_files(&self) -> SoftwareImageFilesApi {
Resource::new(self.client.clone(), "dcim/software-image-files/")
}
pub fn software_versions(&self) -> SoftwareVersionsApi {
Resource::new(self.client.clone(), "dcim/software-versions/")
}
pub fn virtual_chassis(&self) -> VirtualChassisApi {
Resource::new(self.client.clone(), "dcim/virtual-chassis/")
}
pub fn virtual_device_contexts(&self) -> VirtualDeviceContextsApi {
Resource::new(self.client.clone(), "dcim/virtual-device-contexts/")
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ClientConfig;
use httpmock::{Method::GET, MockServer};
use serde_json::json;
fn test_client() -> Client {
let config = ClientConfig::new("https://nautobot.example.com", "token");
Client::new(config).unwrap()
}
fn assert_path<T>(resource: Resource<T>, expected: &str)
where
T: serde::de::DeserializeOwned,
{
let paginator = resource.paginate(None).unwrap();
assert_eq!(paginator.next_url(), Some(expected));
}
#[test]
fn dcim_accessors_return_expected_paths() {
let api = DcimApi::new(test_client());
assert_path(api.cables(), "dcim/cables/");
assert_path(api.console_connections(), "dcim/console-connections/");
assert_path(api.console_port_templates(), "dcim/console-port-templates/");
assert_path(api.console_ports(), "dcim/console-ports/");
assert_path(
api.console_server_port_templates(),
"dcim/console-server-port-templates/",
);
assert_path(api.console_server_ports(), "dcim/console-server-ports/");
assert_path(
api.controller_managed_device_groups(),
"dcim/controller-managed-device-groups/",
);
assert_path(api.controllers(), "dcim/controllers/");
assert_path(api.device_bay_templates(), "dcim/device-bay-templates/");
assert_path(api.device_bays(), "dcim/device-bays/");
assert_path(api.device_families(), "dcim/device-families/");
assert_path(
api.device_redundancy_groups(),
"dcim/device-redundancy-groups/",
);
assert_path(
api.device_types_to_software_image_files(),
"dcim/device-types-to-software-image-files/",
);
assert_path(api.device_types(), "dcim/device-types/");
assert_path(api.devices(), "dcim/devices/");
assert_path(api.front_port_templates(), "dcim/front-port-templates/");
assert_path(api.front_ports(), "dcim/front-ports/");
assert_path(api.interface_connections(), "dcim/interface-connections/");
assert_path(
api.interface_redundancy_group_associations(),
"dcim/interface-redundancy-group-associations/",
);
assert_path(
api.interface_redundancy_groups(),
"dcim/interface-redundancy-groups/",
);
assert_path(api.interface_templates(), "dcim/interface-templates/");
assert_path(
api.interface_vdc_assignments(),
"dcim/interface-vdc-assignments/",
);
assert_path(api.interfaces(), "dcim/interfaces/");
assert_path(api.inventory_items(), "dcim/inventory-items/");
assert_path(api.location_types(), "dcim/location-types/");
assert_path(api.locations(), "dcim/locations/");
assert_path(api.manufacturers(), "dcim/manufacturers/");
assert_path(api.module_bay_templates(), "dcim/module-bay-templates/");
assert_path(api.module_bays(), "dcim/module-bays/");
assert_path(api.module_families(), "dcim/module-families/");
assert_path(api.module_types(), "dcim/module-types/");
assert_path(api.modules(), "dcim/modules/");
assert_path(api.platforms(), "dcim/platforms/");
assert_path(api.power_connections(), "dcim/power-connections/");
assert_path(api.power_feeds(), "dcim/power-feeds/");
assert_path(api.power_outlet_templates(), "dcim/power-outlet-templates/");
assert_path(api.power_outlets(), "dcim/power-outlets/");
assert_path(api.power_panels(), "dcim/power-panels/");
assert_path(api.power_port_templates(), "dcim/power-port-templates/");
assert_path(api.power_ports(), "dcim/power-ports/");
assert_path(api.rack_groups(), "dcim/rack-groups/");
assert_path(api.rack_reservations(), "dcim/rack-reservations/");
assert_path(api.racks(), "dcim/racks/");
assert_path(api.rear_port_templates(), "dcim/rear-port-templates/");
assert_path(api.rear_ports(), "dcim/rear-ports/");
assert_path(api.software_image_files(), "dcim/software-image-files/");
assert_path(api.software_versions(), "dcim/software-versions/");
assert_path(api.virtual_chassis(), "dcim/virtual-chassis/");
assert_path(
api.virtual_device_contexts(),
"dcim/virtual-device-contexts/",
);
}
#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn dcim_connected_device_and_traces_hit_expected_paths() {
let server = MockServer::start();
let config = ClientConfig::new(server.base_url(), "token").with_max_retries(0);
let client = Client::new(config).unwrap();
let api = DcimApi::new(client);
server.mock(|when, then| {
when.method(GET)
.path("/api/dcim/connected-device/")
.query_param("peer_device", "dev1")
.query_param("peer_interface", "eth0");
then.status(200).json_body(json!([]));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/console-ports/1/trace/");
then.status(200).json_body(json!({"name": "console-1"}));
});
server.mock(|when, then| {
when.method(GET)
.path("/api/dcim/console-server-ports/1/trace/");
then.status(200).json_body(json!({"name": "cs-1"}));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/interfaces/1/trace/");
then.status(200).json_body(json!({
"name": "eth0",
"type": {},
"status": {}
}));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/power-feeds/1/trace/");
then.status(200).json_body(json!({
"name": "feed-1",
"power_panel": {},
"status": {}
}));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/power-outlets/1/trace/");
then.status(200).json_body(json!({"name": "outlet-1"}));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/power-ports/1/trace/");
then.status(200).json_body(json!({"name": "port-1"}));
});
let connected = api.connected_device("dev1", "eth0", None).await.unwrap();
assert!(connected.is_empty());
let _ = api.console_port_trace("1").await.unwrap();
let _ = api.console_server_port_trace("1").await.unwrap();
let _ = api.interface_trace("1").await.unwrap();
let _ = api.power_feed_trace("1").await.unwrap();
let _ = api.power_outlet_trace("1").await.unwrap();
let _ = api.power_port_trace("1").await.unwrap();
}
#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn dcim_assignment_resources_hit_expected_paths() {
let server = MockServer::start();
let config = ClientConfig::new(server.base_url(), "token").with_max_retries(0);
let client = Client::new(config).unwrap();
let api = DcimApi::new(client);
let list_response = json!({
"count": 0,
"next": null,
"previous": null,
"results": []
});
server.mock(|when, then| {
when.method(GET)
.path("/api/dcim/controller-managed-device-groups/");
then.status(200).json_body(list_response.clone());
});
server.mock(|when, then| {
when.method(GET)
.path("/api/dcim/device-types-to-software-image-files/");
then.status(200).json_body(list_response.clone());
});
server.mock(|when, then| {
when.method(GET)
.path("/api/dcim/interface-redundancy-group-associations/");
then.status(200).json_body(list_response.clone());
});
let controller_groups = api
.controller_managed_device_groups()
.list(None)
.await
.unwrap();
assert!(controller_groups.results.is_empty());
let device_types_to_software = api
.device_types_to_software_image_files()
.list(None)
.await
.unwrap();
assert!(device_types_to_software.results.is_empty());
let interface_associations = api
.interface_redundancy_group_associations()
.list(None)
.await
.unwrap();
assert!(interface_associations.results.is_empty());
}
#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn dcim_special_endpoints_hit_expected_paths() {
let server = MockServer::start();
let config = ClientConfig::new(server.base_url(), "token").with_max_retries(0);
let client = Client::new(config).unwrap();
let api = DcimApi::new(client);
let list_response = json!({
"count": 0,
"next": null,
"previous": null,
"results": []
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/devices/1/napalm/");
then.status(200).json_body(json!({ "method": {} }));
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/front-ports/1/paths/");
then.status(200).json_body(list_response.clone());
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/rear-ports/1/paths/");
then.status(200).json_body(list_response.clone());
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/racks/1/elevation/");
then.status(200).json_body(list_response.clone());
});
server.mock(|when, then| {
when.method(GET).path("/api/dcim/locations/1/stats/");
then.status(200).json_body(json!({
"count": 1,
"next": null,
"previous": null,
"results": [
{
"title": "Devices",
"count": 5,
"ui_url": "https://nautobot.example.com/dcim/devices/?location=1",
"api_url": "https://nautobot.example.com/api/dcim/devices/?location=1"
}
]
}));
});
let napalm = api.device_napalm("1").await.unwrap();
assert!(napalm.method.is_empty());
let front_paths = api.front_port_paths("1", None).await.unwrap();
assert!(front_paths.results.is_empty());
let rear_paths = api.rear_port_paths("1", None).await.unwrap();
assert!(rear_paths.results.is_empty());
let elevation = api.rack_elevation("1", None).await.unwrap();
assert!(elevation.results.is_empty());
let stats = api.location_stats("1", None).await.unwrap();
assert_eq!(stats.count, 1);
assert_eq!(stats.results[0].title, "Devices");
assert_eq!(stats.results[0].count, 5);
}
}