summaryrefslogtreecommitdiff
path: root/vyroute/basic_function/BGPRoute.py
diff options
context:
space:
mode:
authorhochikong <1097225749@qq.com>2016-08-21 19:37:29 +0800
committerhochikong <1097225749@qq.com>2016-08-21 19:37:29 +0800
commit655811f476a95b8eac2f65c78323a982d59eff1b (patch)
tree6aa2a938dfb73d1b185f56f026fbb519197a2bf3 /vyroute/basic_function/BGPRoute.py
parent2584bea48c4c243fdf694cb21505bfbde6834a7f (diff)
downloadpython-vyos-mgmt-655811f476a95b8eac2f65c78323a982d59eff1b.tar.gz
python-vyos-mgmt-655811f476a95b8eac2f65c78323a982d59eff1b.zip
T133:Add a generic method set() and delete()
Rename the project Add set and delete method Rewrite README
Diffstat (limited to 'vyroute/basic_function/BGPRoute.py')
-rw-r--r--vyroute/basic_function/BGPRoute.py120
1 files changed, 0 insertions, 120 deletions
diff --git a/vyroute/basic_function/BGPRoute.py b/vyroute/basic_function/BGPRoute.py
deleted file mode 100644
index a84c896..0000000
--- a/vyroute/basic_function/BGPRoute.py
+++ /dev/null
@@ -1,120 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def bgp_as(obj, self_as, neighbor, multihop, remote_as, update_source):
- """VyOS BGP router basic setting about AS
-
- Parameter example:
- 'self_as':'65538'
- 'neighbor':'192.168.10.5'
- 'multihop':'2'
- 'remote_as':'65537'
- 'update_source':'192.168.10.6'
-
- :param obj: A connection object
- :param self_as: The AS number of the router you login
- :param neighbor: The neighbor router address
- :param multihop: The amount of hops
- :param remote_as: The remote AS number
- :param update_source: The update source
- :return: A message or an error
- """
- bgp_multihop_configuration = "set protocols bgp %s neighbor %s ebgp-multihop %s"
- bgp_remote_as_configuration = "set protocols bgp %s neighbor %s remote-as %s"
- bgp_update_source_configuration = "set protocols bgp %s neighbor %s update-source %s"
-
- try:
- reg = 0
- error_message = []
- obj.sendline(bgp_multihop_configuration % (self_as, neighbor, multihop))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_message.append(obj.before)
- reg += 1
- obj.sendline(bgp_remote_as_configuration % (self_as, neighbor, remote_as))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_message.append(obj.before)
- reg += 1
- obj.sendline(bgp_update_source_configuration % (self_as, neighbor, update_source))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_message.append(obj.before)
- reg += 1
- if reg > 0:
- return error_message
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e
-
-
-def bgp_network(obj, self_as, network_range):
- """Add a network to BGP router
-
- Parameter example:
- 'self_as':'65538'
- 'network_range':'10.20.10.0/24'
-
- :param obj: A connection object
- :param self_as: The AS number of the router you login
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- bgp_network_configuration = "set protocols bgp %s network %s"
-
- try:
- obj.sendline(bgp_network_configuration % (self_as, network_range))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e
-
-
-def bgp_router_id(obj, self_as, router_id):
- """Set a router id for the router you login
-
- Parameter example:
- 'self_as':'65538'
- 'router_id':'10.20.10.0'
-
- :param obj:A connection object
- :param self_as: The AS number of the router you login
- :param router_id: The router id,or you can use the router address as router id
- :return: A message or an error
- """
- bgp_router_id_configuration = "set protocols bgp %s parameters router-id %s"
-
- try:
- obj.sendline(bgp_router_id_configuration % (self_as, router_id))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e
-
-
-def bgp_blackhole_route(obj, network_range):
- """Set a blackhole route
-
- Parameter example:
- '10.20.10.0/24'
-
- :param obj: A connection object
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- bgp_blackhole_configuration = "set protocols static route %s blackhole distance 254"
-
- try:
- obj.sendline(bgp_blackhole_configuration % network_range)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e