forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
plans.go
122 lines (98 loc) · 2.66 KB
/
plans.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package packngo
const planBasePath = "/plans"
// PlanService interface defines available plan methods
type PlanService interface {
List() ([]Plan, *Response, error)
}
type planRoot struct {
Plans []Plan `json:"plans"`
}
// Plan represents a Packet service plan
type Plan struct {
ID string `json:"id"`
Slug string `json:"slug,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Line string `json:"line,omitempty"`
Specs *Specs `json:"specs,omitempty"`
Pricing *Pricing `json:"pricing,omitempty"`
}
func (p Plan) String() string {
return Stringify(p)
}
// Specs - the server specs for a plan
type Specs struct {
Cpus []*Cpus `json:"cpus,omitempty"`
Memory *Memory `json:"memory,omitempty"`
Drives []*Drives `json:"drives,omitempty"`
Nics []*Nics `json:"nics,omitempty"`
Features *Features `json:"features,omitempty"`
}
func (s Specs) String() string {
return Stringify(s)
}
// Cpus - the CPU config details for specs on a plan
type Cpus struct {
Count int `json:"count,omitempty"`
Type string `json:"type,omitempty"`
}
func (c Cpus) String() string {
return Stringify(c)
}
// Memory - the RAM config details for specs on a plan
type Memory struct {
Total string `json:"total,omitempty"`
}
func (m Memory) String() string {
return Stringify(m)
}
// Drives - the storage config details for specs on a plan
type Drives struct {
Count int `json:"count,omitempty"`
Size string `json:"size,omitempty"`
Type string `json:"type,omitempty"`
}
func (d Drives) String() string {
return Stringify(d)
}
// Nics - the network hardware details for specs on a plan
type Nics struct {
Count int `json:"count,omitempty"`
Type string `json:"type,omitempty"`
}
func (n Nics) String() string {
return Stringify(n)
}
// Features - other features in the specs for a plan
type Features struct {
Raid bool `json:"raid,omitempty"`
Txt bool `json:"txt,omitempty"`
}
func (f Features) String() string {
return Stringify(f)
}
// Pricing - the pricing options on a plan
type Pricing struct {
Hourly float32 `json:"hourly,omitempty"`
Monthly float32 `json:"monthly,omitempty"`
}
func (p Pricing) String() string {
return Stringify(p)
}
// PlanServiceOp implements PlanService
type PlanServiceOp struct {
client *Client
}
// List method returns all available plans
func (s *PlanServiceOp) List() ([]Plan, *Response, error) {
req, err := s.client.NewRequest("GET", planBasePath, nil)
if err != nil {
return nil, nil, err
}
root := new(planRoot)
resp, err := s.client.Do(req, root)
if err != nil {
return nil, resp, err
}
return root.Plans, resp, err
}