Skip to content

Commit 54e6c8f

Browse files
author
Jesse Anttila
committed
apiclient: add --ebs-volumes and --prefer options to ephemeral-storage init command
1 parent 75cbb74 commit 54e6c8f

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

sources/api/apiclient/src/ephemeral_storage.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use model::ephemeral_storage::{Bind, Filesystem, Init};
1+
use model::ephemeral_storage::{Bind, Filesystem, Init, Preference};
22
use snafu::ResultExt;
33
use std::path::Path;
44

@@ -7,13 +7,20 @@ pub async fn initialize<P>(
77
socket_path: P,
88
filesystem: Option<Filesystem>,
99
disks: Option<Vec<String>>,
10+
ebs_volumes: Option<Vec<String>>,
11+
prefer: Option<Vec<Preference>>,
1012
) -> Result<()>
1113
where
1214
P: AsRef<Path>,
1315
{
1416
let uri = "/actions/ephemeral-storage/init";
15-
let opts =
16-
serde_json::to_string(&Init { filesystem, disks }).context(error::JsonSerializeSnafu {})?;
17+
let opts = serde_json::to_string(&Init {
18+
filesystem,
19+
disks,
20+
ebs_volumes,
21+
prefer,
22+
})
23+
.context(error::JsonSerializeSnafu {})?;
1724
let method = "POST";
1825
let (_status, _body) = crate::raw_request(&socket_path, &uri, method, Some(opts))
1926
.await

sources/api/apiclient/src/main.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use apiclient::{apply, ephemeral_storage, exec, get, reboot, report, set, update, SettingsInput};
1010
use log::{info, log_enabled, trace, warn};
11-
use model::ephemeral_storage::Filesystem;
11+
use model::ephemeral_storage::{Filesystem, Preference};
1212
use serde::{Deserialize, Serialize};
1313
use simplelog::{
1414
ColorChoice, ConfigBuilder as LogConfigBuilder, LevelFilter, TermLogger, TerminalMode,
@@ -157,6 +157,8 @@ enum EphemeralStorageSubcommand {
157157
#[derive(Debug)]
158158
struct EphemeralStorageInitArgs {
159159
disks: Option<Vec<String>>,
160+
ebs_volumes: Option<Vec<String>>,
161+
prefer: Option<Vec<Preference>>,
160162
filesystem: Option<Filesystem>,
161163
}
162164

@@ -269,7 +271,13 @@ fn usage() -> ! {
269271
operation does nothing.
270272
--disks DISK [DISK ...] Local disks to configure for storage. Default is all ephemeral
271273
disks.
272-
274+
--ebs-volumes VOLUME [VOLUME ..]
275+
EBS volumes in the `xvdda`-`xvddx` range to configure for storage.
276+
--prefer PREFERENCE [PREFERENCE ..]
277+
Epheremeral storage type preference, in descending order. Allowed
278+
values: `ephemeral-disk`, `ebs-volume` or a combination of these
279+
joined by `+`. Defaults to `ephemeral-disk` only. This option is
280+
ignored if `--disks` or `--ebs-volumes` is set.
273281
ephemeral-storage bind options:
274282
--dirs DIR [DIR ...] Directories to bind to configured ephemeral storage
275283
(e.g. /var/lib/containerd). If no ephemeral disks are found
@@ -760,6 +768,8 @@ fn parse_ephemeral_storage_args(args: Vec<String>) -> Subcommand {
760768
/// Parses arguments for the 'init' ephemeral-storage subcommand.
761769
fn parse_ephemeral_storage_init_args(args: Vec<String>) -> EphemeralStorageSubcommand {
762770
let mut disks: Option<Vec<String>> = None;
771+
let mut ebs_volumes: Option<Vec<String>> = None;
772+
let mut prefer: Option<Vec<Preference>> = None;
763773
let mut filesystem = None;
764774
let mut iter = args.into_iter().peekable();
765775
while let Some(arg) = iter.next() {
@@ -786,10 +796,45 @@ fn parse_ephemeral_storage_init_args(args: Vec<String>) -> EphemeralStorageSubco
786796
disks = Some(names);
787797
}
788798
}
799+
"--ebs-volumes" => {
800+
let mut names = collect_non_args(&mut iter);
801+
if names.is_empty() {
802+
usage_msg("Did not give argument to --ebs-volumes")
803+
}
804+
if let Some(existing) = &mut ebs_volumes {
805+
existing.append(&mut names);
806+
} else {
807+
ebs_volumes = Some(names);
808+
}
809+
}
810+
"--prefer" => {
811+
let prefs = collect_non_args(&mut iter);
812+
if prefs.is_empty() {
813+
usage_msg("Did not give argument to --prefer")
814+
}
815+
if let Some(existing) = &mut prefer {
816+
for p in &prefs {
817+
if let Ok(p) = p.as_str().try_into() {
818+
existing.push(p);
819+
} else {
820+
usage_msg("Invalid ephemeral storage type preference");
821+
}
822+
}
823+
} else if let Ok(p) = prefs.iter().map(|x| x.as_str().try_into()).collect() {
824+
prefer = Some(p);
825+
} else {
826+
usage_msg("Invalid ephemeral storage type preference");
827+
}
828+
}
789829
x => usage_msg(format!("Unknown argument '{x}'")),
790830
}
791831
}
792-
EphemeralStorageSubcommand::Init(EphemeralStorageInitArgs { disks, filesystem })
832+
EphemeralStorageSubcommand::Init(EphemeralStorageInitArgs {
833+
disks,
834+
ebs_volumes,
835+
filesystem,
836+
prefer,
837+
})
793838
}
794839

795840
/// Parses arguments for the 'bind' ephemeral-storage subcommand.
@@ -1059,6 +1104,8 @@ async fn run() -> Result<()> {
10591104
&args.socket_path,
10601105
cfg_args.filesystem,
10611106
cfg_args.disks,
1107+
cfg_args.ebs_volumes,
1108+
cfg_args.prefer,
10621109
)
10631110
.await
10641111
.context(error::EphemeralStorageSnafu)?;

0 commit comments

Comments
 (0)