-
Notifications
You must be signed in to change notification settings - Fork 6
/
storagepool.go
55 lines (45 loc) · 1.66 KB
/
storagepool.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
/*
Copyright (c) 2019 Dell Corporation
All Rights Reserved
*/
package gounity
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/dell/gounity/api"
"github.com/dell/gounity/types"
)
// Storagepool structure
type Storagepool struct {
client *Client
}
// NewStoragePool returns storagepool
func NewStoragePool(client *Client) *Storagepool {
return &Storagepool{client}
}
// FindStoragePoolByName - Find the volume by it's name. If the volume is not found, an error will be returned.
func (sp *Storagepool) FindStoragePoolByName(ctx context.Context, poolName string) (*types.StoragePool, error) {
if len(poolName) == 0 {
return nil, errors.New("poolName shouldn't be empty")
}
spResponse := &types.StoragePool{}
err := sp.client.executeWithRetryAuthenticate(ctx, http.MethodGet, fmt.Sprintf(api.UnityAPIGetResourceByNameWithFieldsURI, api.PoolAction, poolName, StoragePoolFields), nil, spResponse)
if err != nil {
return nil, fmt.Errorf("find storage pool by name failed %s err: %v", poolName, err)
}
return spResponse, nil
}
// FindStoragePoolByID - Find the volume by it's Id. If the volume is not found, an error will be returned.
func (sp *Storagepool) FindStoragePoolByID(ctx context.Context, poolID string) (*types.StoragePool, error) {
if len(poolID) == 0 {
return nil, errors.New("pool Id cannot be empty")
}
spResponse := &types.StoragePool{}
err := sp.client.executeWithRetryAuthenticate(ctx, http.MethodGet, fmt.Sprintf(api.UnityAPIGetResourceWithFieldsURI, api.PoolAction, poolID, StoragePoolFields), nil, spResponse)
if err != nil {
return nil, fmt.Errorf("find storage pool by ID failed %s err: %v", poolID, err)
}
return spResponse, nil
}