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 (68 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (2)
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
package policytypes

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

// PolicyType represents a clustering policy type in the Openstack cloud.
type PolicyType struct {
	Name          string                         `json:"name"`
	Version       string                         `json:"version"`
	SupportStatus map[string][]SupportStatusType `json:"support_status"`
}

// SupportStatusType represents the support status information for a
// clustering policy type.
type SupportStatusType struct {
	Status string `json:"status"`
	Since  string `json:"since"`
}

// PolicyTypeDetail represents the detailed policy type information for a
// clustering policy type.
type PolicyTypeDetail struct {
	Name          string                         `json:"name"`
	Schema        map[string]interface{}         `json:"schema"`
	SupportStatus map[string][]SupportStatusType `json:"support_status,omitempty"`
}

// policyTypeResult is the base result of a Policy Type operation.
type policyTypeResult struct {
	gophercloud.Result
}

// Extract interprets any policyTypeResult result as a PolicyTypeDetail.
func (r policyTypeResult) Extract() (*PolicyTypeDetail, error) {
	var s struct {
		PolicyType *PolicyTypeDetail `json:"policy_type"`
	}
	err := r.ExtractInto(&s)
	return s.PolicyType, err
}

// GetResult is the result of a Get operation. Call its Extract method to
// interpret it as a PolicyTypeDetail.
type GetResult struct {
	policyTypeResult
}

// PolicyTypePage contains a single page of all policy types from a List call.
type PolicyTypePage struct {
	pagination.SinglePageBase
}

// IsEmpty determines if a PolicyType contains any results.
func (page PolicyTypePage) IsEmpty() (bool, error) {
	policyTypes, err := ExtractPolicyTypes(page)
	return len(policyTypes) == 0, err
}

// ExtractPolicyTypes returns a slice of PolicyTypes from a List operation.
func ExtractPolicyTypes(r pagination.Page) ([]PolicyType, error) {
	var s struct {
		PolicyTypes []PolicyType `json:"policy_types"`
	}
	err := (r.(PolicyTypePage)).ExtractInto(&s)
	return s.PolicyTypes, err
}