File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (180 lines) | stat: -rw-r--r-- 5,811 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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 Allocation struct {
	Resources map[string]int `json:"resources"`
}

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

type ResourceProviderAllocations struct {
	ResourceProviderGeneration int                   `json:"resource_provider_generation"`
	Allocations                map[string]Allocation `json:"allocations"`
}

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
}

// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the request succeeded or failed.
type DeleteResult struct {
	gophercloud.ErrResult
}

// GetResult represents the result of a create operation. Call its Extract
// method to interpret it as a ResourceProvider.
type GetResult struct {
	resourceProviderResult
}

// UpdateResult represents the result of a update operation. Call its Extract
// method to interpret it as a ResourceProvider.
type UpdateResult 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) {
	if page.StatusCode == 204 {
		return true, nil
	}

	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
}

// GetAllocationsResult is the response of a Get allocations operations. Call its Extract method
// to interpret it as a ResourceProviderAllocations.
type GetAllocationsResult struct {
	gophercloud.Result
}

// Extract interprets a GetAllocationsResult as a ResourceProviderAllocations.
func (r GetAllocationsResult) Extract() (*ResourceProviderAllocations, error) {
	var s ResourceProviderAllocations
	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
}