Skip to content

Commit

Permalink
fix: Fix units, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dsieradzki authored Oct 10, 2023
1 parent bbf27b6 commit 3db07a3
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 213 deletions.
5 changes: 2 additions & 3 deletions core/src/dispatcher/usecase/change_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) fn execute(
cluster_name: String,
node_name: String,
cores: u16,
memory: u64,
memory: u32,
) -> Result<(), String> {
info!("Cluster creation request has been received");
let proxmox_client = proxmox_client.operations(access);
Expand All @@ -36,12 +36,11 @@ pub(crate) fn execute(
.iter()
.find(|i| i.name == node_name)
.ok_or("Cannot find node to create")?;

proxmox_client.update_config(VmConfig {
vm_id: node_to_change.vm_id,
node: cluster.node.clone(),
cores,
memory,
memory: u64::from(memory),
})?;

common::vm::stop_vm(&proxmox_client, &cluster.node, node_to_change.vm_id)?;
Expand Down
6 changes: 3 additions & 3 deletions core/src/dispatcher/usecase/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) mod vm {
node: cluster.node.clone(),
name: format!("{}-{}", cluster.cluster_name, node.name),
cores: node.cores,
memory: node.memory,
memory: u64::from(node.memory),
os_type: OsType::L26,
net: HashMap::from([(
"net0".to_owned(),
Expand Down Expand Up @@ -324,7 +324,7 @@ pub(crate) mod vm {
"echo '{} {}' | sudo tee -a /etc/cloud/templates/hosts.debian.tmpl",
ip, host
)
.as_str(),
.as_str(),
)?;
ssh_client
.execute(format!("echo '{} {}' | sudo tee -a /etc/hosts", ip, host).as_str())?;
Expand Down Expand Up @@ -363,7 +363,7 @@ pub(crate) mod cluster {
.clone()
.unwrap_or("1.24/stable".to_owned())
)
.as_str(),
.as_str(),
)?;
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Event {
cluster_name: String,
node_name: String,
cores: u16,
memory: u64,
#[doc = "Unit: MiB"]
memory: u32,
},
}
16 changes: 10 additions & 6 deletions core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ pub struct ClusterNode {
pub vm_id: u32,
pub name: String,
pub cores: u16,
pub memory: u64,
#[doc="Unit: MiB"]
pub memory: u32,
pub ip_address: String,
pub storage_pool: String,
pub node_type: ClusterNodeType,
Expand Down Expand Up @@ -164,8 +165,8 @@ pub struct Cluster {
pub node_password: String,
pub helm_apps: Vec<HelmApp>,
pub cluster_resources: Vec<ClusterResource>,
#[doc = "Disk size id GB"]
pub disk_size: u64,
#[doc = "Disk size id GiB"]
pub disk_size: u32,
pub nodes: Vec<ClusterNode>,
pub network: Network,
pub status: ClusterStatus,
Expand All @@ -185,7 +186,8 @@ pub struct ClusterRequest {
pub node_password: String,
pub helm_apps: Vec<HelmApp>,
pub cluster_resources: Vec<ClusterResource>,
pub disk_size: u64,
#[doc = "Unit: GiB"]
pub disk_size: u32,
pub nodes: Vec<ClusterNode>,
pub network: Network,
}
Expand All @@ -197,8 +199,10 @@ pub struct ClusterHeader {
pub name: String,
pub nodes_count: u16,
pub cores_sum: u16,
pub memory_sum: u64,
pub disk_size_sum: u64,
#[doc = "Unit: MiB"]
pub memory_sum: u32,
#[doc = "Unit: GiB"]
pub disk_size_sum: u32,
pub status: ClusterStatus,
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Operator {
cluster_name: String,
node_name: String,
cores: u16,
memory: u64,
memory: u32,
) -> crate::Result<()> {
info!("Start changing node resources");
let mut cluster = self
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Operator {

let memory = i.nodes.iter().map(|i| i.memory).reduce(|a, b| a + b);

let node_count = u64::try_from(i.nodes.len()).unwrap_or(0);
let node_count = u32::try_from(i.nodes.len()).unwrap_or(0);

ClusterHeader {
name: i.cluster_name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: web.install web.generate-models web.build app.build.release
.PHONY:
.ONESHELL:
web.generate-models:
typeshare ./src --lang=typescript -c ./typeshare.toml --output-file=src-web/src/api/model.ts
typeshare ../ --lang=typescript -c ./typeshare.toml --output-file=src-web/src/api/model.ts

.PHONY:
.ONESHELL:
Expand Down
8 changes: 4 additions & 4 deletions web/src-web/src/api/clusters.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ActionLogEntry, ChangeNodeResourcesRequest,
ChangeNodeResourcesRequest,
Cluster,
ClusterHeader,
ClusterNode,
ClusterNodeStatus,
ClusterNodeVmStatus,
ClusterRequest
ClusterRequest, LogEntry
} from "@/api/model";
import axios from "axios";

Expand Down Expand Up @@ -49,10 +49,10 @@ export namespace clusters {
return axios.get("/api/v1/clusters/generate").then(e => e.data);
}

export function logsForCluster(name: string): Promise<ActionLogEntry[]> {
export function logsForCluster(name: string): Promise<LogEntry[]> {
return axios.get(`/api/v1/clusters/${name}/logs`).then(e => e.data);
}
export function clearLogsForCluster(name: string): Promise<ActionLogEntry[]> {
export function clearLogsForCluster(name: string): Promise<LogEntry[]> {
return axios.delete(`/api/v1/clusters/${name}/logs`).then(e => e.data);
}

Expand Down
Loading

0 comments on commit 3db07a3

Please sign in to comment.