bugfixes and refactored the project a bit

1. Fixed bugs in `.execute_post`.
2. Functions that take a single input string were updated to take a
   string and then create the request body from it instead of asking
user to enter the request body.
3. Moved tests from `tests/` to their specific modules
4. Added few more methods
master
Ishan Jain 4 months ago
parent 7cfa7beddd
commit 845fbe13bc
  1. 43
      src/client.rs
  2. 2
      src/interface/types.rs
  3. 110
      src/ip/address.rs
  4. 113
      src/ip/dhcp_client.rs
  5. 87
      src/ip/dhcp_server.rs
  6. 34
      src/ip/route.rs
  7. 20
      src/ip/types.rs
  8. 212
      tests/ip_test.rs
  9. 212
      tests/routing_test.rs

@ -3,7 +3,7 @@ use reqwest::{
Method, Request, Url,
};
use serde::{de::DeserializeOwned, ser::Serialize};
use std::num::ParseFloatError;
use std::{fmt::Display, num::ParseFloatError};
use thiserror::Error;
pub struct Client {
@ -76,13 +76,14 @@ impl Client {
*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?;
req.headers_mut()
.insert("Content-Type", HeaderValue::from_static("application/json"));
Ok(response)
match self.client.execute(req).await {
Ok(v) if v.status().is_success() => Ok(v.json::<Q>().await?),
Ok(v) => Err(ClientError::MikrotikError(v.json::<MikrotikError>().await?)),
Err(e) => Err(e.into()),
}
}
pub async fn execute_post_with_no_response<P: Serialize>(
@ -104,10 +105,11 @@ impl Client {
req.headers_mut()
.insert("Content-Type", HeaderValue::from_static("application/json"));
self.client.execute(req).await?;
// TODO(ishan): Check status code!!
Ok(())
match self.client.execute(req).await {
Ok(v) if v.status().is_success() => Ok(()),
Ok(v) => Err(ClientError::MikrotikError(v.json::<MikrotikError>().await?)),
Err(e) => Err(e.into()),
}
}
}
@ -124,4 +126,23 @@ pub enum ClientError {
#[error(transparent)]
SerdeJsonError(#[from] serde_json::Error),
#[error(transparent)]
MikrotikError(#[from] MikrotikError),
}
use serde::{Deserialize as DeserializeDerive, Serialize as SerializeDerive};
#[derive(Default, Error, Debug, Clone, PartialEq, SerializeDerive, DeserializeDerive)]
#[serde(rename_all = "camelCase")]
pub struct MikrotikError {
pub error: u16,
pub message: String,
pub detail: String,
}
impl Display for MikrotikError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.message)
}
}

@ -19,6 +19,8 @@ pub enum InterfaceType {
Wireguard,
#[serde(rename = "pppoe-out")]
PPPoE,
#[serde(rename = "6to4-tunnel")]
Tunnel6to4,
}
impl Default for InterfaceType {

@ -1,5 +1,6 @@
pub use crate::ip::types::Address;
pub use crate::ip::types::{AddAddressInput, AddAddressOutput, Address};
use crate::{Client, ClientError};
use serde::{Deserialize, Serialize};
/// list all configurd ipv4 addresses
pub async fn list(client: &mut Client) -> Result<Vec<Address>, ClientError> {
@ -14,3 +15,110 @@ pub async fn get(client: &mut Client, aid: &str) -> Result<Address, ClientError>
client.execute_get::<Address>(&url).await
}
pub async fn add(
client: &mut Client,
input: AddAddressInput,
) -> Result<AddAddressOutput, ClientError> {
let url = format!("{}/address/add", super::BASE);
client
.execute_post::<AddAddressInput, AddAddressOutput>(&url, input)
.await
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
struct RemoveAddressInput {
pub numbers: String,
}
pub async fn remove(client: &mut Client, id: &str) -> Result<(), ClientError> {
let url = format!("{}/address/remove", super::BASE);
client
.execute_post_with_no_response::<RemoveAddressInput>(
&url,
RemoveAddressInput {
numbers: id.to_string(),
},
)
.await
}
#[cfg(test)]
mod test {
use super::*;
use reqwest::Url;
#[tokio::test]
async fn remove_address() -> Result<(), ClientError> {
let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "pia".to_string(), "qwertyuiop".to_string(), true)
.expect("error in creating client");
let response = crate::ip::address::add(
&mut client,
AddAddressInput {
address: "10.20.0.1/24".to_string(),
disabled: false,
interface: "pia".to_string(),
..Default::default()
},
)
.await?;
crate::ip::address::remove(&mut client, &response.ret).await?;
Ok(())
}
#[tokio::test]
async fn add_address() -> Result<(), ClientError> {
let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "pia".to_string(), "qwertyuiop".to_string(), true)
.expect("error in creating client");
let response = crate::ip::address::add(
&mut client,
AddAddressInput {
address: "10.20.0.1/24".to_string(),
disabled: false,
interface: "pia".to_string(),
..Default::default()
},
)
.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 = crate::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 = crate::ip::address::list(&mut client).await?;
let response = crate::ip::address::get(&mut client, &response[0].id).await?;
println!("{:?}", response);
Ok(())
}
}

@ -17,55 +17,146 @@ pub async fn get(client: &mut Client, id: &str) -> Result<DhcpClient, ClientErro
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DhcpClientInput {
struct DhcpClientInput {
pub numbers: String,
}
/// Release a DHCP Lease
pub async fn release(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
pub async fn release(client: &mut Client, input: &str) -> Result<(), ClientError> {
let url = format!("{}/dhcp-client/release", super::BASE);
client
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
.execute_post_with_no_response::<DhcpClientInput>(
&url,
DhcpClientInput {
numbers: input.to_string(),
},
)
.await?;
Ok(())
}
/// Renew a DHCP Lease
pub async fn renew(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
pub async fn renew(client: &mut Client, input: &str) -> Result<(), ClientError> {
let url = format!("{}/dhcp-client/renew", super::BASE);
client
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
.execute_post_with_no_response::<DhcpClientInput>(
&url,
DhcpClientInput {
numbers: input.to_string(),
},
)
.await
}
/// Remove a DHCP client
pub async fn remove(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
pub async fn remove(client: &mut Client, input: &str) -> Result<(), ClientError> {
let url = format!("{}/dhcp-client/remove", super::BASE);
client
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
.execute_post_with_no_response::<DhcpClientInput>(
&url,
DhcpClientInput {
numbers: input.to_string(),
},
)
.await
}
/// Disable a DHCP client
pub async fn disable(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
pub async fn disable(client: &mut Client, input: &str) -> Result<(), ClientError> {
let url = format!("{}/dhcp-client/disable", super::BASE);
client
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
.execute_post_with_no_response::<DhcpClientInput>(
&url,
DhcpClientInput {
numbers: input.to_string(),
},
)
.await
}
/// Enable a DHCP client
pub async fn enable(client: &mut Client, input: DhcpClientInput) -> Result<(), ClientError> {
pub async fn enable(client: &mut Client, input: &str) -> Result<(), ClientError> {
let url = format!("{}/dhcp-client/enable", super::BASE);
client
.execute_post_with_no_response::<DhcpClientInput>(&url, input)
.execute_post_with_no_response::<DhcpClientInput>(
&url,
DhcpClientInput {
numbers: input.to_string(),
},
)
.await
}
// TODO(ishan): Add reset/set/unset methods
#[cfg(test)]
mod test {
use super::*;
use reqwest::Url;
#[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 = crate::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 = crate::ip::dhcp_client::list(&mut client).await?;
let response = crate::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 = crate::ip::dhcp_client::list(&mut client).await?;
let response = crate::ip::dhcp_client::renew(&mut client, &response[0].id).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 = crate::ip::dhcp_client::list(&mut client).await?;
println!("{:?}", response);
let response = crate::ip::dhcp_client::release(&mut client, &response[0].id).await?;
println!("{:?}", response);
Ok(())
}
}

@ -42,3 +42,90 @@ pub async fn get_lease(client: &mut Client, lease_id: &str) -> Result<Lease, Cli
client.execute_get::<Lease>(&url).await
}
#[cfg(test)]
mod test {
use super::*;
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 = crate::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 = crate::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 = crate::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 = crate::ip::dhcp_server::list_network(&mut client).await?;
let response = crate::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 = crate::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 = crate::ip::dhcp_server::list_leases(&mut client).await?;
let response = crate::ip::dhcp_server::get_lease(&mut client, &response[0].id).await?;
println!("{:?}", response);
Ok(())
}
}

@ -49,3 +49,37 @@ pub async fn remove(client: &mut Client, input: RouteInput) -> Result<(), Client
}
//TODO(ishan): add set/unset/reset
#[cfg(test)]
mod test {
use super::*;
use reqwest::Url;
#[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 = crate::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 = crate::ip::route::list(&mut client).await?;
let response = crate::ip::route::get(&mut client, &response[0].id).await?;
println!("{:?}", response);
Ok(())
}
}

@ -185,3 +185,23 @@ pub struct Route {
#[serde(rename = "local-address")]
pub local_address: Option<String>,
}
#[derive(Default, Hash, Eq, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AddAddressInput {
pub address: String,
pub comment: Option<String>,
#[serde(deserialize_with = "deserialize_bool")]
pub disabled: bool,
pub interface: String,
// TODO(ishan): Do not serialize this if this was none
#[serde(skip_serializing_if = "Option::is_none")]
pub network: Option<String>,
}
#[derive(Default, Hash, Eq, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AddAddressOutput {
pub ret: String,
}

@ -1,212 +0,0 @@
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(())
}

@ -1,212 +0,0 @@
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…
Cancel
Save