-
Notifications
You must be signed in to change notification settings - Fork 16
/
pcc.go
207 lines (185 loc) · 5.82 KB
/
pcc.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package profitbricks
import (
"github.com/ionos-cloud/sdk-go/v5"
"net/http"
)
// PrivateCrossConnect type
type PrivateCrossConnect struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// metadata
Metadata *Metadata `json:"metadata,omitempty"`
// properties
// Required: true
Properties *PrivateCrossConnectProperties `json:"properties"`
// The type of object
// Read Only: true
// Enum: [pcc]
PBType string `json:"type,omitempty"`
}
// PrivateCrossConnects type
type PrivateCrossConnects struct {
// URL to the collection representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// Unique representation for private cros-connect as a collection on a resource.
// Read Only: true
ID string `json:"id,omitempty"`
// Slice of items in that collection
// Read Only: true
Items []PrivateCrossConnect `json:"items"`
// The type of resource within a collection
// Read Only: true
// Enum: [collection]
PBType string `json:"type,omitempty"`
}
// PrivateCrossConnectProperties type
type PrivateCrossConnectProperties struct {
// The desired name for the PrivateCrossConnect
// Required: true
Name string `json:"name,omitempty"`
// A description for this PrivateCrossConnect
// Required: true
Description string `json:"description,omitempty"`
// The peers of the PrivateCrossConnect
// Required: false
// Readonly: true
Peers *[]PCCPeer `json:"peers,omitempty"`
// The Connectable VDC's
// Required: false
// Readonly: true
ConnectableDatacenters *[]PCCConnectableDataCenter `json:"connectableDatacenters,omitempty"`
}
// PCCPeer type
type PCCPeer struct {
// The id of the cross-connected LAN
// Required: false
LANId string `json:"id,omitempty"`
// The name of the cross-connected LAN
// Required: false
LANName string `json:"name,omitempty"`
// The id of the cross-connected VDC
// Required: false
DataCenterID string `json:"datacenterId,omitempty"`
// The name of the cross-connected VDC
// Required: false
DataCenterName string `json:"datacenterName,omitempty"`
// The location of the cross-connected VDC
// Required: false
Location string `json:"location,omitempty"`
}
// PCCConnectableDataCenter type
type PCCConnectableDataCenter struct {
// The id of the cross-connectable VDC
// Required: false
ID string `json:"id,omitempty"`
// The name of the cross-connectable VDC
// Required: false
Name string `json:"name,omitempty"`
// The name of the cross-connectable VDC
// Required: false
Location string `json:"location,omitempty"`
}
// ListPrivateCrossConnects gets a list of all private cross-connects
func (c *Client) ListPrivateCrossConnects() (*PrivateCrossConnects, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.PrivateCrossConnectApi.PccsGet(ctx).Execute()
ret := PrivateCrossConnects{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
rsp := &PrivateCrossConnects{}
return rsp, c.GetOK(PrivateCrossConnectsPath(), rsp)
*/
}
// GetPrivateCrossConnect gets a private cross-connect with given id
func (c *Client) GetPrivateCrossConnect(pccID string) (*PrivateCrossConnect, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.PrivateCrossConnectApi.PccsFindById(ctx, pccID).Execute()
ret := PrivateCrossConnect{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
rsp := &PrivateCrossConnect{}
return rsp, c.GetOK(PrivateCrossConnectPath(pccID), rsp)
*/
}
// CreatePrivateCrossConnect creates a private cross-connect
func (c *Client) CreatePrivateCrossConnect(pcc PrivateCrossConnect) (*PrivateCrossConnect, error) {
input := ionoscloud.PrivateCrossConnect{}
if errConvert := convertToCore(&pcc, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.PrivateCrossConnectApi.PccsPost(ctx).Pcc(input).Execute()
ret := PrivateCrossConnect{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
rsp := &PrivateCrossConnect{}
return rsp, c.PostAcc(PrivateCrossConnectsPath(), pcc, rsp)
*/
}
// UpdatePrivateCrossConnect updates a private cross-connect
func (c *Client) UpdatePrivateCrossConnect(pccID string, pcc PrivateCrossConnect) (*PrivateCrossConnect, error) {
input := ionoscloud.PrivateCrossConnect{}
if errConvert := convertToCore(&pcc, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.PrivateCrossConnectApi.PccsPatch(ctx, pccID).Pcc(*input.Properties).Execute()
ret := PrivateCrossConnect{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
rsp := &PrivateCrossConnect{}
return rsp, c.PatchAcc(PrivateCrossConnectPath(pccID), pcc.Properties, rsp)
*/
}
// DeletePrivateCrossConnect deletes a private cross-connect by its id
func (c *Client) DeletePrivateCrossConnect(pccID string) (*http.Header, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
_, apiResponse, err := c.CoreSdk.PrivateCrossConnectApi.PccsDelete(ctx, pccID).Execute()
if apiResponse != nil {
return &apiResponse.Header, err
} else {
return nil, err
}
/*
h := &http.Header{}
return h, c.Delete(PrivateCrossConnectPath(pccID), h, http.StatusAccepted)
*/
}