forked from cloudfoundry/bosh-softlayer-cpi-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
softlayer_stemcell.go
executable file
·70 lines (53 loc) · 1.91 KB
/
softlayer_stemcell.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
60
61
62
63
64
65
66
67
68
69
70
package stemcell
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
sl "github.com/maximilien/softlayer-go/softlayer"
)
const softLayerStemcellLogTag = "SoftLayerStemcell"
const VirtualDiskImageKind = "VirtualDiskImage"
const VirtualGuestDeviceTemplateGroupKind = "VirtualGuestDeviceTemplateGroup"
const DefaultKind = VirtualGuestDeviceTemplateGroupKind
type SoftLayerStemcell struct {
id int
uuid string
kind string
softLayerClient sl.Client
logger boshlog.Logger
}
func NewSoftLayerStemcell(id int, uuid string, kind string, softLayerClient sl.Client, logger boshlog.Logger) SoftLayerStemcell {
return SoftLayerStemcell{
id: id,
uuid: uuid,
kind: kind,
softLayerClient: softLayerClient,
logger: logger,
}
}
func (s SoftLayerStemcell) ID() int { return s.id }
func (s SoftLayerStemcell) Uuid() string { return s.uuid }
func (s SoftLayerStemcell) Kind() string { return s.kind }
func (s SoftLayerStemcell) Delete() error {
if s.kind == VirtualGuestDeviceTemplateGroupKind {
return s.deleteVirtualGuestDiskTemplateGroup(s.id)
} else if s.kind == VirtualDiskImageKind {
return nil
} else {
return bosherr.WrapError(nil, "Unknown SoftLayer stemcell kind")
}
}
func (s SoftLayerStemcell) deleteVirtualGuestDiskTemplateGroup(id int) error {
vgdtgService, err := s.softLayerClient.GetSoftLayer_Virtual_Guest_Block_Device_Template_Group_Service()
if err != nil {
return bosherr.WrapError(err, "Getting SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service from SoftLayer client")
}
deleted, err := vgdtgService.DeleteObject(id)
if err != nil {
return bosherr.WrapError(err, "Deleting VirtualGuestBlockDeviceTemplateGroup from service")
}
if !deleted {
return bosherr.WrapError(nil, fmt.Sprintf("Could not delete VirtualGuestBlockDeviceTemplateGroup with id `%d`", id))
}
return err
}