use serde::{Deserialize, Serialize}; use crate::{Client, ApiClient}; use crate::api::{BulkCreateDomainExtention, BulkDeleteDomainExtention, BulkReadDomainExtention, BulkUpdateDomainExtention, DomainExtention}; use crate::api::folders::FolderAttributes; impl Client { pub fn host_api(&self) -> ApiClient { self.into() } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct HostConfig { pub folder: String, pub attributes: FolderAttributes, pub effective_attributes: FolderAttributes, pub is_cluster: bool, pub is_offline: bool, pub cluster_nodes: Option> } impl DomainExtention for HostConfig { const DOMAIN_TYPE: super::DomainType = super::DomainType::HostConfig; type CreationRequest = HostCreationRequest; type CreationQuery = HostCreationQuery; type ReadQuery = HostReadQuery; type UpdateRequest = HostUpdateRequest; type DeleteQuery = (); } #[derive(Serialize)] pub struct HostCreationRequest { pub hostname: String, pub folder: String, pub attributes: FolderAttributes } #[derive(Serialize)] pub struct HostCreationQuery { pub bake_agent: bool } #[derive(Serialize)] pub struct HostReadQuery { pub effective_attributes: bool } #[derive(Serialize)] pub struct HostUpdateRequest { #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option, #[serde(skip_serializing_if = "Option::is_none")] pub update_attributes: Option, #[serde(skip_serializing_if = "Vec::is_empty")] pub remove_attributes: Vec, } impl HostCreationRequest { pub fn new(hostname: String, folder: String, attributes: FolderAttributes) -> Self { HostCreationRequest { hostname, folder, attributes } } } impl HostCreationQuery { pub fn new(bake_agent: bool) -> Self { Self { bake_agent } } } impl HostReadQuery { pub fn new(effective_attributes: bool) -> Self { Self { effective_attributes } } } impl HostUpdateRequest { pub fn replace(attributes: FolderAttributes) -> Self { Self { attributes: Some(attributes), update_attributes: None, remove_attributes: Vec::new(), } } pub fn update(attributes: FolderAttributes) -> Self { Self { attributes: None, update_attributes: Some(attributes), remove_attributes: Vec::new(), } } pub fn remove(attributes: Vec) -> Self { Self { attributes: None, update_attributes: None, remove_attributes: attributes, } } } impl BulkCreateDomainExtention for HostConfig {} impl BulkReadDomainExtention for HostConfig { type BulkReadQuery = HostBulkReadQuery; } impl BulkUpdateDomainExtention for HostConfig { type BulkUpdateRequest = HostBulkUpdateRequest; } impl BulkDeleteDomainExtention for HostConfig {} #[derive(Debug, Default, Clone, Serialize)] pub struct HostBulkReadQuery { effective_attributes: bool, #[serde(skip_serializing_if = "Option::is_none")] fields: Option, #[serde(skip_serializing_if = "Vec::is_empty")] hostnames: Vec, #[serde(skip_serializing_if = "Option::is_none")] site: Option } impl HostBulkReadQuery { pub fn new() -> Self { Self::default() } pub fn set_effective_attributes(&mut self, effective_attributes: bool) { self.effective_attributes = effective_attributes; } pub fn with_effective_attributes(mut self, effective_attributes: bool) -> Self { self.set_effective_attributes(effective_attributes); self } pub fn set_fields(&mut self, fields: String) { self.fields = Some(fields); } pub fn with_fields(mut self, fields: String) -> Self { self.set_fields(fields); self } pub fn add_hostname(&mut self, hostname: String) { self.hostnames.push(hostname); } pub fn with_hostname(mut self, hostname: String) -> Self { self.add_hostname(hostname); self } pub fn set_hostnames(&mut self, hostnames: Vec) { self.hostnames = hostnames; } pub fn with_hostnames(mut self, hostnames: Vec) -> Self { self.set_hostnames(hostnames); self } pub fn set_site(&mut self, site: String) { self.site = Some(site); } pub fn with_site(mut self, site: String) -> Self { self.set_site(site); self } } #[derive(Serialize)] pub struct HostBulkUpdateRequest { host_name: String, #[serde(flatten)] update_request: HostUpdateRequest } impl HostBulkUpdateRequest { pub fn new(host_name: String, update_request: HostUpdateRequest) -> Self { Self { host_name, update_request } } }