Created
January 6, 2017 19:41
-
-
Save cholcombe973/ba191516af6f346a425ca46c42bfaaf3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 enable_volume_quota() -> Result<(), String> { | |
// Gather our action parameters | |
let volume = match juju::action_get("volume") { | |
Ok(v) => v, | |
Err(e) => { | |
// Notify the user of the failure and then return the error up the stack | |
juju::action_fail(&e.to_string()).map_err(|e| e.to_string())?; | |
return Err(e.to_string()); | |
} | |
}; | |
let usage_limit = match juju::action_get("usage-limit") { | |
Ok(usage) => usage, | |
Err(e) => { | |
// Notify the user of the failure and then return the error up the stack | |
juju::action_fail(&e.to_string()).map_err(|e| e.to_string())?; | |
return Err(e.to_string()); | |
} | |
}; | |
let parsed_usage_limit = u64::from_str(&usage_limit).map_err(|e| e.to_string())?; | |
let path = match juju::action_get("path") { | |
Ok(p) => p, | |
Err(e) => { | |
// Notify the user of the failure and then return the error up the stack | |
juju::action_fail(&e.to_string()).map_err(|e| e.to_string())?; | |
return Err(e.to_string()); | |
} | |
}; | |
// Turn quotas on if not already enabled | |
let quotas_enabled = gluster::volume_quotas_enabled(&volume).map_err(|e| e.to_string())?; | |
if !quotas_enabled { | |
gluster::volume_enable_quotas(&volume).map_err(|e| e.to_string())?; | |
} | |
gluster::volume_add_quota(&volume, PathBuf::from(path), parsed_usage_limit) | |
.map_err(|e| e.to_string())?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment