forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cluster.go
224 lines (189 loc) · 6.41 KB
/
cluster.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package api
import (
"encoding/base64"
"encoding/json"
)
// Cluster represents high-level information about a LXD cluster.
//
// swagger:model
//
// API extension: clustering
type Cluster struct {
// Name of the cluster member answering the request
// Example: lxd01
ServerName string `json:"server_name" yaml:"server_name"`
// Whether clustering is enabled
// Example: true
Enabled bool `json:"enabled" yaml:"enabled"`
// List of member configuration keys (used during join)
// Example: []
//
// API extension: clustering_join
MemberConfig []ClusterMemberConfigKey `json:"member_config" yaml:"member_config"`
}
// ClusterMemberConfigKey represents a single config key that a new member of
// the cluster is required to provide when joining.
//
// The Value field is empty when getting clustering information with GET
// /1.0/cluster, and should be filled by the joining node when performing a PUT
// /1.0/cluster join request.
//
// swagger:model
//
// API extension: clustering_join
type ClusterMemberConfigKey struct {
// The kind of configuration key (network, storage-pool, ...)
// Example: storage-pool
Entity string `json:"entity" yaml:"entity"`
// The name of the object requiring this key
// Example: local
Name string `json:"name" yaml:"name"`
// The name of the key
// Example: source
Key string `json:"key" yaml:"key"`
// The value on the answering cluster member
// Example: /dev/sdb
Value string `json:"value" yaml:"value"`
// A human friendly description key
// Example: "source" property for storage pool "local"
Description string `json:"description" yaml:"description"`
}
// ClusterPut represents the fields required to bootstrap or join a LXD
// cluster.
//
// swagger:model
//
// API extension: clustering
type ClusterPut struct {
Cluster `yaml:",inline"`
// The address of the cluster you wish to join
// Example: 10.0.0.1:8443
ClusterAddress string `json:"cluster_address" yaml:"cluster_address"`
// The expected certificate (X509 PEM encoded) for the cluster
// Example: X509 PEM certificate
ClusterCertificate string `json:"cluster_certificate" yaml:"cluster_certificate"`
// The local address to use for cluster communication
// Example: 10.0.0.2:8443
//
// API extension: clustering_join
ServerAddress string `json:"server_address" yaml:"server_address"`
// The trust password of the cluster you're trying to join
// Example: blah
//
// API extension: clustering_join
ClusterPassword string `json:"cluster_password" yaml:"cluster_password"`
}
// ClusterMembersPost represents the fields required to request a join token to add a member to the cluster.
//
// swagger:model
//
// API extension: clustering_join_token
type ClusterMembersPost struct {
// The name of the new cluster member
// Example: lxd02
ServerName string `json:"server_name" yaml:"server_name"`
}
// ClusterMemberJoinToken represents the fields contained within an encoded cluster member join token.
//
// swagger:model
//
// API extension: clustering_join_token
type ClusterMemberJoinToken struct {
// The name of the new cluster member
// Example: lxd02
ServerName string `json:"server_name" yaml:"server_name"`
// The fingerprint of the network certificate
// Example: 57bb0ff4340b5bb28517e062023101adf788c37846dc8b619eb2c3cb4ef29436
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
// The addresses of existing online cluster members
// Example: ["10.98.30.229:8443"]
Addresses []string `json:"addresses" yaml:"addresses"`
// The random join secret.
// Example: 2b2284d44db32675923fe0d2020477e0e9be11801ff70c435e032b97028c35cd
Secret string `json:"secret" yaml:"secret"`
}
// String encodes the cluster member join token as JSON and then Base64.
func (t *ClusterMemberJoinToken) String() string {
joinTokenJSON, err := json.Marshal(t)
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString(joinTokenJSON)
}
// ClusterMemberPost represents the fields required to rename a LXD node.
//
// swagger:model
//
// API extension: clustering
type ClusterMemberPost struct {
// The new name of the cluster member
// Example: lxd02
ServerName string `json:"server_name" yaml:"server_name"`
}
// ClusterMember represents the a LXD node in the cluster.
//
// swagger:model
//
// API extension: clustering
type ClusterMember struct {
ClusterMemberPut `yaml:",inline"`
// Name of the cluster member
// Example: lxd01
ServerName string `json:"server_name" yaml:"server_name"`
// URL at which the cluster member can be reached
// Example: https://10.0.0.1:8443
URL string `json:"url" yaml:"url"`
// Whether the cluster member is a database server
// Example: true
Database bool `json:"database" yaml:"database"`
// Current status
// Example: Online
Status string `json:"status" yaml:"status"`
// Additional status information
// Example: fully operational
Message string `json:"message" yaml:"message"`
// The primary architecture of the cluster member
// Example: x86_64
//
// API extension: clustering_architecture
Architecture string `json:"architecture" yaml:"architecture"`
}
// Writable converts a full Profile struct into a ProfilePut struct (filters read-only fields)
func (member *ClusterMember) Writable() ClusterMemberPut {
return member.ClusterMemberPut
}
// ClusterMemberPut represents the the modifiable fields of a LXD cluster member
//
// swagger:model
//
// API extension: clustering_edit_roles
type ClusterMemberPut struct {
// List of roles held by this cluster member
// Example: ["database"]
//
// API extension: clustering_roles
Roles []string `json:"roles" yaml:"roles"`
// Name of the failure domain for this cluster member
// Example: rack1
//
// API extension: clustering_failure_domains
FailureDomain string `json:"failure_domain" yaml:"failure_domain"`
// Cluster member description
// Example: AMD Epyc 32c/64t
//
// API extension: clustering_description
Description string `json:"description" yaml:"description"`
}
// ClusterCertificatePut represents the certificate and key pair for all members in a LXD Cluster
//
// swagger:model
//
// API extension: clustering_update_certs
type ClusterCertificatePut struct {
// The new certificate (X509 PEM encoded) for the cluster
// Example: X509 PEM certificate
ClusterCertificate string `json:"cluster_certificate" yaml:"cluster_certificate"`
// The new certificate key (X509 PEM encoded) for the cluster
// Example: X509 PEM certificate key
ClusterCertificateKey string `json:"cluster_certificate_key" yaml:"cluster_certificate_key"`
}