forked from projectcalico/libcalico-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgppeer.go
103 lines (86 loc) · 3.53 KB
/
bgppeer.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
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package api
import (
"fmt"
"github.com/projectcalico/libcalico-go/lib/api/unversioned"
"github.com/projectcalico/libcalico-go/lib/net"
"github.com/projectcalico/libcalico-go/lib/numorstring"
"github.com/projectcalico/libcalico-go/lib/scope"
)
// BGPPeer contains information about a BGP peer resource that is a peer of a Calico
// compute node.
type BGPPeer struct {
unversioned.TypeMetadata
// Metadata for a BGPPeer.
Metadata BGPPeerMetadata `json:"metadata,omitempty"`
// Specification for a BGPPeer.
Spec BGPPeerSpec `json:"spec,omitempty"`
}
func (t BGPPeer) GetResourceMetadata() unversioned.ResourceMetadata {
return t.Metadata
}
// String() returns the human-readable string representation of a BGPPeer instance
// which is defined by its PeerIP and Scope.
func (t BGPPeer) String() string {
if t.Metadata.Scope == scope.Node && t.Metadata.Node == "" {
return fmt.Sprintf("BGPPeer(PeerIP=%s, Scope=%s)", t.Metadata.PeerIP.IP.String(), t.Metadata.Scope)
}
return fmt.Sprintf("BGPPeer(PeerIP=%s, Scope=%s, Node=%s)", t.Metadata.PeerIP.IP.String(), t.Metadata.Scope, t.Metadata.Node)
}
// BGPPeerMetadata contains the metadata for a BGPPeer resource.
type BGPPeerMetadata struct {
unversioned.ObjectMetadata
// The scope of the peer. This may be global or node. A global peer is a
// BGP device that peers with all Calico nodes. A node peer is a BGP device that
// peers with the specified Calico node (specified by the node hostname).
Scope scope.Scope `json:"scope" validate:"omitempty,scopeglobalornode"`
// The node name identifying the Calico node instance that is peering with this peer.
// When modifying a BGP peer, the node must be specified when the scope is `node`, and
// must be omitted when the scope is `global`.
Node string `json:"node,omitempty" validate:"omitempty,name"`
// The IP address of the peer.
PeerIP net.IP `json:"peerIP" validate:"omitempty"`
}
// BGPPeerSpec contains the specification for a BGPPeer resource.
type BGPPeerSpec struct {
// The AS Number of the peer.
ASNumber numorstring.ASNumber `json:"asNumber"`
}
// NewBGPPeer creates a new (zeroed) BGPPeer struct with the TypeMetadata initialised to the current
// version.
func NewBGPPeer() *BGPPeer {
return &BGPPeer{
TypeMetadata: unversioned.TypeMetadata{
Kind: "bgpPeer",
APIVersion: unversioned.VersionCurrent,
},
}
}
// BGPPeerList contains a list of BGP Peer resources. List types are returned from List()
// enumerations in the client interface.
type BGPPeerList struct {
unversioned.TypeMetadata
Metadata unversioned.ListMetadata `json:"metadata,omitempty"`
Items []BGPPeer `json:"items" validate:"dive"`
}
// NewBGPPeerList creates a new (zeroed) BGPPeerList struct with the TypeMetadata initialised to the current
// version.
func NewBGPPeerList() *BGPPeerList {
return &BGPPeerList{
TypeMetadata: unversioned.TypeMetadata{
Kind: "bgpPeerList",
APIVersion: unversioned.VersionCurrent,
},
}
}