-
Notifications
You must be signed in to change notification settings - Fork 4
/
rest_port.go
38 lines (34 loc) · 984 Bytes
/
rest_port.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
package ecx
import (
"fmt"
"net/http"
"github.com/equinix/ecx-go/v2/internal/api"
)
//GetUserPorts operation retrieves Equinix Fabric user ports
func (c RestClient) GetUserPorts() ([]Port, error) {
path := "/ecx/v3/port/userport"
respBody := []api.Port{}
req := c.R().SetResult(&respBody)
if err := c.Execute(req, http.MethodGet, path); err != nil {
return nil, err
}
mapped := make([]Port, len(respBody))
for i := range respBody {
mapped[i] = mapPortAPIToDomain(respBody[i])
}
return mapped, nil
}
func mapPortAPIToDomain(apiPort api.Port) Port {
return Port{
UUID: apiPort.UUID,
Name: apiPort.Name,
Region: apiPort.Region,
IBX: apiPort.IBX,
MetroCode: apiPort.MetroCode,
Priority: apiPort.DevicePriority,
Encapsulation: apiPort.Encapsulation,
Buyout: apiPort.Buyout,
Bandwidth: String(fmt.Sprintf("%d", Int64Value(apiPort.TotalBandwidth))),
Status: apiPort.ProvisionStatus,
}
}