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 (144 lines) | stat: -rw-r--r-- 4,203 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
package registeredlimits

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

// A model describing the configured enforcement model used by the deployment.
type EnforcementModel struct {
	// The name of the enforcement model.
	Name string `json:"name"`

	// A short description of the enforcement model used.
	Description string `json:"description"`
}

// EnforcementModelResult is the response from a GetEnforcementModel operation. Call its Extract method
// to interpret it as a EnforcementModel.
type EnforcementModelResult struct {
	gophercloud.Result
}

// Extract interprets EnforcementModelResult as a EnforcementModel.
func (r EnforcementModelResult) Extract() (*EnforcementModel, error) {
	var out struct {
		Model *EnforcementModel `json:"model"`
	}
	err := r.ExtractInto(&out)
	return out.Model, err
}

// A registered limit is the limit that is default for all projects.
type RegisteredLimit struct {
	// ID is the unique ID of the limit.
	ID string `json:"id"`

	// RegionID is the ID of the region where the limit is applied.
	RegionID string `json:"region_id"`

	// ServiceID is the ID of the service where the limit is applied.
	ServiceID string `json:"service_id"`

	// Description of the limit.
	Description string `json:"description"`

	// ResourceName is the name of the resource that the limit is applied to.
	ResourceName string `json:"resource_name"`

	// DefaultLimit is the default limit.
	DefaultLimit int `json:"default_limit"`

	// Links contains referencing links to the limit.
	Links map[string]interface{} `json:"links"`
}

// A LimitsOutput is an array of limits returned by List and BatchCreate operations
type RegisteredLimitsOutput struct {
	RegisteredLimits []RegisteredLimit `json:"registered_limits"`
}

// A RegisteredLimitOutput is an encapsulated Limit returned by Get and Update operations
type RegisteredLimitOutput struct {
	RegisteredLimit *RegisteredLimit `json:"registered_limit"`
}

// RegisteredLimitPage is a single page of Registered Limit results.
type RegisteredLimitPage struct {
	pagination.LinkedPageBase
}

type commonResult struct {
	gophercloud.Result
}

// GetResult is the response from a Get operation. Call its Extract method
// to interpret it as a RegisteredLimit.
type GetResult struct {
	commonResult
}

// CreateResult is the response from a Create operation. Call its Extract method
// to interpret it as a Registered Limits.
type CreateResult struct {
	gophercloud.Result
}

// UpdateResult is the result of an Update request. Call its Extract method to
// interpret it as a Limit.
type UpdateResult struct {
	commonResult
}

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

// IsEmpty determines whether or not a page of Limits contains any results.
func (r RegisteredLimitPage) IsEmpty() (bool, error) {
	if r.StatusCode == 204 {
		return true, nil
	}

	registered_limits, err := ExtractRegisteredLimits(r)
	return len(registered_limits) == 0, err
}

// NextPageURL extracts the "next" link from the links section of the result.
func (r RegisteredLimitPage) NextPageURL() (string, error) {
	var s struct {
		Links struct {
			Next     string `json:"next"`
			Previous string `json:"previous"`
		} `json:"links"`
	}
	err := r.ExtractInto(&s)
	if err != nil {
		return "", err
	}
	return s.Links.Next, err
}

// ExtractRegisteredLimits returns a slice of Registered Limits contained in a single page of
// results.
func ExtractRegisteredLimits(r pagination.Page) ([]RegisteredLimit, error) {
	var out RegisteredLimitsOutput
	err := (r.(RegisteredLimitPage)).ExtractInto(&out)
	return out.RegisteredLimits, err
}

// Extract interprets CreateResult as slice of RegisteredLimits.
func (r CreateResult) Extract() ([]RegisteredLimit, error) {
	var out RegisteredLimitsOutput
	err := r.ExtractInto(&out)
	return out.RegisteredLimits, err
}

// Extract interprets any commonResult as a RegisteredLimit.
func (r commonResult) Extract() (*RegisteredLimit, error) {
	var out RegisteredLimitOutput
	err := r.ExtractInto(&out)
	return out.RegisteredLimit, err
}