optimize for shimCreateCommand

Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
This commit is contained in:
yuexiao-wang 2017-05-05 01:32:43 +08:00
parent 0fe0d8feeb
commit 41308ffa57

View File

@ -78,7 +78,11 @@ var shimCreateCommand = cli.Command{
}, },
), ),
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
id := context.Args().First() var (
id = context.Args().First()
ctx = gocontext.Background()
)
if id == "" { if id == "" {
return errors.New("container id must be provided") return errors.New("container id must be provided")
} }
@ -91,7 +95,7 @@ var shimCreateCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
r, err := service.Create(gocontext.Background(), &shim.CreateRequest{ r, err := service.Create(ctx, &shim.CreateRequest{
ID: id, ID: id,
Bundle: context.String("bundle"), Bundle: context.String("bundle"),
Runtime: context.String("runtime"), Runtime: context.String("runtime"),
@ -115,7 +119,7 @@ var shimCreateCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
if _, err := service.Pty(gocontext.Background(), &shim.PtyRequest{ if _, err := service.Pty(ctx, &shim.PtyRequest{
Pid: r.Pid, Pid: r.Pid,
Width: uint32(size.Width), Width: uint32(size.Width),
Height: uint32(size.Height), Height: uint32(size.Height),
@ -210,6 +214,7 @@ var shimExecCommand = cli.Command{
), ),
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
service, err := getShimService() service, err := getShimService()
ctx := gocontext.Background()
if err != nil { if err != nil {
return err return err
} }
@ -235,7 +240,7 @@ var shimExecCommand = cli.Command{
Stderr: context.String("stderr"), Stderr: context.String("stderr"),
Terminal: tty, Terminal: tty,
} }
r, err := service.Exec(gocontext.Background(), rq) r, err := service.Exec(ctx, rq)
if err != nil { if err != nil {
return err return err
} }
@ -252,7 +257,7 @@ var shimExecCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
if _, err := service.Pty(gocontext.Background(), &shim.PtyRequest{ if _, err := service.Pty(ctx, &shim.PtyRequest{
Pid: r.Pid, Pid: r.Pid,
Width: uint32(size.Width), Width: uint32(size.Width),
Height: uint32(size.Height), Height: uint32(size.Height),