diff --git a/dysche-cli/src/main.rs b/dysche-cli/src/main.rs index 0910af82059868b2379f6e3a8241e7ae22c30ebc..f5c032aa9ff323ce34a5dc2fc95e132497a45eea 100644 --- a/dysche-cli/src/main.rs +++ b/dysche-cli/src/main.rs @@ -13,11 +13,14 @@ fn main() { let mut ret = 0; if let Some(_sc) = matches.subcommand_matches("list") { + let mut verb = false; if _sc.is_present("verbose") { println!("List partition details: "); + verb = true; } else { println!("List partitions:"); } + list_partitions(verb); } else if let Some(sc) = matches.subcommand_matches("create") { println!("create app partition:"); @@ -42,6 +45,28 @@ fn main() { } else if let Some(sc) = matches.subcommand_matches("destroy") { let pid = sc.value_of("pid").unwrap_or("-1"); ret = destroy_partition(pid); + } else if let Some(sc) = matches.subcommand_matches("migrate") { + println!("migrate resources between partitions:"); + + let cpus = sc.value_of("cpu").unwrap_or(""); + let sp = sc.value_of("source_partition").unwrap_or(""); + let dp = sc.value_of("dest_partition").unwrap_or(""); + + if cpus == "" { + ret = 1; + println!("Core (lists) is needed."); + } + + if sp == "" || dp == "" { + ret = 1; + println!("source & dest partitions need be specified."); + } + + if ret <= 0 { + println!(" migrate cpu {} from partition {} to partition {}", cpus, + sp, dp); + ret = migrate_partition(sp, dp, cpus); + } } if ret > 0 { @@ -50,6 +75,26 @@ fn main() { } +fn list_partitions(_verbose: bool) -> i32 { + let mut ret = 0; + println!("Read partition information form : {}", DYSCHE_STS); + + if let Ok(lines) = read_lines(DYSCHE_STS) { + for line in lines { + if let Ok(l) = line { + println!("{}", l); + } + } + } else { + println!("{} is not present.", DYSCHE_STS); + println!(" check if the kernel module is enabled or not."); + println!(); + ret = 1; + } + + return ret; +} + fn create_partition(cpus: &str, kernel_img: &str, kernel_param: &str, dev_list: &str) -> i32 { let mut ret = 0; println!("Info: cpu: {}, kernel: {}, kernel_param: {}, dev_list: {}", @@ -91,6 +136,12 @@ fn destroy_partition(pid: &str) -> i32 { return _ret; } +fn migrate_partition(_sp: &str, _dp: &str, _cpus: &str) -> i32 { + println!("place holder. need impl later."); + + return 0; +} + fn write_line(filename: &str, line: &str) -> i32 { let mut ret = 0; diff --git a/dysche-cli/src/param.yml b/dysche-cli/src/param.yml index 3fa74b8302b9787846b85c9f8e28de0805016059..650cb94b12e5cbed5d6fc2559122a81d000e4294 100644 --- a/dysche-cli/src/param.yml +++ b/dysche-cli/src/param.yml @@ -37,6 +37,25 @@ subcommands: help: "specify partition id that will be destoried." takes_value: true short: p + + - migrate: + about: "migrate an app partition" + short: m + multiple: true + args: + - cpu: + help: "specify core(list) that will be migrated" + takes_value: true + short: c + - source_partition: + help: "specify the source partition that resource migrated out" + takes_value: true + short: s + - dest_partition: + help: "specify the dest partition that resource migrated in" + takes_value: true + short: d + - list: about: "show available partitions" args: