Skip to content

Commit

Permalink
fleetctl: destroy using wildcards can search in the repository
Browse files Browse the repository at this point in the history
Curerntly, fleetctl destroy *.service, it will search the units
in the local directory. The args with wildcards have already parsed
by golang package before be passed into runDestroyUnits. So
runDestroyUnits cannot do anything.

This patch support wildcards just search in the repository,
not from local directory. But need support a new interface. The new
interface is:
    fleetctl destroy "xx*.service".
We found that if bracket the service name, the arg will not be
parsed by golang package to local directory. Then we can do match it
with the service name in the repository.

Fixes coreos#710
  • Loading branch information
wuqixuan committed Jun 18, 2015
1 parent 8275b70 commit 84f9cb8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions fleetctl/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package main

import (
"path"
)

var cmdDestroyUnit = &Command{
Name: "destroy",
Summary: "Destroy one or more units in the cluster",
Expand All @@ -29,14 +33,27 @@ Destroyed units are impossible to start unless re-submitted.`,
}

func runDestroyUnits(args []string) (exit int) {
states, err := cAPI.UnitStates()
if err != nil {
stderr("Error retrieving list of units from repository: %v", err)
return 1
}

for _, v := range args {
name := unitNameMangle(v)
err := cAPI.DestroyUnit(name)
if err != nil {
continue
}
for _, us := range states {
if match, _ := path.Match(name, us.Name); match == false {
continue
}

err = cAPI.DestroyUnit(us.Name)
if err != nil {
stderr("Error destroying unit %s: %v", us.Name, err)
continue
}

stdout("Destroyed %s", name)
stdout("Destroyed %s", us.Name)
}
}
return
}

0 comments on commit 84f9cb8

Please sign in to comment.