Compare commits
5 Commits
f39ed466f6
...
16b3673fb4
Author | SHA1 | Date |
---|---|---|
Ishan Jain | 16b3673fb4 | |
Ishan Jain | 8b04dbb4d2 | |
Ishan Jain | 4d21251a5b | |
Ishan Jain | 3a5163f284 | |
Ishan Jain | 26393517fa |
|
@ -364,11 +364,12 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
|||
|
||||
[[package]]
|
||||
name = "mikrotik"
|
||||
version = "0.0.7"
|
||||
version = "0.0.10"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-test",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mikrotik"
|
||||
version = "0.0.7"
|
||||
version = "0.0.10"
|
||||
edition = "2021"
|
||||
description = "REST API Wrapper for Mikrotik API"
|
||||
license = "MIT"
|
||||
|
@ -14,5 +14,6 @@ tokio = { version = "1.17.0", features = ["macros"] }
|
|||
base64 = "0.13.0"
|
||||
reqwest = { version = "0.11.4", features = ["rustls-tls", "serde_json", "json"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
thiserror = "1.0.30"
|
||||
url = "2.2.2"
|
||||
|
|
|
@ -2,7 +2,7 @@ use reqwest::{
|
|||
header::{HeaderMap, HeaderValue},
|
||||
Method, Request, Url,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{de::DeserializeOwned, ser::Serialize};
|
||||
use std::num::ParseFloatError;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -59,6 +59,56 @@ impl Client {
|
|||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn execute_post<P: Serialize, Q: DeserializeOwned>(
|
||||
&mut self,
|
||||
url: &str,
|
||||
payload: P,
|
||||
) -> Result<Q, ClientError> {
|
||||
let url = self.base_url.join(url)?;
|
||||
|
||||
// Serialize request body
|
||||
let body = serde_json::to_string(&payload)?;
|
||||
let body: reqwest::Body = body.into();
|
||||
|
||||
let mut req = Request::new(Method::POST, url);
|
||||
self.add_credentials(req.headers_mut());
|
||||
*req.body_mut() = Some(body);
|
||||
|
||||
// Add Content-Type Header
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
|
||||
*req.headers_mut() = headers;
|
||||
|
||||
let response = self.client.execute(req).await?.json::<Q>().await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn execute_post_with_no_response<P: Serialize>(
|
||||
&mut self,
|
||||
url: &str,
|
||||
payload: P,
|
||||
) -> Result<(), ClientError> {
|
||||
let url = self.base_url.join(url)?;
|
||||
|
||||
// Serialize request body
|
||||
let body = serde_json::to_string(&payload)?;
|
||||
let body: reqwest::Body = body.into();
|
||||
|
||||
let mut req = Request::new(Method::POST, url);
|
||||
self.add_credentials(req.headers_mut());
|
||||
*req.body_mut() = Some(body);
|
||||
|
||||
// Add Content-Type Header
|
||||
req.headers_mut()
|
||||
.insert("Content-Type", HeaderValue::from_static("application/json"));
|
||||
|
||||
self.client.execute(req).await?;
|
||||
// TODO(ishan): Check status code!!
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
@ -71,4 +121,7 @@ pub enum ClientError {
|
|||
|
||||
#[error(transparent)]
|
||||
ParseFloatError(#[from] ParseFloatError),
|
||||
|
||||
#[error(transparent)]
|
||||
SerdeJsonError(#[from] serde_json::Error),
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::{interface::types::WireguardInterface, Client, ClientError};
|
||||
pub use crate::interface::types::WireguardInterface;
|
||||
use crate::{Client, ClientError};
|
||||
|
||||
/// list all wireguard interfaces
|
||||
pub async fn list(client: &mut Client) -> Result<Vec<WireguardInterface>, ClientError> {
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
pub use crate::ip::types::DhcpClient;
|
||||
use crate::{Client, ClientError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// List all DHCPv4 Clients
|
||||
pub async fn list(client: &mut Client) -> Result<Vec<DhcpClient>, ClientError> {
|
||||
let url = format!("{}/dhcp-client", super::BASE);
|
||||
|
||||
client.execute_get::<Vec<DhcpClient>>(&url).await
|
||||
}
|
||||
|
||||
/// Get a specific DHCPv4 Client
|
||||
pub async fn get(client: &mut Client, id: &str) -> Result<DhcpClient, ClientError> {
|
||||
let url = format!("{}/dhcp-client/{}", super::BASE, id);
|
||||
|
||||
client.execute_get::<DhcpClient>(&url).await
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DhcpClientInput {
|
||||
pub numbers: String,
|
||||
}
|
||||
|
||||
/// Release a DHCP Lease
|
||||
pub async fn release(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/dhcp-client/release", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Renew a DHCP Lease
|
||||
pub async fn renew(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/dhcp-client/renew", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Remove a DHCP client
|
||||
pub async fn remove(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/dhcp-client/remove", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Disable a DHCP client
|
||||
pub async fn disable(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/dhcp-client/disable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Enable a DHCP client
|
||||
pub async fn enable(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/dhcp-client/enable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
// TODO(ishan): Add reset/set/unset methods
|
|
@ -1,5 +1,7 @@
|
|||
pub mod address;
|
||||
pub mod dhcp_client;
|
||||
pub mod dhcp_server;
|
||||
pub mod route;
|
||||
mod types;
|
||||
|
||||
const BASE: &str = "rest/ip";
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
pub use crate::ip::types::Route;
|
||||
use crate::{Client, ClientError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// List all IPv4 Routes
|
||||
pub async fn list(client: &mut Client) -> Result<Vec<Route>, ClientError> {
|
||||
let url = format!("{}/route", super::BASE);
|
||||
|
||||
client.execute_get::<Vec<Route>>(&url).await
|
||||
}
|
||||
|
||||
/// Get a specific IPv4 Route
|
||||
pub async fn get(client: &mut Client, rid: &str) -> Result<Route, ClientError> {
|
||||
let url = format!("{}/route/{}", super::BASE, rid);
|
||||
|
||||
client.execute_get::<Route>(&url).await
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RouteInput {
|
||||
pub numbers: String,
|
||||
}
|
||||
|
||||
/// Disable an IPv4 Route
|
||||
pub async fn disable(client: &mut Client, input: RouteInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/route/disable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RouteInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Enable an IPv4 Route
|
||||
pub async fn enable(client: &mut Client, input: RouteInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/route/enable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RouteInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Remove a IPv4 Route
|
||||
pub async fn remove(client: &mut Client, input: RouteInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/route/remove", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RouteInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
//TODO(ishan): add set/unset/reset
|
|
@ -1,4 +1,4 @@
|
|||
use crate::serde_helpers::deserialize_bool;
|
||||
use crate::serde_helpers::{deserialize_bool, deserialize_u16};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -106,3 +106,82 @@ pub struct Address {
|
|||
pub invalid: bool,
|
||||
pub network: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DhcpClient {
|
||||
#[serde(rename = ".id")]
|
||||
pub id: String,
|
||||
#[serde(rename = "add-default-route")]
|
||||
pub add_default_route: String,
|
||||
pub address: String,
|
||||
#[serde(rename = "dhcp-options")]
|
||||
pub dhcp_options: String,
|
||||
#[serde(rename = "dhcp-server")]
|
||||
pub dhcp_server: String,
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
pub disabled: bool,
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
pub dynamic: bool,
|
||||
#[serde(rename = "expires-after")]
|
||||
pub expires_after: String,
|
||||
pub gateway: String,
|
||||
pub interface: String,
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
pub invalid: bool,
|
||||
#[serde(rename = "primary-dns")]
|
||||
pub primary_dns: String,
|
||||
#[serde(rename = "secondary-dns")]
|
||||
pub secondary_dns: String,
|
||||
pub status: String,
|
||||
#[serde(rename = "use-peer-dns", deserialize_with = "deserialize_bool")]
|
||||
pub use_peer_dns: bool,
|
||||
#[serde(rename = "use-peer-ntp", deserialize_with = "deserialize_bool")]
|
||||
pub use_peer_ntp: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Route {
|
||||
#[serde(rename = ".id")]
|
||||
pub id: String,
|
||||
pub comment: Option<String>,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub disabled: bool,
|
||||
pub distance: String,
|
||||
#[serde(rename = "dst-address")]
|
||||
pub dst_address: String,
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
pub dynamic: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub ecmp: bool,
|
||||
pub gateway: String,
|
||||
#[serde(rename = "hw-offloaded", deserialize_with = "deserialize_bool")]
|
||||
pub hw_offloaded: bool,
|
||||
#[serde(rename = "immediate-gw")]
|
||||
pub immediate_gw: String,
|
||||
#[serde(deserialize_with = "deserialize_bool")]
|
||||
pub inactive: bool,
|
||||
#[serde(rename = "pref-src")]
|
||||
pub pref_src: Option<String>,
|
||||
#[serde(rename = "routing-table")]
|
||||
pub routing_table: String,
|
||||
#[serde(deserialize_with = "deserialize_u16")]
|
||||
pub scope: u16,
|
||||
#[serde(default, rename = "static", deserialize_with = "deserialize_bool")]
|
||||
pub static_field: bool,
|
||||
#[serde(rename = "suppress-hw-offload", deserialize_with = "deserialize_bool")]
|
||||
pub suppress_hw_offload: bool,
|
||||
#[serde(
|
||||
default,
|
||||
rename = "target-scope",
|
||||
deserialize_with = "deserialize_bool"
|
||||
)]
|
||||
pub target_scope: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub active: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub connect: bool,
|
||||
#[serde(rename = "local-address")]
|
||||
pub local_address: Option<String>,
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
mod client;
|
||||
mod serde_helpers;
|
||||
|
||||
pub mod interface;
|
||||
pub mod ip;
|
||||
mod serde_helpers;
|
||||
pub mod routing;
|
||||
pub mod system;
|
||||
|
||||
pub use client::*;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
pub mod rule;
|
||||
mod types;
|
||||
|
||||
const BASE: &str = "rest/routing";
|
|
@ -0,0 +1,52 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Client, ClientError};
|
||||
|
||||
pub use crate::routing::types::Rule;
|
||||
|
||||
/// List all routing rules
|
||||
pub async fn list(client: &mut Client) -> Result<Vec<Rule>, ClientError> {
|
||||
let url = format!("{}/rule", super::BASE);
|
||||
|
||||
client.execute_get::<Vec<Rule>>(&url).await
|
||||
}
|
||||
|
||||
/// Get a specific routing rule
|
||||
pub async fn get(client: &mut Client, id: &str) -> Result<Rule, ClientError> {
|
||||
let url = format!("{}/rule/{}", super::BASE, id);
|
||||
|
||||
client.execute_get::<Rule>(&url).await
|
||||
}
|
||||
|
||||
// TODO(ishan): Figure out a smarter way to implement these common operations
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RuleInput {
|
||||
pub numbers: String,
|
||||
}
|
||||
|
||||
/// Disable a rule
|
||||
pub async fn disable(client: &mut Client, input: RuleInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/rule/disable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RuleInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Enable a rule
|
||||
pub async fn enable(client: &mut Client, input: RuleInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/rule/enable", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RuleInput>(&url, input)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Remove a rule
|
||||
pub async fn remove(client: &mut Client, input: RuleInput) -> Result<(), ClientError> {
|
||||
let url = format!("{}/rule/remove", super::BASE);
|
||||
|
||||
client
|
||||
.execute_post_with_no_response::<RuleInput>(&url, input)
|
||||
.await
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
use crate::serde_helpers::deserialize_bool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Rule {
|
||||
#[serde(rename = ".id")]
|
||||
pub id: String,
|
||||
#[serde(rename = ".nextid")]
|
||||
pub nextid: Option<String>,
|
||||
pub action: String,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub disabled: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub inactive: bool,
|
||||
#[serde(rename = "src-address")]
|
||||
pub src_address: String,
|
||||
pub table: String,
|
||||
}
|
|
@ -52,6 +52,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn maybe_deserialize_u64<'de, D>(deserializer: D) -> Result<Option<u64>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
|
|
|
@ -8,7 +8,7 @@ pub async fn health(client: &mut Client) -> Result<Vec<Health>, ClientError> {
|
|||
client.execute_get::<Vec<Health>>(&url).await
|
||||
}
|
||||
|
||||
/// voltage can be used to get device's voltag reading
|
||||
/// voltage can be used to get device's voltage reading
|
||||
pub async fn voltage(client: &mut Client) -> Result<f32, ClientError> {
|
||||
let url = format!("{}/health/voltage", super::BASE);
|
||||
|
||||
|
|
102
tests/ip_test.rs
102
tests/ip_test.rs
|
@ -1,4 +1,4 @@
|
|||
use mikrotik::{Client, ClientError};
|
||||
use mikrotik::{ip::dhcp_client::DhcpClientInput, Client, ClientError};
|
||||
use reqwest::Url;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -110,3 +110,103 @@ async fn get_address() -> Result<(), ClientError> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_dhcp_client() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_dhcp_client() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::get(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn renew_dhcp_lease() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::renew(
|
||||
&mut client,
|
||||
DhcpClientInput {
|
||||
numbers: response[0].id.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn release_dhcp_lease() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::release(
|
||||
&mut client,
|
||||
DhcpClientInput {
|
||||
numbers: response[0].id.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_routes() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::route::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_route() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::route::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::route::get(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
use mikrotik::{ip::dhcp_client::DhcpClientInput, Client, ClientError};
|
||||
use reqwest::Url;
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_dhcp_servers() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_dhcp_server() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::get(&mut client, "vlan-150").await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_network() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_network() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::get_network(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_leases() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_lease() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_server::get_lease(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_address() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::address::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_address() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::address::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::address::get(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_dhcp_client() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_dhcp_client() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::get(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn renew_dhcp_lease() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::renew(
|
||||
&mut client,
|
||||
DhcpClientInput {
|
||||
numbers: response[0].id.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn release_dhcp_lease() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
let response = mikrotik::ip::dhcp_client::release(
|
||||
&mut client,
|
||||
DhcpClientInput {
|
||||
numbers: response[0].id.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_routes() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::route::list(&mut client).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_route() -> Result<(), ClientError> {
|
||||
let base = Url::parse("https://10.0.10.1")?;
|
||||
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
|
||||
.expect("error in creating client");
|
||||
|
||||
let response = mikrotik::ip::route::list(&mut client).await?;
|
||||
|
||||
let response = mikrotik::ip::route::get(&mut client, &response[0].id).await?;
|
||||
|
||||
println!("{:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue