adapting CLI to the surreal brain

This commit is contained in:
ghe0 2025-04-23 04:13:07 +03:00
parent fb8558f7a9
commit 520aff964f
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
4 changed files with 16 additions and 47 deletions

2
Cargo.lock generated

@ -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",

@ -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]

@ -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.",

@ -64,20 +64,16 @@ impl TryFrom<grpc::proto::VmContract> 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<Self> {
// 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<Distro> {
impl Distro {
pub fn get_template_list() -> Vec<Self> {
// 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<proto::VmContract> 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,
}