-
Notifications
You must be signed in to change notification settings - Fork 296
/
args.rs
108 lines (92 loc) · 3.49 KB
/
args.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::metrics::PROMETHEUS_HTTP_PORT;
use clap::Parser;
use ic_config::{Config, ConfigSource};
use std::net::Ipv4Addr;
use std::path::PathBuf;
use std::{
fs,
net::{SocketAddr, SocketAddrV4},
};
#[derive(Debug, Parser)]
#[clap(
name = "orchestrator",
about = "Arguments for the Internet Computer Orchestrator.",
version
)]
/// Arguments for the orchestrator binary.
pub struct OrchestratorArgs {
/// The directory where Orchestrator will store Replica binaries
#[clap(long, parse(from_os_str))]
pub(crate) replica_binary_dir: PathBuf,
/// The directory where Orchestrator will store catch-up packages (CUPs)
#[clap(long, parse(from_os_str))]
pub(crate) cup_dir: PathBuf,
/// The path to the Replica config file
#[clap(long, parse(from_os_str))]
pub(crate) replica_config_file: PathBuf,
/// The path to the Replica binary location containing the following in case
/// of guest OS deployment: version.txt, manageboot.sh, replica,
/// install-upgrade.sh
#[clap(long, parse(from_os_str))]
pub(crate) ic_binary_directory: Option<PathBuf>,
/// If not set, the default listen addr (0.0.0.0:[`PROMETHEUS_HTTP_PORT`])
/// will be used to export metrics.
#[clap(long)]
pub(crate) metrics_listen_addr: Option<SocketAddr>,
/// Provisional CLI-option intended to be used in bootstrap testing. Enables
/// the registration procedure.
#[clap(long)]
pub(crate) enable_provisional_registration: bool,
/// The path to the version file.
#[clap(long, parse(from_os_str))]
pub(crate) version_file: PathBuf,
/// Print the replica's current node ID.
#[clap(long)]
pub node_id: bool,
/// Print the DC ID where the current replica is located.
#[clap(long)]
pub dc_id: bool,
/// The path to directory that is dedicated to data specific to the orchstrator.
/// If not provided, the relevant data are not persisted to the disk.
#[clap(long, parse(from_os_str))]
pub(crate) orchestrator_data_directory: PathBuf,
}
impl OrchestratorArgs {
/// Create replica binary and CUP directories associated with this object if
/// they don't already exist
pub(crate) fn create_dirs(&self) {
if !&self.replica_binary_dir.exists() {
fs::create_dir(&self.replica_binary_dir).unwrap_or_else(|err| {
panic!(
"Failed to create dir {}: {}",
self.replica_binary_dir.display(),
err,
)
});
}
if !self.cup_dir.exists() {
fs::create_dir(&self.cup_dir).unwrap_or_else(|err| {
panic!("Failed to create dir {}: {}", self.cup_dir.display(), err)
});
}
}
/// Parse `self.replica_config_file` and persist in
/// [`TempDir`][tempfile::TempDir] "ic_config"
pub(crate) fn get_ic_config(&self) -> Config {
let tmpdir = tempfile::Builder::new()
.prefix("ic_config")
.tempdir()
.unwrap()
.path()
.to_path_buf();
let config_source = ConfigSource::File(self.replica_config_file.clone());
Config::load_with_tmpdir(config_source, tmpdir)
}
/// Return the configured metrics address or
/// "0.0.0.0:[`PROMETHEUS_HTTP_PORT`]" if none is set
pub(crate) fn get_metrics_addr(&self) -> SocketAddr {
self.metrics_listen_addr.unwrap_or_else(|| {
SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), PROMETHEUS_HTTP_PORT).into()
})
}
}