88
99use apiclient:: { apply, ephemeral_storage, exec, get, reboot, report, set, update, SettingsInput } ;
1010use log:: { info, log_enabled, trace, warn} ;
11- use model:: ephemeral_storage:: Filesystem ;
11+ use model:: ephemeral_storage:: { Filesystem , Preference } ;
1212use serde:: { Deserialize , Serialize } ;
1313use simplelog:: {
1414 ColorChoice , ConfigBuilder as LogConfigBuilder , LevelFilter , TermLogger , TerminalMode ,
@@ -157,6 +157,8 @@ enum EphemeralStorageSubcommand {
157157#[ derive( Debug ) ]
158158struct 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.
761769fn 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