This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinfo.go
187 lines (177 loc) · 6.13 KB
/
info.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
181
182
183
184
185
186
187
package models
import (
"net"
"runtime"
)
// HaPassiveState the state of the passive node
//
// swagger:model
type HaPassiveState struct {
// required: true
Id string `json:"id"`
// required: true
Address string `json:"address"`
// required: true
State string `json:"state"`
// required: true
Electable bool `json:"electable"`
}
// Stat contains a basic statistic about dr-provision
//
// swagger:model
type Stat struct {
// required: true
Name string `json:"name"`
// required: true
Count int `json:"count"`
}
// Info contains information on how the running instance of
// dr-provision is configured.
//
// For passive nodes, the license, scopes, and stats are not filled in.
//
// swagger:model
type Info struct {
// Arch is the system architecture of the running dr-provision endpoint.
// It is the same value that would be return by runtime.GOARCH
// required: true
Arch string `json:"arch"`
// Os is the operating system the dr-provision endpoint is running on.
// It is the same value returned by runtime.GOARCH
// required: true
Os string `json:"os"`
// Version is the full version of dr-provision.
// required: true
Version string `json:"version"`
// Id is the local ID for this dr-provision. If not overridden by
// an environment variable or a command line argument, it will
// be the lowest MAC address of all the physical nics attached to the system.
// required: true
Id string `json:"id"`
// LocalId is the same as Id, except it is always the MAC address form.
// required: true
LocalId string `json:"local_id"`
// HaId is the user-assigned high-availability ID for this endpoint.
// All endpoints in the same HA cluster must have the same HaId.
// required: true
HaId string `json:"ha_id"`
// ApiPort is the TCP port that the API lives on. Defaults to 8092
// required: true
ApiPort int `json:"api_port"`
// FilePort is the TCP port that the static file HTTP server lives on.
// Defaults to 8091
// required: true
FilePort int `json:"file_port"`
// SecureFilePort is the TCP port that the static file HTTPS server lives on.
// Defaults to 8090
// required: true
SecureFilePort int `json:"secure_file_port"`
// DhcpPort is the UDP port that the DHCPv4 server listens on.
// Defaults to 67
// required: true
DhcpPort int `json:"dhcp_port"`
// BinlPort is the UDP port that the BINL server listens on.
// Defaults to 4011
// required: true
BinlPort int `json:"binl_port"`
// TftpPort is the UDP port that the TFTP server listens on.
// Defaults to 69, dude.
// required: true
TftpPort int `json:"tftp_port"`
// TftpEnabled is true if the TFTP server is enabled.
// required: true
TftpEnabled bool `json:"tftp_enabled"`
// DhcpEnabled is true if the DHCP server is enabled.
// required: true
DhcpEnabled bool `json:"dhcp_enabled"`
// BinlEnabled is true if the BINL server is enabled.
// required: true
BinlEnabled bool `json:"binl_enabled"`
// ProvisionerEnabled is true if the static file HTTP server is enabled.
// required: true
ProvisionerEnabled bool `json:"prov_enabled"`
// SecureProvisionerEnabled is true if the static file HTTPS server is enabled.
// required: true
SecureProvisionerEnabled bool `json:"secure_prov_enabled"`
// Address is the IP address that the system appears to listen on.
// If a default address was assigned via environment variable or command line,
// it will be that address, otherwise it will be the IP address of the interface
// that has the default IPv4 route.
// required: true
Address net.IP `json:"address"`
// ServerHostname is the DNS name for the DRP endpoint that managed systems should use.
// If a default hostname was assigned via environment variable or command line,
// it will be that hostname, otherwise it will be an empty string
ServerHostname string `json:"server_hostname"`
// Manager indicates whether this dr-provision can act as a manager of
// other dr-provision instances.
// required: true
Manager bool `json:"manager"`
// Stats lists some basic object statistics.
// required: true
Stats []Stat `json:"stats"`
// Features is a list of features implemented in this dr-provision endpoint.
// Clients should use this field when determining what features are available
// on anu given dr-provision instance.
Features []string `json:"features"`
// Scopes lists all static permission scopes available.
Scopes map[string]map[string]struct{} `json:"scopes"`
// License is an embedded copy of the licenses present on the system.
License LicenseBundle
// Errors returns the current system errors.
// required: true
Errors []string `json:"errors"`
// HaEnabled indicates if High Availability is enabled
HaEnabled bool `json:"ha_enabled"`
// HaVirtualAddress is the Virtual IP Address of the systems
HaVirtualAddress string `json:"ha_virtual_address"`
// HaIsActive indicates Active (true) or Passive (false)
// required: true
HaIsActive bool `json:"ha_is_active"`
// HaStatus indicates current state
// For Active, Up is the only value.
// For Passive, Connecting, Syncing, In-Sync
// required: true
HaStatus string `json:"ha_status"`
// HaActiveId is the id of current active node
HaActiveId string `json:"ha_active_id"`
// HaPassiveState is a list of passive node's and their current state
// This is only valid from the Active node
HaPassiveState []*HaPassiveState `json:"ha_passive_state"`
// ClusterState is the current state of the consensus cluster that this
// node is a member of. As of v4.6, all nodes are in at least a single-node cluster
ClusterState ClusterState
}
// HasFeature is a helper function to determine if a requested feature
// is present.
func (i *Info) HasFeature(f string) bool {
for _, v := range i.Features {
if v == f {
return true
}
}
return false
}
func (i *Info) Fill() {
i.Arch = runtime.GOARCH
i.Os = runtime.GOOS
if i.Stats == nil {
i.Stats = make([]Stat, 0, 0)
}
if i.Features == nil {
i.Features = []string{}
}
if i.Scopes == nil {
scopes := map[string]map[string]struct{}{}
actionScopeLock.Lock()
defer actionScopeLock.Unlock()
Remarshal(allScopes, &scopes)
i.Scopes = scopes
}
if i.Errors == nil {
i.Errors = []string{}
}
if i.HaPassiveState == nil {
i.HaPassiveState = []*HaPassiveState{}
}
}