-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvolume.go
90 lines (80 loc) · 2.6 KB
/
volume.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
// Copyright 2020 Hewlett Packard Enterprise Development LP
package main
import (
"fmt"
"github.com/hpe-storage/nimble-golang-sdk/pkg/client/v1/nimbleos"
"github.com/hpe-storage/nimble-golang-sdk/pkg/param"
"github.com/hpe-storage/nimble-golang-sdk/pkg/service"
"os"
)
func main() {
host := os.Getenv("SDK_TARGET_HOST")
user := os.Getenv("SDK_TARGET_USER")
password := os.Getenv("SDK_TARGET_PASSWORD")
if host == "" || user == "" || password == "" {
fmt.Println("ERROR: Missing one of these environment variables: SDK_TARGET_HOST, SDK_TARGET_USER, SDK_TARGET_PASSWORD")
fmt.Println("Usage:")
fmt.Println("SDK_TARGET_HOST - Management hostname or IP of array")
fmt.Println("SDK_TARGET_USER - User (non-tenant) username")
fmt.Println("SDK_TARGET_PASSWORD - User (non-tenant) password")
os.Exit(1)
}
groupService, err := service.NewNimbleGroupService(
service.WithHost(host),
service.WithUser(user),
service.WithPassword(password))
if err != nil {
fmt.Printf("NewGroupService(): Unable to connect to group, err: %v\n", err.Error())
os.Exit(1)
}
defer groupService.LogoutService()
// get volume service instance
volSvc := groupService.GetVolumeService()
// Initialize volume attributes
var sizeField int64 = 5120
descriptionField := "This volume was created as part of a unit test"
var limitIopsField int64 = 256
var limitMbpsField int64 = 1
// set volume attributes
newVolume := &nimbleos.Volume{
Name: param.NewString("TestDemo1"),
Size: &sizeField,
Description: &descriptionField,
ThinlyProvisioned: param.NewBool(true),
Online: param.NewBool(true),
LimitIops: &limitIopsField,
LimitMbps: &limitMbpsField,
MultiInitiator: param.NewBool(true),
AgentType: nimbleos.NsAgentTypeNone,
}
// create volume
volume, err := volSvc.CreateVolume(newVolume)
if err != nil {
fmt.Printf("Failed to create volume, err: %v,\n", err)
return
}
fmt.Println(volume)
// get volume by name
volume, err = volSvc.GetVolumeByName("TestDemo1")
if err != nil {
fmt.Printf("Failed to get volume by name, err: %v,\n", err)
return
}
fmt.Println(volume)
// get volume with params
requestParams := new(param.GetParams)
fieldList := []string{
nimbleos.VolumeFields.ID,
nimbleos.VolumeFields.Name,
nimbleos.VolumeFields.Size,
nimbleos.VolumeFields.LimitMbps,
}
requestParams.WithFields(fieldList)
volumeList, err := volSvc.GetVolumes(requestParams)
if err != nil {
fmt.Printf("Error: get volume with params. Message: %v\n", err)
}
fmt.Println(volumeList)
// delete volume, cleanup
volSvc.DeleteVolume(*volume.ID)
}