use crate::{
data::instance::{ScalewayInstance, ScalewayInstanceRoot},
ScalewayApi, ScalewayError,
};
pub struct ScalewayListInstanceBuilder {
api: ScalewayApi,
params: Vec<(&'static str, String)>,
}
impl ScalewayListInstanceBuilder {
pub fn new(api: ScalewayApi) -> Self {
ScalewayListInstanceBuilder {
api,
params: vec![],
}
}
pub fn per_page(mut self, count: u32) -> ScalewayListInstanceBuilder {
self.params.push(("per_page", count.to_string()));
self
}
pub fn page(mut self, count: u32) -> ScalewayListInstanceBuilder {
self.params.push(("page", count.to_string()));
self
}
pub fn organization(mut self, organization: &str) -> ScalewayListInstanceBuilder {
self.params.push(("organization", organization.to_string()));
self
}
pub fn project(mut self, project: &str) -> ScalewayListInstanceBuilder {
self.params.push(("project", project.to_string()));
self
}
pub fn name(mut self, name: &str) -> ScalewayListInstanceBuilder {
self.params.push(("name", name.to_string()));
self
}
pub fn private_ip(mut self, private_ip: &str) -> ScalewayListInstanceBuilder {
self.params.push(("private_ip", private_ip.to_string()));
self
}
pub fn without_ip(mut self, without_ip: bool) -> ScalewayListInstanceBuilder {
self.params.push(("without_ip", without_ip.to_string()));
self
}
pub fn commercial_type(mut self, commercial_type: &str) -> ScalewayListInstanceBuilder {
self.params
.push(("commercial_type", commercial_type.to_string()));
self
}
pub fn state(mut self, state: &str) -> ScalewayListInstanceBuilder {
self.params.push(("state", state.to_string()));
self
}
pub fn tags(mut self, tags: &str) -> ScalewayListInstanceBuilder {
self.params.push(("tags", tags.to_string()));
self
}
pub fn private_network(mut self, private_network: &str) -> ScalewayListInstanceBuilder {
self.params
.push(("private_network", private_network.to_string()));
self
}
pub fn order(mut self, order: &str) -> ScalewayListInstanceBuilder {
self.params.push(("order", order.to_string()));
self
}
pub fn private_networks(mut self, private_networks: &str) -> ScalewayListInstanceBuilder {
self.params
.push(("private_networks", private_networks.to_string()));
self
}
pub fn private_nic_mac_address(
mut self,
private_nic_mac_address: &str,
) -> ScalewayListInstanceBuilder {
self.params.push((
"private_nic_mac_address",
private_nic_mac_address.to_string(),
));
self
}
pub fn servers(mut self, servers: &str) -> ScalewayListInstanceBuilder {
self.params.push(("servers", servers.to_string()));
self
}
#[cfg(feature = "blocking")]
pub fn run(self) -> Result<ScalewayInstance, ScalewayError> {
let url = &format!(
"https://api.scaleway.com/instance/v1/zones/{zone}/servers",
zone = self.api.zone
);
Ok(self
.api
.get(&url, self.params)?
.json::<ScalewayInstanceRoot>()?
.servers)
}
pub async fn run_async(self) -> Result<ScalewayInstance, ScalewayError> {
let url = &format!(
"https://api.scaleway.com/instance/v1/zones/{zone}/servers",
zone = self.api.zone
);
Ok(self
.api
.get_async(&url, self.params)
.await?
.json::<ScalewayInstanceRoot>()
.await?
.server)
}
}