mirror of https://github.com/docker/docs.git
Implement Get on containers
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
15246051d3
commit
c792360599
|
@ -120,6 +120,7 @@ func (f *forwarder) newContainer(id string) beam.Sender {
|
||||||
instance.OnAttach(beam.Handler(c.attach))
|
instance.OnAttach(beam.Handler(c.attach))
|
||||||
instance.OnStart(beam.Handler(c.start))
|
instance.OnStart(beam.Handler(c.start))
|
||||||
instance.OnStop(beam.Handler(c.stop))
|
instance.OnStop(beam.Handler(c.stop))
|
||||||
|
instance.OnGet(beam.Handler(c.get))
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +198,25 @@ func (c *container) stop(ctx *beam.Message) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *container) get(ctx *beam.Message) error {
|
||||||
|
path := fmt.Sprintf("/containers/%s/json", c.id)
|
||||||
|
resp, err := c.forwarder.client.call("GET", path, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
respBody, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("%s", respBody)
|
||||||
|
}
|
||||||
|
if _, err := ctx.Ret.Send(&beam.Message{Verb: beam.Set, Args: []string{string(respBody)}}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
proto string
|
proto string
|
||||||
|
|
|
@ -132,6 +132,21 @@ func doCmd(instance *beam.Object, args []string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if args[0] == "inspect" {
|
||||||
|
if len(args) != 2 {
|
||||||
|
return fmt.Errorf("usage: inspect CONTAINER")
|
||||||
|
}
|
||||||
|
_, container, err := instance.Attach(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("attach: %v", err)
|
||||||
|
}
|
||||||
|
json, err := container.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println(json)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("unrecognised command: %s", args[0])
|
return fmt.Errorf("unrecognised command: %s", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue