From 8818e23b3abe04cee4ddb6c46005cdb3ef5afae4 Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Thu, 4 Sep 2025 08:33:34 +0100 Subject: [PATCH 1/2] Add a local-switch-id command to gateway-cli This is intended to be used for the switch zone shell prompt, which currently uses curl to talk to the local MGS. Having gateway-cli do it instead means that: 1) the program would automatically pick up new changes to the API 2) things would break at build-time if the API were broken 3) ls-apis would see this consumer Addresses #8976 Signed-off-by: Andrii Sultanov --- gateway-cli/src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gateway-cli/src/main.rs b/gateway-cli/src/main.rs index a9b19e011e2..6d98e2e1391 100644 --- a/gateway-cli/src/main.rs +++ b/gateway-cli/src/main.rs @@ -301,6 +301,9 @@ enum Command { /// Component to reset component: String, }, + + /// Get the ID for the switch this MGS instance is connected to. + LocalSwitchId {}, } fn level_from_str(s: &str) -> Result { @@ -607,6 +610,10 @@ async fn main_impl() -> Result<()> { Command::ResetComponent { sp, component } => { client.sp_component_reset(sp.type_, sp.slot, &component).await?; } + Command::LocalSwitchId {} => { + let sp_id = client.sp_local_switch_id().await?.into_inner(); + dumper.dump(&sp_id)?; + } } Ok(()) From 118dd4abbbb0d1d57219b867d5293c4bc092262e Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Thu, 4 Sep 2025 08:58:55 +0100 Subject: [PATCH 2/2] Package gateway-cli into switch zone, use it in the shell zone prompt instead of curl Fixes #8976 Signed-off-by: Andrii Sultanov --- package-manifest.toml | 18 +++++++++++++++--- smf/profile/bashrc | 2 +- smf/profile/profile | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package-manifest.toml b/package-manifest.toml index b503a8fd4ab..f250a5b68fa 100644 --- a/package-manifest.toml +++ b/package-manifest.toml @@ -832,7 +832,8 @@ source.packages = [ "xcvradm.tar.gz", "omicron-omdb.tar.gz", "zone-setup.tar.gz", - "zone-network-install.tar.gz" + "zone-network-install.tar.gz", + "gateway-cli.tar.gz" ] output.type = "zone" @@ -858,7 +859,8 @@ source.packages = [ "sp-sim-stub.tar.gz", "omicron-omdb.tar.gz", "zone-setup.tar.gz", - "zone-network-install.tar.gz" + "zone-network-install.tar.gz", + "gateway-cli.tar.gz" ] output.type = "zone" @@ -884,7 +886,8 @@ source.packages = [ "sp-sim-softnpu.tar.gz", "omicron-omdb.tar.gz", "zone-setup.tar.gz", - "zone-network-install.tar.gz" + "zone-network-install.tar.gz", + "gateway-cli.tar.gz" ] output.type = "zone" @@ -926,6 +929,15 @@ source.rust.release = true output.type = "zone" output.intermediate_only = true +[package.gateway-cli] +service_name = "gateway-cli" +only_for_targets.image = "standard" +source.type = "local" +source.rust.binary_names = ["gateway-cli"] +source.rust.release = true +output.type = "zone" +output.intermediate_only = true + [package.oxlog] service_name = "oxlog" only_for_targets.image = "standard" diff --git a/smf/profile/bashrc b/smf/profile/bashrc index 3afe2fa845d..c142079f9ab 100644 --- a/smf/profile/bashrc +++ b/smf/profile/bashrc @@ -10,7 +10,7 @@ typeset _hstc="$C_RED$HOSTNAME" case "$_hst" in oxz_switch) # Try to determine which switch zone we are - _switchid=$(curl -H 'api-version: 1.0.0' -s http://localhost:12225/local/switch-id \ + _switchid=$(gateway-cli --server "[::1]:12225" local-switch-id \ | /opt/ooce/bin/jq -r .slot) if (( $? == 0 )) && [[ -n "$_switchid" ]]; then _hst+="$_switchid" diff --git a/smf/profile/profile b/smf/profile/profile index e3802d1bd48..280b63bad65 100644 --- a/smf/profile/profile +++ b/smf/profile/profile @@ -4,7 +4,7 @@ PATH+=:/opt/ooce/bin case "$HOSTNAME" in oxz_switch) # Add tools like xcvradm, swadm & ddmadm to the PATH by default - PATH+=:/opt/oxide/bin:/opt/oxide/dendrite/bin:/opt/oxide/mg-ddm/bin:/opt/oxide/omdb/bin:/opt/oxide/mgd/bin + PATH+=:/opt/oxide/bin:/opt/oxide/dendrite/bin:/opt/oxide/mg-ddm/bin:/opt/oxide/omdb/bin:/opt/oxide/mgd/bin:/opt/oxide/gateway-cli/bin ;; oxz_cockroachdb*) PATH+=:/opt/oxide/cockroachdb/bin