Skip to content

Commit 26413d8

Browse files
committed
minor cleanup
1 parent cac26dd commit 26413d8

File tree

1 file changed

+66
-71
lines changed

1 file changed

+66
-71
lines changed

zone-setup/src/bin/zone-setup.rs

Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -257,36 +257,43 @@ maxslewrate 2708.333
257257
258258
";
259259

260+
let ChronySetupArgs {
261+
file: config_path,
262+
boundary: is_boundary,
263+
servers,
264+
allow,
265+
} = args;
266+
260267
let mut new_config =
261-
if args.boundary { boundary_ntp_tpl } else { internal_ntp_tpl }
268+
if is_boundary { boundary_ntp_tpl } else { internal_ntp_tpl }
262269
.to_string();
263270

264-
if let Some(allow) = args.allow {
271+
if let Some(allow) = allow {
265272
new_config = new_config.replace("@ALLOW@", &allow);
266273
}
267274

268-
if args.boundary {
269-
for s in args.servers {
275+
if is_boundary {
276+
for s in servers {
270277
writeln!(
271278
&mut new_config,
272279
"pool {s} iburst maxdelay 0.1 maxsources 16"
273280
)
274281
.expect("write to String is infallible");
275282
}
276283
} else {
277-
for s in args.servers {
284+
for s in servers {
278285
writeln!(&mut new_config, "server {s} iburst minpoll 0 maxpoll 4")
279286
.expect("write to String is infallible");
280287
}
281288
}
282289

283290
// We read the contents from the old configuration file if it existed
284291
// so that we can verify if it changed.
285-
let old_file = if args.file.exists() {
286-
Some(read_to_string(&args.file).with_context(|| {
292+
let old_file = if config_path.exists() {
293+
Some(read_to_string(&config_path).with_context(|| {
287294
format!(
288295
"failed reading old chrony config file {}",
289-
args.file.display(),
296+
config_path.display(),
290297
)
291298
})?)
292299
} else {
@@ -297,26 +304,28 @@ maxslewrate 2708.333
297304
.write(true)
298305
.create(true)
299306
.truncate(true)
300-
.open(&args.file)
307+
.open(&config_path)
301308
.with_context(|| {
302309
format!(
303-
"failed to create chrony config file {}",
304-
args.file.display(),
310+
"failed to create chrony config config_path {}",
311+
config_path.display(),
305312
)
306313
})?;
307314
config_file.write(new_config.as_bytes()).with_context(|| {
308315
format!(
309316
"failed writing chrony configuration file {}",
310-
args.file.display(),
317+
config_path.display(),
311318
)
312319
})?;
313320

314-
if old_file.clone().is_some_and(|f| f != new_config) {
315-
info!(
316-
&log, "Chrony configuration file has changed";
317-
"old configuration file" => ?old_file,
318-
"new configuration file" => ?new_config,
319-
);
321+
if let Some(old_config) = old_file {
322+
if old_config != new_config {
323+
info!(
324+
log, "Chrony configuration file has changed";
325+
"old configuration file" => ?old_config,
326+
"new configuration file" => ?new_config,
327+
);
328+
}
320329
}
321330

322331
Ok(())
@@ -328,57 +337,48 @@ async fn common_nw_set_up(
328337
) -> anyhow::Result<()> {
329338
let zonename =
330339
zone::current().await.context("could not determine local zone name")?;
340+
let CommonNetworkingArgs { datalink, gateway, static_addr } = args;
331341

332342
// TODO: remove when https://github.com/oxidecomputer/stlouis/issues/435 is
333343
// addressed
334344
info!(
335345
log, "Ensuring a temporary IP interface is created";
336-
"data link" => ?args.datalink,
346+
"data link" => ?datalink,
337347
);
338-
Ipadm::set_temp_interface_for_datalink(&args.datalink).with_context(
339-
|| {
340-
format!(
341-
"failed to ensure temporary IP interface on datalink {}",
342-
args.datalink
343-
)
344-
},
345-
)?;
348+
Ipadm::set_temp_interface_for_datalink(&datalink).with_context(|| {
349+
format!(
350+
"failed to ensure temporary IP interface on datalink {datalink}",
351+
)
352+
})?;
346353

347354
info!(
348355
log, "Setting MTU to 9000 for IPv6 and IPv4";
349-
"data link" => ?args.datalink,
356+
"data link" => ?datalink,
350357
);
351-
Ipadm::set_interface_mtu(&args.datalink).with_context(|| {
352-
format!("failed to set MTU on datalink {}", args.datalink)
353-
})?;
358+
Ipadm::set_interface_mtu(&datalink)
359+
.with_context(|| format!("failed to set MTU on datalink {datalink}"))?;
354360

355361
info!(
356362
log,
357363
"Ensuring static and auto-configured addresses are set on the IP \
358364
interface";
359-
"data link" => ?args.datalink,
360-
"static address" => ?args.static_addr);
361-
Ipadm::create_static_and_autoconfigured_addrs(
362-
&args.datalink,
363-
&args.static_addr,
364-
)
365-
.with_context(|| {
366-
format!(
367-
"failed to ensure static address {} on datalink {}",
368-
args.static_addr, args.datalink
369-
)
370-
})?;
365+
"data link" => ?datalink,
366+
"static address" => ?static_addr);
367+
Ipadm::create_static_and_autoconfigured_addrs(&datalink, &static_addr)
368+
.with_context(|| {
369+
format!(
370+
"failed to ensure static address {static_addr} \
371+
on datalink {datalink}",
372+
)
373+
})?;
371374

372375
info!(
373376
log, "Ensuring there is a default route";
374-
"gateway" => ?args.gateway,
377+
"gateway" => ?gateway,
375378
);
376-
Route::ensure_default_route_with_gateway(Gateway::Ipv6(args.gateway))
379+
Route::ensure_default_route_with_gateway(Gateway::Ipv6(gateway))
377380
.with_context(|| {
378-
format!(
379-
"failed to ensure default route via gateway {}",
380-
args.gateway
381-
)
381+
format!("failed to ensure default route via gateway {gateway}")
382382
})?;
383383

384384
info!(
@@ -391,9 +391,8 @@ async fn common_nw_set_up(
391391
r#"
392392
::1 localhost loghost
393393
127.0.0.1 localhost loghost
394-
{} {zonename}.local {zonename}
394+
{static_addr} {zonename}.local {zonename}
395395
"#,
396-
args.static_addr
397396
),
398397
)
399398
.with_context(|| format!("failed to write hosts file {HOSTS_FILE}"))?;
@@ -405,40 +404,36 @@ async fn opte_interface_set_up(
405404
args: OpteInterfaceArgs,
406405
log: &Logger,
407406
) -> anyhow::Result<()> {
407+
let OpteInterfaceArgs { interface, gateway, ip } = args;
408408
info!(
409409
log,
410410
"Creating gateway on the OPTE IP interface if it doesn't already exist";
411-
"OPTE interface" => ?args.interface
411+
"OPTE interface" => ?interface
412412
);
413-
Ipadm::create_opte_gateway(&args.interface).with_context(|| {
414-
format!("failed to create OPTE gateway on interface {}", args.interface)
413+
Ipadm::create_opte_gateway(&interface).with_context(|| {
414+
format!("failed to create OPTE gateway on interface {interface}")
415415
})?;
416416

417417
info!(
418418
log, "Ensuring there is a gateway route";
419-
"OPTE gateway" => ?args.gateway,
420-
"OPTE interface" => ?args.interface,
421-
"OPTE IP" => ?args.ip,
419+
"OPTE gateway" => ?gateway,
420+
"OPTE interface" => ?interface,
421+
"OPTE IP" => ?ip,
422422
);
423-
Route::ensure_opte_route(&args.gateway, &args.interface, &args.ip)
424-
.with_context(|| {
425-
format!(
426-
"failed to ensure OPTE gateway route on interface {} \
427-
with gateway {} and IP {}",
428-
args.interface, args.gateway, args.ip
429-
)
430-
})?;
423+
Route::ensure_opte_route(&gateway, &interface, &ip).with_context(|| {
424+
format!(
425+
"failed to ensure OPTE gateway route on interface {interface} \
426+
with gateway {gateway} and IP {ip}",
427+
)
428+
})?;
431429

432430
info!(
433431
log, "Ensuring there is a default route";
434-
"gateway" => ?args.gateway,
432+
"gateway" => ?gateway,
435433
);
436-
Route::ensure_default_route_with_gateway(Gateway::Ipv4(args.gateway))
434+
Route::ensure_default_route_with_gateway(Gateway::Ipv4(gateway))
437435
.with_context(|| {
438-
format!(
439-
"failed to ensure default route via gateway {}",
440-
args.gateway
441-
)
436+
format!("failed to ensure default route via gateway {gateway}")
442437
})?;
443438

444439
Ok(())

0 commit comments

Comments
 (0)