-
Notifications
You must be signed in to change notification settings - Fork 161
/
vm.go
59 lines (45 loc) · 957 Bytes
/
vm.go
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
48
49
50
51
52
53
54
55
56
57
58
59
package director
import (
"fmt"
"net/url"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type VMResp struct {
VMCID string `json:"vm_cid"`
}
func (d DeploymentImpl) DeleteVM(cid string) error {
err := d.client.DeleteVM(cid)
if err != nil {
resps, listErr := d.client.VMs()
if listErr != nil {
return err
}
for _, resp := range resps {
if resp.VMCID == cid {
return err
}
}
}
return nil
}
func (c Client) DeleteVM(cid string) error {
if len(cid) == 0 {
return bosherr.Error("Expected non-empty VM CID")
}
path := fmt.Sprintf("/vms/%s", url.PathEscape(cid))
_, err := c.taskClientRequest.DeleteResult(path)
if err != nil {
return bosherr.WrapErrorf(
err, "Deleting VM '%s'", cid)
}
return nil
}
func (c Client) VMs() ([]VMResp, error) {
var vms []VMResp
err := c.clientRequest.Get("/vms", &vms)
if err != nil {
return vms, bosherr.WrapErrorf(
err, "Listing VMs")
}
return vms, nil
}