Skip to content

Commit 50b145b

Browse files
services cleanup and dendrite update
1 parent c57cc16 commit 50b145b

File tree

1 file changed

+73
-134
lines changed

1 file changed

+73
-134
lines changed

Diff for: sled-agent/src/services.rs

+73-134
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,63 @@ fn display_zone_init_errors(errors: &[(String, Box<Error>)]) -> String {
371371
output
372372
}
373373

374+
/// Helper function to add properties to a PropertyGroupBuilder for a sled
375+
/// agent centered around rack and sled identifiers.
376+
fn add_sled_ident_properties(
377+
config: PropertyGroupBuilder,
378+
info: &SledAgentInfo,
379+
) -> PropertyGroupBuilder {
380+
config
381+
.add_property("rack_id", "astring", &info.rack_id.to_string())
382+
.add_property(
383+
"sled_id",
384+
"astring",
385+
&info.config.sled_identifiers.sled_id.to_string(),
386+
)
387+
.add_property(
388+
"sled_model",
389+
"astring",
390+
&info.config.sled_identifiers.model.to_string(),
391+
)
392+
.add_property(
393+
"sled_serial",
394+
"astring",
395+
&info.config.sled_identifiers.serial.to_string(),
396+
)
397+
.add_property(
398+
"sled_revision",
399+
"astring",
400+
&info.config.sled_identifiers.revision.to_string(),
401+
)
402+
}
403+
404+
/// Helper function to set properties on a SmfHelper for a sled agent centered
405+
/// around rack and sled identifiers.
406+
fn setprop_sled_ident_properties(
407+
smfh: &SmfHelper,
408+
info: &SledAgentInfo,
409+
) -> Result<(), Error> {
410+
smfh.setprop_default_instance("config/rack_id", info.rack_id)?;
411+
smfh.setprop_default_instance(
412+
"config/sled_id",
413+
info.config.sled_identifiers.sled_id,
414+
)?;
415+
smfh.setprop_default_instance(
416+
"config/sled_model",
417+
info.config.sled_identifiers.model.to_string(),
418+
)?;
419+
smfh.setprop_default_instance(
420+
"config/sled_revision",
421+
info.config.sled_identifiers.revision,
422+
)?;
423+
smfh.setprop_default_instance(
424+
"config/sled_serial",
425+
info.config.sled_identifiers.serial.to_string(),
426+
)?;
427+
428+
Ok(())
429+
}
430+
374431
/// Configuration parameters which modify the [`ServiceManager`]'s behavior.
375432
pub struct Config {
376433
/// Identifies the sled being configured
@@ -2674,45 +2731,11 @@ impl ServiceManager {
26742731
PropertyGroupBuilder::new("config");
26752732

26762733
if let Some(i) = info {
2677-
dendrite_config = dendrite_config
2678-
.add_property(
2679-
"rack_id",
2680-
"astring",
2681-
&i.rack_id.to_string(),
2682-
)
2683-
.add_property(
2684-
"sled_id",
2685-
"astring",
2686-
&i.config
2687-
.sled_identifiers
2688-
.sled_id
2689-
.to_string(),
2690-
)
2691-
.add_property(
2692-
"sled_model",
2693-
"astring",
2694-
&i.config
2695-
.sled_identifiers
2696-
.model
2697-
.to_string(),
2698-
)
2699-
.add_property(
2700-
"sled_serial",
2701-
"astring",
2702-
&i.config
2703-
.sled_identifiers
2704-
.serial
2705-
.to_string(),
2706-
)
2707-
.add_property(
2708-
"sled_revision",
2709-
"astring",
2710-
&i.config
2711-
.sled_identifiers
2712-
.revision
2713-
.to_string(),
2714-
);
2715-
}
2734+
dendrite_config = add_sled_ident_properties(
2735+
dendrite_config,
2736+
i,
2737+
)
2738+
};
27162739

27172740
for address in addresses {
27182741
dendrite_config = dendrite_config.add_property(
@@ -2837,64 +2860,30 @@ impl ServiceManager {
28372860
}
28382861
SwitchService::Tfport { pkt_source, asic } => {
28392862
info!(self.inner.log, "Setting up tfport service");
2863+
28402864
let mut tfport_config =
28412865
PropertyGroupBuilder::new("config");
28422866

28432867
tfport_config = tfport_config
28442868
.add_property(
2845-
"host",
2869+
"dpd_host",
28462870
"astring",
28472871
&format!("[{}]", Ipv6Addr::LOCALHOST),
28482872
)
28492873
.add_property(
2850-
"port",
2874+
"dpd_port",
28512875
"astring",
28522876
&format!("{}", DENDRITE_PORT),
28532877
);
2878+
28542879
if let Some(i) = info {
2855-
tfport_config = tfport_config
2856-
.add_property(
2857-
"rack_id",
2858-
"astring",
2859-
&i.rack_id.to_string(),
2860-
)
2861-
.add_property(
2862-
"sled_id",
2863-
"astring",
2864-
&i.config
2865-
.sled_identifiers
2866-
.sled_id
2867-
.to_string(),
2868-
)
2869-
.add_property(
2870-
"sled_model",
2871-
"astring",
2872-
&i.config
2873-
.sled_identifiers
2874-
.model
2875-
.to_string(),
2876-
)
2877-
.add_property(
2878-
"sled_revision",
2879-
"astring",
2880-
&i.config
2881-
.sled_identifiers
2882-
.revision
2883-
.to_string(),
2884-
)
2885-
.add_property(
2886-
"sled_serial",
2887-
"astring",
2888-
&i.config
2889-
.sled_identifiers
2890-
.serial
2891-
.to_string(),
2892-
);
2880+
tfport_config =
2881+
add_sled_ident_properties(tfport_config, i);
28932882
}
28942883

28952884
for address in addresses {
28962885
tfport_config = tfport_config.add_property(
2897-
"address",
2886+
"listen_address",
28982887
"astring",
28992888
&format!("[{}]:{}", address, TFPORTD_PORT),
29002889
);
@@ -4435,32 +4424,7 @@ impl ServiceManager {
44354424
"configuring dendrite service"
44364425
);
44374426
if let Some(info) = self.inner.sled_info.get() {
4438-
smfh.setprop_default_instance(
4439-
"config/rack_id",
4440-
info.rack_id,
4441-
)?;
4442-
smfh.setprop_default_instance(
4443-
"config/sled_id",
4444-
info.config.sled_identifiers.sled_id,
4445-
)?;
4446-
smfh.setprop_default_instance(
4447-
"config/sled_model",
4448-
info.config
4449-
.sled_identifiers
4450-
.model
4451-
.to_string(),
4452-
)?;
4453-
smfh.setprop_default_instance(
4454-
"config/sled_revision",
4455-
info.config.sled_identifiers.revision,
4456-
)?;
4457-
smfh.setprop_default_instance(
4458-
"config/sled_serial",
4459-
info.config
4460-
.sled_identifiers
4461-
.serial
4462-
.to_string(),
4463-
)?;
4427+
setprop_sled_ident_properties(&smfh, info)?;
44644428
} else {
44654429
info!(
44664430
self.inner.log,
@@ -4541,45 +4505,20 @@ impl ServiceManager {
45414505
SwitchService::Tfport { pkt_source, asic } => {
45424506
info!(self.inner.log, "configuring tfport service");
45434507
if let Some(info) = self.inner.sled_info.get() {
4544-
smfh.setprop_default_instance(
4545-
"config/rack_id",
4546-
info.rack_id,
4547-
)?;
4548-
smfh.setprop_default_instance(
4549-
"config/sled_id",
4550-
info.config.sled_identifiers.sled_id,
4551-
)?;
4552-
smfh.setprop_default_instance(
4553-
"config/sled_model",
4554-
info.config
4555-
.sled_identifiers
4556-
.model
4557-
.to_string(),
4558-
)?;
4559-
smfh.setprop_default_instance(
4560-
"config/sled_revision",
4561-
info.config.sled_identifiers.revision,
4562-
)?;
4563-
smfh.setprop_default_instance(
4564-
"config/sled_serial",
4565-
info.config
4566-
.sled_identifiers
4567-
.serial
4568-
.to_string(),
4569-
)?;
4508+
setprop_sled_ident_properties(&smfh, info)?;
45704509
} else {
45714510
info!(
45724511
self.inner.log,
45734512
"no sled info available yet"
45744513
);
45754514
}
45764515
smfh.delpropvalue_default_instance(
4577-
"config/address",
4516+
"config/listen_address",
45784517
"*",
45794518
)?;
45804519
for address in &request.addresses {
45814520
smfh.addpropvalue_type_default_instance(
4582-
"config/address",
4521+
"config/listen_address",
45834522
&format!("[{}]:{}", address, TFPORTD_PORT),
45844523
"astring",
45854524
)?;

0 commit comments

Comments
 (0)