Skip to content

Commit

Permalink
Fix govm remove --all
Browse files Browse the repository at this point in the history
Fixes #26

Signed-off-by: Obed N Munoz <[email protected]>
  • Loading branch information
obedmr committed Feb 21, 2019
1 parent ac20f45 commit 3d8c080
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,38 @@ func remove() cli.Command {
},
},
Action: func(c *cli.Context) error {
if c.NArg() <= 0 {
if c.NArg() <= 0 && !c.Bool("all") {
err := errors.New("missing VM name")
fmt.Println(err)
fmt.Printf("USAGE:\n govm remove [command options] [name]\n")
os.Exit(1)
}

namespace := c.String("namespace")
name := c.Args().First()

engine := docker.Engine{}
engine.Init()
err := engine.Delete(namespace, name)
if err != nil {
log.Fatalf("Error when removing the VM %v: %v", name, err)

names := []string{}
if all := c.Bool("all"); all {
instances, err := engine.List(namespace, all)
if err != nil {
log.Fatalf("Error when listing current GoVM instances: %v", err)
}
for _, instance := range instances {
names = append(names, instance.Name)
}
} else {
names = append(names, c.Args().First())
}

log.Printf("GoVM Instance %v has been successfully removed", name)
for _, name := range names {
err := engine.Delete(namespace, name)
if err != nil {
log.Fatalf("Error when removing the VM %v: %v", name, err)
}

log.Printf("GoVM Instance %v has been successfully removed", name)
}
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion engines/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type VMEngine interface {
Create(spec vm.Instance) (string, error)
Start(namespace, id string) error
Delete(namespace, id string) error
List() ([]vm.Instance, error)
List(namespace string, all bool) ([]vm.Instance, error)
}

0 comments on commit 3d8c080

Please sign in to comment.