-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
node_meta.go
71 lines (58 loc) · 1.78 KB
/
node_meta.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
// NodeMetaApplyRequest contains the Node meta update.
type NodeMetaApplyRequest struct {
NodeID string
Meta map[string]*string
}
// NodeMetaResponse contains the merged Node metadata.
type NodeMetaResponse struct {
// Meta is the merged static + dynamic Node metadata
Meta map[string]string
// Dynamic is the dynamic Node metadata (set via API)
Dynamic map[string]*string
// Static is the static Node metadata (set via agent configuration)
Static map[string]string
}
// NodeMeta is a client for manipulating dynamic Node metadata.
type NodeMeta struct {
client *Client
}
// Meta returns a NodeMeta client.
func (n *Nodes) Meta() *NodeMeta {
return &NodeMeta{client: n.client}
}
// Apply dynamic Node metadata updates to a Node. If NodeID is unset then Node
// receiving the request is modified.
func (n *NodeMeta) Apply(meta *NodeMetaApplyRequest, qo *QueryOptions) (*NodeMetaResponse, error) {
var out NodeMetaResponse
_, err := n.client.postQuery("/v1/client/metadata", meta, &out, qo)
if err != nil {
return nil, err
}
return &out, nil
}
// Read Node metadata (dynamic and static merged) from a Node directly. May
// differ from Node.Info as dynamic Node metadata updates are batched and may
// be delayed up to 10 seconds.
//
// If nodeID is empty then the metadata for the Node receiving the request is
// returned.
func (n *NodeMeta) Read(nodeID string, qo *QueryOptions) (*NodeMetaResponse, error) {
if qo == nil {
qo = &QueryOptions{}
}
if qo.Params == nil {
qo.Params = make(map[string]string)
}
if nodeID != "" {
qo.Params["node_id"] = nodeID
}
var out NodeMetaResponse
_, err := n.client.query("/v1/client/metadata", &out, qo)
if err != nil {
return nil, err
}
return &out, nil
}