@@ -16,7 +16,7 @@ const RUNTIME_BIN: &str = "/usr/bin/crun";
16
16
/// An actively running OCI container.
17
17
#[ derive( Debug ) ]
18
18
pub struct Container {
19
- name : String ,
19
+ id : String ,
20
20
uuid : Uuid ,
21
21
pid : i32 ,
22
22
console_sock : UnixSeqpacket ,
@@ -28,7 +28,6 @@ impl Container {
28
28
/// Spawns a new container with the given `id` from the `rt` OCI bundle.
29
29
pub async fn create ( id : & str , rt : OciBundle ) -> anyhow:: Result < Self > {
30
30
let uuid = Uuid :: new_v4 ( ) ;
31
-
32
31
let start_pipe = StartPipe :: new ( ) ?;
33
32
let mut sync_pipe = SyncPipe :: new ( ) ?;
34
33
@@ -38,9 +37,9 @@ impl Container {
38
37
. stderr ( Stdio :: piped ( ) )
39
38
. args ( & [ "--syslog" , "--log-level=debug" ] )
40
39
. arg ( "--terminal" ) // Passes `--console-sock` to `crun`.
41
- . args ( & [ "--cid" , id] )
40
+ . args ( & [ "--cid" , & id] )
42
41
. args ( & [ "--cuuid" , & uuid. to_string ( ) ] )
43
- . args ( & [ "--name" , id] )
42
+ . args ( & [ "--name" , & id] )
44
43
. args ( & [ "--runtime" , RUNTIME_BIN ] )
45
44
. args ( & [ "--runtime-arg" , "--rootless=true" ] )
46
45
. args ( & [ "--bundle" , & rt. bundle_dir . display ( ) . to_string ( ) ] )
@@ -92,7 +91,7 @@ impl Container {
92
91
eprintln ! ( "connected to console socket!" ) ;
93
92
94
93
Ok ( Container {
95
- name : id. to_string ( ) ,
94
+ id : id. to_string ( ) ,
96
95
uuid,
97
96
pid,
98
97
console_sock,
@@ -104,38 +103,38 @@ impl Container {
104
103
/// Start the container, if it isn't already running.
105
104
pub async fn start ( & self ) -> anyhow:: Result < ( ) > {
106
105
let mut pause_cmd = Command :: new ( RUNTIME_BIN ) ;
107
- pause_cmd. args ( & [ "start" , & self . name ] ) ;
106
+ pause_cmd. args ( & [ "start" , & self . id ] ) ;
108
107
exec_command ( & mut pause_cmd) . await ?;
109
108
Ok ( ( ) )
110
109
}
111
110
112
111
/// Pause the container's execution, if it currently running.
113
112
pub async fn pause ( & self ) -> anyhow:: Result < ( ) > {
114
113
let mut pause_cmd = Command :: new ( RUNTIME_BIN ) ;
115
- pause_cmd. args ( & [ "pause" , & self . name ] ) ;
114
+ pause_cmd. args ( & [ "pause" , & self . id ] ) ;
116
115
exec_command ( & mut pause_cmd) . await ?;
117
116
Ok ( ( ) )
118
117
}
119
118
120
119
/// Resume the container's execution, if it currently paused.
121
120
pub async fn resume ( & self ) -> anyhow:: Result < ( ) > {
122
121
let mut resume_cmd = Command :: new ( RUNTIME_BIN ) ;
123
- resume_cmd. args ( & [ "resume" , & self . name ] ) ;
122
+ resume_cmd. args ( & [ "resume" , & self . id ] ) ;
124
123
exec_command ( & mut resume_cmd) . await ?;
125
124
Ok ( ( ) )
126
125
}
127
126
128
127
/// Delete the container immediately.
129
128
pub async fn delete ( self ) -> anyhow:: Result < ( ) > {
130
129
let mut delete_cmd = Command :: new ( RUNTIME_BIN ) ;
131
- delete_cmd. args ( & [ "delete" , "--force" , & self . name ] ) ;
130
+ delete_cmd. args ( & [ "delete" , "--force" , & self . id ] ) ;
132
131
exec_command ( & mut delete_cmd) . await ?;
133
132
Ok ( ( ) )
134
133
}
135
134
136
- /// Returns the name of the container.
137
- pub fn name ( & self ) -> & str {
138
- & self . name
135
+ /// Returns the ID of the container.
136
+ pub fn id ( & self ) -> & str {
137
+ & self . id
139
138
}
140
139
141
140
/// Returns the UUIDv4 assigned to the container.
0 commit comments