File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (136 lines) | stat: -rw-r--r-- 4,486 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package resourceproviders

import (
	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/pagination"
)

type ResourceProviderLinks struct {
	Href string `json:"href"`
	Rel  string `json:"rel"`
}

// ResourceProvider are entities which provider consumable inventory of one or more classes of resource
type ResourceProvider struct {
	// Generation is a consistent view marker that assists with the management of concurrent resource provider updates.
	Generation int `json:"generation"`

	// UUID of a resource provider.
	UUID string `json:"uuid"`

	// Links is a list of links associated with one resource provider.
	Links []ResourceProviderLinks `json:"links"`

	// Name of one resource provider.
	Name string `json:"name"`

	// The ParentProviderUUID contains the UUID of the immediate parent of the resource provider.
	// Requires microversion 1.14 or above
	ParentProviderUUID string `json:"parent_provider_uuid"`

	// The RootProviderUUID contains the read-only UUID of the top-most provider in this provider tree.
	// Requires microversion 1.14 or above
	RootProviderUUID string `json:"root_provider_uuid"`
}

type ResourceProviderUsage struct {
	ResourceProviderGeneration int            `json:"resource_provider_generation"`
	Usages                     map[string]int `json:"usages"`
}

type Inventory struct {
	AllocationRatio float32 `json:"allocation_ratio"`
	MaxUnit         int     `json:"max_unit"`
	MinUnit         int     `json:"min_unit"`
	Reserved        int     `json:"reserved"`
	StepSize        int     `json:"step_size"`
	Total           int     `json:"total"`
}

type ResourceProviderInventories struct {
	ResourceProviderGeneration int                  `json:"resource_provider_generation"`
	Inventories                map[string]Inventory `json:"inventories"`
}

type ResourceProviderTraits struct {
	ResourceProviderGeneration int      `json:"resource_provider_generation"`
	Traits                     []string `json:"traits"`
}

// resourceProviderResult is the response of a base ResourceProvider result.
type resourceProviderResult struct {
	gophercloud.Result
}

// Extract interpets any resourceProviderResult-base result as a ResourceProvider.
func (r resourceProviderResult) Extract() (*ResourceProvider, error) {
	var s ResourceProvider
	err := r.ExtractInto(&s)

	return &s, err
}

// CreateResult is the result of a Create operation. Call its Extract
// method to interpret it as a ResourceProvider.
type CreateResult struct {
	resourceProviderResult
}

// ResourceProvidersPage contains a single page of all resource providers from a List call.
type ResourceProvidersPage struct {
	pagination.SinglePageBase
}

// IsEmpty determines if a ResourceProvidersPage contains any results.
func (page ResourceProvidersPage) IsEmpty() (bool, error) {
	resourceProviders, err := ExtractResourceProviders(page)
	return len(resourceProviders) == 0, err
}

// ExtractResourceProviders returns a slice of ResourceProvider from a List operation.
func ExtractResourceProviders(r pagination.Page) ([]ResourceProvider, error) {
	var s struct {
		ResourceProviders []ResourceProvider `json:"resource_providers"`
	}
	err := (r.(ResourceProvidersPage)).ExtractInto(&s)
	return s.ResourceProviders, err
}

// GetUsagesResult is the response of a Get usage operations. Call its Extract method
// to interpret it as a ResourceProviderUsage.
type GetUsagesResult struct {
	gophercloud.Result
}

// Extract interprets a GetUsagesResult as a ResourceProviderUsage.
func (r GetUsagesResult) Extract() (*ResourceProviderUsage, error) {
	var s ResourceProviderUsage
	err := r.ExtractInto(&s)
	return &s, err
}

// GetInventoriesResult is the response of a Get inventories operations. Call its Extract method
// to interpret it as a ResourceProviderInventories.
type GetInventoriesResult struct {
	gophercloud.Result
}

// Extract interprets a GetInventoriesResult as a ResourceProviderInventories.
func (r GetInventoriesResult) Extract() (*ResourceProviderInventories, error) {
	var s ResourceProviderInventories
	err := r.ExtractInto(&s)
	return &s, err
}

// GetTraitsResult is the response of a Get traits operations. Call its Extract method
// to interpret it as a ResourceProviderTraits.
type GetTraitsResult struct {
	gophercloud.Result
}

// Extract interprets a GetTraitsResult as a ResourceProviderTraits.
func (r GetTraitsResult) Extract() (*ResourceProviderTraits, error) {
	var s ResourceProviderTraits
	err := r.ExtractInto(&s)
	return &s, err
}