-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdestroy.go
More file actions
47 lines (44 loc) · 961 Bytes
/
destroy.go
File metadata and controls
47 lines (44 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package client
import (
"fmt"
"regexp"
"strconv"
)
// Destroy unschedules one unit for a given component type
func (c *FleetClient) Destroy(component string) (err error) {
// see if we were provided a specific target
r := regexp.MustCompile(`([a-z-]+)\.([\d]+)`)
match := r.FindStringSubmatch(component)
var (
num int
unitName string
)
if len(match) == 3 {
num, err = strconv.Atoi(match[2])
if err != nil {
return err
}
unitName, err = formatUnitName(component, 0)
} else {
num, err = c.lastUnit(component)
if err != nil {
return err
}
unitName, err = formatUnitName(component, num)
if err != nil {
return err
}
}
if num == 0 {
return fmt.Errorf("no units to destroy")
}
_, err = c.Fleet.Job(unitName)
if err != nil {
return
}
if err = c.Fleet.DestroyJob(unitName); err != nil {
return fmt.Errorf("failed destroying job %s: %v", unitName, err)
}
fmt.Printf("Destroyed Unit %s\n", unitName)
return
}