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
|
package packngo
import "fmt"
var bgpSessionBasePath = "/bgp/sessions"
// BGPSessionService interface defines available BGP session methods
type BGPSessionService interface {
Get(string, *GetOptions) (*BGPSession, *Response, error)
Create(string, CreateBGPSessionRequest) (*BGPSession, *Response, error)
Delete(string) (*Response, error)
}
type bgpSessionsRoot struct {
Sessions []BGPSession `json:"bgp_sessions"`
Meta meta `json:"meta"`
}
// BGPSessionServiceOp implements BgpSessionService
type BGPSessionServiceOp struct {
client *Client
}
// BGPSession represents a Packet BGP Session
type BGPSession struct {
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
LearnedRoutes []string `json:"learned_routes,omitempty"`
AddressFamily string `json:"address_family,omitempty"`
Device Device `json:"device,omitempty"`
Href string `json:"href,omitempty"`
DefaultRoute *bool `json:"default_route,omitempty"`
}
// CreateBGPSessionRequest struct
type CreateBGPSessionRequest struct {
AddressFamily string `json:"address_family"`
DefaultRoute *bool `json:"default_route,omitempty"`
}
// Create function
func (s *BGPSessionServiceOp) Create(deviceID string, request CreateBGPSessionRequest) (*BGPSession, *Response, error) {
path := fmt.Sprintf("%s/%s%s", deviceBasePath, deviceID, bgpSessionBasePath)
session := new(BGPSession)
resp, err := s.client.DoRequest("POST", path, request, session)
if err != nil {
return nil, resp, err
}
return session, resp, err
}
// Delete function
func (s *BGPSessionServiceOp) Delete(id string) (*Response, error) {
path := fmt.Sprintf("%s/%s", bgpSessionBasePath, id)
return s.client.DoRequest("DELETE", path, nil, nil)
}
// Get function
func (s *BGPSessionServiceOp) Get(id string, getOpt *GetOptions) (session *BGPSession, response *Response, err error) {
params := createGetOptionsURL(getOpt)
path := fmt.Sprintf("%s/%s?%s", bgpSessionBasePath, id, params)
session = new(BGPSession)
response, err = s.client.DoRequest("GET", path, nil, session)
if err != nil {
return nil, response, err
}
return session, response, err
}
|