forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
microversions.go
101 lines (75 loc) · 2.44 KB
/
microversions.go
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
package capsules
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ExtractV132 is a function that accepts a result and extracts a capsule resource.
func (r commonResult) ExtractV132() (*CapsuleV132, error) {
var s *CapsuleV132
err := r.ExtractInto(&s)
return s, err
}
// Represents a Capsule at microversion vXY or greater.
type CapsuleV132 struct {
// UUID for the capsule
UUID string `json:"uuid"`
// User ID for the capsule
UserID string `json:"user_id"`
// Project ID for the capsule
ProjectID string `json:"project_id"`
// cpu for the capsule
CPU float64 `json:"cpu"`
// Memory for the capsule
Memory string `json:"memory"`
// The name of the capsule
MetaName string `json:"name"`
// Indicates whether capsule is currently operational.
Status string `json:"status"`
// Indicates whether capsule is currently operational.
StatusReason string `json:"status_reason"`
// The created time of the capsule.
CreatedAt time.Time `json:"-"`
// The updated time of the capsule.
UpdatedAt time.Time `json:"-"`
// Links includes HTTP references to the itself, useful for passing along to
// other APIs that might want a capsule reference.
Links []interface{} `json:"links"`
// The capsule restart policy
RestartPolicy map[string]string `json:"restart_policy"`
// The capsule metadata labels
MetaLabels map[string]string `json:"labels"`
// The capsule IP addresses
Addresses map[string][]Address `json:"addresses"`
// The container object inside capsule
Containers []Container `json:"containers"`
// The capsule host
Host string `json:"host"`
}
// ExtractCapsulesV132 accepts a Page struct, specifically a CapsulePage struct,
// and extracts the elements into a slice of CapsuleV132 structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractCapsulesV132(r pagination.Page) ([]CapsuleV132, error) {
var s struct {
Capsules []CapsuleV132 `json:"capsules"`
}
err := (r.(CapsulePage)).ExtractInto(&s)
return s.Capsules, err
}
func (r *CapsuleV132) UnmarshalJSON(b []byte) error {
type tmp CapsuleV132
var s struct {
tmp
CreatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = CapsuleV132(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
return nil
}