/
api.go
69 lines (58 loc) · 1.68 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
/*
Package mdb implements a simple in-memory Machine DataBase.
*/
package mdb
import (
"io"
"github.com/Cloud-Foundations/Dominator/lib/tags"
"github.com/Cloud-Foundations/Dominator/lib/verstr"
)
type AwsMetadata struct {
AccountId string
AccountName string
InstanceId string
Region string
Tags tags.Tags
}
// Machine describes a single machine with a unique Hostname and optional
// metadata about the machine.
type Machine struct {
Hostname string
IpAddress string `json:",omitempty"`
RequiredImage string `json:",omitempty"`
PlannedImage string `json:",omitempty"`
DisableUpdates bool `json:",omitempty"`
OwnerGroup string `json:",omitempty"`
Tags tags.Tags `json:",omitempty"`
AwsMetadata *AwsMetadata `json:",omitempty"`
}
func (left Machine) Compare(right Machine) bool {
return left.compare(right)
}
// UpdateFrom updates dest with data from source.
func (dest *Machine) UpdateFrom(source Machine) {
dest.updateFrom(source)
}
// Mdb describes a list of Machines. It implements sort.Interface.
type Mdb struct {
Machines []Machine
}
// DebugWrite writes the JSON representation to w.
func (mdb *Mdb) DebugWrite(w io.Writer) error {
return mdb.debugWrite(w)
}
// Len returns the number of machines.
func (mdb *Mdb) Len() int {
return len(mdb.Machines)
}
// Less compares the hostnames of left and right.
func (mdb *Mdb) Less(left, right int) bool {
return verstr.Less(mdb.Machines[left].Hostname,
mdb.Machines[right].Hostname)
}
// Swap swaps two entries in mdb.
func (mdb *Mdb) Swap(left, right int) {
tmp := mdb.Machines[left]
mdb.Machines[left] = mdb.Machines[right]
mdb.Machines[right] = tmp
}