Skip to content

Commit de332c3

Browse files
authored
allow overriding platform and system (#26)
1 parent 15ece65 commit de332c3

11 files changed

Lines changed: 211 additions & 115 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coman/.config/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[cscs]
22
current_system = "daint"
3+
current_platform = "HPC"
34

45
image = "ubuntu"
56

coman/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ serde_json = "1.0.132"
4949
signal-hook = "0.3.17"
5050
strip-ansi-escapes = "0.2.0"
5151
strum = { version = "0.26.3", features = ["derive"] }
52+
strum_macros = "0.27.2"
5253
tokio = { version = "1.47.1", features = ["full"] }
5354
tokio-util = "0.7.16"
5455
toml = "0.9.7"

coman/src/cli.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::{error::Error, path::PathBuf};
22

3-
use clap::{Parser, Subcommand};
3+
use clap::{Parser, Subcommand, builder::TypedValueParser};
4+
use strum::VariantNames;
45

56
use crate::{
6-
config::{get_config_dir, get_data_dir},
7+
config::{ComputePlatform, get_config_dir, get_data_dir},
78
util::types::DockerImageUrl,
89
};
910

@@ -13,6 +14,10 @@ pub enum CliCommands {
1314
Cscs {
1415
#[command(subcommand)]
1516
command: CscsCommands,
17+
#[clap(short, long, help = "override compute system (e.g. 'eiger', 'daint')")]
18+
system: Option<String>,
19+
#[clap(short, long, ignore_case=true, value_parser=clap::builder::PossibleValuesParser::new(ComputePlatform::VARIANTS).map(|s|s.parse::<ComputePlatform>().unwrap()),help = "override compute platform (one of 'hpc', 'ml' or 'cw')")]
20+
platform: Option<ComputePlatform>,
1621
},
1722
#[clap(about = "Create a new project configuration file")]
1823
Init {

coman/src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use directories::ProjectDirs;
77
use eyre::eyre;
88
use lazy_static::lazy_static;
99
use serde::{Deserialize, Serialize};
10+
use strum_macros::{EnumString, VariantNames};
1011

1112
const DEFAULT_CONFIG_TOML: &str = include_str!("../.config/config.toml");
1213

@@ -23,11 +24,23 @@ pub struct AppConfig {
2324
pub config_dir: PathBuf,
2425
}
2526

27+
#[derive(Clone, Debug, Serialize, Deserialize, Default, strum::Display, EnumString, VariantNames)]
28+
#[strum(serialize_all = "lowercase")]
29+
#[allow(clippy::upper_case_acronyms)]
30+
pub enum ComputePlatform {
31+
#[default]
32+
HPC,
33+
ML,
34+
CW,
35+
}
36+
2637
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
2738
pub struct CscsConfig {
2839
#[serde(default)]
2940
pub current_system: String,
3041
#[serde(default)]
42+
pub current_platform: ComputePlatform,
43+
#[serde(default)]
3144
pub account: String,
3245
#[serde(default)]
3346
pub sbatch_script_template: String,

coman/src/cscs/api_client.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use firecrest_client::{
2424
use reqwest::Url;
2525
use strum::Display;
2626

27-
use crate::trace_dbg;
27+
use crate::{
28+
config::{ComputePlatform, Config},
29+
trace_dbg,
30+
};
2831

2932
#[derive(Debug, Eq, Clone, PartialEq, PartialOrd, Ord, tabled::Tabled)]
3033
pub struct UserInfo {
@@ -365,9 +368,13 @@ pub struct CscsApi {
365368
}
366369

367370
impl CscsApi {
368-
pub fn new(token: String) -> Result<Self> {
371+
pub fn new(token: String, platform: Option<ComputePlatform>) -> Result<Self> {
372+
let config = Config::new()?;
369373
let client = FirecrestClient::default()
370-
.base_path("https://api.cscs.ch/hpc/firecrest/v2/".to_owned())?
374+
.base_path(format!(
375+
"https://api.cscs.ch/{}/firecrest/v2/",
376+
platform.unwrap_or(config.cscs.current_platform)
377+
))?
371378
.token(token);
372379
Ok(Self { client })
373380
}

coman/src/cscs/cli.rs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tokio::{
1616
};
1717

1818
use crate::{
19+
config::ComputePlatform,
1920
cscs::{
2021
api_client::JobStatus,
2122
handlers::{
@@ -38,8 +39,8 @@ pub(crate) async fn cli_cscs_login() -> Result<()> {
3839
};
3940
Ok(())
4041
}
41-
pub(crate) async fn cli_cscs_job_list() -> Result<()> {
42-
match cscs_job_list().await {
42+
pub(crate) async fn cli_cscs_job_list(system: Option<String>, platform: Option<ComputePlatform>) -> Result<()> {
43+
match cscs_job_list(system, platform).await {
4344
Ok(jobs) => {
4445
let mut table = tabled::Table::new(jobs);
4546
table.with(tabled::settings::Style::modern());
@@ -49,8 +50,12 @@ pub(crate) async fn cli_cscs_job_list() -> Result<()> {
4950
Err(e) => Err(e),
5051
}
5152
}
52-
pub(crate) async fn cli_cscs_job_detail(job_id: i64) -> Result<()> {
53-
match cscs_job_details(job_id).await {
53+
pub(crate) async fn cli_cscs_job_detail(
54+
job_id: i64,
55+
system: Option<String>,
56+
platform: Option<ComputePlatform>,
57+
) -> Result<()> {
58+
match cscs_job_details(job_id, system, platform).await {
5459
Ok(Some(job)) => {
5560
let data = &[
5661
("Id", job.id.to_string()),
@@ -80,8 +85,12 @@ pub(crate) async fn cli_cscs_job_detail(job_id: i64) -> Result<()> {
8085
}
8186
}
8287

83-
pub(crate) async fn cli_cscs_job_log(job_id: i64) -> Result<()> {
84-
match cscs_job_log(job_id).await {
88+
pub(crate) async fn cli_cscs_job_log(
89+
job_id: i64,
90+
system: Option<String>,
91+
platform: Option<ComputePlatform>,
92+
) -> Result<()> {
93+
match cscs_job_log(job_id, system, platform).await {
8594
Ok(content) => {
8695
println!("{}", content);
8796
Ok(())
@@ -96,16 +105,22 @@ pub(crate) async fn cli_cscs_job_start(
96105
command: Option<Vec<String>>,
97106
workdir: Option<String>,
98107
env: Vec<(String, String)>,
108+
system: Option<String>,
109+
platform: Option<ComputePlatform>,
99110
) -> Result<()> {
100-
cscs_start_job(script_file, image, command, workdir, env).await
111+
cscs_start_job(script_file, image, command, workdir, env, system, platform).await
101112
}
102113

103-
pub(crate) async fn cli_cscs_job_cancel(job_id: i64) -> Result<()> {
104-
cscs_job_cancel(job_id).await
114+
pub(crate) async fn cli_cscs_job_cancel(
115+
job_id: i64,
116+
system: Option<String>,
117+
platform: Option<ComputePlatform>,
118+
) -> Result<()> {
119+
cscs_job_cancel(job_id, system, platform).await
105120
}
106121

107-
pub(crate) async fn cli_cscs_system_list() -> Result<()> {
108-
match cscs_system_list().await {
122+
pub(crate) async fn cli_cscs_system_list(platform: Option<ComputePlatform>) -> Result<()> {
123+
match cscs_system_list(platform).await {
109124
Ok(systems) => {
110125
let mut table = tabled::Table::new(systems);
111126
table.with(tabled::settings::Style::modern());
@@ -119,8 +134,12 @@ pub(crate) async fn cli_cscs_set_system(system_name: String, global: bool) -> Re
119134
cscs_system_set(system_name, global).await
120135
}
121136

122-
pub(crate) async fn cli_cscs_file_list(path: PathBuf) -> Result<()> {
123-
match cscs_file_list(path).await {
137+
pub(crate) async fn cli_cscs_file_list(
138+
path: PathBuf,
139+
system: Option<String>,
140+
platform: Option<ComputePlatform>,
141+
) -> Result<()> {
142+
match cscs_file_list(path, system, platform).await {
124143
Ok(path_entries) => {
125144
let mut table = tabled::Table::new(path_entries);
126145
table.with(tabled::settings::Style::empty());
@@ -131,8 +150,14 @@ pub(crate) async fn cli_cscs_file_list(path: PathBuf) -> Result<()> {
131150
}
132151
}
133152

134-
pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, account: Option<String>) -> Result<()> {
135-
match cscs_file_download(remote, local.clone(), account).await {
153+
pub(crate) async fn cli_cscs_file_download(
154+
remote: PathBuf,
155+
local: PathBuf,
156+
account: Option<String>,
157+
system: Option<String>,
158+
platform: Option<ComputePlatform>,
159+
) -> Result<()> {
160+
match cscs_file_download(remote, local.clone(), account, system.clone(), platform.clone()).await {
136161
Ok(None) => {
137162
println!("File successfully downloaded");
138163
Ok(())
@@ -143,7 +168,7 @@ pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, acco
143168
println!("started s3 transfer job {}", job_data.0);
144169
let mut transfer_done = false;
145170
while !transfer_done {
146-
if let Some(job) = cscs_job_details(job_data.0).await? {
171+
if let Some(job) = cscs_job_details(job_data.0, system.clone(), platform.clone()).await? {
147172
match job.status {
148173
JobStatus::Pending | JobStatus::Running => {}
149174
JobStatus::Finished => transfer_done = true,
@@ -182,8 +207,14 @@ pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, acco
182207
}
183208
}
184209

185-
pub(crate) async fn cli_cscs_file_upload(local: PathBuf, remote: PathBuf, account: Option<String>) -> Result<()> {
186-
match cscs_file_upload(local.clone(), remote, account).await {
210+
pub(crate) async fn cli_cscs_file_upload(
211+
local: PathBuf,
212+
remote: PathBuf,
213+
account: Option<String>,
214+
system: Option<String>,
215+
platform: Option<ComputePlatform>,
216+
) -> Result<()> {
217+
match cscs_file_upload(local.clone(), remote, account, system, platform).await {
187218
Ok(None) => {
188219
println!("File successfully uploaded");
189220
Ok(())

0 commit comments

Comments
 (0)