def get_bgp_peers(self, version, hostname=None): """ Get the configured BGP Peers. :param version: "v4" for IPv4, "v6" for IPv6 :param hostname: Optional hostname. If supplied, this returns the node-specific BGP peers. If None, this returns the globally configured BGP peers. :return: List of BGPPeer. """ assert version in ("v4", "v6") if hostname is None: bgp_peers_path = BGP_PEERS_PATH % {"version": version} else: bgp_peers_path = HOST_BGP_PEERS_PATH % {"hostname": hostname, "version": version} try: nodes = self.etcd_client.read(bgp_peers_path).children except EtcdKeyNotFound: # Path doesn't exist. return [] # If there are no children etcd returns a single value with the parent # key and no value (so skip empty values). peers = [BGPPeer.from_json(node.value) for node in nodes if node.value] return peers
def get_bgp_peers(self, version, hostname=None): """ Get the configured BGP Peers. :param version: 4 for IPv4, 6 for IPv6 :param hostname: Optional hostname. If supplied, this returns the node-specific BGP peers. If None, this returns the globally configured BGP peers. :return: List of BGPPeer. """ assert version in (4, 6) if hostname is None: bgp_peers_path = BGP_GLOBAL_PEERS_PATH % {"version": str(version)} else: bgp_peers_path = BGP_HOST_PEERS_PATH % {"hostname": hostname, "version": str(version)} try: nodes = self.etcd_client.read(bgp_peers_path).children except EtcdKeyNotFound: # Path doesn't exist. return [] # If there are no children etcd returns a single value with the parent # key and no value (so skip empty values). peers = [BGPPeer.from_json(node.value) for node in nodes if node.value] return peers
def node_bgppeer_add(ip, version, as_num): """ Add a new BGP peer with the supplied IP address and AS Number to this node. :param ip: The address to add :param version: 4 or 6 :param as_num: The peer AS Number. :return: None """ address = IPAddress(ip) peer = BGPPeer(address, as_num) client.add_bgp_peer(version, peer, hostname=hostname)
def bgp_peer_add(ip, version, as_num): """ Add a new global BGP peer with the supplied IP address and AS Number. All nodes will peer with this. :param ip: The address to add :param version: 4 or 6 :param as_num: The peer AS Number. :return: None """ address = IPAddress(ip) peer = BGPPeer(address, as_num) client.add_bgp_peer(version, peer)