make every node and plugin removal call api

Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
allencloud 2016-10-19 06:29:27 +08:00
parent 668189e7f0
commit c6d57ca076
2 changed files with 15 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package node
import ( import (
"fmt" "fmt"
"strings"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -35,12 +36,21 @@ func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error { func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error {
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
var errs []string
for _, nodeID := range args { for _, nodeID := range args {
err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force}) err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
if err != nil { if err != nil {
return err errs = append(errs, err.Error())
continue
} }
fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID) fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
} }
if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n"))
}
return nil return nil
} }

View file

@ -45,14 +45,16 @@ func runRemove(dockerCli *command.DockerCli, opts *rmOptions) error {
for _, name := range opts.plugins { for _, name := range opts.plugins {
named, err := reference.ParseNamed(name) // FIXME: validate named, err := reference.ParseNamed(name) // FIXME: validate
if err != nil { if err != nil {
return err errs = append(errs, err)
continue
} }
if reference.IsNameOnly(named) { if reference.IsNameOnly(named) {
named = reference.WithDefaultTag(named) named = reference.WithDefaultTag(named)
} }
ref, ok := named.(reference.NamedTagged) ref, ok := named.(reference.NamedTagged)
if !ok { if !ok {
return fmt.Errorf("invalid name: %s", named.String()) errs = append(errs, fmt.Errorf("invalid name: %s", named.String()))
continue
} }
// TODO: pass names to api instead of making multiple api calls // TODO: pass names to api instead of making multiple api calls
if err := dockerCli.Client().PluginRemove(ctx, ref.String(), types.PluginRemoveOptions{Force: opts.force}); err != nil { if err := dockerCli.Client().PluginRemove(ctx, ref.String(), types.PluginRemoveOptions{Force: opts.force}); err != nil {