--wip-- [skip ci]

This commit is contained in:
2026-09-25 03:39:29 +02:00
parent 344f345854
commit 10c6f891d7
12 changed files with 379 additions and 42 deletions
+18 -8
View File
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::net::Ipv4Addr;
use std::path::PathBuf;
use std::process::Command;
@@ -73,7 +74,7 @@ struct ClusterDeserialize {
pub struct Cluster {
pub(crate) name: String,
pub(crate) version: Version,
nodes: Vec<Node>,
nodes: HashMap<String, Node>,
cluster_env: ClusterEnv,
pub(crate) control_plane_ip: Ipv4Addr,
pub(crate) secrets_file: PathBuf,
@@ -114,21 +115,24 @@ impl Cluster {
let cluster = Self {
name: cluster_name.into(),
version: cluster.version,
nodes: vec![],
nodes: HashMap::new(),
cluster_env: cluster.cluster_env,
control_plane_ip: cluster.control_plane_ip,
secrets_file,
};
let nodes = nodes
.iter()
.map(|name| Node::get(name, env, &cluster, &default, &base))
.into_iter()
.map(|name| {
let node = Node::get(&name, env, &cluster, &default, &base);
(node.hostname().into(), node)
})
.collect();
Self { nodes, ..cluster }
}
pub fn get_all() -> Vec<Cluster> {
pub fn get_all() -> HashMap<String, Cluster> {
let env = PathEnvironment::new_patches();
WalkDir::new(get_talos_path().join("clusters"))
@@ -145,13 +149,19 @@ impl Cluster {
return None;
}
Some(Cluster::get(&name, &env))
let cluster = Cluster::get(&name, &env);
Some((name, cluster))
})
.collect()
}
pub fn nodes(&self) -> &[Node] {
&self.nodes
pub fn nodes(&self) -> impl Iterator<Item = &Node> {
self.nodes.values()
}
pub fn node(&self, name: &str) -> Option<&Node> {
self.nodes.get(name)
}
pub fn talosctl_gen_config_command(&self) -> Command {