forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbalancer.go
125 lines (107 loc) · 3.97 KB
/
loadbalancer.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
123
124
125
package profitbricks
import (
"net/http"
)
//Loadbalancer object
type Loadbalancer struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Properties LoadbalancerProperties `json:"properties,omitempty"`
Entities LoadbalancerEntities `json:"entities,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//LoadbalancerProperties object
type LoadbalancerProperties struct {
Name string `json:"name,omitempty"`
IP string `json:"ip,omitempty"`
Dhcp bool `json:"dhcp,omitempty"`
}
//LoadbalancerEntities object
type LoadbalancerEntities struct {
Balancednics *BalancedNics `json:"balancednics,omitempty"`
}
//BalancedNics object
type BalancedNics struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Nic `json:"items,omitempty"`
}
//Loadbalancers object
type Loadbalancers struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Loadbalancer `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//ListLoadbalancers returns a Collection struct for loadbalancers in the Datacenter
func (c *Client) ListLoadbalancers(dcid string) (*Loadbalancers, error) {
url := loadbalancersPath(dcid)
ret := &Loadbalancers{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//CreateLoadbalancer creates a loadbalancer in the datacenter from a jason []byte and returns a Instance struct
func (c *Client) CreateLoadbalancer(dcid string, request Loadbalancer) (*Loadbalancer, error) {
url := loadbalancersPath(dcid)
ret := &Loadbalancer{}
err := c.Post(url, request, ret, http.StatusAccepted)
return ret, err
}
//GetLoadbalancer pulls data for the Loadbalancer where id = lbalid returns a Instance struct
func (c *Client) GetLoadbalancer(dcid, lbalid string) (*Loadbalancer, error) {
url := loadbalancerPath(dcid, lbalid)
ret := &Loadbalancer{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//UpdateLoadbalancer updates a load balancer
func (c *Client) UpdateLoadbalancer(dcid string, lbalid string, obj LoadbalancerProperties) (*Loadbalancer, error) {
url := loadbalancerPath(dcid, lbalid)
ret := &Loadbalancer{}
err := c.Patch(url, obj, ret, http.StatusAccepted)
return ret, err
}
//DeleteLoadbalancer deletes a load balancer
func (c *Client) DeleteLoadbalancer(dcid, lbalid string) (*http.Header, error) {
url := loadbalancerPath(dcid, lbalid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}
//ListBalancedNics lists balanced nics
func (c *Client) ListBalancedNics(dcid, lbalid string) (*Nics, error) {
url := balancedNicsPath(dcid, lbalid)
ret := &Nics{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//AssociateNic attach a nic to load balancer
func (c *Client) AssociateNic(dcid string, lbalid string, nicid string) (*Nic, error) {
sm := map[string]string{"id": nicid}
url := balancedNicsPath(dcid, lbalid)
ret := &Nic{}
err := c.Post(url, sm, ret, http.StatusAccepted)
return ret, err
}
//GetBalancedNic gets a balanced nic
func (c *Client) GetBalancedNic(dcid, lbalid, balnicid string) (*Nic, error) {
url := balancedNicPath(dcid, lbalid, balnicid)
ret := &Nic{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//DeleteBalancedNic removes a balanced nic
func (c *Client) DeleteBalancedNic(dcid, lbalid, balnicid string) (*http.Header, error) {
url := balancedNicPath(dcid, lbalid, balnicid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}