github.com/gophercloud/gophercloud@v1.11.0/openstack/placement/v1/resourceproviders/results.go (about)

     1  package resourceproviders
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type ResourceProviderLinks struct {
     9  	Href string `json:"href"`
    10  	Rel  string `json:"rel"`
    11  }
    12  
    13  // ResourceProvider are entities which provider consumable inventory of one or more classes of resource
    14  type ResourceProvider struct {
    15  	// Generation is a consistent view marker that assists with the management of concurrent resource provider updates.
    16  	Generation int `json:"generation"`
    17  
    18  	// UUID of a resource provider.
    19  	UUID string `json:"uuid"`
    20  
    21  	// Links is a list of links associated with one resource provider.
    22  	Links []ResourceProviderLinks `json:"links"`
    23  
    24  	// Name of one resource provider.
    25  	Name string `json:"name"`
    26  
    27  	// The ParentProviderUUID contains the UUID of the immediate parent of the resource provider.
    28  	// Requires microversion 1.14 or above
    29  	ParentProviderUUID string `json:"parent_provider_uuid"`
    30  
    31  	// The RootProviderUUID contains the read-only UUID of the top-most provider in this provider tree.
    32  	// Requires microversion 1.14 or above
    33  	RootProviderUUID string `json:"root_provider_uuid"`
    34  }
    35  
    36  type ResourceProviderUsage struct {
    37  	ResourceProviderGeneration int            `json:"resource_provider_generation"`
    38  	Usages                     map[string]int `json:"usages"`
    39  }
    40  
    41  type Inventory struct {
    42  	AllocationRatio float32 `json:"allocation_ratio"`
    43  	MaxUnit         int     `json:"max_unit"`
    44  	MinUnit         int     `json:"min_unit"`
    45  	Reserved        int     `json:"reserved"`
    46  	StepSize        int     `json:"step_size"`
    47  	Total           int     `json:"total"`
    48  }
    49  
    50  type Allocation struct {
    51  	Resources map[string]int `json:"resources"`
    52  }
    53  
    54  type ResourceProviderInventories struct {
    55  	ResourceProviderGeneration int                  `json:"resource_provider_generation"`
    56  	Inventories                map[string]Inventory `json:"inventories"`
    57  }
    58  
    59  type ResourceProviderAllocations struct {
    60  	ResourceProviderGeneration int                   `json:"resource_provider_generation"`
    61  	Allocations                map[string]Allocation `json:"allocations"`
    62  }
    63  
    64  type ResourceProviderTraits struct {
    65  	ResourceProviderGeneration int      `json:"resource_provider_generation"`
    66  	Traits                     []string `json:"traits"`
    67  }
    68  
    69  // resourceProviderResult is the response of a base ResourceProvider result.
    70  type resourceProviderResult struct {
    71  	gophercloud.Result
    72  }
    73  
    74  // Extract interpets any resourceProviderResult-base result as a ResourceProvider.
    75  func (r resourceProviderResult) Extract() (*ResourceProvider, error) {
    76  	var s ResourceProvider
    77  	err := r.ExtractInto(&s)
    78  
    79  	return &s, err
    80  }
    81  
    82  // CreateResult is the result of a Create operation. Call its Extract
    83  // method to interpret it as a ResourceProvider.
    84  type CreateResult struct {
    85  	resourceProviderResult
    86  }
    87  
    88  // DeleteResult represents the result of a delete operation. Call its
    89  // ExtractErr method to determine if the request succeeded or failed.
    90  type DeleteResult struct {
    91  	gophercloud.ErrResult
    92  }
    93  
    94  // GetResult represents the result of a create operation. Call its Extract
    95  // method to interpret it as a ResourceProvider.
    96  type GetResult struct {
    97  	resourceProviderResult
    98  }
    99  
   100  // UpdateResult represents the result of a update operation. Call its Extract
   101  // method to interpret it as a ResourceProvider.
   102  type UpdateResult struct {
   103  	resourceProviderResult
   104  }
   105  
   106  // ResourceProvidersPage contains a single page of all resource providers from a List call.
   107  type ResourceProvidersPage struct {
   108  	pagination.SinglePageBase
   109  }
   110  
   111  // IsEmpty determines if a ResourceProvidersPage contains any results.
   112  func (page ResourceProvidersPage) IsEmpty() (bool, error) {
   113  	if page.StatusCode == 204 {
   114  		return true, nil
   115  	}
   116  
   117  	resourceProviders, err := ExtractResourceProviders(page)
   118  	return len(resourceProviders) == 0, err
   119  }
   120  
   121  // ExtractResourceProviders returns a slice of ResourceProvider from a List operation.
   122  func ExtractResourceProviders(r pagination.Page) ([]ResourceProvider, error) {
   123  	var s struct {
   124  		ResourceProviders []ResourceProvider `json:"resource_providers"`
   125  	}
   126  	err := (r.(ResourceProvidersPage)).ExtractInto(&s)
   127  	return s.ResourceProviders, err
   128  }
   129  
   130  // GetUsagesResult is the response of a Get usage operations. Call its Extract method
   131  // to interpret it as a ResourceProviderUsage.
   132  type GetUsagesResult struct {
   133  	gophercloud.Result
   134  }
   135  
   136  // Extract interprets a GetUsagesResult as a ResourceProviderUsage.
   137  func (r GetUsagesResult) Extract() (*ResourceProviderUsage, error) {
   138  	var s ResourceProviderUsage
   139  	err := r.ExtractInto(&s)
   140  	return &s, err
   141  }
   142  
   143  // GetInventoriesResult is the response of a Get inventories operations. Call its Extract method
   144  // to interpret it as a ResourceProviderInventories.
   145  type GetInventoriesResult struct {
   146  	gophercloud.Result
   147  }
   148  
   149  // Extract interprets a GetInventoriesResult as a ResourceProviderInventories.
   150  func (r GetInventoriesResult) Extract() (*ResourceProviderInventories, error) {
   151  	var s ResourceProviderInventories
   152  	err := r.ExtractInto(&s)
   153  	return &s, err
   154  }
   155  
   156  // GetAllocationsResult is the response of a Get allocations operations. Call its Extract method
   157  // to interpret it as a ResourceProviderAllocations.
   158  type GetAllocationsResult struct {
   159  	gophercloud.Result
   160  }
   161  
   162  // Extract interprets a GetAllocationsResult as a ResourceProviderAllocations.
   163  func (r GetAllocationsResult) Extract() (*ResourceProviderAllocations, error) {
   164  	var s ResourceProviderAllocations
   165  	err := r.ExtractInto(&s)
   166  	return &s, err
   167  }
   168  
   169  // GetTraitsResult is the response of a Get traits operations. Call its Extract method
   170  // to interpret it as a ResourceProviderTraits.
   171  type GetTraitsResult struct {
   172  	gophercloud.Result
   173  }
   174  
   175  // Extract interprets a GetTraitsResult as a ResourceProviderTraits.
   176  func (r GetTraitsResult) Extract() (*ResourceProviderTraits, error) {
   177  	var s ResourceProviderTraits
   178  	err := r.ExtractInto(&s)
   179  	return &s, err
   180  }