-
Notifications
You must be signed in to change notification settings - Fork 6
/
api.go
180 lines (151 loc) · 4.92 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package hypervisors
import (
"io"
"net"
"sync"
"time"
"github.com/Cloud-Foundations/Dominator/fleetmanager/topology"
"github.com/Cloud-Foundations/Dominator/lib/log"
"github.com/Cloud-Foundations/Dominator/lib/srpc"
"github.com/Cloud-Foundations/Dominator/lib/tags"
fm_proto "github.com/Cloud-Foundations/Dominator/proto/fleetmanager"
hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor"
)
const (
probeStatusNotYetProbed probeStatus = iota
probeStatusConnected
probeStatusAccessDenied
probeStatusNoSrpc
probeStatusNoService
probeStatusConnectionRefused
probeStatusUnreachable
probeStatusOff
)
type hypervisorType struct {
logger log.DebugLogger
receiveChannel chan struct{}
mutex sync.RWMutex
cachedSerialNumber string
conn *srpc.Conn
deleteScheduled bool
healthStatus string
lastIpmiProbe time.Time
localTags tags.Tags
location string
machine *fm_proto.Machine
migratingVms map[string]*vmInfoType // Key: VM IP address.
ownerUsers map[string]struct{}
probeStatus probeStatus
serialNumber string
subnets []hyper_proto.Subnet
vms map[string]*vmInfoType // Key: VM IP address.
}
type ipStorer interface {
AddIPsForHypervisor(hypervisor net.IP, addrs []net.IP) error
CheckIpIsRegistered(addr net.IP) (bool, error)
GetHypervisorForIp(addr net.IP) (net.IP, error)
GetIPsForHypervisor(hypervisor net.IP) ([]net.IP, error)
SetIPsForHypervisor(hypervisor net.IP, addrs []net.IP) error
UnregisterHypervisor(hypervisor net.IP) error
}
type locationType struct {
notifiers map[<-chan fm_proto.Update]chan<- fm_proto.Update
}
type Manager struct {
ipmiPasswordFile string
ipmiUsername string
logger log.DebugLogger
storer Storer
mutex sync.RWMutex // Protect everything below.
allocatingIPs map[string]struct{} // Key: VM IP address.
hypervisors map[string]*hypervisorType // Key: hypervisor machine name.
locations map[string]*locationType // Key: location.
migratingIPs map[string]struct{} // Key: VM IP address.
notifiers map[<-chan fm_proto.Update]*locationType
topology *topology.Topology
subnets map[string]*subnetType // Key: Gateway IP.
vms map[string]*vmInfoType // Key: VM IP address.
}
type probeStatus uint
type serialStorer interface {
ReadMachineSerialNumber(hypervisor net.IP) (string, error)
WriteMachineSerialNumber(hypervisor net.IP, serialNumber string) error
}
type StartOptions struct {
IpmiPasswordFile string
IpmiUsername string
Logger log.DebugLogger
Storer Storer
}
type Storer interface {
ipStorer
serialStorer
tagsStorer
vmStorer
}
type subnetType struct {
subnet *topology.Subnet
startIp net.IP
stopIp net.IP
nextIp net.IP
}
type tagsStorer interface {
ReadMachineTags(hypervisor net.IP) (tags.Tags, error)
WriteMachineTags(hypervisor net.IP, tgs tags.Tags) error
}
type vmInfoType struct {
ipAddr string
hyper_proto.VmInfo
hypervisor *hypervisorType
}
type vmStorer interface {
DeleteVm(hypervisor net.IP, ipAddr string) error
ListVMs(hypervisor net.IP) ([]string, error)
ReadVm(hypervisor net.IP, ipAddr string) (*hyper_proto.VmInfo, error)
WriteVm(hypervisor net.IP, ipAddr string, vmInfo hyper_proto.VmInfo) error
}
func New(startOptions StartOptions) (*Manager, error) {
return newManager(startOptions)
}
func (m *Manager) ChangeMachineTags(hostname string,
authInfo *srpc.AuthInformation, tgs tags.Tags) error {
return m.changeMachineTags(hostname, authInfo, tgs)
}
func (m *Manager) CloseUpdateChannel(channel <-chan fm_proto.Update) {
m.closeUpdateChannel(channel)
}
func (m *Manager) GetHypervisorForVm(ipAddr net.IP) (string, error) {
return m.getHypervisorForVm(ipAddr)
}
func (m *Manager) GetMachineInfo(hostname string) (fm_proto.Machine, error) {
return m.getMachineInfo(hostname)
}
func (m *Manager) GetTopology() (*topology.Topology, error) {
return m.getTopology()
}
func (m *Manager) ListHypervisorsInLocation(
request fm_proto.ListHypervisorsInLocationRequest) ([]string, error) {
return m.listHypervisorsInLocation(request)
}
func (m *Manager) ListLocations(dirname string) ([]string, error) {
return m.listLocations(dirname)
}
func (m *Manager) ListVMsInLocation(dirname string) ([]net.IP, error) {
return m.listVMsInLocation(dirname)
}
func (m *Manager) MakeUpdateChannel(location string) <-chan fm_proto.Update {
return m.makeUpdateChannel(location)
}
func (m *Manager) MoveIpAddresses(hostname string, ipAddresses []net.IP) error {
return m.moveIpAddresses(hostname, ipAddresses)
}
func (m *Manager) PowerOnMachine(hostname string,
authInfo *srpc.AuthInformation) error {
return m.powerOnMachine(hostname, authInfo)
}
func (m *Manager) WriteHtml(writer io.Writer) {
m.writeHtml(writer)
}
func (m *Manager) UpdateTopology(t *topology.Topology) {
m.updateTopology(t)
}