forked from cloudfoundry/bosh-softlayer-cpi-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
softlayer_vm.go
executable file
·109 lines (80 loc) · 2.78 KB
/
softlayer_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package vm
import (
"encoding/json"
"fmt"
"time"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
sl "github.com/maximilien/softlayer-go/softlayer"
bslcommon "github.com/maximilien/bosh-softlayer-cpi/softlayer/common"
bslcdisk "github.com/maximilien/bosh-softlayer-cpi/softlayer/disk"
)
const softLayerVMtag = "SoftLayerVM"
type SoftLayerVM struct {
id int
softLayerClient sl.Client
agentEnvService AgentEnvService
logger boshlog.Logger
}
func NewSoftLayerVM(id int, softLayerClient sl.Client, agentEnvService AgentEnvService, logger boshlog.Logger) SoftLayerVM {
bslcommon.TIMEOUT = 10 * time.Minute
bslcommon.POLLING_INTERVAL = 10 * time.Second
return SoftLayerVM{
id: id,
softLayerClient: softLayerClient,
agentEnvService: agentEnvService,
logger: logger,
}
}
func (vm SoftLayerVM) ID() int { return vm.id }
func (vm SoftLayerVM) Delete() error {
virtualGuestService, err := vm.softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating SoftLayer VirtualGuestService from client")
}
deleted, err := virtualGuestService.DeleteObject(vm.ID())
if err != nil {
return bosherr.WrapError(err, "Deleting SoftLayer VirtualGuest from client")
}
if !deleted {
return bosherr.WrapError(nil, "Did not delete SoftLayer VirtualGuest from client")
}
return nil
}
func (vm SoftLayerVM) Reboot() error {
virtualGuestService, err := vm.softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating SoftLayer VirtualGuestService from client")
}
rebooted, err := virtualGuestService.RebootSoft(vm.ID())
if err != nil {
return bosherr.WrapError(err, "Rebooting (soft) SoftLayer VirtualGuest from client")
}
if !rebooted {
return bosherr.WrapError(nil, "Did not reboot (soft) SoftLayer VirtualGuest from client")
}
return nil
}
func (vm SoftLayerVM) SetMetadata(vmMetadata VMMetadata) error {
//TODO: reconcile this metadata (from VMMetadata) abd SoftLayerCreator.Run metadata
metadata, err := json.Marshal(vmMetadata)
if err != nil {
return bosherr.WrapError(err, "Marshalling VM metadata")
}
err = bslcommon.ConfigureMetadataOnVirtualGuest(vm.softLayerClient, vm.id, string(metadata), bslcommon.TIMEOUT, bslcommon.POLLING_INTERVAL)
if err != nil {
return bosherr.WrapError(err, fmt.Sprintf("Configuring metadata on VirtualGuest `%d`", vm.id))
}
return nil
}
func (vm SoftLayerVM) ConfigureNetworks(networks Networks) error {
return NotSupportedError{}
}
func (vm SoftLayerVM) AttachDisk(disk bslcdisk.Disk) error {
vm.logger.Info(softLayerVMtag, "Not yet implemented!")
return nil
}
func (vm SoftLayerVM) DetachDisk(disk bslcdisk.Disk) error {
vm.logger.Info(softLayerVMtag, "Not yet implemented!")
return nil
}