-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcloud.go
More file actions
91 lines (72 loc) · 2.45 KB
/
cloud.go
File metadata and controls
91 lines (72 loc) · 2.45 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
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
// Package cloud contains CloudStack related
// functions.
package cloud
import (
"context"
"errors"
"github.com/apache/cloudstack-go/v2/cloudstack"
)
// Interface is the CloudStack client interface.
//nolint:interfacebloat
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
CreateVolumeFromSnapshot(ctx context.Context, zoneID, name, projectID, snapshotID string, sizeInGB int64) (*Volume, error)
GetSnapshotByID(ctx context.Context, snapshotID string) (*Snapshot, error)
GetSnapshotByName(ctx context.Context, name string) (*Snapshot, error)
CreateSnapshot(ctx context.Context, volumeID, name string) (*Snapshot, error)
DeleteSnapshot(ctx context.Context, snapshotID string) error
ListSnapshots(ctx context.Context, volumeID, snapshotID string) ([]*Snapshot, error)
}
// Volume represents a CloudStack volume.
type Volume struct {
ID string
Name string
// Size in Bytes
Size int64
DiskOfferingID string
DomainID string
ProjectID string
ZoneID string
VirtualMachineID string
DeviceID string
}
type Snapshot struct {
ID string
Name string
Size int64
DomainID string
ProjectID string
ZoneID string
VolumeID string
CreatedAt 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")
ErrAlreadyExists = errors.New("already exists")
)
// 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}
}