Add addProcess cli 'exec' command

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-10 11:03:36 -08:00
parent 21259f7fec
commit 288b9a0cc3
2 changed files with 59 additions and 9 deletions

View File

@ -28,13 +28,13 @@ var ListCheckpointCommand = cli.Command{
func listCheckpoints(context *cli.Context) {
var (
cli = getClient()
id = context.Args().First()
c = getClient()
id = context.Args().First()
)
if id == "" {
fatal("container id cannot be empty", 1)
}
resp, err := cli.ListCheckpoint(netcontext.Background(), &types.ListCheckpointRequest{
resp, err := c.ListCheckpoint(netcontext.Background(), &types.ListCheckpointRequest{
Id: id,
})
if err != nil {
@ -82,8 +82,8 @@ var CreateCheckpointCommand = cli.Command{
if name == "" {
fatal("checkpoint name cannot be empty", 1)
}
cli := getClient()
if _, err := cli.CreateCheckpoint(netcontext.Background(), &types.CreateCheckpointRequest{
c := getClient()
if _, err := c.CreateCheckpoint(netcontext.Background(), &types.CreateCheckpointRequest{
Id: containerID,
Checkpoint: &types.Checkpoint{
Name: name,
@ -108,8 +108,8 @@ var DeleteCheckpointCommand = cli.Command{
if name == "" {
fatal("checkpoint name cannot be empty", 1)
}
cli := getClient()
if _, err := cli.DeleteCheckpoint(netcontext.Background(), &types.DeleteCheckpointRequest{
c := getClient()
if _, err := c.DeleteCheckpoint(netcontext.Background(), &types.DeleteCheckpointRequest{
Id: containerID,
Name: name,
}); err != nil {

View File

@ -27,6 +27,7 @@ var ContainersCommand = cli.Command{
StartCommand,
ListCommand,
KillCommand,
ExecCommand,
},
Action: listContainers,
}
@ -38,8 +39,8 @@ var ListCommand = cli.Command{
}
func listContainers(context *cli.Context) {
cli := getClient()
resp, err := cli.State(netcontext.Background(), &types.StateRequest{})
c := getClient()
resp, err := c.State(netcontext.Background(), &types.StateRequest{})
if err != nil {
fatal(err.Error(), 1)
}
@ -114,3 +115,52 @@ var KillCommand = cli.Command{
}
},
}
var ExecCommand = cli.Command{
Name: "exec",
Usage: "exec another process in an existing container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "container id to add the process to",
},
cli.StringFlag{
Name: "cwd",
Usage: "current working directory for the process",
},
cli.BoolFlag{
Name: "tty,t",
Usage: "create a terminal for the process",
},
cli.StringSliceFlag{
Name: "env,e",
Value: &cli.StringSlice{},
Usage: "environment variables for the process",
},
cli.IntFlag{
Name: "uid,u",
Usage: "user id of the user for the process",
},
cli.IntFlag{
Name: "gid,g",
Usage: "group id of the user for the process",
},
},
Action: func(context *cli.Context) {
p := &types.AddProcessRequest{
Args: context.Args(),
Cwd: context.String("cwd"),
Terminal: context.Bool("tty"),
Id: context.String("id"),
Env: context.StringSlice("env"),
User: &types.User{
Uid: uint32(context.Int("uid")),
Gid: uint32(context.Int("gid")),
},
}
c := getClient()
if _, err := c.AddProcess(netcontext.Background(), p); err != nil {
fatal(err.Error(), 1)
}
},
}