aboutsummaryrefslogtreecommitdiff
path: root/src/garage/cli/layout.rs
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-30 12:07:12 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-30 12:07:12 +0100
commit69ddaafc6061d06d277fe772dfaa7fe64ecafcc1 (patch)
tree8513758d6205e4f2ba3c2d6fa3ff768ff3a660ce /src/garage/cli/layout.rs
parent145130481eac30793c6c08caa4d208ddddfc30e8 (diff)
downloadgarage-69ddaafc6061d06d277fe772dfaa7fe64ecafcc1.tar.gz
garage-69ddaafc6061d06d277fe772dfaa7fe64ecafcc1.zip
wip: migrate garage status and garage layout assign
Diffstat (limited to 'src/garage/cli/layout.rs')
-rw-r--r--src/garage/cli/layout.rs141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/garage/cli/layout.rs b/src/garage/cli/layout.rs
index f053eef4..d0b62fc7 100644
--- a/src/garage/cli/layout.rs
+++ b/src/garage/cli/layout.rs
@@ -10,147 +10,6 @@ use garage_rpc::*;
use crate::cli::*;
-pub async fn cli_layout_command_dispatch(
- cmd: LayoutOperation,
- system_rpc_endpoint: &Endpoint<SystemRpc, ()>,
- rpc_host: NodeID,
-) -> Result<(), Error> {
- match cmd {
- LayoutOperation::Assign(assign_opt) => {
- cmd_assign_role(system_rpc_endpoint, rpc_host, assign_opt).await
- }
- LayoutOperation::Remove(remove_opt) => {
- cmd_remove_role(system_rpc_endpoint, rpc_host, remove_opt).await
- }
- LayoutOperation::Show => cmd_show_layout(system_rpc_endpoint, rpc_host).await,
- LayoutOperation::Apply(apply_opt) => {
- cmd_apply_layout(system_rpc_endpoint, rpc_host, apply_opt).await
- }
- LayoutOperation::Revert(revert_opt) => {
- cmd_revert_layout(system_rpc_endpoint, rpc_host, revert_opt).await
- }
- LayoutOperation::Config(config_opt) => {
- cmd_config_layout(system_rpc_endpoint, rpc_host, config_opt).await
- }
- LayoutOperation::History => cmd_layout_history(system_rpc_endpoint, rpc_host).await,
- LayoutOperation::SkipDeadNodes(assume_sync_opt) => {
- cmd_layout_skip_dead_nodes(system_rpc_endpoint, rpc_host, assume_sync_opt).await
- }
- }
-}
-
-pub async fn cmd_assign_role(
- rpc_cli: &Endpoint<SystemRpc, ()>,
- rpc_host: NodeID,
- args: AssignRoleOpt,
-) -> Result<(), Error> {
- let status = match rpc_cli
- .call(&rpc_host, SystemRpc::GetKnownNodes, PRIO_NORMAL)
- .await??
- {
- SystemRpc::ReturnKnownNodes(nodes) => nodes,
- resp => return Err(Error::Message(format!("Invalid RPC response: {:?}", resp))),
- };
-
- let mut layout = fetch_layout(rpc_cli, rpc_host).await?;
- let all_nodes = layout.get_all_nodes();
-
- let added_nodes = args
- .node_ids
- .iter()
- .map(|node_id| {
- find_matching_node(
- status
- .iter()
- .map(|adv| adv.id)
- .chain(all_nodes.iter().cloned()),
- node_id,
- )
- })
- .collect::<Result<Vec<_>, _>>()?;
-
- let mut roles = layout.current().roles.clone();
- roles.merge(&layout.staging.get().roles);
-
- for replaced in args.replace.iter() {
- let replaced_node = find_matching_node(all_nodes.iter().cloned(), replaced)?;
- match roles.get(&replaced_node) {
- Some(NodeRoleV(Some(_))) => {
- layout
- .staging
- .get_mut()
- .roles
- .merge(&roles.update_mutator(replaced_node, NodeRoleV(None)));
- }
- _ => {
- return Err(Error::Message(format!(
- "Cannot replace node {:?} as it is not currently in planned layout",
- replaced_node
- )));
- }
- }
- }
-
- if args.capacity.is_some() && args.gateway {
- return Err(Error::Message(
- "-c and -g are mutually exclusive, please configure node either with c>0 to act as a storage node or with -g to act as a gateway node".into()));
- }
- if args.capacity == Some(ByteSize::b(0)) {
- return Err(Error::Message("Invalid capacity value: 0".into()));
- }
-
- for added_node in added_nodes {
- let new_entry = match roles.get(&added_node) {
- Some(NodeRoleV(Some(old))) => {
- let capacity = match args.capacity {
- Some(c) => Some(c.as_u64()),
- None if args.gateway => None,
- None => old.capacity,
- };
- let tags = if args.tags.is_empty() {
- old.tags.clone()
- } else {
- args.tags.clone()
- };
- NodeRole {
- zone: args.zone.clone().unwrap_or_else(|| old.zone.to_string()),
- capacity,
- tags,
- }
- }
- _ => {
- let capacity = match args.capacity {
- Some(c) => Some(c.as_u64()),
- None if args.gateway => None,
- None => return Err(Error::Message(
- "Please specify a capacity with the -c flag, or set node explicitly as gateway with -g".into())),
- };
- NodeRole {
- zone: args
- .zone
- .clone()
- .ok_or("Please specify a zone with the -z flag")?,
- capacity,
- tags: args.tags.clone(),
- }
- }
- };
-
- layout
- .staging
- .get_mut()
- .roles
- .merge(&roles.update_mutator(added_node, NodeRoleV(Some(new_entry))));
- }
-
- send_layout(rpc_cli, rpc_host, layout).await?;
-
- println!("Role changes are staged but not yet committed.");
- println!("Use `garage layout show` to view staged role changes,");
- println!("and `garage layout apply` to enact staged changes.");
- Ok(())
-}
-
pub async fn cmd_remove_role(
rpc_cli: &Endpoint<SystemRpc, ()>,
rpc_host: NodeID,