/*
* Hetzner Cloud API
*
* Copied from the official API documentation for the Public Hetzner Cloud.
*
* The version of the OpenAPI document: 0.28.0
*
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize};
/// struct for passing parameters to the method [`add_route_to_network`]
#[derive(Clone, Debug, Default)]
pub struct AddRouteToNetworkParams {
/// ID of the Network.
pub id: i64,
pub body: models::Route,
}
/// struct for passing parameters to the method [`add_subnet_to_network`]
#[derive(Clone, Debug, Default)]
pub struct AddSubnetToNetworkParams {
/// ID of the Network.
pub id: i64,
pub body: models::Subnet,
}
/// struct for passing parameters to the method [`change_ip_range_of_network`]
#[derive(Clone, Debug, Default)]
pub struct ChangeIpRangeOfNetworkParams {
/// ID of the Network.
pub id: i64,
pub change_ip_range_of_network_request: models::ChangeIpRangeOfNetworkRequest,
}
/// struct for passing parameters to the method [`change_network_protection`]
#[derive(Clone, Debug, Default)]
pub struct ChangeNetworkProtectionParams {
/// ID of the Network.
pub id: i64,
pub change_network_protection_request: models::ChangeNetworkProtectionRequest,
}
/// struct for passing parameters to the method [`create_network`]
#[derive(Clone, Debug, Default)]
pub struct CreateNetworkParams {
pub create_network_request: models::CreateNetworkRequest,
}
/// struct for passing parameters to the method [`delete_network`]
#[derive(Clone, Debug, Default)]
pub struct DeleteNetworkParams {
/// ID of the Network.
pub id: i64,
}
/// struct for passing parameters to the method [`delete_route_from_network`]
#[derive(Clone, Debug, Default)]
pub struct DeleteRouteFromNetworkParams {
/// ID of the Network.
pub id: i64,
pub body: models::Route,
}
/// struct for passing parameters to the method [`delete_subnet_from_network`]
#[derive(Clone, Debug, Default)]
pub struct DeleteSubnetFromNetworkParams {
/// ID of the Network.
pub id: i64,
pub delete_subnet_from_network_request: models::DeleteSubnetFromNetworkRequest,
}
/// struct for passing parameters to the method [`get_action_for_network`]
#[derive(Clone, Debug, Default)]
pub struct GetActionForNetworkParams {
/// ID of the Network.
pub id: i64,
/// ID of the Action.
pub action_id: i64,
}
/// struct for passing parameters to the method [`get_network`]
#[derive(Clone, Debug, Default)]
pub struct GetNetworkParams {
/// ID of the Network.
pub id: i64,
}
/// struct for passing parameters to the method [`get_network_action`]
#[derive(Clone, Debug, Default)]
pub struct GetNetworkActionParams {
/// ID of the Action.
pub id: i64,
}
/// struct for passing parameters to the method [`list_actions_for_network`]
#[derive(Clone, Debug, Default)]
pub struct ListActionsForNetworkParams {
/// ID of the Network.
pub id: i64,
/// Sort actions by field and direction. Can be used multiple times. For more information, see \"Sorting\".
pub sort: Option<Vec<String>>,
/// Filter the actions by status. Can be used multiple times. The response will only contain actions matching the specified statuses.
pub status: Option<Vec<String>>,
/// Page number to return. For more information, see \"Pagination\".
pub page: Option<i64>,
/// Maximum number of entries returned per page. For more information, see \"Pagination\".
pub per_page: Option<i64>,
}
/// struct for passing parameters to the method [`list_network_actions`]
#[derive(Clone, Debug, Default)]
pub struct ListNetworkActionsParams {
/// Filter the actions by ID. Can be used multiple times. The response will only contain actions matching the specified IDs.
pub id: Option<Vec<i64>>,
/// Sort actions by field and direction. Can be used multiple times. For more information, see \"Sorting\".
pub sort: Option<Vec<String>>,
/// Filter the actions by status. Can be used multiple times. The response will only contain actions matching the specified statuses.
pub status: Option<Vec<String>>,
/// Page number to return. For more information, see \"Pagination\".
pub page: Option<i64>,
/// Maximum number of entries returned per page. For more information, see \"Pagination\".
pub per_page: Option<i64>,
}
/// struct for passing parameters to the method [`list_networks`]
#[derive(Clone, Debug, Default)]
pub struct ListNetworksParams {
/// Sort resources by field and direction. Can be used multiple times. For more information, see \"Sorting\".
pub sort: Option<Vec<String>>,
/// Filter resources by their name. The response will only contain the resources matching exactly the specified name.
pub name: Option<String>,
/// Filter resources by labels. The response will only contain resources matching the label selector. For more information, see \"Label Selector\".
pub label_selector: Option<String>,
/// Page number to return. For more information, see \"Pagination\".
pub page: Option<i64>,
/// Maximum number of entries returned per page. For more information, see \"Pagination\".
pub per_page: Option<i64>,
}
/// struct for passing parameters to the method [`replace_network`]
#[derive(Clone, Debug, Default)]
pub struct ReplaceNetworkParams {
/// ID of the Network.
pub id: i64,
pub replace_network_request: models::ReplaceNetworkRequest,
}
/// struct for typed errors of method [`add_route_to_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddRouteToNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`add_subnet_to_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddSubnetToNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`change_ip_range_of_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChangeIpRangeOfNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`change_network_protection`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChangeNetworkProtectionError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_route_from_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteRouteFromNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_subnet_from_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSubnetFromNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_action_for_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetActionForNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_network_action`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetNetworkActionError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_actions_for_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListActionsForNetworkError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_network_actions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListNetworkActionsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_networks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListNetworksError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`replace_network`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReplaceNetworkError {
UnknownValue(serde_json::Value),
}
/// Adds a route entry to a Network. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn add_route_to_network(
configuration: &configuration::Configuration,
params: AddRouteToNetworkParams,
) -> Result<models::AddRouteToNetworkResponse, Error<AddRouteToNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!(
"{}/networks/{id}/actions/add_route",
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<AddRouteToNetworkError> =
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))
}
}
/// Adds a new subnet to the Network. If the subnet `ip_range` is not provided, the first available `/24` IP range will be used. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn add_subnet_to_network(
configuration: &configuration::Configuration,
params: AddSubnetToNetworkParams,
) -> Result<models::AddSubnetToNetworkResponse, Error<AddSubnetToNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!(
"{}/networks/{id}/actions/add_subnet",
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<AddSubnetToNetworkError> =
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))
}
}
/// Changes the IP range of a Network. The following restrictions apply to changing the IP range: - IP ranges can only be extended and never shrunk. - IPs can only be added to the end of the existing range, therefore only the netmask is allowed to be changed. To update the routes on the connected Servers, they need to be rebooted or the routes to be updated manually. For example if the Network has a range of `10.0.0.0/16` to extend it the new range has to start with the IP `10.0.0.0` as well. The netmask `/16` can be changed to a smaller one then `16` therefore increasing the IP range. A valid entry would be `10.0.0.0/15`, `10.0.0.0/14` or `10.0.0.0/13` and so on. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn change_ip_range_of_network(
configuration: &configuration::Configuration,
params: ChangeIpRangeOfNetworkParams,
) -> Result<models::ChangeIpRangeOfNetworkResponse, Error<ChangeIpRangeOfNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
let id = params.id;
let change_ip_range_of_network_request = params.change_ip_range_of_network_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!(
"{}/networks/{id}/actions/change_ip_range",
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(&change_ip_range_of_network_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<ChangeIpRangeOfNetworkError> =
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))
}
}
/// Changes the protection settings of a Network. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn change_network_protection(
configuration: &configuration::Configuration,
params: ChangeNetworkProtectionParams,
) -> Result<models::ChangeNetworkProtectionResponse, Error<ChangeNetworkProtectionError>> {
let local_var_configuration = configuration;
// unbox the parameters
let id = params.id;
let change_network_protection_request = params.change_network_protection_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!(
"{}/networks/{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(&change_network_protection_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<ChangeNetworkProtectionError> =
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))
}
}
/// Creates a Network. The provided `ip_range` can only be extended later on, but not reduced. Subnets can be added now or later on using the add subnet action. If you do not specify an `ip_range` for the subnet the first available /24 range will be used. Routes can be added now or later by using the add route action.
pub async fn create_network(
configuration: &configuration::Configuration,
params: CreateNetworkParams,
) -> Result<models::CreateNetworkResponse, Error<CreateNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
let create_network_request = params.create_network_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!("{}/networks", 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_network_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<CreateNetworkError> =
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))
}
}
/// Deletes a Network. Attached resources will be detached automatically.
pub async fn delete_network(
configuration: &configuration::Configuration,
params: DeleteNetworkParams,
) -> Result<(), Error<DeleteNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!("{}/networks/{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<DeleteNetworkError> =
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))
}
}
/// Delete a route entry from a Network. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn delete_route_from_network(
configuration: &configuration::Configuration,
params: DeleteRouteFromNetworkParams,
) -> Result<models::DeleteRouteFromNetworkResponse, Error<DeleteRouteFromNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!(
"{}/networks/{id}/actions/delete_route",
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<DeleteRouteFromNetworkError> =
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))
}
}
/// Deletes a single subnet entry from a Network. Subnets containing attached resources can not be deleted, they must be detached beforehand. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn delete_subnet_from_network(
configuration: &configuration::Configuration,
params: DeleteSubnetFromNetworkParams,
) -> Result<models::DeleteSubnetFromNetworkResponse, Error<DeleteSubnetFromNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
let id = params.id;
let delete_subnet_from_network_request = params.delete_subnet_from_network_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!(
"{}/networks/{id}/actions/delete_subnet",
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(&delete_subnet_from_network_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<DeleteSubnetFromNetworkError> =
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))
}
}
/// Returns a specific Action for a Network.
pub async fn get_action_for_network(
configuration: &configuration::Configuration,
params: GetActionForNetworkParams,
) -> Result<models::GetActionResponse, Error<GetActionForNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!(
"{}/networks/{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<GetActionForNetworkError> =
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))
}
}
/// Get a specific Network.
pub async fn get_network(
configuration: &configuration::Configuration,
params: GetNetworkParams,
) -> Result<models::GetNetworkResponse, Error<GetNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!("{}/networks/{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<GetNetworkError> =
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))
}
}
/// Returns a single Action.
pub async fn get_network_action(
configuration: &configuration::Configuration,
params: GetNetworkActionParams,
) -> Result<models::GetActionResponse, Error<GetNetworkActionError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!("{}/networks/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<GetNetworkActionError> =
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))
}
}
/// Lists Actions for a Network. Use the provided URI parameters to modify the result.
pub async fn list_actions_for_network(
configuration: &configuration::Configuration,
params: ListActionsForNetworkParams,
) -> Result<models::ListActionsResponse, Error<ListActionsForNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!("{}/networks/{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<ListActionsForNetworkError> =
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))
}
}
/// Lists multiple Actions. Use the provided URI parameters to modify the result.
pub async fn list_network_actions(
configuration: &configuration::Configuration,
params: ListNetworkActionsParams,
) -> Result<models::ListActionsResponse, Error<ListNetworkActionsError>> {
let local_var_configuration = configuration;
// unbox the parameters
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!("{}/networks/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<ListNetworkActionsError> =
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))
}
}
/// List multiple Networks. Use the provided URI parameters to modify the result.
pub async fn list_networks(
configuration: &configuration::Configuration,
params: ListNetworksParams,
) -> Result<models::ListNetworksResponse, Error<ListNetworksError>> {
let local_var_configuration = configuration;
// unbox the parameters
let sort = params.sort;
let name = params.name;
let label_selector = params.label_selector;
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!("{}/networks", 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) = 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) = 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) = 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<ListNetworksError> =
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))
}
}
/// Update a Network. If a change is currently being performed on this Network, a error response with code `conflict` will be returned.
pub async fn replace_network(
configuration: &configuration::Configuration,
params: ReplaceNetworkParams,
) -> Result<models::ReplaceNetworkResponse, Error<ReplaceNetworkError>> {
let local_var_configuration = configuration;
// unbox the parameters
let id = params.id;
let replace_network_request = params.replace_network_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!("{}/networks/{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_network_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<ReplaceNetworkError> =
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))
}
}