summaryrefslogtreecommitdiff
path: root/vyroute/basic_function
diff options
context:
space:
mode:
Diffstat (limited to 'vyroute/basic_function')
-rw-r--r--vyroute/basic_function/BGPRoute.py120
-rw-r--r--vyroute/basic_function/DeleteRoute.py60
-rw-r--r--vyroute/basic_function/Modifylo.py24
-rw-r--r--vyroute/basic_function/OSPFRoute.py178
-rw-r--r--vyroute/basic_function/RIPRoute.py42
-rw-r--r--vyroute/basic_function/StaticRoute.py27
-rw-r--r--vyroute/basic_function/__init__.py0
7 files changed, 0 insertions, 451 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
diff --git a/vyroute/basic_function/DeleteRoute.py b/vyroute/basic_function/DeleteRoute.py
deleted file mode 100644
index 175b712..0000000
--- a/vyroute/basic_function/DeleteRoute.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def deleteroute(obj, route_type):
- """This method provide a router configuration delete function
-
- Parameter example:
- 'rip'/'static'/'ospf'/'bgp'/'all'
-
- WARNING!
- When you use this function,please don't forget this func will delete all same type
- router configuration,when your 'config' in data is 'rip',it will delete all rip router setting.
- If you do not want your setting disappear,you can delete router configuration manually or rewrite
- this func.
-
- :param obj: A connection object
- :param route_type: Route type
- :return: A message or an error
- """
- delete_basic_configuration = "delete protocols %s"
- delete_all_protocols = "delete protocols"
-
- try:
- if route_type == "all":
- obj.sendline(delete_all_protocols)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Delete successfully."
- elif route_type == 'rip':
- obj.sendline(delete_basic_configuration % 'rip')
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Delete successfully."
- elif route_type == 'static':
- obj.sendline(delete_basic_configuration % 'static')
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Delete successfully."
- elif route_type == 'bgp':
- obj.sendline(delete_basic_configuration % 'bgp')
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Delete successfully."
- elif route_type == 'ospf':
- obj.sendline(delete_basic_configuration % 'ospf')
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Delete successfully."
- else:
- return "Error : Nonsupport protocols type."
- except Exception as e:
- return e
diff --git a/vyroute/basic_function/Modifylo.py b/vyroute/basic_function/Modifylo.py
deleted file mode 100644
index ee247f0..0000000
--- a/vyroute/basic_function/Modifylo.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def modifylo(obj, lo_address):
- """This method provide a loopback address configuration function
-
- Parameter example:
- '1.1.1.1/32'
-
- :param obj: A connection object
- :param lo_address: The target address you want.Don't forget the netmask
- :return: A message or an error
- """
-
- lo_basic_configuration = "set interfaces loopback lo address %s"
-
- try:
- # Configure loopback interface lo address
- obj.sendline(lo_basic_configuration % lo_address)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
- else:
- return "Result : Add successfully."
- except Exception as e:
- return e
diff --git a/vyroute/basic_function/OSPFRoute.py b/vyroute/basic_function/OSPFRoute.py
deleted file mode 100644
index 4f80b88..0000000
--- a/vyroute/basic_function/OSPFRoute.py
+++ /dev/null
@@ -1,178 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def ospfarea(obj, area, network_range):
- """This method provide a OSPF area configuration function
-
- Parameter example:
- 'area':'0'
- 'network_range':'192.168.10.0/24'
-
- :param obj: A connection object
- :param area: The ospf area number
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- ospf_basic_configuration = "set protocols ospf area %s network %s"
-
- try:
- # Configure ospf area
- obj.sendline(ospf_basic_configuration % (area, 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 ospf_router_id(obj, router_id):
- """This method provide a router id configuration function
-
- Parameter example:
- '1.1.1.1'
-
- :param obj: a connection object
- :param router_id: The router id
- :return: A message or an error
- """
- router_id_configuration = "set protocols ospf parameters router-id %s"
- try:
- # Configure router id
- obj.sendline(router_id_configuration % 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 ospf_redistribute(obj, metric_type):
- """This method provide a router redistribute function
-
- Parameter example:
- '2'
-
- :param obj: A connection object
- :param metric_type: The metric-type
- :return: A message or an error
- """
- redistribute_configuration = {"0": "set protocols ospf redistribute connected metric-type %s",
- "1": "set protocols ospf redistribute connected route-map CONNECT",
- }
- try:
- reg = 0
- error_message = []
- obj.sendline(redistribute_configuration['0'] % metric_type)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_message.append(obj.before)
- reg += 1
- obj.sendline(redistribute_configuration['1'])
- 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 ospf_adjacency(obj):
- """This method execute : set protocols ospf log-adjacency-changes
-
- :param obj: a connection object
- :return: A message or an error
- """
- log_adjacency_changes_configuration = "set protocols ospf log-adjacency-changes"
- try:
- obj.sendline(log_adjacency_changes_configuration)
- 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 ospf_default_route(obj, metric, metric_type):
- """This method execute the commands to configure default route
-
- Parameter example:
- 'metric':'10'
- 'metric-type':'2'
-
- :param obj: A connection object
- :param metric: The metric,a number
- :param metric_type: The metric-type
- :return: A message or an error
- """
- default_route_configuration = {"0": "set protocols ospf default-information originate always",
- "1": "set protocols ospf default-information originate metric %s",
- "2": "set protocols ospf default-information originate metric-type %s",
- }
- try:
- reg = 0
- error_messsage = []
- obj.sendline(default_route_configuration['0'])
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_messsage.append(obj.before)
- reg += 1
- obj.sendline(default_route_configuration['1'] % metric)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_messsage.append(obj.before)
- reg += 1
- obj.sendline(default_route_configuration['2'] % metric_type)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_messsage.append(obj.before)
- reg += 1
- if reg > 0:
- return error_messsage
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e
-
-
-def ospf_route_map(obj, rule, interface):
- """This method is used for VyOS route-map setting when you configure a OSPF router
-
- Parameter example:
- 'rule':'10'
- 'interface':'lo'
-
- :param obj: A connection object
- :param rule: The route-map rule number
- :param interface: The interface name
- :return: A message or an error
- """
- route_map_configuration = {"0": "set policy route-map CONNECT rule %s action permit",
- "1": "set policy route-map CONNECT rule %s match interface %s",
- }
- try:
- reg = 0
- error_messsage = []
- obj.sendline(route_map_configuration['0'] % rule)
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_messsage.append(obj.before)
- reg += 1
- obj.sendline(route_map_configuration['1'] % (rule, interface))
- obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- error_messsage.append(obj.before)
- reg += 1
- if reg > 0:
- return error_messsage
- else:
- return "Result : Configured successfully"
- except Exception as e:
- return e
diff --git a/vyroute/basic_function/RIPRoute.py b/vyroute/basic_function/RIPRoute.py
deleted file mode 100644
index 632dc6d..0000000
--- a/vyroute/basic_function/RIPRoute.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def rip_network(obj, network_range):
- """This method provide a RIP router network configuration function
-
- 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
- """
- rip_basic_configuration = "set protocols rip network %s"
-
- try:
- # Configure RIP router
- obj.sendline(rip_basic_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
-
-
-def rip_redistribute(obj):
- """Execute 'set protocols rip redistribute connected' command
-
- :param obj: A connection object
- :return: A message or an error
- """
- redistribute_configuration = "set protocols rip redistribute connected"
-
- try:
- obj.sendline(redistribute_configuration)
- 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
diff --git a/vyroute/basic_function/StaticRoute.py b/vyroute/basic_function/StaticRoute.py
deleted file mode 100644
index d210785..0000000
--- a/vyroute/basic_function/StaticRoute.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) 2016 Hochikong
-def staticroute(obj, network_range, next_hop, distance):
- """This method provide a basic static router configuration function
-
- Parameter example:
- 'network_range':'10.20.10.0/24'
- 'next-hop':'10.20.10.1'
- 'distance':'1'
-
- :param obj: A connection object
- :param network_range: The target network,don't forget the netmask
- :param next_hop: The next hop
- :param distance: The distance
- :return: A message or an error
- """
- static_basic_configuration = "set protocols static route %s next-hop %s distance %s"
-
- try:
- # Configure static router
- obj.sendline(static_basic_configuration % (network_range, next_hop, distance))
- 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
diff --git a/vyroute/basic_function/__init__.py b/vyroute/basic_function/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/vyroute/basic_function/__init__.py
+++ /dev/null