/
doc.go
163 lines (127 loc) · 3.67 KB
/
doc.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 volumes provides information and interaction with volumes in the
OpenStack Block Storage service. A volume is a detachable block storage
device, akin to a USB hard drive. It can only be attached to one instance at
a time.
Example of creating Volume B on a Different Host than Volume A
schedulerHints := volumes.SchedulerHints{
DifferentHost: []string{
"volume-a-uuid",
}
}
createOpts := volumes.CreateOpts{
Name: "volume_b",
Size: 10,
SchedulerHints: schedulerHints,
}
volume, err := volumes.Create(context.TODO(), computeClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example of creating Volume B on the Same Host as Volume A
schedulerHints := volumes.SchedulerHints{
SameHost: []string{
"volume-a-uuid",
}
}
createOpts := volumes.CreateOpts{
Name: "volume_b",
Size: 10
SchedulerHints: schedulerHints,
}
volume, err := volumes.Create(context.TODO(), computeClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example of creating a Volume from a Backup
backupID := "20c792f0-bb03-434f-b653-06ef238e337e"
options := volumes.CreateOpts{
Name: "vol-001",
BackupID: &backupID,
}
client.Microversion = "3.47"
volume, err := volumes.Create(context.TODO(), client, options).Extract()
if err != nil {
panic(err)
}
fmt.Println(volume)
Example of Creating an Image from a Volume
uploadImageOpts := volumes.UploadImageOpts{
ImageName: "my_vol",
Force: true,
}
volumeImage, err := volumes.UploadImage(context.TODO(), client, volume.ID, uploadImageOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", volumeImage)
Example of Extending a Volume's Size
extendOpts := volumes.ExtendSizeOpts{
NewSize: 100,
}
err := volumes.ExtendSize(context.TODO(), client, volume.ID, extendOpts).ExtractErr()
if err != nil {
panic(err)
}
Example of Initializing a Volume Connection
connectOpts := &volumes.InitializeConnectionOpts{
IP: "127.0.0.1",
Host: "stack",
Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
Multipath: gophercloud.Disabled,
Platform: "x86_64",
OSType: "linux2",
}
connectionInfo, err := volumes.InitializeConnection(context.TODO(), client, volume.ID, connectOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", connectionInfo["data"])
terminateOpts := &volumes.InitializeConnectionOpts{
IP: "127.0.0.1",
Host: "stack",
Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
Multipath: gophercloud.Disabled,
Platform: "x86_64",
OSType: "linux2",
}
err = volumes.TerminateConnection(context.TODO(), client, volume.ID, terminateOpts).ExtractErr()
if err != nil {
panic(err)
}
Example of Setting a Volume's Bootable status
options := volumes.BootableOpts{
Bootable: true,
}
err := volumes.SetBootable(context.TODO(), client, volume.ID, options).ExtractErr()
if err != nil {
panic(err)
}
Example of Changing Type of a Volume
changeTypeOpts := volumes.ChangeTypeOpts{
NewType: "ssd",
MigrationPolicy: volumes.MigrationPolicyOnDemand,
}
err = volumes.ChangeType(context.TODO(), client, volumeID, changeTypeOpts).ExtractErr()
if err != nil {
panic(err)
}
Example of Attaching a Volume to an Instance
attachOpts := volumes.AttachOpts{
MountPoint: "/mnt",
Mode: "rw",
InstanceUUID: server.ID,
}
err := volumes.Attach(context.TODO(), client, volume.ID, attachOpts).ExtractErr()
if err != nil {
panic(err)
}
detachOpts := volumes.DetachOpts{
AttachmentID: volume.Attachments[0].AttachmentID,
}
err = volumes.Detach(context.TODO(), client, volume.ID, detachOpts).ExtractErr()
if err != nil {
panic(err)
}
*/
package volumes