This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
provider.go
86 lines (74 loc) · 1.71 KB
/
provider.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
package infra
import (
"fmt"
"io"
"sort"
)
type Address struct {
Location string
FrontendPort uint16
BackendPort uint16
}
func (a Address) String() string {
return fmt.Sprintf("%s:%d", a.Location, a.FrontendPort)
}
type ProviderCurrent interface {
Pools() map[string]Pool
Ingresses() map[string]*Address
}
type Ingress struct {
Pools []string
HealthChecksPath string
}
type Pool interface {
EnsureMembers() error
EnsureMember(Machine) error
GetMachines() (Machines, error)
AddMachine() (Machine, error)
}
type Machine interface {
ID() string
IP() string
Remove() error
Execute(stdin io.Reader, cmd string) ([]byte, error)
Shell() error
WriteFile(path string, data io.Reader, permissions uint16) error
ReadFile(path string, data io.Writer) error
RebootRequired() (required bool, require func(), unrequire func())
ReplacementRequired() (required bool, require func(), unrequire func())
}
type Machines []Machine
func (c Machines) ToChan() <-chan Machine {
compChan := make(chan Machine)
go func() {
for _, comp := range c {
compChan <- comp
}
close(compChan)
}()
return compChan
}
func (c Machines) String() string {
list := ""
for _, comp := range c {
list += "|" + comp.ID()
}
if len(list) > 0 {
list = list[1:]
}
return "(" + list + ")"
}
func (c Machines) Len() int { return len(c) }
func (c Machines) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c Machines) Less(i, j int) bool { return c[i].ID() < c[j].ID() }
func (c Machines) IDs() []string {
l := len(c)
machines := make([]Machine, l, l)
copy(machines, c)
sort.Sort(Machines(machines))
ids := make([]string, l, l)
for idx, machine := range machines {
ids[idx] = machine.ID()
}
return ids
}