This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
bgp_configs.go
94 lines (78 loc) · 2.94 KB
/
bgp_configs.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
package packngo
import (
"path"
)
var (
bgpConfigPostBasePath = "/bgp-configs"
bgpConfigGetBasePath = "/bgp-config"
)
// BGPConfigService interface defines available BGP config methods
type BGPConfigService interface {
Get(projectID string, getOpt *GetOptions) (*BGPConfig, *Response, error)
Create(projectID string, request CreateBGPConfigRequest) (*Response, error)
// Delete(configID string) (resp *Response, err error) TODO: Not in Equinix Metal API
}
// BGPConfigServiceOp implements BgpConfigService
type BGPConfigServiceOp struct {
client *Client
}
// CreateBGPConfigRequest struct
type CreateBGPConfigRequest struct {
DeploymentType string `json:"deployment_type,omitempty"`
Asn int `json:"asn,omitempty"`
Md5 string `json:"md5,omitempty"`
UseCase string `json:"use_case,omitempty"`
}
// BGPConfig represents an Equinix Metal BGP Config
type BGPConfig struct {
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
DeploymentType string `json:"deployment_type,omitempty"`
Asn int `json:"asn,omitempty"`
RouteObject string `json:"route_object,omitempty"`
Md5 string `json:"md5,omitempty"`
MaxPrefix int `json:"max_prefix,omitempty"`
Project Project `json:"project,omitempty"`
CreatedAt Timestamp `json:"created_at,omitempty"`
RequestedAt Timestamp `json:"requested_at,omitempty"`
Sessions []BGPSession `json:"sessions,omitempty"`
Href string `json:"href,omitempty"`
}
// Create function
func (s *BGPConfigServiceOp) Create(projectID string, request CreateBGPConfigRequest) (*Response, error) {
if validateErr := ValidateUUID(projectID); validateErr != nil {
return nil, validateErr
}
apiPath := path.Join(projectBasePath, projectID, bgpConfigPostBasePath)
resp, err := s.client.DoRequest("POST", apiPath, request, nil)
if err != nil {
return resp, err
}
return resp, err
}
// Get function
func (s *BGPConfigServiceOp) Get(projectID string, opts *GetOptions) (bgpConfig *BGPConfig, resp *Response, err error) {
if validateErr := ValidateUUID(projectID); validateErr != nil {
return nil, nil, validateErr
}
endpointPath := path.Join(projectBasePath, projectID, bgpConfigGetBasePath)
apiPathQuery := opts.WithQuery(endpointPath)
subset := new(BGPConfig)
resp, err = s.client.DoRequest("GET", apiPathQuery, nil, subset)
if err != nil {
return nil, resp, err
}
return subset, resp, err
}
// Delete function TODO: this is not implemented in the Equinix Metal API
// func (s *BGPConfigServiceOp) Delete(configID string) (resp *Response, err error) {
// if validateErr := ValidateUUID(configID); validateErr != nil {
// return nil, validateErr
// }
// apiPath := fmt.Sprintf("%ss/%s", bgpConfigBasePath, configID)
// resp, err = s.client.DoRequest("DELETE", apiPath, nil, nil)
// if err != nil {
// return resp, err
// }
// return resp, err
// }