Skip to content

Commit

Permalink
services cleanup and dendrite update
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Nov 1, 2024
1 parent 701b06f commit 01f2a0b
Showing 1 changed file with 73 additions and 134 deletions.
207 changes: 73 additions & 134 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,63 @@ fn display_zone_init_errors(errors: &[(String, Box<Error>)]) -> String {
output
}

/// Helper function to add properties to a PropertyGroupBuilder for a sled
/// agent centered around rack and sled identifiers.
fn add_sled_ident_properties(
config: PropertyGroupBuilder,
info: &SledAgentInfo,
) -> PropertyGroupBuilder {
config
.add_property("rack_id", "astring", &info.rack_id.to_string())
.add_property(
"sled_id",
"astring",
&info.config.sled_identifiers.sled_id.to_string(),
)
.add_property(
"sled_model",
"astring",
&info.config.sled_identifiers.model.to_string(),
)
.add_property(
"sled_serial",
"astring",
&info.config.sled_identifiers.serial.to_string(),
)
.add_property(
"sled_revision",
"astring",
&info.config.sled_identifiers.revision.to_string(),
)
}

/// Helper function to set properties on a SmfHelper for a sled agent centered
/// around rack and sled identifiers.
fn setprop_sled_ident_properties(
smfh: &SmfHelper,
info: &SledAgentInfo,
) -> Result<(), Error> {
smfh.setprop_default_instance("config/rack_id", info.rack_id)?;
smfh.setprop_default_instance(
"config/sled_id",
info.config.sled_identifiers.sled_id,
)?;
smfh.setprop_default_instance(
"config/sled_model",
info.config.sled_identifiers.model.to_string(),
)?;
smfh.setprop_default_instance(
"config/sled_revision",
info.config.sled_identifiers.revision,
)?;
smfh.setprop_default_instance(
"config/sled_serial",
info.config.sled_identifiers.serial.to_string(),
)?;

Ok(())
}

/// Configuration parameters which modify the [`ServiceManager`]'s behavior.
pub struct Config {
/// Identifies the sled being configured
Expand Down Expand Up @@ -2674,45 +2731,11 @@ impl ServiceManager {
PropertyGroupBuilder::new("config");

if let Some(i) = info {
dendrite_config = dendrite_config
.add_property(
"rack_id",
"astring",
&i.rack_id.to_string(),
)
.add_property(
"sled_id",
"astring",
&i.config
.sled_identifiers
.sled_id
.to_string(),
)
.add_property(
"sled_model",
"astring",
&i.config
.sled_identifiers
.model
.to_string(),
)
.add_property(
"sled_serial",
"astring",
&i.config
.sled_identifiers
.serial
.to_string(),
)
.add_property(
"sled_revision",
"astring",
&i.config
.sled_identifiers
.revision
.to_string(),
);
}
dendrite_config = add_sled_ident_properties(
dendrite_config,
i,
)
};

for address in addresses {
dendrite_config = dendrite_config.add_property(
Expand Down Expand Up @@ -2837,64 +2860,30 @@ impl ServiceManager {
}
SwitchService::Tfport { pkt_source, asic } => {
info!(self.inner.log, "Setting up tfport service");

let mut tfport_config =
PropertyGroupBuilder::new("config");

tfport_config = tfport_config
.add_property(
"host",
"dpd_host",
"astring",
&format!("[{}]", Ipv6Addr::LOCALHOST),
)
.add_property(
"port",
"dpd_port",
"astring",
&format!("{}", DENDRITE_PORT),
);

if let Some(i) = info {
tfport_config = tfport_config
.add_property(
"rack_id",
"astring",
&i.rack_id.to_string(),
)
.add_property(
"sled_id",
"astring",
&i.config
.sled_identifiers
.sled_id
.to_string(),
)
.add_property(
"sled_model",
"astring",
&i.config
.sled_identifiers
.model
.to_string(),
)
.add_property(
"sled_revision",
"astring",
&i.config
.sled_identifiers
.revision
.to_string(),
)
.add_property(
"sled_serial",
"astring",
&i.config
.sled_identifiers
.serial
.to_string(),
);
tfport_config =
add_sled_ident_properties(tfport_config, i);
}

for address in addresses {
tfport_config = tfport_config.add_property(
"address",
"listen_address",
"astring",
&format!("[{}]:{}", address, TFPORTD_PORT),
);
Expand Down Expand Up @@ -4434,32 +4423,7 @@ impl ServiceManager {
"configuring dendrite service"
);
if let Some(info) = self.inner.sled_info.get() {
smfh.setprop_default_instance(
"config/rack_id",
info.rack_id,
)?;
smfh.setprop_default_instance(
"config/sled_id",
info.config.sled_identifiers.sled_id,
)?;
smfh.setprop_default_instance(
"config/sled_model",
info.config
.sled_identifiers
.model
.to_string(),
)?;
smfh.setprop_default_instance(
"config/sled_revision",
info.config.sled_identifiers.revision,
)?;
smfh.setprop_default_instance(
"config/sled_serial",
info.config
.sled_identifiers
.serial
.to_string(),
)?;
setprop_sled_ident_properties(&smfh, info)?;
} else {
info!(
self.inner.log,
Expand Down Expand Up @@ -4540,45 +4504,20 @@ impl ServiceManager {
SwitchService::Tfport { pkt_source, asic } => {
info!(self.inner.log, "configuring tfport service");
if let Some(info) = self.inner.sled_info.get() {
smfh.setprop_default_instance(
"config/rack_id",
info.rack_id,
)?;
smfh.setprop_default_instance(
"config/sled_id",
info.config.sled_identifiers.sled_id,
)?;
smfh.setprop_default_instance(
"config/sled_model",
info.config
.sled_identifiers
.model
.to_string(),
)?;
smfh.setprop_default_instance(
"config/sled_revision",
info.config.sled_identifiers.revision,
)?;
smfh.setprop_default_instance(
"config/sled_serial",
info.config
.sled_identifiers
.serial
.to_string(),
)?;
setprop_sled_ident_properties(&smfh, info)?;
} else {
info!(
self.inner.log,
"no sled info available yet"
);
}
smfh.delpropvalue_default_instance(
"config/address",
"config/listen_address",
"*",
)?;
for address in &request.addresses {
smfh.addpropvalue_type_default_instance(
"config/address",
"config/listen_address",
&format!("[{}]:{}", address, TFPORTD_PORT),
"astring",
)?;
Expand Down

0 comments on commit 01f2a0b

Please sign in to comment.