From 288b9a0cc35586b8bb779fb6ba428afd2997704b Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 10 Dec 2015 11:03:36 -0800 Subject: [PATCH] Add addProcess cli 'exec' command Signed-off-by: Michael Crosby --- ctr/checkpoint.go | 14 ++++++------ ctr/container.go | 54 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/ctr/checkpoint.go b/ctr/checkpoint.go index 7118ae4..5960640 100644 --- a/ctr/checkpoint.go +++ b/ctr/checkpoint.go @@ -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 { diff --git a/ctr/container.go b/ctr/container.go index 574402e..522bd2b 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -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) + } + }, +}