Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
cuttr
Commits
e967b292
Commit
e967b292
authored
Sep 21, 2018
by
Alexis Janon
Browse files
Changed "Container" to "Slice"
Reflects the name change
parent
3367ac25
Changes
12
Hide whitespace changes
Inline
Side-by-side
TODO.md
View file @
e967b292
...
...
@@ -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.
...
...
src/configuration/sysfscontroller.rs
View file @
e967b292
...
...
@@ -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?
...
...
src/parsing.rs
View file @
e967b292
...
...
@@ -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
(
Create
Container
::
new
(
Box
::
new
(
Create
Slice
::
new
(
self
.name
.clone
(),
self
.args
.clone
(),
Rc
::
clone
(
&
controllers
),
)),
Box
::
new
(
Modify
Container
::
new
(
Box
::
new
(
Modify
Slice
::
new
(
self
.name
.clone
(),
Rc
::
clone
(
&
controllers
),
&
properties
,
)),
]))),
None
=>
Ok
(
Box
::
new
(
Create
Container
::
new
(
None
=>
Ok
(
Box
::
new
(
Create
Slice
::
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
(
Modify
Container
::
new
(
Some
(
ref
properties
)
=>
Ok
(
Box
::
new
(
Modify
Slice
::
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
(
Remove
Container
::
new
(
fn
to_remove_
slice
(
&
self
,
controllers
:
Rc
<
SysFsControllerList
>
)
->
Result
<
Box
<
Command
>>
{
Ok
(
Box
::
new
(
Remove
Slice
::
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
),
...
...
src/show/slice.rs
View file @
e967b292
...
...
@@ -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
()
...
...
src/transaction/fs/find_get_set_value.rs
View file @
e967b292
...
...
@@ -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
()
...
...
src/transaction/hl/create_
container
.rs
→
src/transaction/hl/create_
slice
.rs
View file @
e967b292
...
...
@@ -3,12 +3,12 @@ use configuration::sysfscontroller::*;
use
std
::
path
;
use
std
::
rc
::
Rc
;
pub
struct
Create
Container
{
pub
struct
Create
Slice
{
name
:
String
,
list
:
CommandList
,
}
impl
Create
Container
{
impl
Create
Slice
{
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
();
Create
Container
{
Create
Slice
{
name
:
name
,
list
:
CommandList
::
new
(
commands
),
}
}
}
impl
Command
for
Create
Container
{
impl
Command
for
Create
Slice
{
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
=
Create
Container
::
new
(
EXEC_NAME
.to_owned
(),
None
,
Rc
::
clone
(
&
rc_controllers
));
let
mut
cmd
=
Create
Slice
::
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
()
{
...
...
src/transaction/hl/exec.rs
View file @
e967b292
...
...
@@ -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
()
)),
...
...
src/transaction/hl/fork_exec.rs
View file @
e967b292
...
...
@@ -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
()
})
...
...
src/transaction/hl/mod.rs
View file @
e967b292
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
;
src/transaction/hl/modify_
container
.rs
→
src/transaction/hl/modify_
slice
.rs
View file @
e967b292
...
...
@@ -4,14 +4,14 @@ use error::*;
use
std
::
collections
::
HashMap
;
use
std
::
rc
::
Rc
;
pub
struct
Modify
Container
{
pub
struct
Modify
Slice
{
name
:
String
,
list
:
CommandList
,
}
type
PropertyList
=
HashMap
<
String
,
String
>
;
impl
Modify
Container
{
impl
Modify
Slice
{
pub
fn
new
(
name
:
String
,
controllers
:
Rc
<
SysFsControllerList
>
,
...
...
@@ -29,21 +29,21 @@ impl ModifyContainer {
})
.map
(
Box
::
new
)
.map
(|
b
|
b
as
Box
<
Command
>
)
.collect
();
Modify
Container
{
Modify
Slice
{
name
:
name
,
list
:
CommandList
::
new
(
commands
),
}
}
}
impl
Command
for
Modify
Container
{
impl
Command
for
Modify
Slice
{
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
=
Modify
Container
::
new
(
let
mut
cmd
=
Modify
Slice
::
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
=
Modify
Container
::
new
(
let
mut
cmd
=
Modify
Slice
::
new
(
ROLLBACK_NAME
.to_owned
(),
Rc
::
clone
(
&
rc_controllers
),
&
properties
,
...
...
src/transaction/hl/remove_
container
.rs
→
src/transaction/hl/remove_
slice
.rs
View file @
e967b292
...
...
@@ -4,12 +4,12 @@ use error::*;
use
std
::
path
;
use
std
::
rc
::
Rc
;
pub
struct
Remove
Container
{
pub
struct
Remove
Slice
{
name
:
String
,
list
:
CommandList
,
}
impl
Remove
Container
{
impl
Remove
Slice
{
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
();
Remove
Container
{
Remove
Slice
{
name
:
name
,
list
:
CommandList
::
new
(
commands
),
}
}
}
impl
Command
for
Remove
Container
{
impl
Command
for
Remove
Slice
{
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
=
Remove
Container
::
new
(
EXEC_NAME
.to_owned
(),
Rc
::
clone
(
&
controllers
));
let
mut
cmd
=
Remove
Slice
::
new
(
EXEC_NAME
.to_owned
(),
Rc
::
clone
(
&
controllers
));
// Test
assert
!
(
cmd
.exec
()
.is_ok
());
for
c
in
controllers
.values
()
{
...
...
src/transaction/hl/spawn.rs
View file @
e967b292
...
...
@@ -7,7 +7,7 @@ pub struct Spawn {
name
:
String
,
cmd
:
String
,
list
:
CommandList
,
remove
:
Remove
Container
,
remove
:
Remove
Slice
,
}
impl
Spawn
{
...
...
@@ -22,13 +22,13 @@ impl Spawn {
properties
:
&
Option
<
HashMap
<
String
,
String
>>
,
controllers
:
Rc
<
SysFsControllerList
>
,
)
->
Self
{
let
mut
commands
=
vec!
[
Box
::
new
(
Create
Container
::
new
(
let
mut
commands
=
vec!
[
Box
::
new
(
Create
Slice
::
new
(
name
.clone
(),
args
,
Rc
::
clone
(
&
controllers
),
))
as
Box
<
Command
>
];
if
let
Some
(
properties
)
=
properties
{
commands
.push
(
Box
::
new
(
Modify
Container
::
new
(
commands
.push
(
Box
::
new
(
Modify
Slice
::
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
:
Remove
Container
::
new
(
name
,
Rc
::
clone
(
&
controllers
)),
remove
:
Remove
Slice
::
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
()
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment