Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 5871f3d

Browse files
committed
add hyper pause client command
only support hyper pause pod now. Signed-off-by: Gao feng <[email protected]>
1 parent ed6fa33 commit 5871f3d

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

client/pause.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"strings"
7+
8+
"github.com/hyperhq/hyper/engine"
9+
gflag "github.com/jessevdk/go-flags"
10+
)
11+
12+
func (cli *HyperClient) HyperCmdPause(args ...string) error {
13+
var parser = gflag.NewParser(nil, gflag.Default|gflag.IgnoreUnknown)
14+
parser.Usage = "pause Pod\n\nPause the pod"
15+
args, err := parser.ParseArgs(args)
16+
if err != nil {
17+
if !strings.Contains(err.Error(), "Usage") {
18+
return err
19+
} else {
20+
return nil
21+
}
22+
}
23+
if len(args) == 0 {
24+
return fmt.Errorf("Can not accept the 'pause' command without Pod ID!")
25+
}
26+
27+
v := url.Values{}
28+
v.Set("podId", args[0])
29+
30+
body, _, err := readBody(cli.call("POST", "/pod/pause?"+v.Encode(), nil, nil))
31+
if err != nil {
32+
return err
33+
}
34+
35+
out := engine.NewOutput()
36+
if _, err = out.AddEnv(); err != nil {
37+
return err
38+
}
39+
40+
if _, err := out.Write(body); err != nil {
41+
return err
42+
}
43+
out.Close()
44+
return nil
45+
}

client/unpause.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"strings"
7+
8+
"github.com/hyperhq/hyper/engine"
9+
gflag "github.com/jessevdk/go-flags"
10+
)
11+
12+
func (cli *HyperClient) HyperCmdUnpause(args ...string) error {
13+
var parser = gflag.NewParser(nil, gflag.Default|gflag.IgnoreUnknown)
14+
parser.Usage = "unpause Pod\n\nUnpause the pod"
15+
args, err := parser.ParseArgs(args)
16+
if err != nil {
17+
if !strings.Contains(err.Error(), "Usage") {
18+
return err
19+
} else {
20+
return nil
21+
}
22+
}
23+
if len(args) == 0 {
24+
return fmt.Errorf("Can not accept the 'unpause' command without Pod ID!")
25+
}
26+
27+
v := url.Values{}
28+
v.Set("podId", args[0])
29+
30+
body, _, err := readBody(cli.call("POST", "/pod/unpause?"+v.Encode(), nil, nil))
31+
if err != nil {
32+
return err
33+
}
34+
out := engine.NewOutput()
35+
if _, err = out.AddEnv(); err != nil {
36+
return err
37+
}
38+
39+
if _, err := out.Write(body); err != nil {
40+
return err
41+
}
42+
out.Close()
43+
return nil
44+
}

0 commit comments

Comments
 (0)