-
Notifications
You must be signed in to change notification settings - Fork 16
/
ipblock.go
177 lines (150 loc) · 4.6 KB
/
ipblock.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package profitbricks
import (
"github.com/ionos-cloud/sdk-go/v5"
"net/http"
)
//IPBlock object
type IPBlock struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Properties IPBlockProperties `json:"properties,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//IPBlockProperties object
type IPBlockProperties struct {
Name string `json:"name,omitempty"`
IPs []string `json:"ips,omitempty"`
IPConsumers []IPConsumer `json:"ipConsumers,omitempty"`
Location string `json:"location,omitempty"`
Size int `json:"size,omitempty"`
}
type IPConsumer struct {
IP string `json:"ip,omitempty"`
Mac string `json:"mac,omitempty"`
NicID string `json:"nicId,omitempty"`
ServerID string `json:"serverId,omitempty"`
ServerName string `json:"serverName,omitempty"`
DatacenterID string `json:"datacenterId,omitempty"`
DatacenterName string `json:"datacenterName,omitempty"`
}
//IPBlocks object
type IPBlocks struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []IPBlock `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//ListIPBlocks lists all IP blocks
func (c *Client) ListIPBlocks() (*IPBlocks, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.IPBlocksApi.IpblocksGet(ctx).Execute()
ret := IPBlocks{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
url := ipblocksPath()
ret := &IPBlocks{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
*/
}
//ReserveIPBlock creates an IP block
func (c *Client) ReserveIPBlock(request IPBlock) (*IPBlock, error) {
input := ionoscloud.IpBlock{}
if errConvert := convertToCore(&request, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.IPBlocksApi.IpblocksPost(ctx).Ipblock(input).Execute()
ret := IPBlock{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
url := ipblocksPath()
ret := &IPBlock{}
err := c.Post(url, request, ret, http.StatusAccepted)
return ret, err
*/
}
//GetIPBlock gets an IP blocks
func (c *Client) GetIPBlock(ipblockid string) (*IPBlock, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.IPBlocksApi.IpblocksFindById(ctx, ipblockid).Execute()
ret := IPBlock{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
url := ipblockPath(ipblockid)
ret := &IPBlock{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
*/
}
// UpdateIPBlock partial update of ipblock properties
func (c *Client) UpdateIPBlock(ipblockid string, props IPBlockProperties) (*IPBlock, error) {
input := ionoscloud.IpBlockProperties{}
if errConvert := convertToCore(&props, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.IPBlocksApi.IpblocksPatch(ctx, ipblockid).Ipblock(input).Execute()
ret := IPBlock{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
url := ipblockPath(ipblockid)
ret := &IPBlock{}
err := c.Patch(url, props, ret, http.StatusAccepted)
return ret, err
*/
}
//ReleaseIPBlock deletes an IP block
func (c *Client) ReleaseIPBlock(ipblockid string) (*http.Header, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
_, apiResponse, err := c.CoreSdk.IPBlocksApi.IpblocksDelete(ctx, ipblockid).Execute()
if apiResponse != nil {
return &apiResponse.Header, err
} else {
return nil, err
}
/*
url := ipblockPath(ipblockid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
*/
}