-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfailover-group.go
113 lines (96 loc) · 3.06 KB
/
failover-group.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
package cloud66
import (
"log"
"strings"
"time"
)
type CurrentStackType int
const (
StkPrimary = CurrentStackType(1)
StkSecondary = CurrentStackType(2)
)
type FailoverGroup struct {
Uid string `json:"uid"`
Address string `json:"address"`
PrimaryStackName string `json:"primary_stack_name"`
PrimaryStackUid string `json:"primary_stack_uid"`
SecondaryStackName string `json:"secondary_stack_name"`
SecondaryStackUid string `json:"secondary_stack_uid"`
CurrentStack CurrentStackType `json:"current_stack"`
BusyToggling bool `json:"busy_toggling"`
Readonly bool `json:"readonly"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (c *Client) FailoverGroupList() ([]FailoverGroup, error) {
queryStrings := make(map[string]string)
var result []FailoverGroup
req, err := c.NewRequest("GET", "/failover_groups.json", nil, queryStrings)
if err != nil {
return nil, err
}
err = c.DoReq(req, &result, nil)
if err != nil {
return nil, err
}
return result, nil
}
func (c *Client) AddFailoverGroup(primaryStack *string, secondaryStack *string, currentStack *CurrentStackType) error {
params := struct {
PrimaryStack *string `json:"primary_stack_uid"`
SecondaryStack *string `json:"secondary_stack_uid"`
CurrentStack *CurrentStackType `json:"current_stack"`
}{
PrimaryStack: primaryStack,
SecondaryStack: secondaryStack,
CurrentStack: currentStack,
}
req, err := c.NewRequest("POST", "/failover_groups", params, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}
func (c *Client) UpdateFailoverGroup(failoverGroupUid string, primaryStack *string, secondaryStack *string, currentStack *CurrentStackType) error {
params := struct {
PrimaryStack *string `json:"primary_stack_uid"`
SecondaryStack *string `json:"secondary_stack_uid"`
CurrentStack *CurrentStackType `json:"current_stack"`
}{
PrimaryStack: primaryStack,
SecondaryStack: secondaryStack,
CurrentStack: currentStack,
}
req, err := c.NewRequest("PUT", "/failover_groups/"+failoverGroupUid, params, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}
func (c *Client) DeleteFailoverGroup(failoverGroupUid string) error {
req, err := c.NewRequest("DELETE", "/failover_groups/"+failoverGroupUid, nil, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}
func (currentStackType *CurrentStackType) String() string {
switch *currentStackType {
case StkPrimary:
return "Primary"
case StkSecondary:
return "Secondary"
}
log.Fatal("Current should only have values \"primary\" or \"secondary\"")
return ""
}
func ParseCurrentStack(param string) CurrentStackType {
if strings.EqualFold(param, "primary") {
return StkPrimary
}
if strings.EqualFold(param, "secondary") {
return StkSecondary
}
log.Fatal("Current should only have values \"primary\" or \"secondary\"")
return StkPrimary
}