use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default)]
pub struct AssignFloatingIpToServerParams {
pub id: i64,
pub assign_floating_ip_to_server_request: models::AssignFloatingIpToServerRequest,
}
#[derive(Clone, Debug, Default)]
pub struct ChangeFloatingIpProtectionParams {
pub id: i64,
pub body: models::Protection,
}
#[derive(Clone, Debug, Default)]
pub struct ChangeReverseDnsRecordsForFloatingIpParams {
pub id: i64,
pub body: models::DnsPtr,
}
#[derive(Clone, Debug, Default)]
pub struct CreateFloatingIpParams {
pub create_floating_ip_request: models::CreateFloatingIpRequest,
}
#[derive(Clone, Debug, Default)]
pub struct DeleteFloatingIpParams {
pub id: i64,
}
#[derive(Clone, Debug, Default)]
pub struct GetActionForFloatingIpParams {
pub id: i64,
pub action_id: i64,
}
#[derive(Clone, Debug, Default)]
pub struct GetFloatingIpParams {
pub id: i64,
}
#[derive(Clone, Debug, Default)]
pub struct GetFloatingIpActionParams {
pub id: i64,
}
#[derive(Clone, Debug, Default)]
pub struct ListActionsForFloatingIpParams {
pub id: i64,
pub sort: Option<Vec<String>>,
pub status: Option<Vec<String>>,
pub page: Option<i64>,
pub per_page: Option<i64>,
}
#[derive(Clone, Debug, Default)]
pub struct ListFloatingIpActionsParams {
pub id: Option<Vec<i64>>,
pub sort: Option<Vec<String>>,
pub status: Option<Vec<String>>,
pub page: Option<i64>,
pub per_page: Option<i64>,
}
#[derive(Clone, Debug, Default)]
pub struct ListFloatingIpsParams {
pub name: Option<String>,
pub label_selector: Option<String>,
pub sort: Option<Vec<String>>,
pub page: Option<i64>,
pub per_page: Option<i64>,
}
#[derive(Clone, Debug, Default)]
pub struct ReplaceFloatingIpParams {
pub id: i64,
pub replace_floating_ip_request: models::ReplaceFloatingIpRequest,
}
#[derive(Clone, Debug, Default)]
pub struct UnassignFloatingIpParams {
pub id: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AssignFloatingIpToServerError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChangeFloatingIpProtectionError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChangeReverseDnsRecordsForFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetActionForFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFloatingIpActionError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListActionsForFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFloatingIpActionsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFloatingIpsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReplaceFloatingIpError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UnassignFloatingIpError {
UnknownValue(serde_json::Value),
}
pub async fn assign_floating_ip_to_server(
configuration: &configuration::Configuration,
params: AssignFloatingIpToServerParams,
) -> Result<models::AssignFloatingIpToServerResponse, Error<AssignFloatingIpToServerError>> {
let local_var_configuration = configuration;
let id = params.id;
let assign_floating_ip_to_server_request = params.assign_floating_ip_to_server_request;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!(
"{}/floating_ips/{id}/actions/assign",
local_base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&assign_floating_ip_to_server_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<AssignFloatingIpToServerError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn change_floating_ip_protection(
configuration: &configuration::Configuration,
params: ChangeFloatingIpProtectionParams,
) -> Result<models::ChangeFloatingIpProtectionResponse, Error<ChangeFloatingIpProtectionError>> {
let local_var_configuration = configuration;
let id = params.id;
let body = params.body;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!(
"{}/floating_ips/{id}/actions/change_protection",
local_base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&body);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ChangeFloatingIpProtectionError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn change_reverse_dns_records_for_floating_ip(
configuration: &configuration::Configuration,
params: ChangeReverseDnsRecordsForFloatingIpParams,
) -> Result<
models::ChangeReverseDnsRecordsForFloatingIpResponse,
Error<ChangeReverseDnsRecordsForFloatingIpError>,
> {
let local_var_configuration = configuration;
let id = params.id;
let body = params.body;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!(
"{}/floating_ips/{id}/actions/change_dns_ptr",
local_base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&body);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ChangeReverseDnsRecordsForFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn create_floating_ip(
configuration: &configuration::Configuration,
params: CreateFloatingIpParams,
) -> Result<models::CreateFloatingIpResponse, Error<CreateFloatingIpError>> {
let local_var_configuration = configuration;
let create_floating_ip_request = params.create_floating_ip_request;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips", local_base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&create_floating_ip_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreateFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn delete_floating_ip(
configuration: &configuration::Configuration,
params: DeleteFloatingIpParams,
) -> Result<(), Error<DeleteFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/{id}", local_base_path, id = id);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<DeleteFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_action_for_floating_ip(
configuration: &configuration::Configuration,
params: GetActionForFloatingIpParams,
) -> Result<models::GetActionResponse, Error<GetActionForFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let action_id = params.action_id;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!(
"{}/floating_ips/{id}/actions/{action_id}",
local_base_path,
id = id,
action_id = action_id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetActionForFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_floating_ip(
configuration: &configuration::Configuration,
params: GetFloatingIpParams,
) -> Result<models::GetFloatingIpResponse, Error<GetFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/{id}", local_base_path, id = id);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_floating_ip_action(
configuration: &configuration::Configuration,
params: GetFloatingIpActionParams,
) -> Result<models::GetActionResponse, Error<GetFloatingIpActionError>> {
let local_var_configuration = configuration;
let id = params.id;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/actions/{id}", local_base_path, id = id);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFloatingIpActionError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn list_actions_for_floating_ip(
configuration: &configuration::Configuration,
params: ListActionsForFloatingIpParams,
) -> Result<models::ListActionsResponse, Error<ListActionsForFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let sort = params.sort;
let status = params.status;
let page = params.page;
let per_page = params.per_page;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/{id}/actions", local_base_path, id = id);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = sort {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("sort".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"sort",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = status {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("status".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"status",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListActionsForFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn list_floating_ip_actions(
configuration: &configuration::Configuration,
params: ListFloatingIpActionsParams,
) -> Result<models::ListActionsResponse, Error<ListFloatingIpActionsError>> {
let local_var_configuration = configuration;
let id = params.id;
let sort = params.sort;
let status = params.status;
let page = params.page;
let per_page = params.per_page;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/actions", local_base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = id {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("id".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"id",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = sort {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("sort".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"sort",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = status {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("status".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"status",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListFloatingIpActionsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn list_floating_ips(
configuration: &configuration::Configuration,
params: ListFloatingIpsParams,
) -> Result<models::ListFloatingIpsResponse, Error<ListFloatingIpsError>> {
let local_var_configuration = configuration;
let name = params.name;
let label_selector = params.label_selector;
let sort = params.sort;
let page = params.page;
let per_page = params.per_page;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips", local_base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = name {
local_var_req_builder =
local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = label_selector {
local_var_req_builder =
local_var_req_builder.query(&[("label_selector", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = sort {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(
&local_var_str
.iter()
.map(|p| ("sort".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => local_var_req_builder.query(&[(
"sort",
&local_var_str
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListFloatingIpsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn replace_floating_ip(
configuration: &configuration::Configuration,
params: ReplaceFloatingIpParams,
) -> Result<models::ReplaceFloatingIpResponse, Error<ReplaceFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let replace_floating_ip_request = params.replace_floating_ip_request;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!("{}/floating_ips/{id}", local_base_path, id = id);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&replace_floating_ip_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ReplaceFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn unassign_floating_ip(
configuration: &configuration::Configuration,
params: UnassignFloatingIpParams,
) -> Result<models::UnassignFloatingIpResponse, Error<UnassignFloatingIpError>> {
let local_var_configuration = configuration;
let id = params.id;
let local_var_client = &local_var_configuration.client;
let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
let local_var_uri_str = format!(
"{}/floating_ips/{id}/actions/unassign",
local_base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UnassignFloatingIpError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}