forked from rexray/gocsi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.go
163 lines (136 loc) · 3.34 KB
/
node.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
package gocsi
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"github.com/codedellemc/gocsi/csi"
)
const (
// FMGetNodeID is the full method name for the
// eponymous RPC message.
FMGetNodeID = "/" + Namespace +
".Node/" +
"GetNodeID"
// FMNodePublishVolume is the full method name for the
// eponymous RPC message.
FMNodePublishVolume = "/" + Namespace +
".Node/" +
"NodePublishVolume"
// FMNodeUnpublishVolume is the full method name for the
// eponymous RPC message.
FMNodeUnpublishVolume = "/" + Namespace +
".Node/" +
"NodeUnpublishVolume"
// FMProbeNode is the full method name for the
// eponymous RPC message.
FMProbeNode = "/" + Namespace +
".Node/" +
"ProbeNode"
// FMNodeGetCapabilities is the full method name for the
// eponymous RPC message.
FMNodeGetCapabilities = "/" + Namespace +
".Node/" +
"NodeGetCapabilities"
)
// GetNodeID issues a
// GetNodeID request
// to a CSI controller.
func GetNodeID(
ctx context.Context,
c csi.NodeClient,
version *csi.Version,
callOpts ...grpc.CallOption) (*csi.NodeID, error) {
req := &csi.GetNodeIDRequest{
Version: version,
}
res, err := c.GetNodeID(ctx, req, callOpts...)
if err != nil {
return nil, err
}
return res.GetResult().NodeId, nil
}
// NodePublishVolume issues a
// NodePublishVolume request
// to a CSI controller.
func NodePublishVolume(
ctx context.Context,
c csi.NodeClient,
version *csi.Version,
volumeID *csi.VolumeID,
volumeMetadata *csi.VolumeMetadata,
publishVolumeInfo *csi.PublishVolumeInfo,
targetPath string,
volumeCapability *csi.VolumeCapability,
readonly bool,
callOpts ...grpc.CallOption) error {
req := &csi.NodePublishVolumeRequest{
Version: version,
VolumeId: volumeID,
VolumeMetadata: volumeMetadata,
PublishVolumeInfo: publishVolumeInfo,
TargetPath: targetPath,
VolumeCapability: volumeCapability,
Readonly: readonly,
}
_, err := c.NodePublishVolume(ctx, req, callOpts...)
if err != nil {
return err
}
return nil
}
// NodeUnpublishVolume issues a
// NodeUnpublishVolume request
// to a CSI controller.
func NodeUnpublishVolume(
ctx context.Context,
c csi.NodeClient,
version *csi.Version,
volumeID *csi.VolumeID,
volumeMetadata *csi.VolumeMetadata,
targetPath string,
callOpts ...grpc.CallOption) error {
req := &csi.NodeUnpublishVolumeRequest{
Version: version,
VolumeId: volumeID,
VolumeMetadata: volumeMetadata,
TargetPath: targetPath,
}
_, err := c.NodeUnpublishVolume(ctx, req, callOpts...)
if err != nil {
return err
}
return nil
}
// ProbeNode issues a
// ProbeNode request
// to a CSI controller.
func ProbeNode(
ctx context.Context,
c csi.NodeClient,
version *csi.Version,
callOpts ...grpc.CallOption) error {
req := &csi.ProbeNodeRequest{
Version: version,
}
_, err := c.ProbeNode(ctx, req, callOpts...)
if err != nil {
return err
}
return nil
}
// NodeGetCapabilities issues a NodeGetCapabilities request to a
// CSI controller.
func NodeGetCapabilities(
ctx context.Context,
c csi.NodeClient,
version *csi.Version,
callOpts ...grpc.CallOption) (
capabilties []*csi.NodeServiceCapability, err error) {
req := &csi.NodeGetCapabilitiesRequest{
Version: version,
}
res, err := c.NodeGetCapabilities(ctx, req, callOpts...)
if err != nil {
return nil, err
}
return res.GetResult().Capabilities, nil
}