Skip to content

Instantly share code, notes, and snippets.

@tilpner
Forked from anonymous/playground.rs
Last active August 29, 2015 14:22
Show Gist options
  • Save tilpner/0a49c94609b0480c5407 to your computer and use it in GitHub Desktop.
Save tilpner/0a49c94609b0480c5407 to your computer and use it in GitHub Desktop.
pub fn volume_create(volume: &str,
count: usize,
transport: Transport,
bricks: Vec<Brick>,
force: bool,
key: &str) ->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 count_str = 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(key.to_string());
arg_list.push(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_replicated(volume: &str,
replica_count: usize,
transport: Transport,
bricks: Vec<Brick>,
force: bool) ->Result<i32, String>{
volume_create(volume, replica_count, transport, bricks, force, "replica")
}
pub fn volume_create_striped(volume: &str,
stripe: usize,
transport: Transport,
bricks: Vec<Brick>,
force: bool)->Result<i32, String>{
volume_create(volume, stripe, transport, bricks, force, "stripe")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment