forked from shapeblue/cloudstack-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloud.go
More file actions
65 lines (51 loc) · 1.65 KB
/
Copy pathcloud.go
File metadata and controls
65 lines (51 loc) · 1.65 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
// 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
}
// 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}
}