This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
api.go
95 lines (87 loc) · 2.19 KB
/
api.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
package types
import (
"time"
konfigadm "github.com/flanksource/konfigadm/pkg/types"
"github.com/vmware/govmomi/vim25/types"
)
// +kubebuilder:object:generate=false
type TagInterface interface {
GetTags() map[string]string
}
// Machine represents a running instance of a VM
// +kubebuilder:object:generate=false
type Machine interface {
TagInterface
String() string
WaitForPoweredOff() error
GetIP(timeout time.Duration) (string, error)
WaitForIP() (string, error)
SetAttributes(attributes map[string]string) error
GetAttributes() (map[string]string, error)
Shutdown() error
PowerOff() error
Terminate() error
Name() string
GetAge() time.Duration
GetTemplate() string
IP() string
Reference() types.ManagedObjectReference
}
// +kubebuilder:object:generate=false
type NullMachine struct {
Hostname string
}
func (n NullMachine) String() string {
return n.Hostname
}
func (n NullMachine) WaitForPoweredOff() error {
return nil
}
func (n NullMachine) GetIP(timeout time.Duration) (string, error) {
return "", nil
}
func (n NullMachine) WaitForIP() (string, error) {
return "", nil
}
func (n NullMachine) SetAttributes(attributes map[string]string) error {
return nil
}
func (n NullMachine) GetAttributes() (map[string]string, error) {
return nil, nil
}
func (n NullMachine) Shutdown() error {
return nil
}
func (n NullMachine) PowerOff() error {
return nil
}
func (n NullMachine) Terminate() error {
return nil
}
func (n NullMachine) Name() string {
return n.Hostname
}
func (n NullMachine) GetAge() time.Duration {
return 0
}
func (n NullMachine) GetTemplate() string {
return ""
}
func (n NullMachine) IP() string {
return ""
}
func (n NullMachine) GetTags() map[string]string {
return make(map[string]string)
}
func (n NullMachine) Reference() types.ManagedObjectReference {
return types.ManagedObjectReference{}
}
// +kubebuilder:object:generate=false
type Cluster interface {
Clone(template VM, config *konfigadm.Config) (Machine, error)
CloneTemplate(template VM, config *konfigadm.Config) (Machine, error)
GetMachine(name string) (Machine, error)
GetMachines() (map[string]Machine, error)
GetMachinesFor(vm *VM) (map[string]Machine, error)
SetTags(vm Machine, tags map[string]string) error
}