2015-05-23 16:05:48 -04:00
|
|
|
package client
|
|
|
|
|
2015-06-08 07:17:24 -04:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2016-11-21 20:29:53 -05:00
|
|
|
"errors"
|
2015-06-08 07:17:24 -04:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2015-06-14 12:00:27 -04:00
|
|
|
"strings"
|
2015-06-08 07:17:24 -04:00
|
|
|
"text/tabwriter"
|
|
|
|
|
2016-01-06 08:23:05 -05:00
|
|
|
"github.com/docker/docker/opts"
|
2015-06-08 07:17:24 -04:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2016-09-07 15:30:02 -04:00
|
|
|
flag "github.com/docker/libnetwork/client/mflag"
|
2016-01-06 08:23:05 -05:00
|
|
|
"github.com/docker/libnetwork/netutils"
|
2015-06-08 07:17:24 -04:00
|
|
|
)
|
|
|
|
|
2015-05-23 16:05:48 -04:00
|
|
|
var (
|
2015-06-08 07:17:24 -04:00
|
|
|
serviceCommands = []command{
|
2015-06-11 11:30:45 -04:00
|
|
|
{"publish", "Publish a service"},
|
|
|
|
{"unpublish", "Remove a service"},
|
2015-06-11 09:52:46 -04:00
|
|
|
{"attach", "Attach a backend (container) to the service"},
|
|
|
|
{"detach", "Detach the backend from the service"},
|
2015-06-11 11:30:45 -04:00
|
|
|
{"ls", "Lists all services"},
|
|
|
|
{"info", "Display information about a service"},
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
2015-05-23 16:05:48 -04:00
|
|
|
)
|
2015-06-08 07:17:24 -04:00
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func lookupServiceID(cli *NetworkCli, nwName, svNameID string) (string, error) {
|
|
|
|
// Sanity Check
|
|
|
|
obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/networks?name=%s", nwName), nil, nil))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
var nwList []networkResource
|
|
|
|
if err = json.Unmarshal(obj, &nwList); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if len(nwList) == 0 {
|
|
|
|
return "", fmt.Errorf("Network %s does not exist", nwName)
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
if nwName == "" {
|
|
|
|
obj, _, err := readBody(cli.call("GET", "/networks/"+nwList[0].ID, nil, nil))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
networkResource := &networkResource{}
|
|
|
|
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(networkResource); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
nwName = networkResource.Name
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// Query service by name
|
|
|
|
obj, statusCode, err := readBody(cli.call("GET", fmt.Sprintf("/services?name=%s", svNameID), nil, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if statusCode != http.StatusOK {
|
2015-06-11 11:30:45 -04:00
|
|
|
return "", fmt.Errorf("name query failed for %s due to: (%d) %s", svNameID, statusCode, string(obj))
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
var list []*serviceResource
|
|
|
|
if err = json.Unmarshal(obj, &list); err != nil {
|
2015-06-08 07:17:24 -04:00
|
|
|
return "", err
|
|
|
|
}
|
2015-06-11 11:30:45 -04:00
|
|
|
for _, sr := range list {
|
|
|
|
if sr.Network == nwName {
|
|
|
|
return sr.ID, nil
|
|
|
|
}
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// Query service by Partial-id (this covers full id as well)
|
|
|
|
obj, statusCode, err = readBody(cli.call("GET", fmt.Sprintf("/services?partial-id=%s", svNameID), nil, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if statusCode != http.StatusOK {
|
2015-06-11 11:30:45 -04:00
|
|
|
return "", fmt.Errorf("partial-id match query failed for %s due to: (%d) %s", svNameID, statusCode, string(obj))
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
if err = json.Unmarshal(obj, &list); err != nil {
|
2015-06-08 07:17:24 -04:00
|
|
|
return "", err
|
|
|
|
}
|
2015-06-11 11:30:45 -04:00
|
|
|
for _, sr := range list {
|
|
|
|
if sr.Network == nwName {
|
|
|
|
return sr.ID, nil
|
|
|
|
}
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
2015-06-11 11:30:45 -04:00
|
|
|
|
|
|
|
return "", fmt.Errorf("Service %s not found on network %s", svNameID, nwName)
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func lookupContainerID(cli *NetworkCli, cnNameID string) (string, error) {
|
2015-06-15 05:27:24 -04:00
|
|
|
// Container is a Docker resource, ask docker about it.
|
|
|
|
// In case of connecton error, we assume we are running in dnet and return whatever was passed to us
|
|
|
|
obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/containers/%s/json", cnNameID), nil, nil))
|
|
|
|
if err != nil {
|
|
|
|
// We are probably running outside of docker
|
|
|
|
return cnNameID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var x map[string]interface{}
|
|
|
|
err = json.Unmarshal(obj, &x)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if iid, ok := x["Id"]; ok {
|
|
|
|
if id, ok := iid.(string); ok {
|
|
|
|
return id, nil
|
|
|
|
}
|
2016-11-21 20:29:53 -05:00
|
|
|
return "", errors.New("Unexpected data type for container ID in json response")
|
2015-06-15 05:27:24 -04:00
|
|
|
}
|
2016-11-21 20:29:53 -05:00
|
|
|
return "", errors.New("Cannot find container ID in json response")
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
func lookupSandboxID(cli *NetworkCli, containerID string) (string, error) {
|
2015-09-09 20:35:07 -04:00
|
|
|
obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/sandboxes?partial-container-id=%s", containerID), nil, nil))
|
2015-07-02 01:00:48 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2015-09-16 01:26:27 -04:00
|
|
|
var sandboxList []SandboxResource
|
2015-07-02 01:00:48 -04:00
|
|
|
err = json.Unmarshal(obj, &sandboxList)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(sandboxList) == 0 {
|
|
|
|
return "", fmt.Errorf("cannot find sandbox for container: %s", containerID)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sandboxList[0].ID, nil
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// CmdService handles the service UI
|
2015-06-08 07:17:24 -04:00
|
|
|
func (cli *NetworkCli) CmdService(chain string, args ...string) error {
|
|
|
|
cmd := cli.Subcmd(chain, "service", "COMMAND [OPTIONS] [arg...]", serviceUsage(chain), false)
|
|
|
|
cmd.Require(flag.Min, 1)
|
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err == nil {
|
|
|
|
cmd.Usage()
|
|
|
|
return fmt.Errorf("Invalid command : %v", args)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
// Parse service name for "SERVICE[.NETWORK]" format
|
|
|
|
func parseServiceName(name string) (string, string) {
|
|
|
|
s := strings.Split(name, ".")
|
|
|
|
var sName, nName string
|
|
|
|
if len(s) > 1 {
|
|
|
|
nName = s[len(s)-1]
|
|
|
|
sName = strings.Join(s[:len(s)-1], ".")
|
|
|
|
} else {
|
|
|
|
sName = s[0]
|
|
|
|
}
|
|
|
|
return sName, nName
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// CmdServicePublish handles service create UI
|
|
|
|
func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd := cli.Subcmd(chain, "publish", "SERVICE[.NETWORK]", "Publish a new service on a network", false)
|
2016-01-07 22:19:31 -05:00
|
|
|
flAlias := opts.NewListOpts(netutils.ValidateAlias)
|
|
|
|
cmd.Var(&flAlias, []string{"-alias"}, "Add alias to self")
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
sn, nn := parseServiceName(cmd.Arg(0))
|
2016-01-07 22:19:31 -05:00
|
|
|
sc := serviceCreate{Name: sn, Network: nn, MyAliases: flAlias.GetAll()}
|
2015-06-11 11:30:45 -04:00
|
|
|
obj, _, err := readBody(cli.call("POST", "/services", sc, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var replyID string
|
|
|
|
err = json.Unmarshal(obj, &replyID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(cli.out, "%s\n", replyID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// CmdServiceUnpublish handles service delete UI
|
|
|
|
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
|
2016-01-11 21:53:27 -05:00
|
|
|
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
sn, nn := parseServiceName(cmd.Arg(0))
|
|
|
|
serviceID, err := lookupServiceID(cli, nn, sn)
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-11 21:53:27 -05:00
|
|
|
sd := serviceDelete{Name: sn, Force: *force}
|
|
|
|
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
|
2015-06-11 11:30:45 -04:00
|
|
|
|
|
|
|
return err
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// CmdServiceLs handles service list UI
|
|
|
|
func (cli *NetworkCli) CmdServiceLs(chain string, args ...string) error {
|
2015-06-11 11:30:45 -04:00
|
|
|
cmd := cli.Subcmd(chain, "ls", "SERVICE", "Lists all the services on a network", false)
|
|
|
|
flNetwork := cmd.String([]string{"net", "-network"}, "", "Only show the services that are published on the specified network")
|
2015-06-08 07:17:24 -04:00
|
|
|
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
|
|
|
|
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
|
2015-06-11 11:30:45 -04:00
|
|
|
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
var obj []byte
|
|
|
|
if *flNetwork == "" {
|
|
|
|
obj, _, err = readBody(cli.call("GET", "/services", nil, nil))
|
|
|
|
} else {
|
|
|
|
obj, _, err = readBody(cli.call("GET", "/services?network="+*flNetwork, nil, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
var serviceResources []serviceResource
|
|
|
|
err = json.Unmarshal(obj, &serviceResources)
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
fmt.Println(err)
|
2015-06-08 07:17:24 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
|
|
|
// unless quiet (-q) is specified, print field titles
|
|
|
|
if !*quiet {
|
2015-09-23 22:29:56 -04:00
|
|
|
fmt.Fprintln(wr, "SERVICE ID\tNAME\tNETWORK\tCONTAINER\tSANDBOX")
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
for _, sr := range serviceResources {
|
|
|
|
ID := sr.ID
|
2015-09-23 22:29:56 -04:00
|
|
|
bkID, sbID, err := getBackendID(cli, ID)
|
2015-06-11 11:30:45 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-06-08 07:17:24 -04:00
|
|
|
if !*noTrunc {
|
|
|
|
ID = stringid.TruncateID(ID)
|
2015-06-11 11:30:45 -04:00
|
|
|
bkID = stringid.TruncateID(bkID)
|
2015-09-23 22:29:56 -04:00
|
|
|
sbID = stringid.TruncateID(sbID)
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
2015-06-11 11:30:45 -04:00
|
|
|
if !*quiet {
|
2015-09-23 22:29:56 -04:00
|
|
|
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t%s\n", ID, sr.Name, sr.Network, bkID, sbID)
|
2015-06-11 11:30:45 -04:00
|
|
|
} else {
|
2015-06-08 07:17:24 -04:00
|
|
|
fmt.Fprintln(wr, ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wr.Flush()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-23 22:29:56 -04:00
|
|
|
func getBackendID(cli *NetworkCli, servID string) (string, string, error) {
|
2015-06-11 11:30:45 -04:00
|
|
|
var (
|
|
|
|
obj []byte
|
|
|
|
err error
|
|
|
|
bk string
|
2015-09-23 22:29:56 -04:00
|
|
|
sb string
|
2015-06-11 11:30:45 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if obj, _, err = readBody(cli.call("GET", "/services/"+servID+"/backend", nil, nil)); err == nil {
|
2015-09-16 01:26:27 -04:00
|
|
|
var sr SandboxResource
|
2015-09-07 11:04:23 -04:00
|
|
|
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(&sr); err == nil {
|
|
|
|
bk = sr.ContainerID
|
2015-09-23 22:29:56 -04:00
|
|
|
sb = sr.ID
|
2015-06-11 11:30:45 -04:00
|
|
|
} else {
|
|
|
|
// Only print a message, don't make the caller cli fail for this
|
2015-09-07 11:04:23 -04:00
|
|
|
fmt.Fprintf(cli.out, "Failed to retrieve backend list for service %s (%v)\n", servID, err)
|
2015-06-11 11:30:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 22:29:56 -04:00
|
|
|
return bk, sb, err
|
2015-06-11 11:30:45 -04:00
|
|
|
}
|
|
|
|
|
2015-06-08 07:17:24 -04:00
|
|
|
// CmdServiceInfo handles service info UI
|
|
|
|
func (cli *NetworkCli) CmdServiceInfo(chain string, args ...string) error {
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd := cli.Subcmd(chain, "info", "SERVICE[.NETWORK]", "Displays detailed information about a service", false)
|
2015-06-11 11:30:45 -04:00
|
|
|
cmd.Require(flag.Min, 1)
|
|
|
|
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
sn, nn := parseServiceName(cmd.Arg(0))
|
|
|
|
serviceID, err := lookupServiceID(cli, nn, sn)
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
obj, _, err := readBody(cli.call("GET", "/services/"+serviceID, nil, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
sr := &serviceResource{}
|
|
|
|
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(sr); err != nil {
|
2015-06-08 07:17:24 -04:00
|
|
|
return err
|
|
|
|
}
|
2015-06-11 11:30:45 -04:00
|
|
|
|
|
|
|
fmt.Fprintf(cli.out, "Service Id: %s\n", sr.ID)
|
|
|
|
fmt.Fprintf(cli.out, "\tName: %s\n", sr.Name)
|
|
|
|
fmt.Fprintf(cli.out, "\tNetwork: %s\n", sr.Network)
|
2015-06-08 07:17:24 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// CmdServiceAttach handles service attach UI
|
|
|
|
func (cli *NetworkCli) CmdServiceAttach(chain string, args ...string) error {
|
2015-06-14 12:00:27 -04:00
|
|
|
cmd := cli.Subcmd(chain, "attach", "CONTAINER SERVICE[.NETWORK]", "Sets a container as a service backend", false)
|
2016-01-06 08:23:05 -05:00
|
|
|
flAlias := opts.NewListOpts(netutils.ValidateAlias)
|
|
|
|
cmd.Var(&flAlias, []string{"-alias"}, "Add alias for another container")
|
2015-06-11 11:30:45 -04:00
|
|
|
cmd.Require(flag.Min, 2)
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
containerID, err := lookupContainerID(cli, cmd.Arg(0))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
sandboxID, err := lookupSandboxID(cli, containerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
sn, nn := parseServiceName(cmd.Arg(1))
|
|
|
|
serviceID, err := lookupServiceID(cli, nn, sn)
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-06 08:23:05 -05:00
|
|
|
nc := serviceAttach{SandboxID: sandboxID, Aliases: flAlias.GetAll()}
|
2015-06-08 07:17:24 -04:00
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
_, _, err = readBody(cli.call("POST", "/services/"+serviceID+"/backend", nc, nil))
|
|
|
|
|
|
|
|
return err
|
2015-06-08 07:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
// CmdServiceDetach handles service detach UI
|
|
|
|
func (cli *NetworkCli) CmdServiceDetach(chain string, args ...string) error {
|
|
|
|
cmd := cli.Subcmd(chain, "detach", "CONTAINER SERVICE", "Removes a container from service backend", false)
|
|
|
|
cmd.Require(flag.Min, 2)
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cmd.ParseFlags(args, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
sn, nn := parseServiceName(cmd.Arg(1))
|
2015-06-11 11:30:45 -04:00
|
|
|
containerID, err := lookupContainerID(cli, cmd.Arg(0))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-08 08:22:29 -04:00
|
|
|
sandboxID, err := lookupSandboxID(cli, containerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
serviceID, err := lookupServiceID(cli, nn, sn)
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-08 08:22:29 -04:00
|
|
|
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID+"/backend/"+sandboxID, nil, nil))
|
2015-06-08 07:17:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func serviceUsage(chain string) string {
|
|
|
|
help := "Commands:\n"
|
|
|
|
|
|
|
|
for _, cmd := range serviceCommands {
|
|
|
|
help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description)
|
|
|
|
}
|
|
|
|
|
|
|
|
help += fmt.Sprintf("\nRun '%s service COMMAND --help' for more information on a command.", chain)
|
|
|
|
return help
|
|
|
|
}
|