/
cloud_service_azure.go
210 lines (195 loc) · 10.2 KB
/
cloud_service_azure.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
208
209
210
package packetfabric
import (
"fmt"
"github.com/go-playground/validator/v10"
"time"
)
const azureHostedMktReqURI = "/v2/services/third-party/hosted/azure"
const azureExpressRouteURI = "/v2/services/cloud/hosted/azure"
const azureExpressRouteConnURI = "/v2.1/services/cloud-routers/%s/connections/azure"
const azureExpressRouteDedicatedURI = "/v2/services/cloud/dedicated/azure"
type AzureBackboneCreateResp struct {
VcCircuitID string `json:"vc_circuit_id,omitempty"`
CustomerUUID string `json:"customer_uuid,omitempty"`
State string `json:"state,omitempty"`
ServiceType string `json:"service_type,omitempty"`
ServiceClass string `json:"service_class,omitempty"`
Mode string `json:"mode,omitempty"`
Connected bool `json:"connected,omitempty"`
Bandwidth Bandwidth `json:"bandwidth,omitempty"`
Description string `json:"description,omitempty"`
RateLimitIn int `json:"rate_limit_in,omitempty"`
RateLimitOut int `json:"rate_limit_out,omitempty"`
TimeCreated string `json:"time_created,omitempty"`
TimeUpdated string `json:"time_updated,omitempty"`
Interfaces []AzureInterfacesCreateResp `json:"interfaces,omitempty"`
}
type AzureInterfacesCreateResp struct {
PortCircuitID string `json:"port_circuit_id,omitempty"`
Pop string `json:"pop,omitempty"`
Site string `json:"site,omitempty"`
SiteName string `json:"site_name,omitempty"`
Speed string `json:"speed,omitempty"`
Media string `json:"media,omitempty"`
Zone string `json:"zone,omitempty"`
Description string `json:"description,omitempty"`
Vlan int `json:"vlan,omitempty"`
Untagged bool `json:"untagged,omitempty"`
ProvisioningStatus string `json:"provisioning_status,omitempty"`
AdminStatus string `json:"admin_status,omitempty"`
OperationalStatus string `json:"operational_status,omitempty"`
CustomerUUID string `json:"customer_uuid,omitempty"`
CustomerName string `json:"customer_name,omitempty"`
Region string `json:"region,omitempty"`
IsCloud bool `json:"is_cloud,omitempty"`
IsPtp bool `json:"is_ptp,omitempty"`
TimeCreated string `json:"time_created,omitempty"`
TimeUpdated string `json:"time_updated,omitempty"`
}
// Struct representation: https://docs.packetfabric.com/api/v2/redoc/#operation/post_azure_marketplace_cloud
type AzureHostedMktReq struct {
RoutingID string `json:"routing_id,omitempty"`
Market string `json:"market,omitempty"`
Description string `json:"description,omitempty"`
AzureServiceKey string `json:"azure_service_key,omitempty"`
AccountUUID string `json:"account_uuid,omitempty"`
Speed string `json:"speed,omitempty"`
ServiceUUID string `json:"service_uuid,omitempty"`
}
type AzureHostedMktReqResp struct {
VcRequestUUID string `json:"vc_request_uuid,omitempty"`
VcCircuitID string `json:"vc_circuit_id,omitempty"`
FromCustomer AzureFromCustomer `json:"from_customer,omitempty"`
ToCustomer AzureToCustomer `json:"to_customer,omitempty"`
Status string `json:"status,omitempty"`
RequestType string `json:"request_type,omitempty"`
Text string `json:"text,omitempty"`
Bandwidth AzureHostedMktBandwidth `json:"bandwidth,omitempty"`
RateLimitIn int `json:"rate_limit_in,omitempty"`
RateLimitOut int `json:"rate_limit_out,omitempty"`
ServiceName string `json:"service_name,omitempty"`
AllowUntaggedZ bool `json:"allow_untagged_z,omitempty"`
TimeCreated string `json:"time_created,omitempty"`
TimeUpdated string `json:"time_updated,omitempty"`
}
type AzureFromCustomer struct {
CustomerUUID string `json:"customer_uuid,omitempty"`
Name string `json:"name,omitempty"`
ContactFirstName string `json:"contact_first_name,omitempty"`
ContactLastName string `json:"contact_last_name,omitempty"`
ContactEmail string `json:"contact_email,omitempty"`
ContactPhone string `json:"contact_phone,omitempty"`
}
type AzureToCustomer struct {
CustomerUUID string `json:"customer_uuid,omitempty"`
Name string `json:"name,omitempty"`
}
type AzureHostedMktBandwidth struct {
AccountUUID string `json:"account_uuid,omitempty"`
SubscriptionTerm int `json:"subscription_term,omitempty"`
LonghaulType string `json:"longhaul_type,omitempty"`
Speed string `json:"speed,omitempty"`
}
// Struct representation: https://docs.packetfabric.com/api/v2/redoc/#operation/provision_marketplace_cloud
type AzureProvisionMktReq struct {
Provider string `json:"provider,omitempty"`
Interface AzureProvisionInterface `json:"interface,omitempty"`
Description string `json:"description,omitempty"`
}
type AzureProvisionInterface struct {
PortCircuitID string `json:"port_circuit_id,omitempty"`
Vlan int `json:"vlan,omitempty"`
}
type AzureProvisionMktReqResp struct {
VcCircuitID string `json:"vc_circuit_id,omitempty"`
CustomerUUID string `json:"customer_uuid,omitempty"`
State string `json:"state,omitempty"`
ServiceType string `json:"service_type,omitempty"`
ServiceClass string `json:"service_class,omitempty"`
Mode string `json:"mode,omitempty"`
Connected bool `json:"connected,omitempty"`
Description string `json:"description,omitempty"`
RateLimitIn int `json:"rate_limit_in,omitempty"`
RateLimitOut int `json:"rate_limit_out,omitempty"`
TimeCreated string `json:"time_created,omitempty"`
TimeUpdated string `json:"time_updated,omitempty"`
Interfaces []AzureInterfacesCreateResp `json:"interfaces,omitempty"`
}
// Struct representation: https://docs.packetfabric.com/api/v2/redoc/#operation/azure_hosted_connection_post
type AzureExpressRoute struct {
AzureServiceKey string `json:"azure_service_key,omitempty"`
AccountUUID string `json:"account_uuid,omitempty"`
Description string `json:"description,omitempty"`
Port string `json:"port,omitempty"`
VlanPrivate int `json:"vlan_private,omitempty"`
VlanMicrosoft int `json:"vlan_microsoft,omitempty"`
SrcSvlan int `json:"src_svlan,omitempty"`
Speed string `json:"speed,omitempty"`
PublishedQuoteLineUUID string `json:"published_quote_line_uuid,omitempty"`
PONumber string `json:"po_number,omitempty"`
}
type AzureExpressRouteConn struct {
MaybeNat bool `json:"maybe_nat,omitempty"`
MaybeDNat bool `json:"maybe_dnat,omitempty"`
AzureServiceKey string `json:"azure_service_key,omitempty"`
AccountUUID string `json:"account_uuid,omitempty"`
Description string `json:"description,omitempty"`
Speed string `json:"speed,omitempty"`
IsPublic bool `json:"is_public,omitempty"`
PublishedQuoteLineUUID string `json:"published_quote_line_uuid,omitempty"`
PONumber string `json:"po_number,omitempty"`
SubscriptionTerm int `json:"subscription_term,omitempty" validate:"oneof=1 12 24 36" default:"1"`
}
// Struct representation: https://docs.packetfabric.com/api/v2/redoc/#operation/azure_dedicated_connection_post
type AzureExpressRouteDedicated struct {
AccountUUID string `json:"account_uuid,omitempty"`
Description string `json:"description,omitempty"`
Zone string `json:"zone,omitempty"`
Pop string `json:"pop,omitempty"`
SubscriptionTerm int `json:"subscription_term,omitempty"`
ServiceClass string `json:"service_class,omitempty"`
Speed string `json:"speed,omitempty"`
Loa string `json:"loa,omitempty"`
Encapsulation string `json:"encapsulation,omitempty"`
PortCategory string `json:"port_category,omitempty"`
PublishedQuoteLineUUID string `json:"published_quote_line_uuid,omitempty"`
PONumber string `json:"po_number,omitempty"`
}
func (c *PFClient) CreateAzureHostedMktRequest(azureMktReq AzureHostedMktReq) (*AzureHostedMktReqResp, error) {
azureMktReqResp := &AzureHostedMktReqResp{}
_, err := c.sendRequest(azureHostedMktReqURI, postMethod, azureMktReq, azureMktReqResp)
if err != nil {
return nil, err
}
return azureMktReqResp, nil
}
func (c *PFClient) CreateAzureExpressRoute(azureExpressRoute AzureExpressRoute) (*CloudServiceConnCreateResp, error) {
expressRouteResp := &CloudServiceConnCreateResp{}
_, err := c.sendRequest(azureExpressRouteURI, postMethod, azureExpressRoute, expressRouteResp)
if err != nil {
return nil, err
}
return expressRouteResp, nil
}
func (c *PFClient) CreateAzureExpressRouteConn(azureExpressRoute AzureExpressRouteConn, cid string) (*CloudRouterConnectionReadResponse, error) {
if err := validator.New().Struct(azureExpressRoute); err != nil {
return nil, err
}
expressRouteResp := &CloudRouterConnectionReadResponse{}
formatedURI := fmt.Sprintf(azureExpressRouteConnURI, cid)
_, err := c.sendRequest(formatedURI, postMethod, azureExpressRoute, expressRouteResp)
if err != nil {
return nil, err
}
return expressRouteResp, nil
}
func (c *PFClient) CreateAzureExpressRouteDedicated(azureExpressDedicated AzureExpressRouteDedicated) (*CloudServiceConnCreateResp, error) {
expressRouteResp := &CloudServiceConnCreateResp{}
_, err := c.sendRequest(azureExpressRouteDedicatedURI, postMethod, azureExpressDedicated, expressRouteResp)
if err != nil {
return nil, err
}
// Add a delay of 15 seconds to allow the billing system to catch up
time.Sleep(15 * time.Second)
return expressRouteResp, nil
}