File: storagepooldefinition.go

package info (click to toggle)
golang-github-linbit-golinstor 0.55.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 480 kB
  • sloc: makefile: 11
file content (83 lines) | stat: -rw-r--r-- 3,672 bytes parent folder | download
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
package client

import "context"

// StoragePoolDefinition represents a storage pool definition in LINSTOR
type StoragePoolDefinition struct {
	StoragePoolName string `json:"storage_pool_name,omitempty"`
	// A string to string property map.
	Props map[string]string `json:"props,omitempty"`
}

// StoragePoolDefinitionModify holds properties of a storage pool definition to modify such a definition.
type StoragePoolDefinitionModify struct {
	GenericPropsModify
}

// custom code

// StoragePoolDefinitionProvider acts as an abstraction for a
// StoragePoolDefinitionService. It can be swapped out for another
// StoragePoolDefinitionService implementation, for example for testing.
type StoragePoolDefinitionProvider interface {
	// GetAll gets information for all existing storage pool definitions.
	GetAll(ctx context.Context, opts ...*ListOpts) ([]StoragePoolDefinition, error)
	// Get gets information for a particular storage pool definition.
	Get(ctx context.Context, spdName string, opts ...*ListOpts) (StoragePoolDefinition, error)
	// Create creates a new storage pool definition
	Create(ctx context.Context, spd StoragePoolDefinition) error
	// Modify modifies the given storage pool definition and sets/deletes the given properties.
	Modify(ctx context.Context, spdName string, props StoragePoolDefinitionModify) error
	// Delete deletes the given storage pool definition.
	Delete(ctx context.Context, spdName string) error
	// GetPropsInfos gets meta information about the properties that can be
	// set on a storage pool definition.
	GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error)
}

var _ StoragePoolDefinitionProvider = &StoragePoolDefinitionService{}

// StoragePoolDefinitionService is the service that deals with storage pool definition related tasks.
type StoragePoolDefinitionService struct {
	client *Client
}

// GetAll gets information for all existing storage pool definitions.
func (s *StoragePoolDefinitionService) GetAll(ctx context.Context, opts ...*ListOpts) ([]StoragePoolDefinition, error) {
	var spds []StoragePoolDefinition
	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions", &spds, opts...)
	return spds, err
}

// Get gets information for a particular storage pool definition.
func (s *StoragePoolDefinitionService) Get(ctx context.Context, spdName string, opts ...*ListOpts) (StoragePoolDefinition, error) {
	var spd StoragePoolDefinition
	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions/"+spdName, &spd, opts...)
	return spd, err
}

// Create creates a new storage pool definition
func (s *StoragePoolDefinitionService) Create(ctx context.Context, spd StoragePoolDefinition) error {
	_, err := s.client.doPOST(ctx, "/v1/storage-pool-definitions", spd)
	return err
}

// Modify modifies the given storage pool definition and sets/deletes the given properties.
func (s *StoragePoolDefinitionService) Modify(ctx context.Context, spdName string, props StoragePoolDefinitionModify) error {
	_, err := s.client.doPUT(ctx, "/v1/storage-pool-definitions/"+spdName, props)
	return err
}

// Delete deletes the given storage pool definition.
func (s *StoragePoolDefinitionService) Delete(ctx context.Context, spdName string) error {
	_, err := s.client.doDELETE(ctx, "/v1/storage-pool-definitions/"+spdName, nil)
	return err
}

// GetPropsInfos gets meta information about the properties that can be set on
// a storage pool definition.
func (s *StoragePoolDefinitionService) GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error) {
	var infos []PropsInfo
	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions/properties/info", &infos, opts...)
	return infos, err
}