forked from LunaNode/lobster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_interface.go
80 lines (62 loc) · 2.69 KB
/
vm_interface.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
package lobster
type VmInterface interface {
// Creates a virtual machine with the given name and plan (specified in vm object), and image.
// Returns vmIdentification string and optional error.
// Should return vmIdentification != "" only if err == nil.
VmCreate(vm *VirtualMachine, options *VMIVmCreateOptions) (string, error)
// Deletes the specified virtual machine.
VmDelete(vm *VirtualMachine) error
VmInfo(vm *VirtualMachine) (*VmInfo, error)
VmStart(vm *VirtualMachine) error
VmStop(vm *VirtualMachine) error
VmReboot(vm *VirtualMachine) error
// action is an element of VmInfo.Actions (although this is not guaranteed)
VmAction(vm *VirtualMachine, action string, value string) error
// returns the number of bytes transferred by the given VM since the last call
// if this is the first call, then BandwidthAccounting must return zero
BandwidthAccounting(vm *VirtualMachine) int64
}
type VMIVmCreateOptions struct {
ImageIdentification string
SSHKey SSHKey
}
type VMIVnc interface {
// On success, url is a link that we should redirect to.
VmVnc(vm *VirtualMachine) (string, error)
}
type VMIRename interface {
VmRename(vm *VirtualMachine, name string) error
}
type VMIReimage interface {
VmReimage(vm *VirtualMachine, imageIdentification string) error
}
type VMISnapshot interface {
// On success, should return image identification of a created snapshot.
// (if backend store images and snapshots separately, the interface can tag the identification, e.g. "snapshot:XYZ" and "image:ABC")
VmSnapshot(vm *VirtualMachine) (string, error)
}
type VMIResize interface {
VmResize(vm *VirtualMachine, plan *Plan) error
}
type VMIAddresses interface {
VmAddresses(vm *VirtualMachine) ([]*IpAddress, error)
VmAddAddress(vm *VirtualMachine) error
VmRemoveAddress(vm *VirtualMachine, ip string, privateip string) error
VmSetRdns(vm *VirtualMachine, ip string, hostname string) error
}
type VMIImages interface {
// Download an image from an external URL.
// Format is currently either 'template' or 'iso' in the form, although user may provide arbitrary format string.
ImageFetch(url string, format string) (string, error)
ImageInfo(imageIdentification string) (*ImageInfo, error)
ImageDelete(imageIdentification string) error
// List public images in backend.
// Only Name, Identification should be set.
ImageList() ([]*Image, error)
}
type VMIPlans interface {
PlanList() ([]*Plan, error)
}
// Note: before calling the VmInterface, we will make sure that the user actually owns the virtual machine
// with the given identification, and same for images. However, VmInterface is responsible for checking any
// other input, e.g. action strings, action parameters, image formats, image URLs.