From 520aff964fbbc29d16745e77f1795154bef6d2c7 Mon Sep 17 00:00:00 2001 From: ghe0 Date: Wed, 23 Apr 2025 04:13:07 +0300 Subject: [PATCH] adapting CLI to the surreal brain --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/snp/grpc.rs | 12 ++++++------ src/snp/mod.rs | 47 ++++++++--------------------------------------- 4 files changed, 16 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c17ffcb..5fdbe40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1182,7 +1182,7 @@ dependencies = [ [[package]] name = "detee-shared" version = "0.1.0" -source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=main#b5289f1f5ba3ddae2ee066d6deb073ce92436b71" +source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=surreal_brain#fb38352e1b47837b14f32d8df5ae7f6b17202aae" dependencies = [ "bincode", "prost", diff --git a/Cargo.toml b/Cargo.toml index 5ddb6c2..33dde0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ tokio-retry = "0.3.0" detee-sgx = { git = "ssh://git@gitea.detee.cloud/testnet/detee-sgx.git", branch = "hratls", features=["hratls", "qvl"] } shadow-rs = { version = "1.1.1", features = ["metadata"] } -detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto.git", branch = "main" } +detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto.git", branch = "surreal_brain" } # detee-shared = { path = "../detee-shared" } [build-dependencies] diff --git a/src/snp/grpc.rs b/src/snp/grpc.rs index 81e7ec0..a2fc231 100644 --- a/src/snp/grpc.rs +++ b/src/snp/grpc.rs @@ -49,18 +49,18 @@ impl crate::HumanOutput for VmContract { "The VM {} has the UUID {}, and it runs on the node {}", self.hostname, self.uuid, self.node_pubkey ); - if self.public_ipv4.is_empty() { + if self.vm_public_ipv4.is_empty() { println!( - "The VM has no public IPv4. The ports published by the VM are: {:?}", - self.exposed_ports + "The VM has no public IPv4. The ports mapped from the host to the VM are: {:?}", + self.mapped_ports ); } else { - println!("The Public IPv4 address of the VM is: {}", self.public_ipv4); + println!("The Public IPv4 address of the VM is: {}", self.vm_public_ipv4); } - if self.public_ipv6.is_empty() { + if self.vm_public_ipv6.is_empty() { println!("The VM does not have a public IPv6 address."); } else { - println!("The Public IPv6 address of the VM is: {}", self.public_ipv6); + println!("The Public IPv6 address of the VM is: {}", self.vm_public_ipv6); } println!( "The VM has {} vCPUS, {}MB of memory and a disk of {} GB.", diff --git a/src/snp/mod.rs b/src/snp/mod.rs index c00165b..9d5ee78 100644 --- a/src/snp/mod.rs +++ b/src/snp/mod.rs @@ -64,20 +64,16 @@ impl TryFrom for VmSshArgs { args.user = "root".to_string(); args.key_path = Config::init_config().get_ssh_pubkey()?.trim_end_matches(".pub").to_string(); - if !contract.public_ipv4.is_empty() { - args.ip = contract.public_ipv4; + if !contract.vm_public_ipv4.is_empty() { + args.ip = contract.vm_public_ipv4; args.port = "22".to_string(); } else { - args.port = contract.exposed_ports[0].to_string(); - log::info!( - "This VM does not have a public IP. Getting node IP for node {}", - contract.node_pubkey + args.port = contract.mapped_ports[0].host_port.to_string(); + log::debug!( + "This VM does not have a public IP. Using node public IP: {}", + contract.node_ip ); - let node = block_on(snp::grpc::get_one_node(proto::VmNodeFilters { - node_pubkey: contract.node_pubkey.clone(), - ..Default::default() - }))?; - args.ip = node.ip; + args.ip = contract.node_ip; } Ok(args) } @@ -97,12 +93,6 @@ pub struct Dtrfs { impl Dtrfs { pub fn print_dtrfs_list() -> Vec { - // let mut dtrfs_vec = Vec::new(); - // dtrfs_vec.push(DEFAULT_DTRFS.clone()); - // dtrfs_vec.push(ALTERNATIVE_INIT[0].clone()); - // dtrfs_vec.push(ALTERNATIVE_INIT[1].clone()); - // dtrfs_vec - vec![DEFAULT_DTRFS.clone(), ALTERNATIVE_INIT[0].clone(), ALTERNATIVE_INIT[1].clone()] } @@ -134,15 +124,6 @@ impl super::HumanOutput for Vec { impl Distro { pub fn get_template_list() -> Vec { - // let mut distro_vec = Vec::new(); - // distro_vec.push(DEFAULT_ARCHLINUX.clone()); - // distro_vec.push(DEFAULT_UBUNTU.clone()); - // distro_vec.push(DEFAULT_FEDORA.clone()); - // distro_vec.push(ALTERNATIVE_DISTROS[0].clone()); - // distro_vec.push(ALTERNATIVE_DISTROS[1].clone()); - // distro_vec.push(ALTERNATIVE_DISTROS[2].clone()); - // distro_vec - vec![ DEFAULT_ARCHLINUX.clone(), DEFAULT_UBUNTU.clone(), @@ -203,25 +184,13 @@ fn display_mins(minutes: &u64) -> String { impl From for VmContract { fn from(brain_contract: proto::VmContract) -> Self { - let node_pubkey = brain_contract.node_pubkey.clone(); - let location = match block_on(snp::grpc::get_one_node(proto::VmNodeFilters { - node_pubkey: node_pubkey.clone(), - ..Default::default() - })) { - Ok(node) => format!("{}, {} ({})", node.city, node.region, node.country), - Err(e) => { - log::warn!("Could not get information about node {node_pubkey} fram brain: {e:?}"); - String::new() - } - }; - Self { uuid: brain_contract.uuid, hostname: brain_contract.hostname, vcpus: brain_contract.vcpus, mem: brain_contract.memory_mb, disk: brain_contract.disk_size_gb, - location, + location: brain_contract.location, cost_h: (brain_contract.nano_per_minute * 60) as f64 / 1_000_000_000.0, time_left: brain_contract.locked_nano / brain_contract.nano_per_minute, }