/
delete_vm.go
44 lines (37 loc) · 1.13 KB
/
delete_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
package action
import (
"bosh-softlayer-cpi/api"
"bosh-softlayer-cpi/registry"
vgs "bosh-softlayer-cpi/softlayer/virtual_guest_service"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boslconfig "bosh-softlayer-cpi/softlayer/config"
)
type DeleteVMAction struct {
vmService vgs.Service
registryClient registry.Client
softlayerOptions boslconfig.Config
}
func NewDeleteVM(
vmDeleterProvider vgs.Service,
registryClient registry.Client,
softlayerOptions boslconfig.Config,
) (action DeleteVMAction) {
action.vmService = vmDeleterProvider
action.registryClient = registryClient
action.softlayerOptions = softlayerOptions
return
}
func (dv DeleteVMAction) Run(vmCID VMCID) (interface{}, error) {
// Delete the VM
if err := dv.vmService.Delete(vmCID.Int(), dv.softlayerOptions.EnableVps); err != nil {
if _, ok := err.(api.CloudError); ok {
return nil, nil
}
return nil, bosherr.WrapErrorf(err, "Deleting vm '%s'", vmCID)
}
// Delete the VM agent settings
if err := dv.registryClient.Delete(vmCID.String()); err != nil {
return nil, bosherr.WrapErrorf(err, "Deleting vm '%s'", vmCID)
}
return nil, nil
}