use crate::client::{HTTPClient, encode_param};
use crate::errors::UbiClientError;
use crate::{make_json_request, make_request};
use serde::Deserialize;
use serde::Serialize;
use std::sync::Arc;
pub struct KCClient {
http_client: Arc<HTTPClient>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct QueryParams {
start_after: Option<String>,
page_size: Option<u32>,
order_column: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ReqClusterCreate {
pub version: String,
pub worker_size: String,
pub cp_nodes: u32,
pub worker_nodes: u32,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ResponseListKubernetesClusters {
pub count: u32,
pub items: Vec<ClusterItem>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ClusterItem {
pub cp_node_count: u32,
pub cp_vms: Option<Vec<VirtualMachine>>,
pub display_state: String,
pub id: String,
pub location: String,
pub name: String,
pub node_size: String,
pub nodepools: Option<Vec<NodePool>>,
pub services_load_balancer_url: Option<String>,
pub version: String,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct NodePool {
pub kubernetes_cluster_id: String,
pub id: String,
pub name: String,
pub node_count: u32,
pub node_size: String,
pub vms: Vec<VirtualMachine>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct VirtualMachine {
pub id: String,
pub ip4: String,
pub ip4_enabled: bool,
pub ip6: String,
pub location: String,
pub name: String,
pub size: String,
pub state: String,
pub storage_size_gib: u32,
pub unix_user: String,
}
impl KCClient {
pub fn new(http_client: Arc<HTTPClient>) -> Self {
KCClient { http_client }
}
pub async fn list_kubernetes_clusters(
&self,
project_id: &str,
query_params: Option<QueryParams>,
) -> Result<ResponseListKubernetesClusters, UbiClientError> {
let url = &format!("project/{}/kubernetes-cluster", encode_param(project_id));
let body_empty = serde_json::json!({});
make_json_request!(
self,
reqwest::Method::GET,
url,
body_empty,
query_params,
ResponseListKubernetesClusters
)
}
pub async fn create_kubernetes_cluster(
&self,
project_id: &str,
location: &str,
kubernetes_cluster_reference: &str,
payload: &ReqClusterCreate,
) -> Result<ClusterItem, UbiClientError> {
let url = &format!(
"project/{}/location/{}/kubernetes-cluster/{}",
encode_param(project_id),
location,
kubernetes_cluster_reference
);
let query_params = [(); 0]; make_json_request!(
self,
reqwest::Method::POST,
url,
payload,
query_params,
ClusterItem
)
}
pub async fn delete_kubernetes_cluster(
&self,
project_id: &str,
location: &str,
kubernetes_cluster_reference: &str,
) -> Result<(), UbiClientError> {
let url = &format!(
"project/{}/location/{}/kubernetes-cluster/{}",
encode_param(project_id),
location,
kubernetes_cluster_reference
);
make_request!(self, reqwest::Method::DELETE, url)
}
}