use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::super::nodegroup;
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Status {
Active,
PendingCreate,
PendingUpdate,
PendingUpgrade,
PendingRotateCerts,
PendingDelete,
PendingResize,
PendingNodeReinstall,
PendingUpgradePatchVersion,
PendingUpgradeMinorVersion,
PendingUpdateNodegroup,
PendingUpgradeMastersConfiguration,
PendingUpgradeClusterConfiguration,
Maintenance,
Error,
Unknown,
}
impl std::fmt::Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Status::Active => "ACTIVE".fmt(f),
Status::PendingCreate => "PENDING_CREATE".fmt(f),
Status::PendingUpdate => "PENDING_UPDATE".fmt(f),
Status::PendingUpgrade => "PENDING_UPGRADE".fmt(f),
Status::PendingRotateCerts => "PENDING_ROTATE_CERTS".fmt(f),
Status::PendingDelete => "PENDING_DELETE".fmt(f),
Status::PendingResize => "PENDING_RESIZE".fmt(f),
Status::PendingNodeReinstall => "PENDING_NODE_REINSTALL".fmt(f),
Status::PendingUpgradePatchVersion => "PENDING_UPGRADE_PATCH_VERSION".fmt(f),
Status::PendingUpgradeMinorVersion => "PENDING_UPGRADE_MINOR_VERSION".fmt(f),
Status::PendingUpdateNodegroup => "PENDING_UPDATE_NODEGROUP".fmt(f),
Status::PendingUpgradeMastersConfiguration => {
"PENDING_UPGRADE_MASTERS_CONFIGURATION".fmt(f)
}
Status::PendingUpgradeClusterConfiguration => {
"PENDING_UPGRADE_CLUSTER_CONFIGURATION".fmt(f)
}
Status::Maintenance => "MAINTENANCE".fmt(f),
Status::Error => "ERROR".fmt(f),
Status::Unknown => "UNKNOWN".fmt(f),
}
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Cluster {
pub id: String,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
pub name: String,
pub status: Status,
pub project_id: String,
pub network_id: String,
pub subnet_id: String,
pub kube_api_ip: String,
pub kube_version: String,
pub region: String,
pub pki_tree_updated_at: Option<DateTime<Utc>>,
pub maintenance_window_start: Option<String>,
pub maintenance_window_end: Option<String>,
pub maintenance_last_start: Option<DateTime<Utc>>,
pub enable_autorepair: bool,
pub enable_patch_version_auto_upgrade: bool,
pub zonal: bool,
pub kubernetes_options: KubernetesOptions,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ClusterRoot {
pub cluster: Cluster,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ListRoot {
pub clusters: Vec<Cluster>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct KubernetesOptions {
pub enable_pod_security_policy: bool,
}
#[derive(Debug, Serialize)]
pub struct CreateOpts {
name: String,
network_id: Option<String>,
subnet_id: Option<String>,
kube_version: String,
region: String,
nodegroups: Option<Vec<nodegroup::schemas::CreateOpts>>,
maintenance_window_start: Option<String>,
enable_autorepair: Option<bool>,
enable_patch_version_auto_upgrade: Option<bool>,
zonal: Option<bool>,
kubernetes_options: Option<KubernetesOptions>,
}
impl CreateOpts {
pub fn new(name: &str, kube_version: &str, region: &str) -> CreateOpts {
CreateOpts {
name: String::from(name),
network_id: None,
subnet_id: None,
kube_version: String::from(kube_version),
region: String::from(region),
nodegroups: None,
maintenance_window_start: None,
enable_autorepair: None,
enable_patch_version_auto_upgrade: None,
zonal: None,
kubernetes_options: None,
}
}
pub fn with_network_id(mut self, network_id: &str) -> CreateOpts {
self.network_id = Some(String::from(network_id));
self
}
pub fn with_subnet_id(mut self, subnet_id: &str) -> CreateOpts {
self.subnet_id = Some(String::from(subnet_id));
self
}
pub fn with_nodegroups(
mut self,
nodegroups: Vec<nodegroup::schemas::CreateOpts>,
) -> CreateOpts {
self.nodegroups = Some(nodegroups);
self
}
pub fn with_maintenance_window_start(mut self, maintenance_window_start: &str) -> CreateOpts {
self.maintenance_window_start = Some(String::from(maintenance_window_start));
self
}
pub fn with_enable_autorepair(mut self, enable_autorepair: bool) -> CreateOpts {
self.enable_autorepair = Some(enable_autorepair);
self
}
pub fn with_enable_patch_version_auto_upgrade(
mut self,
enable_patch_version_auto_upgrade: bool,
) -> CreateOpts {
self.enable_patch_version_auto_upgrade = Some(enable_patch_version_auto_upgrade);
self
}
pub fn with_zonal(mut self, zonal: bool) -> CreateOpts {
self.zonal = Some(zonal);
self
}
pub fn with_kubernetes_options(mut self, kubernetes_options: KubernetesOptions) -> CreateOpts {
self.kubernetes_options = Some(kubernetes_options);
self
}
}
#[derive(Debug, Serialize)]
pub struct CreateOptsRoot<'a> {
pub cluster: &'a CreateOpts,
}