Commit e967b292 authored by Alexis Janon's avatar Alexis Janon
Browse files

Changed "Container" to "Slice"

Reflects the name change
parent 3367ac25
......@@ -2,8 +2,8 @@
## Move command
Moves all processes of a container to another container.
Alternatively, moves one process and all its children to another container.
Moves all processes of a slice to another slice.
Alternatively, moves one process and all its children to another slice.
### Implementation notes
......@@ -43,9 +43,9 @@ but could be useful to have custom "default" values.
Prints data to a stream (or file descriptor) as a JSON object.
Each "Get" is a separate object.
## Randomized container names
## Randomized slice names
Picks a random ASCII name for a container. Would be useful for the spawn
Picks a random ASCII name for a slice. Would be useful for the spawn
command. May be associated with an additional option parameter: a name must
be provided by default, but with the correct option, it can be generated.
Or it could be generated automatically if no name is given by the user.
......
......@@ -38,13 +38,13 @@ impl SysFsControllerList {
SysFsControllerList(HashMap::new())
}
pub fn find_path(&self, container: &str, key: &str) -> Result<path::PathBuf> {
pub fn find_path(&self, slice: &str, key: &str) -> Result<path::PathBuf> {
// TODO: check that the path is still in an authorized sysfs
let mut path_list = self
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|path| path.join(&container).join(&key))
.map(|path| path.join(&slice).join(&key))
.filter(|p| p.exists())
.collect::<Vec<_>>();
// TODO: assign priority? cgroup2 > cgroup?
......
......@@ -32,21 +32,21 @@ pub struct Arguments {
// TODO: remove all these clone()!
impl InCommand {
fn to_create_container(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
fn to_create_slice(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
match self.properties {
Some(ref properties) => Ok(Box::new(CommandList::new(vec![
Box::new(CreateContainer::new(
Box::new(CreateSlice::new(
self.name.clone(),
self.args.clone(),
Rc::clone(&controllers),
)),
Box::new(ModifyContainer::new(
Box::new(ModifySlice::new(
self.name.clone(),
Rc::clone(&controllers),
&properties,
)),
]))),
None => Ok(Box::new(CreateContainer::new(
None => Ok(Box::new(CreateSlice::new(
self.name.clone(),
self.args.clone(),
Rc::clone(&controllers),
......@@ -54,9 +54,9 @@ impl InCommand {
}
}
fn to_modify_container(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
fn to_modify_slice(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
match self.properties {
Some(ref properties) => Ok(Box::new(ModifyContainer::new(
Some(ref properties) => Ok(Box::new(ModifySlice::new(
self.name.clone(),
Rc::clone(&controllers),
properties,
......@@ -65,8 +65,8 @@ impl InCommand {
}
}
fn to_remove_container(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
Ok(Box::new(RemoveContainer::new(
fn to_remove_slice(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
Ok(Box::new(RemoveSlice::new(
self.name.clone(),
Rc::clone(&controllers),
)))
......@@ -121,9 +121,9 @@ impl InCommand {
pub fn to_command(&self, controllers: Rc<SysFsControllerList>) -> Result<Box<Command>> {
match self.command.to_lowercase().as_str() {
"create" => self.to_create_container(controllers),
"remove" => self.to_remove_container(controllers),
"modify" => self.to_modify_container(controllers),
"create" => self.to_create_slice(controllers),
"remove" => self.to_remove_slice(controllers),
"modify" => self.to_modify_slice(controllers),
"exec" => self.to_exec(controllers),
"fork_exec" => self.to_fork_exec(controllers),
"spawn" => self.to_spawn(controllers),
......
......@@ -26,7 +26,7 @@ impl SliceInfoAnswer {
.map(|key| {
let path = controllers.find_path(&request.name, &key).map_err(|err| {
Error::from(format!(
"Could not retrieve path to key {} for container {}: {}",
"Could not retrieve path to key {} for slice {}: {}",
request.name,
key,
err.to_string()
......
......@@ -35,11 +35,11 @@ impl FindGetSetValue {
impl Command for FindGetSetValue {
fn exec(&mut self) -> Result<CommandResult> {
debug!(
"Reading and writing to key {} for container {}",
"Reading and writing to key {} for slice {}",
self.key, self.name
);
trace!(
"Retrieving path to key {} for container {}",
"Retrieving path to key {} for slice {}",
self.key,
self.name
);
......@@ -48,7 +48,7 @@ impl Command for FindGetSetValue {
.find_path(&self.name, &self.key)
.map_err(|err| {
Error::from(format!(
"Could not retrieve path to key {} for container {}: {}",
"Could not retrieve path to key {} for slice {}: {}",
self.name,
self.key,
err.to_string()
......@@ -83,22 +83,22 @@ impl Command for FindGetSetValue {
fn rollback(&mut self) -> Result<CommandResult> {
debug!(
"{{rollback}} Reading and writing to key {} for container {}",
"{{rollback}} Reading and writing to key {} for slice {}",
self.key, self.name
);
let path = match self.path {
Some(ref value) => value,
None => {
warn!("{{rollback}} Missing path to key {} for container {}. (probably an internal bug, you should report it)", self.key, self.name);
warn!("{{rollback}} Missing path to key {} for slice {}. (probably an internal bug, you should report it)", self.key, self.name);
trace!(
"{{rollback}} Retrieving path to key {} for container {}",
"{{rollback}} Retrieving path to key {} for slice {}",
self.key,
self.name
);
self.path = Some(self.controllers.find_path(&self.name, &self.key).map_err(
|err| {
Error::from(format!(
"{{rollback}} Could not retrieve path to key {} for container {}: {}",
"{{rollback}} Could not retrieve path to key {} for slice {}: {}",
self.name,
self.key,
err.to_string()
......
......@@ -3,12 +3,12 @@ use configuration::sysfscontroller::*;
use std::path;
use std::rc::Rc;
pub struct CreateContainer {
pub struct CreateSlice {
name: String,
list: CommandList,
}
impl CreateContainer {
impl CreateSlice {
pub fn new(
name: String,
args: Option<Vec<String>>,
......@@ -43,21 +43,21 @@ impl CreateContainer {
.map(Box::new)
.map(|b| b as Box<Command>)
.collect();
CreateContainer {
CreateSlice {
name: name,
list: CommandList::new(commands),
}
}
}
impl Command for CreateContainer {
impl Command for CreateSlice {
fn exec(&mut self) -> Result<CommandResult> {
info!("Creating container {}", self.name);
info!("Creating slice {}", self.name);
self.list.exec().map(|_| ()).map(From::from)
}
fn rollback(&mut self) -> Result<CommandResult> {
info!("{{rollback}} Removing container {}", self.name);
info!("{{rollback}} Removing slice {}", self.name);
self.list.rollback().map(|_| ()).map(From::from)
}
}
......@@ -72,8 +72,8 @@ mod tests {
use std::fs;
use std::path;
const EXEC_NAME: &str = "test_create_container_exec";
const ROLLBACK_NAME: &str = "test_create_container_rollback";
const EXEC_NAME: &str = "test_create_slice_exec";
const ROLLBACK_NAME: &str = "test_create_slice_rollback";
#[test]
fn test_exec() {
......@@ -108,7 +108,7 @@ mod tests {
.map(fs::create_dir)
.all(|r| r.is_ok())
);
let mut cmd = CreateContainer::new(EXEC_NAME.to_owned(), None, Rc::clone(&rc_controllers));
let mut cmd = CreateSlice::new(EXEC_NAME.to_owned(), None, Rc::clone(&rc_controllers));
// Test
assert!(cmd.exec().is_ok());
for c in rc_controllers.values() {
......@@ -153,8 +153,7 @@ mod tests {
assert!(fs::create_dir(&c.get_path()).is_ok());
assert!(fs::create_dir(&path).is_ok());
}
let mut cmd =
CreateContainer::new(ROLLBACK_NAME.to_owned(), None, Rc::clone(&rc_controllers));
let mut cmd = CreateSlice::new(ROLLBACK_NAME.to_owned(), None, Rc::clone(&rc_controllers));
// Test
assert!(cmd.rollback().is_ok());
for c in rc_controllers.values() {
......
......@@ -66,10 +66,7 @@ impl Exec {
impl Command for Exec {
fn exec(&mut self) -> Result<CommandResult> {
info!(
"Executing \"{}\" in container \"{}\"",
self.full_cmd, self.name
);
info!("Executing \"{}\" in slice \"{}\"", self.full_cmd, self.name);
Err(match self.list.exec() {
Ok(_) => Error::from(format!(
"Could not execute {}: {}",
......@@ -77,7 +74,7 @@ impl Command for Exec {
self.process_cmd.exec().to_string()
)),
Err(err) => Error::from(format!(
"Could not add current process to container {}: {}",
"Could not add current process to slice {}: {}",
self.name,
err.to_string()
)),
......
......@@ -33,7 +33,7 @@ impl ForkExec {
impl Command for ForkExec {
fn exec(&mut self) -> Result<CommandResult> {
info!(
"Forking and executing \"{}\" in container \"{}\"",
"Forking and executing \"{}\" in slice \"{}\"",
self.cmd, self.name
);
let pid = cvt(unsafe { libc::fork() })
......
pub use self::create_container::*;
pub use self::create_slice::*;
pub use self::exec::*;
pub use self::fork_exec::*;
pub use self::modify_container::*;
pub use self::remove_container::*;
pub use self::modify_slice::*;
pub use self::remove_slice::*;
pub use self::spawn::*;
pub mod create_container;
pub mod create_slice;
pub mod exec;
pub mod fork_exec;
pub mod modify_container;
pub mod remove_container;
pub mod modify_slice;
pub mod remove_slice;
pub mod spawn;
......@@ -4,14 +4,14 @@ use error::*;
use std::collections::HashMap;
use std::rc::Rc;
pub struct ModifyContainer {
pub struct ModifySlice {
name: String,
list: CommandList,
}
type PropertyList = HashMap<String, String>;
impl ModifyContainer {
impl ModifySlice {
pub fn new(
name: String,
controllers: Rc<SysFsControllerList>,
......@@ -29,21 +29,21 @@ impl ModifyContainer {
}).map(Box::new)
.map(|b| b as Box<Command>)
.collect();
ModifyContainer {
ModifySlice {
name: name,
list: CommandList::new(commands),
}
}
}
impl Command for ModifyContainer {
impl Command for ModifySlice {
fn exec(&mut self) -> Result<CommandResult> {
info!("Modifying container {}", self.name);
info!("Modifying slice {}", self.name);
self.list.exec().map(|_| ()).map(From::from)
}
fn rollback(&mut self) -> Result<CommandResult> {
info!("{{rollback}} Modifying container {}", self.name);
info!("{{rollback}} Modifying slice {}", self.name);
self.list.rollback().map(|_| ()).map(From::from)
}
}
......@@ -58,8 +58,8 @@ mod tests {
use std::fs;
use std::path;
const EXEC_NAME: &str = "test_modify_container_exec";
const ROLLBACK_NAME: &str = "test_modify_container_rollback";
const EXEC_NAME: &str = "test_modify_slice_exec";
const ROLLBACK_NAME: &str = "test_modify_slice_rollback";
#[test]
fn test_exec() {
......@@ -95,7 +95,7 @@ mod tests {
assert!(fs::write(&filepath, format!("old_{}", value)).is_ok());
}
}
let mut cmd = ModifyContainer::new(
let mut cmd = ModifySlice::new(
EXEC_NAME.to_owned(),
Rc::clone(&rc_controllers),
&properties,
......@@ -150,7 +150,7 @@ mod tests {
assert!(fs::write(&filepath, format!("old_{}", value)).is_ok());
}
}
let mut cmd = ModifyContainer::new(
let mut cmd = ModifySlice::new(
ROLLBACK_NAME.to_owned(),
Rc::clone(&rc_controllers),
&properties,
......
......@@ -4,12 +4,12 @@ use error::*;
use std::path;
use std::rc::Rc;
pub struct RemoveContainer {
pub struct RemoveSlice {
name: String,
list: CommandList,
}
impl RemoveContainer {
impl RemoveSlice {
pub fn new(name: String, controllers: Rc<SysFsControllerList>) -> Self {
let commands = controllers
.values()
......@@ -20,16 +20,16 @@ impl RemoveContainer {
.map(Box::new)
.map(|b| b as Box<Command>)
.collect();
RemoveContainer {
RemoveSlice {
name: name,
list: CommandList::new(commands),
}
}
}
impl Command for RemoveContainer {
impl Command for RemoveSlice {
fn exec(&mut self) -> Result<CommandResult> {
info!("Removing container {}", self.name);
info!("Removing slice {}", self.name);
self.list.exec().map(|_| ()).map(From::from)
}
......@@ -47,7 +47,7 @@ mod tests {
use std::fs;
use std::path;
const EXEC_NAME: &str = "test_remove_container_exec";
const EXEC_NAME: &str = "test_remove_slice_exec";
#[test]
fn test_exec() {
......@@ -81,7 +81,7 @@ mod tests {
assert!(fs::create_dir(&c.get_path()).is_ok());
assert!(fs::create_dir(&path).is_ok());
}
let mut cmd = RemoveContainer::new(EXEC_NAME.to_owned(), Rc::clone(&controllers));
let mut cmd = RemoveSlice::new(EXEC_NAME.to_owned(), Rc::clone(&controllers));
// Test
assert!(cmd.exec().is_ok());
for c in controllers.values() {
......
......@@ -7,7 +7,7 @@ pub struct Spawn {
name: String,
cmd: String,
list: CommandList,
remove: RemoveContainer,
remove: RemoveSlice,
}
impl Spawn {
......@@ -22,13 +22,13 @@ impl Spawn {
properties: &Option<HashMap<String, String>>,
controllers: Rc<SysFsControllerList>,
) -> Self {
let mut commands = vec![Box::new(CreateContainer::new(
let mut commands = vec![Box::new(CreateSlice::new(
name.clone(),
args,
Rc::clone(&controllers),
)) as Box<Command>];
if let Some(properties) = properties {
commands.push(Box::new(ModifyContainer::new(
commands.push(Box::new(ModifySlice::new(
name.clone(),
Rc::clone(&controllers),
properties,
......@@ -47,17 +47,17 @@ impl Spawn {
name: name.clone(),
cmd: cmd.to_owned(),
list: CommandList::new(commands),
remove: RemoveContainer::new(name, Rc::clone(&controllers)),
remove: RemoveSlice::new(name, Rc::clone(&controllers)),
}
}
}
impl Command for Spawn {
fn exec(&mut self) -> Result<CommandResult> {
info!("Spawning \"{}\" in container \"{}\"", self.cmd, self.name);
info!("Spawning \"{}\" in slice \"{}\"", self.cmd, self.name);
if let Err(err) = self.list.exec() {
return Err(Error::from(format!(
"Could not spawn container {}: {}",
"Could not spawn slice {}: {}",
self.name,
err.to_string()
)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment