-
Notifications
You must be signed in to change notification settings - Fork 17
/
fakeClient.go
322 lines (266 loc) · 10.1 KB
/
fakeClient.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package driver
import (
"context"
"net/http"
"github.com/vultr/govultr/v3"
)
func newFakeClient() *govultr.Client {
fakeInstance := FakeInstance{client: nil}
fakeBlockStorage := fakeBS{client: nil}
return &govultr.Client{
Instance: &fakeInstance,
BlockStorage: &fakeBlockStorage,
}
}
func newFakeBS() *govultr.BlockStorage {
return &govultr.BlockStorage{
ID: "c56c7b6e-15c2-445e-9a5d-1063ab5828ec",
DateCreated: "",
Cost: 10,
Status: "active",
SizeGB: 10,
Region: "ewr",
AttachedToInstance: "245bb2fe-b55c-44a0-9a1e-ab80e4b5f088",
Label: "test-bs",
MountID: "c56c7b6e-15c2-445e-9a5d-1063ab5828ec",
}
}
type fakeBS struct {
client *govultr.Client
}
func (f *fakeBS) Create(ctx context.Context, blockReq *govultr.BlockStorageCreate) (*govultr.BlockStorage, *http.Response, error) {
return newFakeBS(), nil, nil
}
func (f *fakeBS) Get(ctx context.Context, blockID string) (*govultr.BlockStorage, *http.Response, error) {
return newFakeBS(), nil, nil
}
func (f *fakeBS) Update(ctx context.Context, blockID string, blockReq *govultr.BlockStorageUpdate) error {
panic("implement me")
}
func (f *fakeBS) Delete(ctx context.Context, blockID string) error {
return nil
}
func (f *fakeBS) List(ctx context.Context, options *govultr.ListOptions) ([]govultr.BlockStorage, *govultr.Meta, *http.Response, error) {
return []govultr.BlockStorage{
{
ID: "c56c7b6e-15c2-445e-9a5d-1063ab5828ec",
DateCreated: "",
Cost: 10,
Status: "active",
SizeGB: 10,
Region: "ewr",
AttachedToInstance: "245bb2fe-b55c-44a0-9a1e-ab80e4b5f088",
Label: "test-bs",
MountID: "c56c7b6e-15c2-445e-9a5d-1063ab5828ec",
},
{
ID: "bda4f333-bfd7-477b-84c2-e4df0ec9e5bf",
DateCreated: "",
Cost: 20,
Status: "active",
SizeGB: 20,
Region: "ewr",
AttachedToInstance: "b9d23eb3-1880-4746-acc7-f1ef56565320",
Label: "test-bs2",
MountID: "b9d23eb3-1880-4746-acc7-f1ef56565320",
},
}, &govultr.Meta{
Total: 0,
Links: &govultr.Links{
Next: "",
Prev: "",
},
}, nil, nil
}
func (f *fakeBS) Attach(ctx context.Context, blockID string, attach *govultr.BlockStorageAttach) error {
panic("implement me")
}
func (f *fakeBS) Detach(ctx context.Context, blockID string, detach *govultr.BlockStorageDetach) error {
list, _, _, err := f.List(ctx, nil) //nolint:bodyclose
if err != nil {
return err
}
for i := range list {
if list[i].ID == blockID {
list[i].AttachedToInstance = ""
}
}
return nil
}
// FakeInstance returns the client
type FakeInstance struct {
client *govultr.Client
}
// Create is not implemented
func (f *FakeInstance) Create(ctx context.Context, instanceReq *govultr.InstanceCreateReq) (*govultr.Instance, *http.Response, error) {
panic("implement me")
}
// Get returns an instance struct
func (f *FakeInstance) Get(ctx context.Context, instanceID string) (*govultr.Instance, *http.Response, error) {
return &govultr.Instance{
ID: "94cf529e-796c-44c0-8a18-6e0be753f155",
MainIP: "149.28.225.110",
VCPUCount: 4,
Region: "ewr",
Status: "running",
NetmaskV4: "255.255.254.0",
GatewayV4: "149.28.224.1",
PowerStatus: "",
ServerStatus: "",
Plan: "vc2-4c-8gb",
Label: "csi-test",
InternalIP: "10.1.95.4",
}, nil, nil
}
// Update updates and instance
func (f *FakeInstance) Update(_ context.Context, _ string, _ *govultr.InstanceUpdateReq) (*govultr.Instance, *http.Response, error) {
panic("implement me")
}
// Delete jis not implemented
func (f *FakeInstance) Delete(ctx context.Context, instanceID string) error {
panic("implement me")
}
// List is not implemented
func (f *FakeInstance) List(ctx context.Context, options *govultr.ListOptions) ([]govultr.Instance, *govultr.Meta, *http.Response, error) {
panic("implement me")
}
// Start is not implemented
func (f *FakeInstance) Start(ctx context.Context, instanceID string) error {
panic("implement me")
}
// Halt is not implemented
func (f *FakeInstance) Halt(ctx context.Context, instanceID string) error {
panic("implement me")
}
// Reboot is not implemented
func (f *FakeInstance) Reboot(ctx context.Context, instanceID string) error {
panic("implement me")
}
// Reinstall reinstalls an instance
func (f *FakeInstance) Reinstall(_ context.Context, _ string, _ *govultr.ReinstallReq) (*govultr.Instance, *http.Response, error) {
panic("implement me")
}
// MassStart is not implemented
func (f *FakeInstance) MassStart(ctx context.Context, instanceList []string) error {
panic("implement me")
}
// MassHalt is not implemented
func (f *FakeInstance) MassHalt(ctx context.Context, instanceList []string) error {
panic("implement me")
}
// MassReboot is not implemented
func (f *FakeInstance) MassReboot(ctx context.Context, instanceList []string) error {
panic("implement me")
}
// Restore restores an instance
func (f *FakeInstance) Restore(_ context.Context, _ string, _ *govultr.RestoreReq) (*http.Response, error) {
panic("implement me")
}
// GetBandwidth gets bandwidth for an instance
func (f *FakeInstance) GetBandwidth(_ context.Context, _ string) (*govultr.Bandwidth, *http.Response, error) {
panic("implement me")
}
// GetNeighbors gets neighors for an instance
func (f *FakeInstance) GetNeighbors(_ context.Context, _ string) (*govultr.Neighbors, *http.Response, error) {
panic("implement me")
}
// ListPrivateNetworks gets private networks
func (f *FakeInstance) ListPrivateNetworks(_ context.Context, _ string, _ *govultr.ListOptions) ([]govultr.PrivateNetwork, *govultr.Meta, *http.Response, error) { //nolint:lll
panic("implement me")
}
// AttachPrivateNetwork attches private networks
func (f *FakeInstance) AttachPrivateNetwork(_ context.Context, _, _ string) error {
panic("implement me")
}
// DetachPrivateNetwork detaches private network from instance
func (f *FakeInstance) DetachPrivateNetwork(_ context.Context, _, _ string) error {
panic("implement me")
}
// ListVPCInfo is not implemented
func (f *FakeInstance) ListVPCInfo(ctx context.Context, instanceID string, options *govultr.ListOptions) ([]govultr.VPCInfo, *govultr.Meta, *http.Response, error) { //nolint:lll
panic("implement me")
}
// AttachVPC is not implemented
func (f *FakeInstance) AttachVPC(ctx context.Context, instanceID, networkID string) error {
panic("implement me")
}
// DetachVPC is not implemented
func (f *FakeInstance) DetachVPC(ctx context.Context, instanceID, networkID string) error {
panic("implement me")
}
// ListVPC2Info is not implemented
func (f *FakeInstance) ListVPC2Info(ctx context.Context, instanceID string, options *govultr.ListOptions) ([]govultr.VPC2Info, *govultr.Meta, *http.Response, error) { //nolint:lll
panic("implement me")
}
// AttachVPC2 is not implemented
func (f *FakeInstance) AttachVPC2(ctx context.Context, instanceID string, vpc2Req *govultr.AttachVPC2Req) error {
panic("implement me")
}
// DetachVPC2 is not implemented
func (f *FakeInstance) DetachVPC2(ctx context.Context, instanceID, vpcID string) error {
panic("implement me")
}
// ISOStatus gets ISO status from instance
func (f *FakeInstance) ISOStatus(_ context.Context, _ string) (*govultr.Iso, *http.Response, error) {
panic("implement me")
}
// AttachISO attaches ISO to instance
func (f *FakeInstance) AttachISO(_ context.Context, _, _ string) (*http.Response, error) {
panic("implement me")
}
// DetachISO detaches ISO from instance
func (f *FakeInstance) DetachISO(_ context.Context, _ string) (*http.Response, error) {
panic("implement me")
}
// GetBackupSchedule gets instance backup stchedule
func (f *FakeInstance) GetBackupSchedule(_ context.Context, _ string) (*govultr.BackupSchedule, *http.Response, error) {
panic("implement me")
}
// SetBackupSchedule sets instance backup schedule
func (f *FakeInstance) SetBackupSchedule(_ context.Context, _ string, _ *govultr.BackupScheduleReq) (*http.Response, error) {
panic("implement me")
}
// CreateIPv4 creates an IPv4 association to instance
func (f *FakeInstance) CreateIPv4(_ context.Context, _ string, _ *bool) (*govultr.IPv4, *http.Response, error) {
panic("implement me")
}
// ListIPv4 gets IPv4 addresses associated with instance
func (f *FakeInstance) ListIPv4(_ context.Context, _ string, _ *govultr.ListOptions) ([]govultr.IPv4, *govultr.Meta, *http.Response, error) { //nolint:lll
panic("implement me")
}
// DeleteIPv4 is not implemented
func (f *FakeInstance) DeleteIPv4(ctx context.Context, instanceID, ip string) error {
panic("implement me")
}
// ListIPv6 lists IPv6 addresses associated with instance
func (f *FakeInstance) ListIPv6(_ context.Context, _ string, _ *govultr.ListOptions) ([]govultr.IPv6, *govultr.Meta, *http.Response, error) { //nolint:lll
panic("implement me")
}
// CreateReverseIPv6 is not implemented
func (f *FakeInstance) CreateReverseIPv6(ctx context.Context, instanceID string, reverseReq *govultr.ReverseIP) error {
panic("implement me")
}
// ListReverseIPv6 gets reverse IP for IPv6 on instance
func (f *FakeInstance) ListReverseIPv6(_ context.Context, _ string) ([]govultr.ReverseIP, *http.Response, error) {
panic("implement me")
}
// DeleteReverseIPv6 is not implemented
func (f *FakeInstance) DeleteReverseIPv6(ctx context.Context, instanceID, ip string) error {
panic("implement me")
}
// CreateReverseIPv4 is not implemented
func (f *FakeInstance) CreateReverseIPv4(ctx context.Context, instanceID string, reverseReq *govultr.ReverseIP) error {
panic("implement me")
}
// DefaultReverseIPv4 is not implemented
func (f *FakeInstance) DefaultReverseIPv4(ctx context.Context, instanceID, ip string) error {
panic("implement me")
}
// GetUserData returns instance userdata
func (f *FakeInstance) GetUserData(_ context.Context, _ string) (*govultr.UserData, *http.Response, error) {
panic("implement me")
}
// GetUpgrades gets instance upgade
func (f *FakeInstance) GetUpgrades(_ context.Context, _ string) (*govultr.Upgrades, *http.Response, error) {
panic("implement me")
}