-
Notifications
You must be signed in to change notification settings - Fork 14
/
models.go
104 lines (88 loc) · 2.75 KB
/
models.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
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package mock
import (
"fmt"
"io"
"strconv"
)
// BMC represents a Baseboard Management Controller.
type BMC struct {
BmcType string `json:"bmcType"`
Ipv4 string `json:"ipv4"`
}
// Label represents an arbitrary key-value pairs.
type Label struct {
Name string `json:"name"`
Value string `json:"value"`
}
// LabelInput represents a label to search machines.
type LabelInput struct {
Name string `json:"name"`
Value string `json:"value"`
}
// Machine represents a physical server in a datacenter rack.
type Machine struct {
Spec MachineSpec `json:"spec"`
Status MachineStatus `json:"status"`
}
// MachineParams is a set of input parameters to search machines.
type MachineParams struct {
Labels []LabelInput `json:"labels"`
Racks []int `json:"racks"`
Roles []string `json:"roles"`
States []MachineState `json:"states"`
MinDaysBeforeRetire *int `json:"minDaysBeforeRetire"`
}
// MachineSpec represents specifications of a machine.
type MachineSpec struct {
Serial string `json:"serial"`
Labels []Label `json:"labels"`
Rack int `json:"rack"`
IndexInRack int `json:"indexInRack"`
Role string `json:"role"`
Ipv4 []string `json:"ipv4"`
RegisterDate string `json:"registerDate"`
RetireDate string `json:"retireDate"`
Bmc BMC `json:"bmc"`
}
// MachineStatus represents status of a Machine.
type MachineStatus struct {
State MachineState `json:"state"`
Timestamp string `json:"timestamp"`
Duration float64 `json:"duration"`
}
// MachineState enumerates machine states.
type MachineState string
const (
MachineStateUninitialized MachineState = "UNINITIALIZED"
MachineStateHealthy MachineState = "HEALTHY"
MachineStateUnhealthy MachineState = "UNHEALTHY"
MachineStateUnreachable MachineState = "UNREACHABLE"
MachineStateUpdating MachineState = "UPDATING"
MachineStateRetiring MachineState = "RETIRING"
MachineStateRetired MachineState = "RETIRED"
)
func (e MachineState) IsValid() bool {
switch e {
case MachineStateUninitialized, MachineStateHealthy, MachineStateUnhealthy, MachineStateUnreachable, MachineStateUpdating, MachineStateRetiring, MachineStateRetired:
return true
}
return false
}
func (e MachineState) String() string {
return string(e)
}
func (e *MachineState) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = MachineState(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid MachineState", str)
}
return nil
}
func (e MachineState) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}