Debian Codegraph @

client/node.go

raw
1 // Copyright (C) LINBIT HA-Solutions GmbH
2 // All Rights Reserved.
3 // Author: Roland Kammerer <[email protected]>
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License"); you may
6 // not use this file except in compliance with the License. You may obtain
7 // a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 // License for the specific language governing permissions and limitations
15 // under the License.
16
17 package client
18
19 import (
20 "context"
21 "net"
22
23 "github.com/LINBIT/golinstor/devicelayerkind"
24 )
25
26 // copy & paste from generated code
27
28 // Node represents a node in LINSTOR
29 type Node struct {
30 Name string `json:"name"`
31 Type string `json:"type"`
32 Flags []string `json:"flags,omitempty"`
33 // A string to string property map.
34 Props map[string]string `json:"props,omitempty"`
35 NetInterfaces []NetInterface `json:"net_interfaces,omitempty"`
36 // Enum describing the current connection status.
37 ConnectionStatus string `json:"connection_status,omitempty"`
38 // unique object id
39 Uuid string `json:"uuid,omitempty"`
40 StorageProviders []ProviderKind `json:"storage_providers,omitempty"`
41 ResourceLayers []devicelayerkind.DeviceLayerKind `json:"resource_layers,omitempty"`
42 UnsupportedProviders map[ProviderKind][]string `json:"unsupported_providers,omitempty"`
43 UnsupportedLayers map[devicelayerkind.DeviceLayerKind][]string `json:"unsupported_layers,omitempty"`
44 // milliseconds since unix epoch in UTC
45 EvictionTimestamp *TimeStampMs `json:"eviction_timestamp,omitempty"`
46 }
47
48 type NodeModify struct {
49 NodeType string `json:"node_type,omitempty"`
50 // A string to string property map.
51 GenericPropsModify
52 }
53
54 type NodeRestore struct {
55 DeleteResources *bool `json:"delete_resources,omitempty"`
56 DeleteSnapshots *bool `json:"delete_snapshots,omitempty"`
57 }
58
59 type NodeEvacuate struct {
60 Target []string `json:"target,omitempty"`
61 DoNotTarget []string `json:"do_not_target,omitempty"`
62 }
63
64 // NetInterface represents a node's network interface.
65 type NetInterface struct {
66 Name string `json:"name"`
67 Address net.IP `json:"address"`
68 SatellitePort int32 `json:"satellite_port,omitempty"`
69 SatelliteEncryptionType string `json:"satellite_encryption_type,omitempty"`
70 // Defines if this netinterface should be used for the satellite connection
71 IsActive bool `json:"is_active,omitempty"`
72 // unique object id
73 Uuid string `json:"uuid,omitempty"`
74 }
75
76 // StoragePool represents a nodes storage pool as defined in LINSTOR.
77 type StoragePool struct {
78 StoragePoolName string `json:"storage_pool_name"`
79 NodeName string `json:"node_name,omitempty"`
80 ProviderKind ProviderKind `json:"provider_kind"`
81 // A string to string property map.
82 Props map[string]string `json:"props,omitempty"`
83 // read only map of static storage pool traits
84 StaticTraits map[string]string `json:"static_traits,omitempty"`
85 // Kibi - read only
86 FreeCapacity int64 `json:"free_capacity,omitempty"`
87 // Kibi - read only
88 TotalCapacity int64 `json:"total_capacity,omitempty"`
89 // read only
90 FreeSpaceMgrName string `json:"free_space_mgr_name,omitempty"`
91 // unique object id
92 Uuid string `json:"uuid,omitempty"`
93 // Currently known report messages for this storage pool
94 Reports []ApiCallRc `json:"reports,omitempty"`
95 // true if the storage pool supports snapshots. false otherwise
96 SupportsSnapshots bool `json:"supports_snapshots,omitempty"`
97 // name of the shared space or null if none given
98 SharedSpace string `json:"shared_space,omitempty"`
99 // true if a shared storage pool uses linstor-external locking, like cLVM
100 ExternalLocking bool `json:"external_locking,omitempty"`
101 }
102
103 // ProviderKind is a type that represents various types of storage.
104 type ProviderKind string
105
106 // List of ProviderKind
107 const (
108 DISKLESS ProviderKind = "DISKLESS"
109 LVM ProviderKind = "LVM"
110 LVM_THIN ProviderKind = "LVM_THIN"
111 ZFS ProviderKind = "ZFS"
112 ZFS_THIN ProviderKind = "ZFS_THIN"
113 FILE ProviderKind = "FILE"
114 FILE_THIN ProviderKind = "FILE_THIN"
115 SPDK ProviderKind = "SPDK"
116 EBS_TARGET ProviderKind = "EBS_TARGET"
117 EBS_INIT ProviderKind = "EBS_INIT"
118 )
119
120 // custom code
121
122 // NodeProvider acts as an abstraction for a NodeService. It can be swapped out
123 // for another NodeService implementation, for example for testing.
124 type NodeProvider interface {
125 // GetAll gets information for all registered nodes.
126 GetAll(ctx context.Context, opts ...*ListOpts) ([]Node, error)
127 // Get gets information for a particular node.
128 Get(ctx context.Context, nodeName string, opts ...*ListOpts) (Node, error)
129 // Create creates a new node object.
130 Create(ctx context.Context, node Node) error
131 // CreateEbsNode creates a special virtual satellite for interacting with EBS.
132 CreateEbsNode(ctx context.Context, name string, remoteName string) error
133 // Modify modifies the given node and sets/deletes the given properties.
134 Modify(ctx context.Context, nodeName string, props NodeModify) error
135 // Delete deletes the given node.
136 Delete(ctx context.Context, nodeName string) error
137 // Lost marks the given node as lost to delete an unrecoverable node.
138 Lost(ctx context.Context, nodeName string) error
139 // Reconnect reconnects a node to the controller.
140 Reconnect(ctx context.Context, nodeName string) error
141 // GetNetInterfaces gets information about all network interfaces of a given node.
142 GetNetInterfaces(ctx context.Context, nodeName string, opts ...*ListOpts) ([]NetInterface, error)
143 // GetNetInterface gets information about a particular network interface on a given node.
144 GetNetInterface(ctx context.Context, nodeName, nifName string, opts ...*ListOpts) (NetInterface, error)
145 // CreateNetInterface creates the given network interface on a given node.
146 CreateNetInterface(ctx context.Context, nodeName string, nif NetInterface) error
147 // ModifyNetInterface modifies the given network interface on a given node.
148 ModifyNetInterface(ctx context.Context, nodeName, nifName string, nif NetInterface) error
149 // DeleteNetinterface deletes the given network interface on a given node.
150 DeleteNetinterface(ctx context.Context, nodeName, nifName string) error
151 // GetStoragePoolView gets information about all storage pools in the cluster.
152 GetStoragePoolView(ctx context.Context, opts ...*ListOpts) ([]StoragePool, error)
153 // GetStoragePools gets information about all storage pools on a given node.
154 GetStoragePools(ctx context.Context, nodeName string, opts ...*ListOpts) ([]StoragePool, error)
155 // GetStoragePool gets information about a specific storage pool on a given node.
156 GetStoragePool(ctx context.Context, nodeName, spName string, opts ...*ListOpts) (StoragePool, error)
157 // CreateStoragePool creates a storage pool on a given node.
158 CreateStoragePool(ctx context.Context, nodeName string, sp StoragePool) error
159 // ModifyStoragePool modifies a storage pool on a given node.
160 ModifyStoragePool(ctx context.Context, nodeName, spName string, genericProps GenericPropsModify) error
161 // DeleteStoragePool deletes a storage pool on a given node.
162 DeleteStoragePool(ctx context.Context, nodeName, spName string) error
163 // CreateDevicePool creates an LVM, LVM-thin or ZFS pool, optional VDO under it on a given node.
164 CreateDevicePool(ctx context.Context, nodeName string, psc PhysicalStorageCreate) error
165 // GetPhysicalStorageView gets a grouped list of physical storage that can be turned into a LINSTOR storage-pool
166 GetPhysicalStorageView(ctx context.Context, opts ...*ListOpts) ([]PhysicalStorageViewItem, error)
167 // GetPhysicalStorage gets a list of unconfigured physical storage on a node.
168 GetPhysicalStorage(ctx context.Context, nodeName string) ([]PhysicalStorageNode, error)
169 // GetStoragePoolPropsInfos gets meta information about the properties
170 // that can be set on a storage pool on a particular node.
171 GetStoragePoolPropsInfos(ctx context.Context, nodeName string, opts ...*ListOpts) ([]PropsInfo, error)
172 // GetPropsInfos gets meta information about the properties that can be
173 // set on a node.
174 GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error)
175 // Evict the given node, migrating resources to the remaining nodes, if possible. This is meant for offline nodes.
176 Evict(ctx context.Context, nodeName string) error
177 // Restore an evicted node, optionally keeping existing resources.
178 Restore(ctx context.Context, nodeName string, restore NodeRestore) error
179 // Evacuate the given node, migrating resources to remaining nodes. While Evict works only on offline nodes, this
180 // is meant for online nodes.
181 Evacuate(ctx context.Context, nodeName string, evacuate NodeEvacuate) error
182 }
183
184 // NodeService is the service that deals with node related tasks.
185 type NodeService struct {
186 client *Client
187 }
188
189 var _ NodeProvider = &NodeService{}
190
191 // GetAll gets information for all registered nodes.
192 func (n *NodeService) GetAll(ctx context.Context, opts ...*ListOpts) ([]Node, error) {
193 var nodes []Node
194 _, err := n.client.doGET(ctx, "/v1/nodes", &nodes, opts...)
195 return nodes, err
196 }
197
198 // Get gets information for a particular node.
199 func (n *NodeService) Get(ctx context.Context, nodeName string, opts ...*ListOpts) (Node, error) {
200 var node Node
201 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName, &node, opts...)
202 return node, err
203 }
204
205 // Create creates a new node object.
206 func (n *NodeService) Create(ctx context.Context, node Node) error {
207 _, err := n.client.doPOST(ctx, "/v1/nodes", node)
208 return err
209 }
210
211 func (n *NodeService) CreateEbsNode(ctx context.Context, name, remoteName string) error {
212 _, err := n.client.doPOST(ctx, "/v1/nodes/ebs", struct {
213 Name string `json:"name"`
214 EbsRemoteName string `json:"ebs_remote_name"`
215 }{
216 Name: name,
217 EbsRemoteName: remoteName,
218 })
219 return err
220 }
221
222 // Modify modifies the given node and sets/deletes the given properties.
223 func (n *NodeService) Modify(ctx context.Context, nodeName string, props NodeModify) error {
224 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName, props)
225 return err
226 }
227
228 // Delete deletes the given node.
229 func (n *NodeService) Delete(ctx context.Context, nodeName string) error {
230 _, err := n.client.doDELETE(ctx, "/v1/nodes/"+nodeName, nil)
231 return err
232 }
233
234 // Lost marks the given node as lost to delete an unrecoverable node.
235 func (n *NodeService) Lost(ctx context.Context, nodeName string) error {
236 _, err := n.client.doDELETE(ctx, "/v1/nodes/"+nodeName+"/lost", nil)
237 return err
238 }
239
240 // Reconnect reconnects a node to the controller.
241 func (n *NodeService) Reconnect(ctx context.Context, nodeName string) error {
242 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/reconnect", nil)
243 return err
244 }
245
246 // GetNetInterfaces gets information about all network interfaces of a given node.
247 func (n *NodeService) GetNetInterfaces(ctx context.Context, nodeName string, opts ...*ListOpts) ([]NetInterface, error) {
248 var nifs []NetInterface
249 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName+"/net-interfaces", &nifs, opts...)
250 return nifs, err
251 }
252
253 // GetNetInterface gets information about a particular network interface on a given node.
254 func (n *NodeService) GetNetInterface(ctx context.Context, nodeName, nifName string, opts ...*ListOpts) (NetInterface, error) {
255 var nif NetInterface
256 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName+"/net-interfaces/"+nifName, &nif, opts...)
257 return nif, err
258 }
259
260 // CreateNetInterface creates the given network interface on a given node.
261 func (n *NodeService) CreateNetInterface(ctx context.Context, nodeName string, nif NetInterface) error {
262 _, err := n.client.doPOST(ctx, "/v1/nodes/"+nodeName+"/net-interfaces", nif)
263 return err
264 }
265
266 // ModifyNetInterface modifies the given network interface on a given node.
267 func (n *NodeService) ModifyNetInterface(ctx context.Context, nodeName, nifName string, nif NetInterface) error {
268 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/net-interfaces/"+nifName, nif)
269 return err
270 }
271
272 // DeleteNetinterface deletes the given network interface on a given node.
273 func (n *NodeService) DeleteNetinterface(ctx context.Context, nodeName, nifName string) error {
274 _, err := n.client.doDELETE(ctx, "/v1/nodes/"+nodeName+"/net-interfaces/"+nifName, nil)
275 return err
276 }
277
278 // GetStoragePoolView gets information about all storage pools in the cluster.
279 func (n *NodeService) GetStoragePoolView(ctx context.Context, opts ...*ListOpts) ([]StoragePool, error) {
280 var sps []StoragePool
281 _, err := n.client.doGET(ctx, "/v1/view/storage-pools", &sps, opts...)
282 return sps, err
283 }
284
285 // GetStoragePools gets information about all storage pools on a given node.
286 func (n *NodeService) GetStoragePools(ctx context.Context, nodeName string, opts ...*ListOpts) ([]StoragePool, error) {
287 var sps []StoragePool
288 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName+"/storage-pools", &sps, opts...)
289 return sps, err
290 }
291
292 // GetStoragePool gets information about a specific storage pool on a given node.
293 func (n *NodeService) GetStoragePool(ctx context.Context, nodeName, spName string, opts ...*ListOpts) (StoragePool, error) {
294 var sp StoragePool
295 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName+"/storage-pools/"+spName, &sp, opts...)
296 return sp, err
297 }
298
299 // CreateStoragePool creates a storage pool on a given node.
300 func (n *NodeService) CreateStoragePool(ctx context.Context, nodeName string, sp StoragePool) error {
301 _, err := n.client.doPOST(ctx, "/v1/nodes/"+nodeName+"/storage-pools", sp)
302 return err
303 }
304
305 // ModifyStoragePool modifies a storage pool on a given node.
306 func (n *NodeService) ModifyStoragePool(ctx context.Context, nodeName, spName string, genericProps GenericPropsModify) error {
307 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/storage-pools/"+spName, genericProps)
308 return err
309 }
310
311 // DeleteStoragePool deletes a storage pool on a given node.
312 func (n *NodeService) DeleteStoragePool(ctx context.Context, nodeName, spName string) error {
313 _, err := n.client.doDELETE(ctx, "/v1/nodes/"+nodeName+"/storage-pools/"+spName, nil)
314 return err
315 }
316
317 // GetStoragePoolPropsInfos gets meta information about the properties that can
318 // be set on a storage pool on a particular node.
319 func (n *NodeService) GetStoragePoolPropsInfos(ctx context.Context, nodeName string, opts ...*ListOpts) ([]PropsInfo, error) {
320 var infos []PropsInfo
321 _, err := n.client.doGET(ctx, "/v1/nodes/"+nodeName+"/storage-pools/properties/info", &infos, opts...)
322 return infos, err
323 }
324
325 // GetPropsInfos gets meta information about the properties that can be set on
326 // a node.
327 func (n *NodeService) GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error) {
328 var infos []PropsInfo
329 _, err := n.client.doGET(ctx, "/v1/nodes/properties/info", &infos, opts...)
330 return infos, err
331 }
332
333 // Evict the given node, migrating resources to the remaining nodes, if possible.
334 func (n NodeService) Evict(ctx context.Context, nodeName string) error {
335 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/evict", nil)
336 return err
337 }
338
339 // Evacuate the given node, migrating resources to remaining nodes. While Evict works only on offline nodes, this
340 // is meant for online nodes.
341 func (n NodeService) Evacuate(ctx context.Context, nodeName string, evacuate NodeEvacuate) error {
342 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/evacuate", evacuate)
343 return err
344 }
345
346 // Restore an evicted node, optionally keeping existing resources.
347 func (n *NodeService) Restore(ctx context.Context, nodeName string, restore NodeRestore) error {
348 _, err := n.client.doPUT(ctx, "/v1/nodes/"+nodeName+"/restore", restore)
349 return err
350 }