...

Source file src/github.com/LINBIT/golinstor/client/storagepooldefinition.go

Documentation: github.com/LINBIT/golinstor/client

     1  package client
     2  
     3  import "context"
     4  
     5  // StoragePoolDefinition represents a storage pool definition in LINSTOR
     6  type StoragePoolDefinition struct {
     7  	StoragePoolName string `json:"storage_pool_name,omitempty"`
     8  	// A string to string property map.
     9  	Props map[string]string `json:"props,omitempty"`
    10  }
    11  
    12  // StoragePoolDefinitionModify holds properties of a storage pool definition to modify such a definition.
    13  type StoragePoolDefinitionModify struct {
    14  	GenericPropsModify
    15  }
    16  
    17  // custom code
    18  
    19  // StoragePoolDefinitionProvider acts as an abstraction for a
    20  // StoragePoolDefinitionService. It can be swapped out for another
    21  // StoragePoolDefinitionService implementation, for example for testing.
    22  type StoragePoolDefinitionProvider interface {
    23  	// GetAll gets information for all existing storage pool definitions.
    24  	GetAll(ctx context.Context, opts ...*ListOpts) ([]StoragePoolDefinition, error)
    25  	// Get gets information for a particular storage pool definition.
    26  	Get(ctx context.Context, spdName string, opts ...*ListOpts) (StoragePoolDefinition, error)
    27  	// Create creates a new storage pool definition
    28  	Create(ctx context.Context, spd StoragePoolDefinition) error
    29  	// Modify modifies the given storage pool definition and sets/deletes the given properties.
    30  	Modify(ctx context.Context, spdName string, props StoragePoolDefinitionModify) error
    31  	// Delete deletes the given storage pool definition.
    32  	Delete(ctx context.Context, spdName string) error
    33  	// GetPropsInfos gets meta information about the properties that can be
    34  	// set on a storage pool definition.
    35  	GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error)
    36  }
    37  
    38  var _ StoragePoolDefinitionProvider = &StoragePoolDefinitionService{}
    39  
    40  // StoragePoolDefinitionService is the service that deals with storage pool definition related tasks.
    41  type StoragePoolDefinitionService struct {
    42  	client *Client
    43  }
    44  
    45  // GetAll gets information for all existing storage pool definitions.
    46  func (s *StoragePoolDefinitionService) GetAll(ctx context.Context, opts ...*ListOpts) ([]StoragePoolDefinition, error) {
    47  	var spds []StoragePoolDefinition
    48  	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions", &spds, opts...)
    49  	return spds, err
    50  }
    51  
    52  // Get gets information for a particular storage pool definition.
    53  func (s *StoragePoolDefinitionService) Get(ctx context.Context, spdName string, opts ...*ListOpts) (StoragePoolDefinition, error) {
    54  	var spd StoragePoolDefinition
    55  	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions/"+spdName, &spd, opts...)
    56  	return spd, err
    57  }
    58  
    59  // Create creates a new storage pool definition
    60  func (s *StoragePoolDefinitionService) Create(ctx context.Context, spd StoragePoolDefinition) error {
    61  	_, err := s.client.doPOST(ctx, "/v1/storage-pool-definitions", spd)
    62  	return err
    63  }
    64  
    65  // Modify modifies the given storage pool definition and sets/deletes the given properties.
    66  func (s *StoragePoolDefinitionService) Modify(ctx context.Context, spdName string, props StoragePoolDefinitionModify) error {
    67  	_, err := s.client.doPUT(ctx, "/v1/storage-pool-definitions/"+spdName, props)
    68  	return err
    69  }
    70  
    71  // Delete deletes the given storage pool definition.
    72  func (s *StoragePoolDefinitionService) Delete(ctx context.Context, spdName string) error {
    73  	_, err := s.client.doDELETE(ctx, "/v1/storage-pool-definitions/"+spdName, nil)
    74  	return err
    75  }
    76  
    77  // GetPropsInfos gets meta information about the properties that can be set on
    78  // a storage pool definition.
    79  func (s *StoragePoolDefinitionService) GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error) {
    80  	var infos []PropsInfo
    81  	_, err := s.client.doGET(ctx, "/v1/storage-pool-definitions/properties/info", &infos, opts...)
    82  	return infos, err
    83  }
    84  

View as plain text