Created
June 3, 2015 18:19
-
-
Save anonymous/bb119c39b3f640044b81 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn volume_create_replicated(volume: &str, | |
replica_count: usize, | |
transport: Transport, | |
bricks: Vec<Brick>, | |
force: bool) ->Result<i32, String>{ | |
if bricks.is_empty(){ | |
return Err("The brick list is empty. Not creating volume".to_string()); | |
} | |
if (bricks.len() % replica_count) != 0 { | |
return Err("The brick list and replica count do not match. Not creating volume".to_string()); | |
} | |
let replica_count_str = replica_count.to_string(); | |
let mut arg_list: Vec<String> = Vec::new(); | |
arg_list.push("volume".to_string()); | |
arg_list.push("create".to_string()); | |
arg_list.push(volume.to_string()); | |
arg_list.push("replica".to_string()); | |
arg_list.push(replica_count_str); | |
arg_list.push("transport".to_string()); | |
arg_list.push(transport.to_string()); | |
for brick in bricks.iter(){ | |
arg_list.push(brick.to_string()); | |
} | |
if force{ | |
arg_list.push("force".to_string()); | |
} | |
let output = run_command("gluster", &arg_list, true, true); | |
let status = output.status; | |
match (status.code()){ | |
Some(v) => Ok(v), | |
None => Err(String::from_utf8(output.stderr).unwrap()), | |
} | |
} | |
pub fn volume_create_striped(volume: &str, | |
stripe: usize, | |
transport: Transport, | |
bricks: Vec<Brick>, | |
force: bool)->Result<i32, String>{ | |
if bricks.is_empty(){ | |
return Err("The brick list is empty. Not creating volume".to_string()); | |
} | |
if (bricks.len() % stripe) != 0 { | |
return Err("The brick list and stripe count do not match. Not creating volume".to_string()); | |
} | |
let mut arg_list: Vec<String> = Vec::new(); | |
arg_list.push("volume".to_string()); | |
arg_list.push("create".to_string()); | |
arg_list.push(volume.to_string()); | |
arg_list.push("stripe".to_string()); | |
arg_list.push(stripe.to_string()); | |
arg_list.push("transport".to_string()); | |
arg_list.push(transport.to_string()); | |
for brick in bricks.iter(){ | |
arg_list.push(brick.to_string()); | |
} | |
if force{ | |
arg_list.push("force".to_string()); | |
} | |
let output = run_command("gluster", &arg_list, true, true); | |
let status = output.status; | |
match (status.code()){ | |
Some(v) => Ok(v), | |
None => Err(String::from_utf8(output.stderr).unwrap()), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment