/
point_to_point.go
100 lines (89 loc) · 3.73 KB
/
point_to_point.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
package packetfabric
import "fmt"
const pointToPointURI = "/v2/services/point-to-point"
const pointToPointByUUIDURI = "/v2/services/point-to-point/%s"
const pointToPointStatus = "/v2.1/services/point-to-point/%s/status"
type PointToPoint struct {
Description string `json:"description,omitempty"`
Speed string `json:"speed,omitempty"`
Media string `json:"media,omitempty"`
Endpoints []Endpoints `json:"endpoints,omitempty"`
AccountUUID string `json:"account_uuid,omitempty"`
SubscriptionTerm int `json:"subscription_term,omitempty"`
PublishedQuoteLineUUID string `json:"published_quote_line_uuid,omitempty"`
PONumber string `json:"po_number,omitempty"`
}
type Endpoints struct {
Pop string `json:"pop,omitempty"`
Zone string `json:"zone,omitempty"`
CustomerSiteCode string `json:"customer_site_code,omitempty"`
Autoneg bool `json:"autoneg,omitempty"`
Loa string `json:"loa,omitempty"`
PortCircuitID string `json:"port_circuit_id,omitempty"`
}
type PointToPointResp struct {
PtpUUID string `json:"ptp_uuid,omitempty"`
PtpCircuitID string `json:"ptp_circuit_id,omitempty"`
Description string `json:"description,omitempty"`
Speed string `json:"speed,omitempty"`
Media string `json:"media,omitempty"`
State string `json:"state,omitempty"`
Billing Billing `json:"billing,omitempty"`
TimeCreated string `json:"time_created,omitempty"`
TimeUpdated string `json:"time_updated,omitempty"`
Deleted bool `json:"deleted,omitempty"`
ServiceClass string `json:"service_class,omitempty"`
Interfaces []Interfaces `json:"interfaces,omitempty"`
PONumber string `json:"po_number,omitempty"`
}
type UpdatePointToPointData struct {
Description string `json:"description"`
PONumber string `json:"po_number,omitempty"`
}
func (c *PFClient) CreatePointToPointService(ptp PointToPoint) (*PointToPointResp, error) {
expectedResp := &PointToPointResp{}
_, err := c.sendRequest(pointToPointURI, postMethod, ptp, expectedResp)
if err != nil {
return nil, err
}
return expectedResp, nil
}
func (c *PFClient) ListPointToPoints() (*[]PointToPointResp, error) {
expectedResp := make([]PointToPointResp, 0)
if _, err := c.sendRequest(pointToPointURI, getMethod, nil, &expectedResp); err != nil {
return nil, err
}
return &expectedResp, nil
}
func (c *PFClient) GetPointToPointStatus(ptpCircuitID string) (*ServiceState, error) {
formatedURI := fmt.Sprintf(pointToPointStatus, ptpCircuitID)
expectedResp := &ServiceState{}
_, err := c.sendRequest(formatedURI, getMethod, nil, expectedResp)
if err != nil {
return nil, err
}
return expectedResp, nil
}
func (c *PFClient) ReadPointToPoint(ptpCircuitID string) (*PointToPointResp, error) {
formatedURI := fmt.Sprintf(pointToPointByUUIDURI, ptpCircuitID)
expectedResp := &PointToPointResp{}
if _, err := c.sendRequest(formatedURI, getMethod, nil, expectedResp); err != nil {
return nil, err
}
return expectedResp, nil
}
func (c *PFClient) UpdatePointToPoint(ptpUuid string, updatePointToPointData UpdatePointToPointData) (*PointToPointResp, error) {
formatedURI := fmt.Sprintf(pointToPointByUUIDURI, ptpUuid)
expectedResp := &PointToPointResp{}
if _, err := c.sendRequest(formatedURI, patchMethod, updatePointToPointData, expectedResp); err != nil {
return nil, err
}
return expectedResp, nil
}
func (c *PFClient) DeletePointToPointService(ptpUuid string) error {
formatedURI := fmt.Sprintf(pointToPointByUUIDURI, ptpUuid)
if _, err := c.sendRequest(formatedURI, deleteMethod, nil, nil); err != nil {
return err
}
return nil
}