~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/goose.v1/cinder/autogenerated_client.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the LGPLv3, see LICENCE file for details.
 
3
 
 
4
// This file was initially autogenerated from the upstream wadl file, but has
 
5
// since been updated by hand.
 
6
// The WADLs were originally sourced from:
 
7
// https://github.com/openstack/api-site/tree/master/api-ref/src/wadls/volume-api/src/v2
 
8
 
 
9
package cinder
 
10
 
 
11
import (
 
12
        "bytes"
 
13
        "encoding/json"
 
14
        "fmt"
 
15
        "io/ioutil"
 
16
        "net/http"
 
17
        "net/url"
 
18
)
 
19
 
 
20
// RequestHandlerFn specifies a function signature which wadl2go will
 
21
// use to process the http.Request. What this means is up to the
 
22
// implementor.
 
23
type RequestHandlerFn func(*http.Request) (*http.Response, error)
 
24
 
 
25
type UpdateVolumeTypeParams struct {
 
26
 
 
27
        // VolumeType is required.
 
28
        //
 
29
        // A volume type offers a way to categorize or group volumes.
 
30
        VolumeType string `json:"volume_type"`
 
31
 
 
32
        //
 
33
        // The unique identifier of the tenant or account.
 
34
        TenantId string `json:"-"`
 
35
 
 
36
        // VolumeTypeId is required.
 
37
        //
 
38
        // The unique identifier for an existing volume type.
 
39
        VolumeTypeId string `json:"-"`
 
40
}
 
41
 
 
42
type VolumeType struct {
 
43
        ExtraSpecs struct {
 
44
                Capabilities string `json:"capabilities"`
 
45
        } `json:"extra_specs"`
 
46
        ID   string `json:"id"`
 
47
        Name string `json:"name"`
 
48
}
 
49
 
 
50
type UpdateVolumeTypeResults struct {
 
51
        VolumeType VolumeType `json:"volume_type"`
 
52
}
 
53
 
 
54
//
 
55
// Updates a volume type.
 
56
func updateVolumeType(client *Client, args UpdateVolumeTypeParams) (*UpdateVolumeTypeResults, error) {
 
57
 
 
58
        argsAsJson, err := json.Marshal(args)
 
59
        if err != nil {
 
60
                return nil, err
 
61
        }
 
62
 
 
63
        urlPath := url.URL{Path: fmt.Sprintf("types/%s", args.VolumeTypeId)}
 
64
        url := client.endpoint.ResolveReference(&urlPath).String()
 
65
 
 
66
        var req *http.Request
 
67
        if string(argsAsJson) != "{}" {
 
68
                req, err = http.NewRequest("PUT", url, bytes.NewBuffer(argsAsJson))
 
69
                if err != nil {
 
70
                        return nil, err
 
71
                }
 
72
                req.Header.Set("Content-Type", "application/json")
 
73
        } else {
 
74
                req, err = http.NewRequest("PUT", url, nil)
 
75
                if err != nil {
 
76
                        return nil, err
 
77
                }
 
78
        }
 
79
 
 
80
        resp, err := client.handleRequest(req)
 
81
        if err != nil {
 
82
                return nil, err
 
83
        }
 
84
 
 
85
        body, err := ioutil.ReadAll(resp.Body)
 
86
        if err != nil {
 
87
                return nil, err
 
88
        }
 
89
 
 
90
        switch resp.StatusCode {
 
91
        default:
 
92
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
93
        case 200:
 
94
                break
 
95
        }
 
96
 
 
97
        var results UpdateVolumeTypeResults
 
98
        json.Unmarshal(body, &results)
 
99
 
 
100
        return &results, nil
 
101
}
 
102
 
 
103
type UpdateVolumeTypeExtraSpecsParams struct {
 
104
 
 
105
        // VolumeType is required.
 
106
        //
 
107
        // A volume type offers a way to categorize or group volumes.
 
108
        VolumeType string `json:"volume_type"`
 
109
 
 
110
        // ExtraSpecs is required.
 
111
        //
 
112
        // A key:value pair that offers a way to show additional specifications associated with the volume type. Examples include capabilities, capacity, compression, and so on, depending on the storage driver in use.
 
113
        ExtraSpecs string `json:"extra_specs"`
 
114
 
 
115
        //
 
116
        // The unique identifier of the tenant or account.
 
117
        TenantId string `json:"-"`
 
118
 
 
119
        // VolumeTypeId is required.
 
120
        //
 
121
        // The unique identifier for an existing volume type.
 
122
        VolumeTypeId string `json:"-"`
 
123
}
 
124
 
 
125
type UpdateVolumeTypeExtraSpecsResults struct {
 
126
        VolumeType VolumeType `json:"volume_type"`
 
127
}
 
128
 
 
129
//
 
130
// Updates the extra specifications assigned to a volume type.
 
131
func updateVolumeTypeExtraSpecs(client *Client, args UpdateVolumeTypeExtraSpecsParams) (*UpdateVolumeTypeExtraSpecsResults, error) {
 
132
 
 
133
        argsAsJson, err := json.Marshal(args)
 
134
        if err != nil {
 
135
                return nil, err
 
136
        }
 
137
 
 
138
        urlPath := url.URL{Path: fmt.Sprintf("types/%s", args.VolumeTypeId)}
 
139
        url := client.endpoint.ResolveReference(&urlPath).String()
 
140
 
 
141
        var req *http.Request
 
142
        if string(argsAsJson) != "{}" {
 
143
                req, err = http.NewRequest("PUT", url, bytes.NewBuffer(argsAsJson))
 
144
                if err != nil {
 
145
                        return nil, err
 
146
                }
 
147
                req.Header.Set("Content-Type", "application/json")
 
148
        } else {
 
149
                req, err = http.NewRequest("PUT", url, nil)
 
150
                if err != nil {
 
151
                        return nil, err
 
152
                }
 
153
        }
 
154
 
 
155
        resp, err := client.handleRequest(req)
 
156
        if err != nil {
 
157
                return nil, err
 
158
        }
 
159
 
 
160
        body, err := ioutil.ReadAll(resp.Body)
 
161
        if err != nil {
 
162
                return nil, err
 
163
        }
 
164
 
 
165
        switch resp.StatusCode {
 
166
        default:
 
167
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
168
        case 200:
 
169
                break
 
170
        }
 
171
 
 
172
        var results UpdateVolumeTypeExtraSpecsResults
 
173
        json.Unmarshal(body, &results)
 
174
 
 
175
        return &results, nil
 
176
}
 
177
 
 
178
type GetSnapshotsSimpleParams struct {
 
179
 
 
180
        //
 
181
        // The unique identifier of the tenant or account.
 
182
        TenantId string `json:"-"`
 
183
}
 
184
 
 
185
type Snapshot struct {
 
186
        CreatedAt   string `json:"created_at"`
 
187
        Description string `json:"description"`
 
188
        ID          string `json:"id"`
 
189
        Metadata    struct {
 
190
                Key string `json:"key"`
 
191
        } `json:"metadata"`
 
192
        Name                                      string `json:"name"`
 
193
        Size                                      int    `json:"size"`
 
194
        Status                                    string `json:"status"`
 
195
        VolumeID                                  string `json:"volume_id"`
 
196
        Os_Extended_Snapshot_Attributes_Progress  string `json:"os-extended-snapshot-attributes:progress"`
 
197
        Os_Extended_Snapshot_Attributes_ProjectID string `json:"os-extended-snapshot-attributes:project_id"`
 
198
}
 
199
 
 
200
type GetSnapshotsSimpleResults struct {
 
201
        Snapshots []Snapshot `json:"snapshots"`
 
202
}
 
203
 
 
204
//
 
205
// Lists summary information for all Block Storage snapshots that the tenant who submits the request can access.
 
206
func getSnapshotsSimple(client *Client, args GetSnapshotsSimpleParams) (*GetSnapshotsSimpleResults, error) {
 
207
 
 
208
        argsAsJson, err := json.Marshal(args)
 
209
        if err != nil {
 
210
                return nil, err
 
211
        }
 
212
 
 
213
        urlPath := url.URL{Path: "snapshots"}
 
214
        url := client.endpoint.ResolveReference(&urlPath).String()
 
215
 
 
216
        var req *http.Request
 
217
        if string(argsAsJson) != "{}" {
 
218
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
219
                if err != nil {
 
220
                        return nil, err
 
221
                }
 
222
                req.Header.Set("Content-Type", "application/json")
 
223
        } else {
 
224
                req, err = http.NewRequest("GET", url, nil)
 
225
                if err != nil {
 
226
                        return nil, err
 
227
                }
 
228
        }
 
229
 
 
230
        resp, err := client.handleRequest(req)
 
231
        if err != nil {
 
232
                return nil, err
 
233
        }
 
234
 
 
235
        body, err := ioutil.ReadAll(resp.Body)
 
236
        if err != nil {
 
237
                return nil, err
 
238
        }
 
239
 
 
240
        switch resp.StatusCode {
 
241
        default:
 
242
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
243
        case 200:
 
244
                break
 
245
        }
 
246
 
 
247
        var results GetSnapshotsSimpleResults
 
248
        json.Unmarshal(body, &results)
 
249
 
 
250
        return &results, nil
 
251
}
 
252
 
 
253
type UpdateSnapshotSnapshotParams struct {
 
254
 
 
255
        //  Describes the snapshot.
 
256
        Description string `json:"description,omitempty"`
 
257
 
 
258
        //  The name of the snapshot.
 
259
        Name string `json:"name,omitempty"`
 
260
}
 
261
 
 
262
type UpdateSnapshotParams struct {
 
263
 
 
264
        // Snapshot is required.
 
265
 
 
266
        Snapshot UpdateSnapshotSnapshotParams `json:"snapshot"`
 
267
 
 
268
        //
 
269
        // The unique identifier of the tenant or account.
 
270
        TenantId string `json:"-"`
 
271
 
 
272
        // SnapshotId is required.
 
273
        //
 
274
        // The unique identifier of an existing snapshot.
 
275
        SnapshotId string `json:"-"`
 
276
}
 
277
 
 
278
type UpdateSnapshotResults struct {
 
279
        Snapshot Snapshot `json:"snapshot"`
 
280
}
 
281
 
 
282
//
 
283
// Updates a specified snapshot.
 
284
func updateSnapshot(client *Client, args UpdateSnapshotParams) (*UpdateSnapshotResults, error) {
 
285
 
 
286
        argsAsJson, err := json.Marshal(args)
 
287
        if err != nil {
 
288
                return nil, err
 
289
        }
 
290
 
 
291
        urlPath := url.URL{Path: fmt.Sprintf("snapshots/%s", args.SnapshotId)}
 
292
        url := client.endpoint.ResolveReference(&urlPath).String()
 
293
 
 
294
        var req *http.Request
 
295
        if string(argsAsJson) != "{}" {
 
296
                req, err = http.NewRequest("PUT", url, bytes.NewBuffer(argsAsJson))
 
297
                if err != nil {
 
298
                        return nil, err
 
299
                }
 
300
                req.Header.Set("Content-Type", "application/json")
 
301
        } else {
 
302
                req, err = http.NewRequest("PUT", url, nil)
 
303
                if err != nil {
 
304
                        return nil, err
 
305
                }
 
306
        }
 
307
 
 
308
        resp, err := client.handleRequest(req)
 
309
        if err != nil {
 
310
                return nil, err
 
311
        }
 
312
 
 
313
        body, err := ioutil.ReadAll(resp.Body)
 
314
        if err != nil {
 
315
                return nil, err
 
316
        }
 
317
 
 
318
        switch resp.StatusCode {
 
319
        default:
 
320
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
321
        case 200:
 
322
                break
 
323
        }
 
324
 
 
325
        var results UpdateSnapshotResults
 
326
        json.Unmarshal(body, &results)
 
327
 
 
328
        return &results, nil
 
329
}
 
330
 
 
331
type ShowSnapshotMetadataParams struct {
 
332
 
 
333
        //
 
334
        // The unique identifier of the tenant or account.
 
335
        TenantId string `json:"-"`
 
336
 
 
337
        // SnapshotId is required.
 
338
        //
 
339
        // The unique identifier of an existing snapshot.
 
340
        SnapshotId string `json:"-"`
 
341
}
 
342
 
 
343
type ShowSnapshotMetadataResults struct {
 
344
        Snapshot Snapshot `json:"snapshot"`
 
345
}
 
346
 
 
347
//
 
348
// Shows the metadata for a specified snapshot.
 
349
func showSnapshotMetadata(client *Client, args ShowSnapshotMetadataParams) (*ShowSnapshotMetadataResults, error) {
 
350
 
 
351
        argsAsJson, err := json.Marshal(args)
 
352
        if err != nil {
 
353
                return nil, err
 
354
        }
 
355
 
 
356
        urlPath := url.URL{Path: fmt.Sprintf("snapshots/%s/metadata", args.SnapshotId)}
 
357
        url := client.endpoint.ResolveReference(&urlPath).String()
 
358
 
 
359
        var req *http.Request
 
360
        if string(argsAsJson) != "{}" {
 
361
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
362
                if err != nil {
 
363
                        return nil, err
 
364
                }
 
365
                req.Header.Set("Content-Type", "application/json")
 
366
        } else {
 
367
                req, err = http.NewRequest("GET", url, nil)
 
368
                if err != nil {
 
369
                        return nil, err
 
370
                }
 
371
        }
 
372
 
 
373
        resp, err := client.handleRequest(req)
 
374
        if err != nil {
 
375
                return nil, err
 
376
        }
 
377
 
 
378
        body, err := ioutil.ReadAll(resp.Body)
 
379
        if err != nil {
 
380
                return nil, err
 
381
        }
 
382
 
 
383
        switch resp.StatusCode {
 
384
        default:
 
385
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
386
        case 200:
 
387
                break
 
388
        }
 
389
 
 
390
        var results ShowSnapshotMetadataResults
 
391
        json.Unmarshal(body, &results)
 
392
 
 
393
        return &results, nil
 
394
}
 
395
 
 
396
type GetVolumesDetailParams struct {
 
397
 
 
398
        //
 
399
        // The unique identifier of the tenant or account.
 
400
        TenantId string `json:"-"`
 
401
}
 
402
 
 
403
type VolumeAttachment struct {
 
404
        Device   string `json:"device"`
 
405
        Id       string `json:"id"`
 
406
        ServerId string `json:"server_id"`
 
407
        VolumeId string `json:"volume_id"`
 
408
}
 
409
 
 
410
type Volume struct {
 
411
        Attachments      []VolumeAttachment `json:"attachments"`
 
412
        AvailabilityZone string             `json:"availability_zone"`
 
413
        Bootable         string             `json:"bootable"`
 
414
        CreatedAt        string             `json:"created_at"`
 
415
        Description      string             `json:"description"`
 
416
        ID               string             `json:"id"`
 
417
        Links            []struct {
 
418
                Href string `json:"href"`
 
419
                Rel  string `json:"rel"`
 
420
        } `json:"links"`
 
421
        Metadata                    map[string]string `json:"metadata"`
 
422
        Name                        string            `json:"name"`
 
423
        Os_Vol_Host_Attr_Host       string            `json:"os-vol-host-attr:host"`
 
424
        Os_Vol_Tenant_Attr_TenantID string            `json:"os-vol-tenant-attr:tenant_id"`
 
425
        Size                        int               `json:"size"`
 
426
        SnapshotID                  interface{}       `json:"snapshot_id"`
 
427
        SourceVolid                 interface{}       `json:"source_volid"`
 
428
        Status                      string            `json:"status"`
 
429
        VolumeType                  string            `json:"volume_type"`
 
430
}
 
431
 
 
432
type GetVolumesDetailResults struct {
 
433
        Volumes []Volume `json:"volumes"`
 
434
}
 
435
 
 
436
//
 
437
// Lists detailed information for all Block Storage volumes that the tenant who submits the request can access.
 
438
func getVolumesDetail(client *Client, args GetVolumesDetailParams) (*GetVolumesDetailResults, error) {
 
439
 
 
440
        argsAsJson, err := json.Marshal(args)
 
441
        if err != nil {
 
442
                return nil, err
 
443
        }
 
444
 
 
445
        urlPath := url.URL{Path: "volumes/detail"}
 
446
        url := client.endpoint.ResolveReference(&urlPath).String()
 
447
 
 
448
        var req *http.Request
 
449
        if string(argsAsJson) != "{}" {
 
450
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
451
                if err != nil {
 
452
                        return nil, err
 
453
                }
 
454
                req.Header.Set("Content-Type", "application/json")
 
455
        } else {
 
456
                req, err = http.NewRequest("GET", url, nil)
 
457
                if err != nil {
 
458
                        return nil, err
 
459
                }
 
460
        }
 
461
 
 
462
        resp, err := client.handleRequest(req)
 
463
        if err != nil {
 
464
                return nil, err
 
465
        }
 
466
 
 
467
        body, err := ioutil.ReadAll(resp.Body)
 
468
        if err != nil {
 
469
                return nil, err
 
470
        }
 
471
 
 
472
        switch resp.StatusCode {
 
473
        default:
 
474
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
475
        case 200:
 
476
                break
 
477
        }
 
478
 
 
479
        var results GetVolumesDetailResults
 
480
        json.Unmarshal(body, &results)
 
481
 
 
482
        return &results, nil
 
483
}
 
484
 
 
485
type GetVolumeParams struct {
 
486
 
 
487
        //
 
488
        // The unique identifier of the tenant or account.
 
489
        TenantId string `json:"-"`
 
490
 
 
491
        // VolumeId is required.
 
492
        //
 
493
        // The unique identifier of an existing volume.
 
494
        VolumeId string `json:"-"`
 
495
}
 
496
 
 
497
type GetVolumeResults struct {
 
498
        Volume Volume `json:"volume"`
 
499
}
 
500
 
 
501
//
 
502
// Shows information about a specified volume.
 
503
// Preconditions
 
504
//
 
505
// The specified volume must exist. :
 
506
func getVolume(client *Client, args GetVolumeParams) (*GetVolumeResults, error) {
 
507
 
 
508
        argsAsJson, err := json.Marshal(args)
 
509
        if err != nil {
 
510
                return nil, err
 
511
        }
 
512
 
 
513
        urlPath := url.URL{Path: fmt.Sprintf("volumes/%s", args.VolumeId)}
 
514
        url := client.endpoint.ResolveReference(&urlPath).String()
 
515
 
 
516
        var req *http.Request
 
517
        if string(argsAsJson) != "{}" {
 
518
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
519
                if err != nil {
 
520
                        return nil, err
 
521
                }
 
522
                req.Header.Set("Content-Type", "application/json")
 
523
        } else {
 
524
                req, err = http.NewRequest("GET", url, nil)
 
525
                if err != nil {
 
526
                        return nil, err
 
527
                }
 
528
        }
 
529
 
 
530
        resp, err := client.handleRequest(req)
 
531
        if err != nil {
 
532
                return nil, err
 
533
        }
 
534
 
 
535
        body, err := ioutil.ReadAll(resp.Body)
 
536
        if err != nil {
 
537
                return nil, err
 
538
        }
 
539
 
 
540
        switch resp.StatusCode {
 
541
        default:
 
542
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
543
        case 200:
 
544
                break
 
545
        }
 
546
 
 
547
        var results GetVolumeResults
 
548
        json.Unmarshal(body, &results)
 
549
 
 
550
        return &results, nil
 
551
}
 
552
 
 
553
type UpdateVolumeVolumeParams struct {
 
554
        Name string `json:"name,omitempty"`
 
555
 
 
556
        Description string `json:"description,omitempty"`
 
557
}
 
558
 
 
559
type UpdateVolumeParams struct {
 
560
 
 
561
        // Volume is required.
 
562
 
 
563
        Volume UpdateVolumeVolumeParams `json:"volume"`
 
564
 
 
565
        //
 
566
        // The unique identifier of the tenant or account.
 
567
        TenantId string `json:"-"`
 
568
 
 
569
        // VolumeId is required.
 
570
        //
 
571
        // The unique identifier of an existing volume.
 
572
        VolumeId string `json:"-"`
 
573
}
 
574
 
 
575
type UpdateVolumeResults struct {
 
576
        Volume Volume `json:"volume"`
 
577
}
 
578
 
 
579
//
 
580
// Updates a volume.
 
581
func updateVolume(client *Client, args UpdateVolumeParams) (*UpdateVolumeResults, error) {
 
582
 
 
583
        argsAsJson, err := json.Marshal(args)
 
584
        if err != nil {
 
585
                return nil, err
 
586
        }
 
587
 
 
588
        urlPath := url.URL{Path: fmt.Sprintf("volumes/%s", args.VolumeId)}
 
589
        url := client.endpoint.ResolveReference(&urlPath).String()
 
590
 
 
591
        var req *http.Request
 
592
        if string(argsAsJson) != "{}" {
 
593
                req, err = http.NewRequest("PUT", url, bytes.NewBuffer(argsAsJson))
 
594
                if err != nil {
 
595
                        return nil, err
 
596
                }
 
597
                req.Header.Set("Content-Type", "application/json")
 
598
        } else {
 
599
                req, err = http.NewRequest("PUT", url, nil)
 
600
                if err != nil {
 
601
                        return nil, err
 
602
                }
 
603
        }
 
604
 
 
605
        resp, err := client.handleRequest(req)
 
606
        if err != nil {
 
607
                return nil, err
 
608
        }
 
609
 
 
610
        body, err := ioutil.ReadAll(resp.Body)
 
611
        if err != nil {
 
612
                return nil, err
 
613
        }
 
614
 
 
615
        switch resp.StatusCode {
 
616
        default:
 
617
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
618
        case 200:
 
619
                break
 
620
        }
 
621
 
 
622
        var results UpdateVolumeResults
 
623
        json.Unmarshal(body, &results)
 
624
 
 
625
        return &results, nil
 
626
}
 
627
 
 
628
type DeleteVolumeParams struct {
 
629
 
 
630
        //
 
631
        // The unique identifier of the tenant or account.
 
632
        TenantId string `json:"-"`
 
633
 
 
634
        // VolumeId is required.
 
635
        //
 
636
        // The unique identifier of an existing volume.
 
637
        VolumeId string `json:"-"`
 
638
}
 
639
 
 
640
type DeleteVolumeResults struct {
 
641
}
 
642
 
 
643
//
 
644
// Deletes a specified volume.
 
645
// Preconditions
 
646
//
 
647
// Volume status must be available, in-use, error, or error_restoring.
 
648
// You cannot already have a snapshot related to the specified volume.
 
649
// You cannot delete a volume that is in a migration. :
 
650
// Asynchronous Postconditions
 
651
//
 
652
// The volume is deleted in volume index.
 
653
// The volume managed by OpenStack Block Storage is deleted in storage node. :
 
654
// Troubleshooting
 
655
//
 
656
// If volume status remains in deleting or becomes error_deleting the request failed. Ensure you meet the preconditions then investigate the storage backend.
 
657
// The volume managed by OpenStack Block Storage is not deleted from the storage system. :
 
658
func deleteVolume(client *Client, args DeleteVolumeParams) (*DeleteVolumeResults, error) {
 
659
 
 
660
        argsAsJson, err := json.Marshal(args)
 
661
        if err != nil {
 
662
                return nil, err
 
663
        }
 
664
 
 
665
        urlPath := url.URL{Path: fmt.Sprintf("volumes/%s", args.VolumeId)}
 
666
        url := client.endpoint.ResolveReference(&urlPath).String()
 
667
 
 
668
        var req *http.Request
 
669
        if string(argsAsJson) != "{}" {
 
670
                req, err = http.NewRequest("DELETE", url, bytes.NewBuffer(argsAsJson))
 
671
                if err != nil {
 
672
                        return nil, err
 
673
                }
 
674
                req.Header.Set("Content-Type", "application/json")
 
675
        } else {
 
676
                req, err = http.NewRequest("DELETE", url, nil)
 
677
                if err != nil {
 
678
                        return nil, err
 
679
                }
 
680
        }
 
681
 
 
682
        resp, err := client.handleRequest(req)
 
683
        if err != nil {
 
684
                return nil, err
 
685
        }
 
686
 
 
687
        body, err := ioutil.ReadAll(resp.Body)
 
688
        if err != nil {
 
689
                return nil, err
 
690
        }
 
691
 
 
692
        switch resp.StatusCode {
 
693
        default:
 
694
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
695
        case 202:
 
696
                break
 
697
        }
 
698
 
 
699
        var results DeleteVolumeResults
 
700
        json.Unmarshal(body, &results)
 
701
 
 
702
        return &results, nil
 
703
}
 
704
 
 
705
type CreateVolumeTypeVolumeTypeExtraSpecsParams struct {
 
706
        Capabilities string `json:"capabilities,omitempty"`
 
707
}
 
708
 
 
709
type CreateVolumeTypeVolumeTypeParams struct {
 
710
 
 
711
        //  The name of the volume type.
 
712
        Name string `json:"name,omitempty"`
 
713
 
 
714
        ExtraSpecs CreateVolumeTypeVolumeTypeExtraSpecsParams `json:"extra_specs,omitempty"`
 
715
}
 
716
 
 
717
type CreateVolumeTypeParams struct {
 
718
 
 
719
        // VolumeType is required.
 
720
        //  A partial representation of a volume type used in the creation process.
 
721
        VolumeType CreateVolumeTypeVolumeTypeParams `json:"volume_type"`
 
722
 
 
723
        //
 
724
        // The unique identifier of the tenant or account.
 
725
        TenantId string `json:"-"`
 
726
}
 
727
 
 
728
type CreateVolumeTypeResults struct {
 
729
        VolumeType VolumeType `json:"volume_type"`
 
730
}
 
731
 
 
732
//
 
733
// Creates a volume type.
 
734
func createVolumeType(client *Client, args CreateVolumeTypeParams) (*CreateVolumeTypeResults, error) {
 
735
 
 
736
        argsAsJson, err := json.Marshal(args)
 
737
        if err != nil {
 
738
                return nil, err
 
739
        }
 
740
 
 
741
        urlPath := url.URL{Path: "types"}
 
742
        url := client.endpoint.ResolveReference(&urlPath).String()
 
743
 
 
744
        var req *http.Request
 
745
        if string(argsAsJson) != "{}" {
 
746
                req, err = http.NewRequest("POST", url, bytes.NewBuffer(argsAsJson))
 
747
                if err != nil {
 
748
                        return nil, err
 
749
                }
 
750
                req.Header.Set("Content-Type", "application/json")
 
751
        } else {
 
752
                req, err = http.NewRequest("POST", url, nil)
 
753
                if err != nil {
 
754
                        return nil, err
 
755
                }
 
756
        }
 
757
 
 
758
        resp, err := client.handleRequest(req)
 
759
        if err != nil {
 
760
                return nil, err
 
761
        }
 
762
 
 
763
        body, err := ioutil.ReadAll(resp.Body)
 
764
        if err != nil {
 
765
                return nil, err
 
766
        }
 
767
 
 
768
        switch resp.StatusCode {
 
769
        default:
 
770
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
771
        case 200:
 
772
                break
 
773
        }
 
774
 
 
775
        var results CreateVolumeTypeResults
 
776
        json.Unmarshal(body, &results)
 
777
 
 
778
        return &results, nil
 
779
}
 
780
 
 
781
type CreateSnapshotSnapshotParams struct {
 
782
 
 
783
        //  [True/False] Indicate whether to snapshot, even if the volume is attached. Default==False.
 
784
        Force bool `json:"force,omitempty"`
 
785
 
 
786
        //  Name of the snapshot. The default is None.
 
787
        Name string `json:"name,omitempty"`
 
788
 
 
789
        //  Description of the snapshot. The default is None.
 
790
        Description string `json:"description,omitempty"`
 
791
 
 
792
        // VolumeId is required.
 
793
        //  To create a snapshot from an existing volume, specify the ID of the existing volume.
 
794
        VolumeId string `json:"volume_id"`
 
795
}
 
796
 
 
797
type CreateSnapshotParams struct {
 
798
 
 
799
        // Snapshot is required.
 
800
        //  A partial representation of a snapshot used in the creation process.
 
801
        Snapshot CreateSnapshotSnapshotParams `json:"snapshot"`
 
802
 
 
803
        //
 
804
        // The unique identifier of the tenant or account.
 
805
        TenantId string `json:"-"`
 
806
}
 
807
 
 
808
type CreateSnapshotResults struct {
 
809
        Snapshot Snapshot `json:"snapshot"`
 
810
}
 
811
 
 
812
//
 
813
// Creates a snapshot, which is a point-in-time complete copy of a volume. You can create a volume from the snapshot.
 
814
func createSnapshot(client *Client, args CreateSnapshotParams) (*CreateSnapshotResults, error) {
 
815
 
 
816
        argsAsJson, err := json.Marshal(args)
 
817
        if err != nil {
 
818
                return nil, err
 
819
        }
 
820
 
 
821
        urlPath := url.URL{Path: "snapshots"}
 
822
        url := client.endpoint.ResolveReference(&urlPath).String()
 
823
 
 
824
        var req *http.Request
 
825
        if string(argsAsJson) != "{}" {
 
826
                req, err = http.NewRequest("POST", url, bytes.NewBuffer(argsAsJson))
 
827
                if err != nil {
 
828
                        return nil, err
 
829
                }
 
830
                req.Header.Set("Content-Type", "application/json")
 
831
        } else {
 
832
                req, err = http.NewRequest("POST", url, nil)
 
833
                if err != nil {
 
834
                        return nil, err
 
835
                }
 
836
        }
 
837
 
 
838
        resp, err := client.handleRequest(req)
 
839
        if err != nil {
 
840
                return nil, err
 
841
        }
 
842
 
 
843
        body, err := ioutil.ReadAll(resp.Body)
 
844
        if err != nil {
 
845
                return nil, err
 
846
        }
 
847
 
 
848
        switch resp.StatusCode {
 
849
        default:
 
850
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
851
        case 200, 202:
 
852
                break
 
853
        }
 
854
 
 
855
        var results CreateSnapshotResults
 
856
        json.Unmarshal(body, &results)
 
857
 
 
858
        return &results, nil
 
859
}
 
860
 
 
861
type GetSnapshotsDetailParams struct {
 
862
 
 
863
        //
 
864
        // The unique identifier of the tenant or account.
 
865
        TenantId string `json:"-"`
 
866
}
 
867
 
 
868
type GetSnapshotsDetailResults struct {
 
869
        Snapshots []Snapshot `json:"snapshots"`
 
870
}
 
871
 
 
872
//
 
873
// Lists detailed information for all Block Storage snapshots that the tenant who submits the request can access.
 
874
func getSnapshotsDetail(client *Client, args GetSnapshotsDetailParams) (*GetSnapshotsDetailResults, error) {
 
875
 
 
876
        argsAsJson, err := json.Marshal(args)
 
877
        if err != nil {
 
878
                return nil, err
 
879
        }
 
880
 
 
881
        urlPath := url.URL{Path: "snapshots/detail"}
 
882
        url := client.endpoint.ResolveReference(&urlPath).String()
 
883
 
 
884
        var req *http.Request
 
885
        if string(argsAsJson) != "{}" {
 
886
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
887
                if err != nil {
 
888
                        return nil, err
 
889
                }
 
890
                req.Header.Set("Content-Type", "application/json")
 
891
        } else {
 
892
                req, err = http.NewRequest("GET", url, nil)
 
893
                if err != nil {
 
894
                        return nil, err
 
895
                }
 
896
        }
 
897
 
 
898
        resp, err := client.handleRequest(req)
 
899
        if err != nil {
 
900
                return nil, err
 
901
        }
 
902
 
 
903
        body, err := ioutil.ReadAll(resp.Body)
 
904
        if err != nil {
 
905
                return nil, err
 
906
        }
 
907
 
 
908
        switch resp.StatusCode {
 
909
        default:
 
910
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
911
        case 200:
 
912
                break
 
913
        }
 
914
 
 
915
        var results GetSnapshotsDetailResults
 
916
        json.Unmarshal(body, &results)
 
917
 
 
918
        return &results, nil
 
919
}
 
920
 
 
921
type GetSnapshotParams struct {
 
922
 
 
923
        //
 
924
        // The unique identifier of the tenant or account.
 
925
        TenantId string `json:"-"`
 
926
 
 
927
        // SnapshotId is required.
 
928
        //
 
929
        // The unique identifier of an existing snapshot.
 
930
        SnapshotId string `json:"-"`
 
931
}
 
932
 
 
933
type GetSnapshotResults struct {
 
934
        Snapshot Snapshot `json:"snapshot"`
 
935
}
 
936
 
 
937
//
 
938
// Shows information for a specified snapshot.
 
939
func getSnapshot(client *Client, args GetSnapshotParams) (*GetSnapshotResults, error) {
 
940
 
 
941
        argsAsJson, err := json.Marshal(args)
 
942
        if err != nil {
 
943
                return nil, err
 
944
        }
 
945
 
 
946
        urlPath := url.URL{Path: fmt.Sprintf("snapshots/%s", args.SnapshotId)}
 
947
        url := client.endpoint.ResolveReference(&urlPath).String()
 
948
 
 
949
        var req *http.Request
 
950
        if string(argsAsJson) != "{}" {
 
951
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
952
                if err != nil {
 
953
                        return nil, err
 
954
                }
 
955
                req.Header.Set("Content-Type", "application/json")
 
956
        } else {
 
957
                req, err = http.NewRequest("GET", url, nil)
 
958
                if err != nil {
 
959
                        return nil, err
 
960
                }
 
961
        }
 
962
 
 
963
        resp, err := client.handleRequest(req)
 
964
        if err != nil {
 
965
                return nil, err
 
966
        }
 
967
 
 
968
        body, err := ioutil.ReadAll(resp.Body)
 
969
        if err != nil {
 
970
                return nil, err
 
971
        }
 
972
 
 
973
        switch resp.StatusCode {
 
974
        default:
 
975
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
976
        case 200:
 
977
                break
 
978
        }
 
979
 
 
980
        var results GetSnapshotResults
 
981
        json.Unmarshal(body, &results)
 
982
 
 
983
        return &results, nil
 
984
}
 
985
 
 
986
type ListVersionsParams struct {
 
987
}
 
988
 
 
989
type Version struct {
 
990
        ID    string `json:"id"`
 
991
        Links []struct {
 
992
                Href string `json:"href"`
 
993
                Rel  string `json:"rel"`
 
994
        } `json:"links"`
 
995
        Media_Types []struct {
 
996
                Base string `json:"base"`
 
997
                Type string `json:"type"`
 
998
        } `json:"media-types"`
 
999
        Status  string `json:"status"`
 
1000
        Updated string `json:"updated"`
 
1001
}
 
1002
 
 
1003
type ListVersionsResults struct {
 
1004
        Versions []Version `json:"versions"`
 
1005
}
 
1006
 
 
1007
//
 
1008
// Lists information about all Block Storage API versions.
 
1009
func listVersions(client *Client, args ListVersionsParams) (*ListVersionsResults, error) {
 
1010
 
 
1011
        argsAsJson, err := json.Marshal(args)
 
1012
        if err != nil {
 
1013
                return nil, err
 
1014
        }
 
1015
 
 
1016
        urlPath := url.URL{Path: "../.."}
 
1017
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1018
 
 
1019
        var req *http.Request
 
1020
        if string(argsAsJson) != "{}" {
 
1021
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1022
                if err != nil {
 
1023
                        return nil, err
 
1024
                }
 
1025
                req.Header.Set("Content-Type", "application/json")
 
1026
        } else {
 
1027
                req, err = http.NewRequest("GET", url, nil)
 
1028
                if err != nil {
 
1029
                        return nil, err
 
1030
                }
 
1031
        }
 
1032
 
 
1033
        resp, err := client.handleRequest(req)
 
1034
        if err != nil {
 
1035
                return nil, err
 
1036
        }
 
1037
 
 
1038
        body, err := ioutil.ReadAll(resp.Body)
 
1039
        if err != nil {
 
1040
                return nil, err
 
1041
        }
 
1042
 
 
1043
        switch resp.StatusCode {
 
1044
        default:
 
1045
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1046
        case 200, 300:
 
1047
                break
 
1048
        }
 
1049
 
 
1050
        var results ListVersionsResults
 
1051
        json.Unmarshal(body, &results)
 
1052
 
 
1053
        return &results, nil
 
1054
}
 
1055
 
 
1056
type VersionDetailsParams struct {
 
1057
}
 
1058
 
 
1059
type VersionDetailsResults struct {
 
1060
        Version Version `json:"version"`
 
1061
}
 
1062
 
 
1063
//
 
1064
// Shows details for Block Storage API v2.
 
1065
func versionDetails(client *Client, args VersionDetailsParams) (*VersionDetailsResults, error) {
 
1066
 
 
1067
        argsAsJson, err := json.Marshal(args)
 
1068
        if err != nil {
 
1069
                return nil, err
 
1070
        }
 
1071
 
 
1072
        urlPath := url.URL{Path: ".."}
 
1073
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1074
 
 
1075
        var req *http.Request
 
1076
        if string(argsAsJson) != "{}" {
 
1077
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1078
                if err != nil {
 
1079
                        return nil, err
 
1080
                }
 
1081
                req.Header.Set("Content-Type", "application/json")
 
1082
        } else {
 
1083
                req, err = http.NewRequest("GET", url, nil)
 
1084
                if err != nil {
 
1085
                        return nil, err
 
1086
                }
 
1087
        }
 
1088
 
 
1089
        resp, err := client.handleRequest(req)
 
1090
        if err != nil {
 
1091
                return nil, err
 
1092
        }
 
1093
 
 
1094
        body, err := ioutil.ReadAll(resp.Body)
 
1095
        if err != nil {
 
1096
                return nil, err
 
1097
        }
 
1098
 
 
1099
        switch resp.StatusCode {
 
1100
        default:
 
1101
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1102
        case 200, 203:
 
1103
                break
 
1104
        }
 
1105
 
 
1106
        var results VersionDetailsResults
 
1107
        json.Unmarshal(body, &results)
 
1108
 
 
1109
        return &results, nil
 
1110
}
 
1111
 
 
1112
type CreateVolumeVolumeParams struct {
 
1113
 
 
1114
        //  To create a volume from an existing volume, specify the ID of the existing volume. If specified, the volume is created with same size of the source volume.
 
1115
        SourceVolid string `json:"source_volid,omitempty"`
 
1116
 
 
1117
        //  To create a volume from an existing snapshot, specify the ID of the existing volume snapshot. If specified, the volume is created in same availability zone and with same size of the snapshot.
 
1118
        SnapshotId string `json:"snapshot_id,omitempty"`
 
1119
 
 
1120
        //  The ID of the image from which you want to create the volume. Required to create a bootable volume.
 
1121
        ImageRef string `json:"imageRef,omitempty"`
 
1122
 
 
1123
        //  The associated volume type.
 
1124
        VolumeType string `json:"volume_type,omitempty"`
 
1125
 
 
1126
        //  Enables or disables the bootable attribute. You can boot an instance from a bootable volume.
 
1127
        Bootable bool `json:"bootable,omitempty"`
 
1128
 
 
1129
        //  One or more metadata key and value pairs to associate with the volume.
 
1130
        Metadata interface{} `json:"metadata,omitempty"`
 
1131
 
 
1132
        //  The availability zone.
 
1133
        AvailabilityZone string `json:"availability_zone,omitempty"`
 
1134
 
 
1135
        //  The volume description.
 
1136
        Description string `json:"description,omitempty"`
 
1137
 
 
1138
        // Size is required.
 
1139
        //  The size of the volume, in GBs.
 
1140
        Size int `json:"size"`
 
1141
 
 
1142
        //  The volume name.
 
1143
        Name string `json:"name,omitempty"`
 
1144
}
 
1145
 
 
1146
type CreateVolumeParams struct {
 
1147
 
 
1148
        // Volume is required.
 
1149
 
 
1150
        Volume CreateVolumeVolumeParams `json:"volume"`
 
1151
 
 
1152
        //
 
1153
        // The unique identifier of the tenant or account.
 
1154
        TenantId string `json:"-"`
 
1155
}
 
1156
 
 
1157
type CreateVolumeResults struct {
 
1158
        Volume Volume `json:"volume"`
 
1159
}
 
1160
 
 
1161
//
 
1162
// Creates a volume.
 
1163
// To create a bootable volume, include the image ID and set the bootable flag to true in the request body.
 
1164
// Preconditions
 
1165
//
 
1166
// The user must have enough volume storage quota remaining to create a volume of size requested. :
 
1167
// Asynchronous Postconditions
 
1168
//
 
1169
// With correct permissions, you can see the volume status as available through API calls.
 
1170
// With correct access, you can see the created volume in the storage system that OpenStack Block Storage manages. :
 
1171
// Troubleshooting
 
1172
//
 
1173
// If volume status remains creating or shows another error status, the request failed. Ensure you meet the preconditions then investigate the storage backend.
 
1174
// Volume is not created in the storage system which OpenStack Block Storage manages.
 
1175
// The storage node needs enough free storage space to match the specified size of the volume creation request. :
 
1176
func createVolume(client *Client, args CreateVolumeParams) (*CreateVolumeResults, error) {
 
1177
 
 
1178
        argsAsJson, err := json.Marshal(args)
 
1179
        if err != nil {
 
1180
                return nil, err
 
1181
        }
 
1182
 
 
1183
        urlPath := url.URL{Path: "volumes"}
 
1184
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1185
 
 
1186
        var req *http.Request
 
1187
        if string(argsAsJson) != "{}" {
 
1188
                req, err = http.NewRequest("POST", url, bytes.NewBuffer(argsAsJson))
 
1189
                if err != nil {
 
1190
                        return nil, err
 
1191
                }
 
1192
                req.Header.Set("Content-Type", "application/json")
 
1193
        } else {
 
1194
                req, err = http.NewRequest("POST", url, nil)
 
1195
                if err != nil {
 
1196
                        return nil, err
 
1197
                }
 
1198
        }
 
1199
 
 
1200
        resp, err := client.handleRequest(req)
 
1201
        if err != nil {
 
1202
                return nil, err
 
1203
        }
 
1204
 
 
1205
        body, err := ioutil.ReadAll(resp.Body)
 
1206
        if err != nil {
 
1207
                return nil, err
 
1208
        }
 
1209
 
 
1210
        switch resp.StatusCode {
 
1211
        default:
 
1212
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1213
        case 200, 202:
 
1214
                break
 
1215
        }
 
1216
 
 
1217
        var results CreateVolumeResults
 
1218
        json.Unmarshal(body, &results)
 
1219
 
 
1220
        return &results, nil
 
1221
}
 
1222
 
 
1223
type GetVolumesSimpleParams struct {
 
1224
 
 
1225
        //
 
1226
        // The unique identifier of the tenant or account.
 
1227
        TenantId string `json:"-"`
 
1228
}
 
1229
 
 
1230
type GetVolumesSimpleResults struct {
 
1231
        Volumes []Volume `json:"volumes"`
 
1232
}
 
1233
 
 
1234
//
 
1235
// Lists summary information for all Block Storage volumes that the tenant who submits the request can access.
 
1236
func getVolumesSimple(client *Client, args GetVolumesSimpleParams) (*GetVolumesSimpleResults, error) {
 
1237
 
 
1238
        argsAsJson, err := json.Marshal(args)
 
1239
        if err != nil {
 
1240
                return nil, err
 
1241
        }
 
1242
 
 
1243
        urlPath := url.URL{Path: "volumes"}
 
1244
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1245
 
 
1246
        var req *http.Request
 
1247
        if string(argsAsJson) != "{}" {
 
1248
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1249
                if err != nil {
 
1250
                        return nil, err
 
1251
                }
 
1252
                req.Header.Set("Content-Type", "application/json")
 
1253
        } else {
 
1254
                req, err = http.NewRequest("GET", url, nil)
 
1255
                if err != nil {
 
1256
                        return nil, err
 
1257
                }
 
1258
        }
 
1259
 
 
1260
        resp, err := client.handleRequest(req)
 
1261
        if err != nil {
 
1262
                return nil, err
 
1263
        }
 
1264
 
 
1265
        body, err := ioutil.ReadAll(resp.Body)
 
1266
        if err != nil {
 
1267
                return nil, err
 
1268
        }
 
1269
 
 
1270
        switch resp.StatusCode {
 
1271
        default:
 
1272
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1273
        case 200:
 
1274
                break
 
1275
        }
 
1276
 
 
1277
        var results GetVolumesSimpleResults
 
1278
        json.Unmarshal(body, &results)
 
1279
 
 
1280
        return &results, nil
 
1281
}
 
1282
 
 
1283
type GetVolumeTypeParams struct {
 
1284
 
 
1285
        //
 
1286
        // The unique identifier of the tenant or account.
 
1287
        TenantId string `json:"-"`
 
1288
 
 
1289
        // VolumeTypeId is required.
 
1290
        //
 
1291
        // The unique identifier for an existing volume type.
 
1292
        VolumeTypeId string `json:"-"`
 
1293
}
 
1294
 
 
1295
type GetVolumeTypeResults struct {
 
1296
        VolumeType VolumeType `json:"volume_type"`
 
1297
}
 
1298
 
 
1299
//
 
1300
// Shows information about a specified volume type.
 
1301
func getVolumeType(client *Client, args GetVolumeTypeParams) (*GetVolumeTypeResults, error) {
 
1302
 
 
1303
        argsAsJson, err := json.Marshal(args)
 
1304
        if err != nil {
 
1305
                return nil, err
 
1306
        }
 
1307
 
 
1308
        urlPath := url.URL{Path: fmt.Sprintf("types/%s", args.VolumeTypeId)}
 
1309
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1310
 
 
1311
        var req *http.Request
 
1312
        if string(argsAsJson) != "{}" {
 
1313
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1314
                if err != nil {
 
1315
                        return nil, err
 
1316
                }
 
1317
                req.Header.Set("Content-Type", "application/json")
 
1318
        } else {
 
1319
                req, err = http.NewRequest("GET", url, nil)
 
1320
                if err != nil {
 
1321
                        return nil, err
 
1322
                }
 
1323
        }
 
1324
 
 
1325
        resp, err := client.handleRequest(req)
 
1326
        if err != nil {
 
1327
                return nil, err
 
1328
        }
 
1329
 
 
1330
        body, err := ioutil.ReadAll(resp.Body)
 
1331
        if err != nil {
 
1332
                return nil, err
 
1333
        }
 
1334
 
 
1335
        switch resp.StatusCode {
 
1336
        default:
 
1337
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1338
        case 200:
 
1339
                break
 
1340
        }
 
1341
 
 
1342
        var results GetVolumeTypeResults
 
1343
        json.Unmarshal(body, &results)
 
1344
 
 
1345
        return &results, nil
 
1346
}
 
1347
 
 
1348
type DeleteSnapshotParams struct {
 
1349
 
 
1350
        //
 
1351
        // The unique identifier of the tenant or account.
 
1352
        TenantId string `json:"-"`
 
1353
 
 
1354
        // SnapshotId is required.
 
1355
        //
 
1356
        // The unique identifier of an existing snapshot.
 
1357
        SnapshotId string `json:"-"`
 
1358
}
 
1359
 
 
1360
type DeleteSnapshotResults struct {
 
1361
}
 
1362
 
 
1363
//
 
1364
// Deletes a specified snapshot.
 
1365
func deleteSnapshot(client *Client, args DeleteSnapshotParams) (*DeleteSnapshotResults, error) {
 
1366
 
 
1367
        argsAsJson, err := json.Marshal(args)
 
1368
        if err != nil {
 
1369
                return nil, err
 
1370
        }
 
1371
 
 
1372
        urlPath := url.URL{Path: fmt.Sprintf("snapshots/%s", args.SnapshotId)}
 
1373
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1374
 
 
1375
        var req *http.Request
 
1376
        if string(argsAsJson) != "{}" {
 
1377
                req, err = http.NewRequest("DELETE", url, bytes.NewBuffer(argsAsJson))
 
1378
                if err != nil {
 
1379
                        return nil, err
 
1380
                }
 
1381
                req.Header.Set("Content-Type", "application/json")
 
1382
        } else {
 
1383
                req, err = http.NewRequest("DELETE", url, nil)
 
1384
                if err != nil {
 
1385
                        return nil, err
 
1386
                }
 
1387
        }
 
1388
 
 
1389
        resp, err := client.handleRequest(req)
 
1390
        if err != nil {
 
1391
                return nil, err
 
1392
        }
 
1393
 
 
1394
        body, err := ioutil.ReadAll(resp.Body)
 
1395
        if err != nil {
 
1396
                return nil, err
 
1397
        }
 
1398
 
 
1399
        switch resp.StatusCode {
 
1400
        default:
 
1401
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1402
        case 202:
 
1403
                break
 
1404
        }
 
1405
 
 
1406
        var results DeleteSnapshotResults
 
1407
        json.Unmarshal(body, &results)
 
1408
 
 
1409
        return &results, nil
 
1410
}
 
1411
 
 
1412
type ListExtensionsCinderV2Params struct {
 
1413
}
 
1414
 
 
1415
type Extension struct {
 
1416
        Alias       string        `json:"alias"`
 
1417
        Description string        `json:"description"`
 
1418
        Links       []interface{} `json:"links"`
 
1419
        Name        string        `json:"name"`
 
1420
        Namespace   string        `json:"namespace"`
 
1421
        Updated     string        `json:"updated"`
 
1422
}
 
1423
 
 
1424
type ListExtensionsCinderV2Results struct {
 
1425
        Extensions []Extension `json:"extensions"`
 
1426
}
 
1427
 
 
1428
//
 
1429
// Lists Block Storage API extensions.
 
1430
func listExtensionsCinderV2(client *Client, args ListExtensionsCinderV2Params) (*ListExtensionsCinderV2Results, error) {
 
1431
 
 
1432
        argsAsJson, err := json.Marshal(args)
 
1433
        if err != nil {
 
1434
                return nil, err
 
1435
        }
 
1436
 
 
1437
        urlPath := url.URL{Path: ".."}
 
1438
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1439
 
 
1440
        var req *http.Request
 
1441
        if string(argsAsJson) != "{}" {
 
1442
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1443
                if err != nil {
 
1444
                        return nil, err
 
1445
                }
 
1446
                req.Header.Set("Content-Type", "application/json")
 
1447
        } else {
 
1448
                req, err = http.NewRequest("GET", url, nil)
 
1449
                if err != nil {
 
1450
                        return nil, err
 
1451
                }
 
1452
        }
 
1453
 
 
1454
        resp, err := client.handleRequest(req)
 
1455
        if err != nil {
 
1456
                return nil, err
 
1457
        }
 
1458
 
 
1459
        body, err := ioutil.ReadAll(resp.Body)
 
1460
        if err != nil {
 
1461
                return nil, err
 
1462
        }
 
1463
 
 
1464
        switch resp.StatusCode {
 
1465
        default:
 
1466
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1467
        case 200, 300:
 
1468
                break
 
1469
        }
 
1470
 
 
1471
        var results ListExtensionsCinderV2Results
 
1472
        json.Unmarshal(body, &results)
 
1473
 
 
1474
        return &results, nil
 
1475
}
 
1476
 
 
1477
type GetVolumeTypesParams struct {
 
1478
 
 
1479
        //
 
1480
        // The unique identifier of the tenant or account.
 
1481
        TenantId string `json:"-"`
 
1482
}
 
1483
 
 
1484
type GetVolumeTypesResults struct {
 
1485
        VolumeTypes []VolumeType `json:"volume_types"`
 
1486
}
 
1487
 
 
1488
//
 
1489
// Lists volume types.
 
1490
func getVolumeTypes(client *Client, args GetVolumeTypesParams) (*GetVolumeTypesResults, error) {
 
1491
 
 
1492
        argsAsJson, err := json.Marshal(args)
 
1493
        if err != nil {
 
1494
                return nil, err
 
1495
        }
 
1496
 
 
1497
        urlPath := url.URL{Path: "types"}
 
1498
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1499
 
 
1500
        var req *http.Request
 
1501
        if string(argsAsJson) != "{}" {
 
1502
                req, err = http.NewRequest("GET", url, bytes.NewBuffer(argsAsJson))
 
1503
                if err != nil {
 
1504
                        return nil, err
 
1505
                }
 
1506
                req.Header.Set("Content-Type", "application/json")
 
1507
        } else {
 
1508
                req, err = http.NewRequest("GET", url, nil)
 
1509
                if err != nil {
 
1510
                        return nil, err
 
1511
                }
 
1512
        }
 
1513
 
 
1514
        resp, err := client.handleRequest(req)
 
1515
        if err != nil {
 
1516
                return nil, err
 
1517
        }
 
1518
 
 
1519
        body, err := ioutil.ReadAll(resp.Body)
 
1520
        if err != nil {
 
1521
                return nil, err
 
1522
        }
 
1523
 
 
1524
        switch resp.StatusCode {
 
1525
        default:
 
1526
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1527
        case 200:
 
1528
                break
 
1529
        }
 
1530
 
 
1531
        var results GetVolumeTypesResults
 
1532
        json.Unmarshal(body, &results)
 
1533
 
 
1534
        return &results, nil
 
1535
}
 
1536
 
 
1537
type DeleteVolumeTypeParams struct {
 
1538
 
 
1539
        //
 
1540
        // The unique identifier of the tenant or account.
 
1541
        TenantId string `json:"-"`
 
1542
 
 
1543
        // VolumeTypeId is required.
 
1544
        //
 
1545
        // The unique identifier for an existing volume type.
 
1546
        VolumeTypeId string `json:"-"`
 
1547
}
 
1548
 
 
1549
type DeleteVolumeTypeResults struct {
 
1550
}
 
1551
 
 
1552
//
 
1553
// Deletes a specified volume type.
 
1554
func deleteVolumeType(client *Client, args DeleteVolumeTypeParams) (*DeleteVolumeTypeResults, error) {
 
1555
 
 
1556
        argsAsJson, err := json.Marshal(args)
 
1557
        if err != nil {
 
1558
                return nil, err
 
1559
        }
 
1560
 
 
1561
        urlPath := url.URL{Path: fmt.Sprintf("types/%s", args.VolumeTypeId)}
 
1562
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1563
 
 
1564
        var req *http.Request
 
1565
        if string(argsAsJson) != "{}" {
 
1566
                req, err = http.NewRequest("DELETE", url, bytes.NewBuffer(argsAsJson))
 
1567
                if err != nil {
 
1568
                        return nil, err
 
1569
                }
 
1570
                req.Header.Set("Content-Type", "application/json")
 
1571
        } else {
 
1572
                req, err = http.NewRequest("DELETE", url, nil)
 
1573
                if err != nil {
 
1574
                        return nil, err
 
1575
                }
 
1576
        }
 
1577
 
 
1578
        resp, err := client.handleRequest(req)
 
1579
        if err != nil {
 
1580
                return nil, err
 
1581
        }
 
1582
 
 
1583
        body, err := ioutil.ReadAll(resp.Body)
 
1584
        if err != nil {
 
1585
                return nil, err
 
1586
        }
 
1587
 
 
1588
        switch resp.StatusCode {
 
1589
        default:
 
1590
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1591
        case 202:
 
1592
                break
 
1593
        }
 
1594
 
 
1595
        var results DeleteVolumeTypeResults
 
1596
        json.Unmarshal(body, &results)
 
1597
 
 
1598
        return &results, nil
 
1599
}
 
1600
 
 
1601
type UpdateSnapshotMetadataMetadataParams struct {
 
1602
 
 
1603
        // Key is required.
 
1604
 
 
1605
        Key string `json:"key"`
 
1606
}
 
1607
 
 
1608
type UpdateSnapshotMetadataParams struct {
 
1609
 
 
1610
        // Metadata is required.
 
1611
        //  One or more metadata key and value pairs to set or unset for the snapshot. To unset a metadata key value, specify only the key name. To set a metadata key value, specify the key and value pair. The Block Storage server does not respect case-sensitive key names. For example, if you specify both "key": "v1" and "KEY": "V1", the server sets and returns only the KEY key and value pair.
 
1612
        Metadata UpdateSnapshotMetadataMetadataParams `json:"metadata"`
 
1613
 
 
1614
        //
 
1615
        // The unique identifier of the tenant or account.
 
1616
        TenantId string `json:"-"`
 
1617
 
 
1618
        // SnapshotId is required.
 
1619
        //
 
1620
        // The unique identifier of an existing snapshot.
 
1621
        SnapshotId string `json:"-"`
 
1622
}
 
1623
 
 
1624
type UpdateSnapshotMetadataResults struct {
 
1625
        Metadata struct {
 
1626
                Key string `json:"key"`
 
1627
        } `json:"metadata"`
 
1628
}
 
1629
 
 
1630
//
 
1631
// Updates the metadata for a specified snapshot.
 
1632
func updateSnapshotMetadata(client *Client, args UpdateSnapshotMetadataParams) (*UpdateSnapshotMetadataResults, error) {
 
1633
 
 
1634
        argsAsJson, err := json.Marshal(args)
 
1635
        if err != nil {
 
1636
                return nil, err
 
1637
        }
 
1638
 
 
1639
        urlPath := url.URL{Path: fmt.Sprintf("snapshots/%s/metadata", args.SnapshotId)}
 
1640
        url := client.endpoint.ResolveReference(&urlPath).String()
 
1641
 
 
1642
        var req *http.Request
 
1643
        if string(argsAsJson) != "{}" {
 
1644
                req, err = http.NewRequest("PUT", url, bytes.NewBuffer(argsAsJson))
 
1645
                if err != nil {
 
1646
                        return nil, err
 
1647
                }
 
1648
                req.Header.Set("Content-Type", "application/json")
 
1649
        } else {
 
1650
                req, err = http.NewRequest("PUT", url, nil)
 
1651
                if err != nil {
 
1652
                        return nil, err
 
1653
                }
 
1654
        }
 
1655
 
 
1656
        resp, err := client.handleRequest(req)
 
1657
        if err != nil {
 
1658
                return nil, err
 
1659
        }
 
1660
 
 
1661
        body, err := ioutil.ReadAll(resp.Body)
 
1662
        if err != nil {
 
1663
                return nil, err
 
1664
        }
 
1665
 
 
1666
        switch resp.StatusCode {
 
1667
        default:
 
1668
                return nil, fmt.Errorf("invalid status (%d): %s", resp.StatusCode, body)
 
1669
        case 200:
 
1670
                break
 
1671
        }
 
1672
 
 
1673
        var results UpdateSnapshotMetadataResults
 
1674
        json.Unmarshal(body, &results)
 
1675
 
 
1676
        return &results, nil
 
1677
}