File: volumes.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (89 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (3)
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
package cs

import (
	"net/http"
)

type VolumeDriverType string

const (
	OSSFSDriver VolumeDriverType = "ossfs"
	NASDriver   VolumeDriverType = "nas"
)

type DriverOptions interface {
	driverOptions()
}

type OSSOpts struct {
	Bucket          string `json:"bucket"`
	AccessKeyId     string `json:"ak_id"`
	AccessKeySecret string `json:"ak_secret"`
	URL             string `json:"url"`
	NoStatCache     string `json:"no_stat_cache"`
	OtherOpts       string `json:"other_opts"`
}

func (*OSSOpts) driverOptions() {}

type NASOpts struct {
	DiskId string `json:"disk_id"`
	Host   string `json:"host"`
	Path   string `json:"path"`
	Mode   string `json:"mode"`
}

func (*NASOpts) driverOptions() {}

type VolumeRef struct {
	Name string `json:"Name"`
	ID   string `json:"ID"`
}

type VolumeCreationArgs struct {
	Name       string           `json:"name"`
	Driver     VolumeDriverType `json:"driver"`
	DriverOpts DriverOptions    `json:"driverOpts"`
}

type VolumeCreationResponse struct {
	Name       string            `json:"Name"`
	Driver     string            `json:"Driver"`
	Mountpoint string            `json:"Mountpoint"`
	Labels     map[string]string `json:"Labels"`
	Scope      string            `json:"Scope"`
}

type GetVolumeResponse struct {
	Name       string            `json:"Name"`
	Driver     string            `json:"Driver"`
	Mountpoint string            `json:"Mountpoint"`
	Labels     map[string]string `json:"Labels"`
	Scope      string            `json:"Scope"`
	Node       string            `json:"Node"`
	Refs       []VolumeRef       `json:"Refs"`
}

type GetVolumesResponse struct {
	Volumes []GetVolumeResponse `json:"Volumes"`
}

func (client *ProjectClient) CreateVolume(args *VolumeCreationArgs) (err error) {
	err = client.Invoke(http.MethodPost, "/volumes/create", nil, args, nil)
	return
}

func (client *ProjectClient) GetVolume(name string) (volume GetVolumeResponse, err error) {
	err = client.Invoke(http.MethodGet, "/volumes/"+name, nil, nil, &volume)
	return
}

func (client *ProjectClient) GetVolumes() (volumes GetVolumesResponse, err error) {
	err = client.Invoke(http.MethodGet, "/volumes", nil, nil, &volumes)
	return
}

func (client *ProjectClient) DeleteVolume(name string) (err error) {
	err = client.Invoke(http.MethodDelete, "/volumes/"+name, nil, nil, nil)
	return
}