-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmcr_types.go
195 lines (175 loc) · 8.33 KB
/
mcr_types.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
package megaport
import "strconv"
// MCROrder represents a request to buy an MCR from the Megaport Products API.
type MCROrder struct {
LocationID int `json:"locationId"`
Name string `json:"productName"`
Term int `json:"term"`
Type string `json:"productType"`
PortSpeed int `json:"portSpeed"`
CostCentre string `json:"costCentre"`
PromoCode string `json:"promoCode,omitempty"`
Config MCROrderConfig `json:"config"`
ResourceTags []ResourceTag `json:"resourceTags,omitempty"`
}
// MCROrderConfig represents the configuration for an MCR order.
type MCROrderConfig struct {
ASN int `json:"mcrAsn,omitempty"`
DiversityZone string `json:"diversityZone,omitempty"`
}
// MCROrderConfirmation represents a response from the Megaport Products API after ordering an MCR.
type MCROrderConfirmation struct {
TechnicalServiceUID string `json:"technicalServiceUid"`
}
// MCR represents a Megaport Cloud Router in the Megaport MCR API.
type MCR struct {
ID int `json:"productId"`
UID string `json:"productUid"`
Name string `json:"productName"`
Type string `json:"productType"`
ProvisioningStatus string `json:"provisioningStatus"`
CreateDate *Time `json:"createDate"`
CreatedBy string `json:"createdBy"`
CostCentre string `json:"costCentre"`
PortSpeed int `json:"portSpeed"`
TerminateDate *Time `json:"terminateDate"`
LiveDate *Time `json:"liveDate"`
Market string `json:"market"`
LocationID int `json:"locationId"`
UsageAlgorithm string `json:"usageAlgorithm"`
MarketplaceVisibility bool `json:"marketplaceVisibility"`
VXCPermitted bool `json:"vxcpermitted"`
VXCAutoApproval bool `json:"vxcAutoApproval"`
SecondaryName string `json:"secondaryName"`
LAGPrimary bool `json:"lagPrimary"`
LAGID int `json:"lagId"`
AggregationID int `json:"aggregationId"`
CompanyUID string `json:"companyUid"`
CompanyName string `json:"companyName"`
ContractStartDate *Time `json:"contractStartDate"`
ContractEndDate *Time `json:"contractEndDate"`
ContractTermMonths int `json:"contractTermMonths"`
AttributeTags map[string]string `json:"attributeTags"`
Virtual bool `json:"virtual"`
BuyoutPort bool `json:"buyoutPort"`
Locked bool `json:"locked"`
AdminLocked bool `json:"adminLocked"`
Cancelable bool `json:"cancelable"`
Resources MCRResources `json:"resources"`
LocationDetails *ProductLocationDetails `json:"locationDetail"`
}
// MCRResources represents the resources associated with an MCR.
type MCRResources struct {
Interface PortInterface `json:"interface"`
VirtualRouter MCRVirtualRouter `json:"virtual_router"`
}
// MCRVirtualRouter represents the virtual router associated with an MCR.
type MCRVirtualRouter struct {
ID int `json:"id"`
ASN int `json:"mcrAsn"`
Name string `json:"name"`
ResourceName string `json:"resource_name"`
ResourceType string `json:"resource_type"`
Speed int `json:"speed"`
}
// MCRPrefixFilterList represents a prefix filter list associated with an MCR.
type MCRPrefixFilterList struct {
ID int `json:"id"` // ID of the prefix filter list.
Description string `json:"description"`
AddressFamily string `json:"addressFamily"`
Entries []*MCRPrefixListEntry `json:"entries"`
}
// APIMCRPrefixFilterListEntry represents an entry in a prefix filter list.
type APIMCRPrefixFilterListEntry struct {
Action string `json:"action"`
Prefix string `json:"prefix"`
Ge string `json:"ge,omitempty"` // Greater than or equal to - (Optional) The minimum starting prefix length to be matched. Valid values are from 0 to 32 (IPv4), or 0 to 128 (IPv6). The minimum (ge) must be no greater than or equal to the maximum value (le).
Le string `json:"le,omitempty"` // Less than or equal to - (Optional) The maximum ending prefix length to be matched. The prefix length is greater than or equal to the minimum value (ge). Valid values are from 0 to 32 (IPv4), or 0 to 128 (IPv6), but the maximum must be no less than the minimum value (ge).
}
// MCRPrefixListEntry represents an entry in a prefix filter list.
type MCRPrefixListEntry struct {
Action string `json:"action"`
Prefix string `json:"prefix"`
Ge int `json:"ge,omitempty"` // Great than or equal to - (Optional) The minimum starting prefix length to be matched. Valid values are from 0 to 32 (IPv4), or 0 to 128 (IPv6). The minimum (ge) must be no greater than or equal to the maximum value (le).
Le int `json:"le,omitempty"` // Less than or equal to - (Optional) The maximum ending prefix length to be matched. The prefix length is greater than or equal to the minimum value (ge). Valid values are from 0 to 32 (IPv4), or 0 to 128 (IPv6), but the maximum must be no less than the minimum value (ge).
}
// MCROrdersResponse represents a response from the Megaport Products API after ordering an MCR.
type MCROrderResponse struct {
Message string `json:"message"`
Terms string `json:"terms"`
Data []*MCROrderConfirmation `json:"data"`
}
// MCRResponse represents a response from the Megaport MCR API after querying an MCR.
type MCRResponse struct {
Message string `json:"message"`
Terms string `json:"terms"`
Data *MCR `json:"data"`
}
// PrefixFilterList represents a prefix filter list associated with an MCR.
type PrefixFilterList struct {
Id int `json:"id"`
Description string `json:"description"`
AddressFamily string `json:"addressFamily"`
}
// CreateMCRPrefixFilterListResponse represents a response from the Megaport MCR API after creating a prefix filter list.
type CreateMCRPrefixFilterListAPIResponse struct {
Message string `json:"message"`
Terms string `json:"terms"`
Data *APIMCRPrefixFilterList `json:"data"`
}
// ListMCRPrefixFilterListResponse represents a response from the Megaport MCR API after querying an MCR's prefix filter list.
type ListMCRPrefixFilterListResponse struct {
Message string `json:"message"`
Terms string `json:"terms"`
Data []*PrefixFilterList `json:"data"`
}
type APIMCRPrefixFilterListResponse struct {
Message string `json:"message"`
Terms string `json:"terms"`
Data *APIMCRPrefixFilterList `json:"data"`
}
type APIMCRPrefixFilterList struct {
ID int `json:"id"`
Description string `json:"description"`
AddressFamily string `json:"addressFamily"`
Entries []*APIMCRPrefixFilterListEntry `json:"entries"`
}
func (e *APIMCRPrefixFilterList) ToMCRPrefixFilterList() (*MCRPrefixFilterList, error) {
entries := make([]*MCRPrefixListEntry, len(e.Entries))
for i, entry := range e.Entries {
mcrEntry, err := entry.ToMCRPrefixFilterListEntry()
if err != nil {
return nil, err
}
entries[i] = mcrEntry
}
return &MCRPrefixFilterList{
ID: e.ID,
Description: e.Description,
AddressFamily: e.AddressFamily,
Entries: entries,
}, nil
}
func (e *APIMCRPrefixFilterListEntry) ToMCRPrefixFilterListEntry() (*MCRPrefixListEntry, error) {
var ge, le int
if e.Ge != "" {
geVal, err := strconv.Atoi(e.Ge)
if err != nil {
return nil, err
}
ge = geVal
}
if e.Le != "" {
leVal, err := strconv.Atoi(e.Le)
if err != nil {
return nil, err
}
le = leVal
}
return &MCRPrefixListEntry{
Action: e.Action,
Prefix: e.Prefix,
Ge: ge,
Le: le,
}, nil
}