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 (141 lines) | stat: -rw-r--r-- 3,479 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
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
package configurations

import (
	"encoding/json"
	"time"

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

// Config represents a configuration group API resource.
type Config struct {
	Created              time.Time `json:"-"`
	Updated              time.Time `json:"-"`
	DatastoreName        string    `json:"datastore_name"`
	DatastoreVersionID   string    `json:"datastore_version_id"`
	DatastoreVersionName string    `json:"datastore_version_name"`
	Description          string
	ID                   string
	Name                 string
	Values               map[string]interface{}
}

func (r *Config) UnmarshalJSON(b []byte) error {
	type tmp Config
	var s struct {
		tmp
		Created gophercloud.JSONRFC3339NoZ `json:"created"`
		Updated gophercloud.JSONRFC3339NoZ `json:"updated"`
	}
	err := json.Unmarshal(b, &s)
	if err != nil {
		return err
	}
	*r = Config(s.tmp)

	r.Created = time.Time(s.Created)
	r.Updated = time.Time(s.Updated)

	return nil
}

// ConfigPage contains a page of Config resources in a paginated collection.
type ConfigPage struct {
	pagination.SinglePageBase
}

// IsEmpty indicates whether a ConfigPage is empty.
func (r ConfigPage) IsEmpty() (bool, error) {
	is, err := ExtractConfigs(r)
	return len(is) == 0, err
}

// ExtractConfigs will retrieve a slice of Config structs from a page.
func ExtractConfigs(r pagination.Page) ([]Config, error) {
	var s struct {
		Configs []Config `json:"configurations"`
	}
	err := (r.(ConfigPage)).ExtractInto(&s)
	return s.Configs, err
}

type commonResult struct {
	gophercloud.Result
}

// Extract will retrieve a Config resource from an operation result.
func (r commonResult) Extract() (*Config, error) {
	var s struct {
		Config *Config `json:"configuration"`
	}
	err := r.ExtractInto(&s)
	return s.Config, err
}

// GetResult represents the result of a Get operation.
type GetResult struct {
	commonResult
}

// CreateResult represents the result of a Create operation.
type CreateResult struct {
	commonResult
}

// UpdateResult represents the result of an Update operation.
type UpdateResult struct {
	gophercloud.ErrResult
}

// ReplaceResult represents the result of a Replace operation.
type ReplaceResult struct {
	gophercloud.ErrResult
}

// DeleteResult represents the result of a Delete operation.
type DeleteResult struct {
	gophercloud.ErrResult
}

// Param represents a configuration parameter API resource.
type Param struct {
	Max             float64
	Min             float64
	Name            string
	RestartRequired bool `json:"restart_required"`
	Type            string
}

// ParamPage contains a page of Param resources in a paginated collection.
type ParamPage struct {
	pagination.SinglePageBase
}

// IsEmpty indicates whether a ParamPage is empty.
func (r ParamPage) IsEmpty() (bool, error) {
	is, err := ExtractParams(r)
	return len(is) == 0, err
}

// ExtractParams will retrieve a slice of Param structs from a page.
func ExtractParams(r pagination.Page) ([]Param, error) {
	var s struct {
		Params []Param `json:"configuration-parameters"`
	}
	err := (r.(ParamPage)).ExtractInto(&s)
	return s.Params, err
}

// ParamResult represents the result of an operation which retrieves details
// about a particular configuration param.
type ParamResult struct {
	gophercloud.Result
}

// Extract will retrieve a param from an operation result.
func (r ParamResult) Extract() (*Param, error) {
	var s *Param
	err := r.ExtractInto(&s)
	return s, err
}