Skip to content

Commit

Permalink
Move smf helper to illumos utils
Browse files Browse the repository at this point in the history
  • Loading branch information
karencfv committed Jul 26, 2024
1 parent ae4cf1c commit de675fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
1 change: 1 addition & 0 deletions illumos-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod opte;
pub mod route;
pub mod running_zone;
pub mod scf;
pub mod smf_helper;
pub mod svc;
pub mod svcadm;
pub mod vmm_reservoir;
Expand Down
19 changes: 10 additions & 9 deletions sled-agent/src/smf_helper.rs → illumos-utils/src/smf_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use illumos_utils::running_zone::RunningZone;
use crate::running_zone::RunningZone;
use crate::zone::SVCCFG;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to do '{intent}' by running command in zone: {err}")]
ZoneCommand {
intent: String,
#[source]
err: illumos_utils::running_zone::RunCommandError,
err: crate::running_zone::RunCommandError,
},
}

Expand Down Expand Up @@ -44,7 +45,7 @@ impl<'t> SmfHelper<'t> {
{
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.default_smf_name,
"setprop",
Expand All @@ -70,7 +71,7 @@ impl<'t> SmfHelper<'t> {
{
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.smf_name,
"addpropvalue",
Expand Down Expand Up @@ -98,7 +99,7 @@ impl<'t> SmfHelper<'t> {
{
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.default_smf_name,
"addpropvalue",
Expand All @@ -124,7 +125,7 @@ impl<'t> SmfHelper<'t> {
{
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.smf_name,
"addpg",
Expand All @@ -148,7 +149,7 @@ impl<'t> SmfHelper<'t> {
{
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.smf_name,
"delpg",
Expand Down Expand Up @@ -176,7 +177,7 @@ impl<'t> SmfHelper<'t> {
match self
.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.default_smf_name,
"delpropvalue",
Expand All @@ -203,7 +204,7 @@ impl<'t> SmfHelper<'t> {
pub fn refresh(&self) -> Result<(), Error> {
self.running_zone
.run_cmd(&[
illumos_utils::zone::SVCCFG,
SVCCFG,
"-s",
&self.default_smf_name,
"refresh",
Expand Down
1 change: 0 additions & 1 deletion sled-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub mod rack_setup;
pub mod server;
pub mod services;
mod sled_agent;
mod smf_helper;
mod storage_monitor;
mod swap_device;
mod updates;
Expand Down
9 changes: 0 additions & 9 deletions sled-agent/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,6 @@ impl OmicronZoneTypeExt for OmicronZoneConfig {
}
}

impl crate::smf_helper::Service for OmicronZoneType {
fn service_name(&self) -> String {
self.kind().service_prefix().to_owned()
}
fn smf_name(&self) -> String {
format!("svc:/oxide/{}", self.service_name())
}
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct TimeSync {
/// The synchronization state of the sled, true when the system clock
Expand Down
6 changes: 3 additions & 3 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::params::{
ZoneBundleCause, ZoneBundleMetadata,
};
use crate::profile::*;
use crate::smf_helper::SmfHelper;
use illumos_utils::smf_helper::SmfHelper;
use crate::zone_bundle::BundleError;
use crate::zone_bundle::ZoneBundler;
use anyhow::anyhow;
Expand Down Expand Up @@ -157,7 +157,7 @@ pub enum Error {
SledLocalZone(anyhow::Error),

#[error("Failed to issue SMF command: {0}")]
SmfCommand(#[from] crate::smf_helper::Error),
SmfCommand(#[from] illumos_utils::smf_helper::Error),

#[error("{}", display_zone_init_errors(.0))]
ZoneInitialize(Vec<(String, Box<Error>)>),
Expand Down Expand Up @@ -498,7 +498,7 @@ enum SwitchService {
SpSim,
}

impl crate::smf_helper::Service for SwitchService {
impl illumos_utils::smf_helper::Service for SwitchService {
fn service_name(&self) -> String {
match self {
SwitchService::ManagementGatewayService => "mgs",
Expand Down

0 comments on commit de675fe

Please sign in to comment.