-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcloud.go
More file actions
66 lines (52 loc) · 1.69 KB
/
cloud.go
File metadata and controls
66 lines (52 loc) · 1.69 KB
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
// Package cloud contains CloudStack related
// functions.
package cloud
import (
"context"
"errors"
"github.com/apache/cloudstack-go/v2/cloudstack"
)
// Interface is the CloudStack client interface.
type Interface interface {
GetNodeInfo(ctx context.Context, vmName string) (*VM, error)
GetVMByID(ctx context.Context, vmID string) (*VM, error)
ListZonesID(ctx context.Context) ([]string, error)
GetVolumeByID(ctx context.Context, volumeID string) (*Volume, error)
GetVolumeByName(ctx context.Context, name string) (*Volume, error)
CreateVolume(ctx context.Context, diskOfferingID, zoneID, name string, sizeInGB int64) (string, error)
DeleteVolume(ctx context.Context, id string) error
AttachVolume(ctx context.Context, volumeID, vmID string) (string, error)
DetachVolume(ctx context.Context, volumeID string) error
ExpandVolume(ctx context.Context, volumeID string, newSizeInGB int64) error
}
// Volume represents a CloudStack volume.
type Volume struct {
ID string
Name string
// Size in Bytes
Size int64
DiskOfferingID string
ZoneID string
VirtualMachineID string
DeviceID string
}
// VM represents a CloudStack Virtual Machine.
type VM struct {
ID string
ZoneID string
}
// Specific errors.
var (
ErrNotFound = errors.New("not found")
ErrTooManyResults = errors.New("too many results")
)
// client is the implementation of Interface.
type client struct {
*cloudstack.CloudStackClient
projectID string
}
// New creates a new cloud connector, given its configuration.
func New(config *Config) Interface {
csClient := cloudstack.NewAsyncClient(config.APIURL, config.APIKey, config.SecretKey, config.VerifySSL)
return &client{csClient, config.ProjectID}
}