summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md293
-rw-r--r--setup.py10
-rw-r--r--vymgmt/Router.py232
-rw-r--r--vymgmt/__init__.py (renamed from vyroute/__init__.py)0
-rw-r--r--vymgmt/mgmt_common.py19
-rw-r--r--vyroute/Router.py678
-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
13 files changed, 289 insertions, 1394 deletions
diff --git a/README.md b/README.md
index afb223d..39ca269 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
-#VyRoute
-A python library for VyOS routing service setting
+#VyMGMT
+A python library for VyOS configurations
-This python library is used for VyOS routing service configuration,now it provide Static, RIP, OSPF and simple BGP configuration functions to users.
+This python library is used for VyOS configurations.Use this library to send the configuration to VyOS.
##Note
###Version:0.1
@@ -14,149 +14,29 @@ This python library is used for VyOS routing service configuration,now it provid
###Requirement:pexpect(pxssh)
-##Overview
-Now,SDN is a technologies trend.Like Openflow and switch controller,they provide us with centralized control and programmable features.But adminstrators of VyOS still need to login the system and
-configure services manually.I need a tool which can configure router service remotely and user can write a program to control the system like SDN controller.So I decide to write this library.Up to now,it just provide static, RIP, OSPF and BGP router configuration function.
-
-There are two classes in library:Router and BasicRouter.Router is a parent class,BasicRouter inherit parent class.When we use this library,we should use VyOS's address and user information to initialize a BasicRouter,then we can use member methods to control the system.
-Just like administrators configure services,in this lib you also need to enter configure mode,execute configuration,commit it and save it.
-
-BasicRouter has a member variable(python dictionary) "status",it store a router substance's status.
-
- self.__status = {"status": None, "commit": None, "save": None, "configure": None}
-
-When it finish initialization,all values in "status" are None.When a
-user login the substance,the value of "status" in self.__status will change to "login".When the user execute configure(),he will enter configure mode and value of "configure" will change to "Yes",during configure mode,all configuration method will change the value of "commit" and "save" to "no",when user finish a operation but not commit,the following method will not change the value of "commit" and "save".
-
-When the user want to exit configure mode,only he have commit and save the configuration can he exit configure mode,the value of "commit" and "save" must change to "Yes".If he don't want to save the configuration,he should use exit_config(force=True) to exit.If the user execute logout(),"status" will change to "logout" and the others will change to None.
-
-When you use this library,the methods you can only use in configure mode will return a message or an exception.Exceptions usually cause by the environment,maybe.If your parameters is correct,it will return a string message:
-
- "Result : Configured successfully"
-
-If there are any mistakes in the parameters,the method will return a string error message which return by VyOS system.
-
- >>> vyos.lo('1.1.1.1')
- 'set interfaces loopback lo address 1.1.1.1\r\n\x1b[?1h\x1b=\r\x1b[m\r\n "1.1.1.1" is not a valid value of type "ipv4net or ipv6net"\x1b[m\r\n Value validation failed\x1b[m\r\n Set failed\x1b[m\r\n\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>'
-
-This kind of error message,high-level application should use print to feedback to user.
-
- >>> print(vyos.lo('1.1.1.1'))
- set interfaces loopback lo address 1.1.1.1
-
- "1.1.1.1" is not a valid value of type "ipv4net or ipv6net"
- Value validation failed
- Set failed
-
-IMPORTANT:Some method will execute more than one command at once.If there are any mistake in your input,those methods will return a
-dictionary includes all error messages cause by your invalid input. High-level application should print every error message in
-the dictionary.
-
##Basic example
-I will show you how to configure a simple static router:
-
-Topo:
-test1---VyOS1———VyOS2---test2
-
-At first,test1 cannot ping test2:
-
- root@test1:~# ping 192.168.157.8
- PING 192.168.157.8 (192.168.157.8) 56(84) bytes of data.
- ^C
- --- 192.168.157.8 ping statistics ---
- 3 packets transmitted, 0 received, 100% packet loss, time 2016ms
-
-test2 also cannot ping test1:
-
- root@test3:~# ping 192.168.225.3
- PING 192.168.225.3 (192.168.225.3) 56(84) bytes of data.
- From 192.168.157.7 icmp_seq=1 Destination Net Unreachable
- From 192.168.157.7 icmp_seq=2 Destination Net Unreachable
- c^C
- --- 192.168.225.3 ping statistics ---
- 6 packets transmitted, 0 received, +2 errors, 100% packet loss, time 5023ms
-
-So,let's use vyroute to set up a static router between test1 and test2:
-
-Router1:
-
- >>> from vyroute.Router import BasicRouter
- >>> vyos = BasicRouter('192.168.225.2','vyos:vyos')
- >>> vyos.login()
- 'Result : Login successfully.'
- >>> vyos.configure()
- 'Result : Active configure mode successfully.'
- >>> vyos.static_route('192.168.225.0/24','192.168.225.2','1')
- 'Result : Configured successfully'
- >>> vyos.static_route('192.168.157.0/24','192.168.10.6','1')
- 'Result : Configured successfully'
- >>> vyos.commit()
- 'Result : Commit successfully.'
- >>> vyos.save()
- 'Result : Save successfully.'
- >>> vyos.exit()
- 'Result : Exit configure mode successfully.'
- >>> vyos.logout()
- 'Result : Logout successfully.'
-
-Router2:
-
- >>> vyos1 = BasicRouter('192.168.10.6','vyos:vyos')
- >>> vyos1.login()
- 'Result : Login successfully.'
- >>> vyos1.configure()
- 'Result : Active configure mode successfully.'
- >>> vyos1.static_route('192.168.225.0/24','192.168.10.5','1')
- 'Result : Configured successfully'
- >>> vyos1.static_route('192.168.157.0/24','192.168.157.7','1')
- 'Result : Configured successfully'
- >>> vyos1.exit()
- 'Error : You should commit first.'
- >>> vyos1.status()
- {'status': 'login', 'commit': 'No', 'save': 'No', 'configure': 'Yes'}
- >>> vyos1.commit()
- 'Result : Commit successfully.'
- >>> vyos1.save()
- 'Result : Save successfully.'
- >>> vyos1.status()
- {'status': 'login', 'commit': 'Yes', 'save': 'Yes', 'configure': 'Yes'}
- >>> vyos1.exit()
- 'Result : Exit configure mode successfully.'
- >>> vyos1.status()
- {'status': 'login', 'commit': None, 'save': None, 'configure': 'No'}
- >>> vyos1.logout()
- 'Result : Logout successfully.'
-
-Check the network:
-
- root@test1:~# ping 192.168.157.8 -c 5
- PING 192.168.157.8 (192.168.157.8) 56(84) bytes of data.
- 64 bytes from 192.168.157.8: icmp_seq=1 ttl=62 time=0.663 ms
- 64 bytes from 192.168.157.8: icmp_seq=2 ttl=62 time=0.998 ms
- 64 bytes from 192.168.157.8: icmp_seq=3 ttl=62 time=0.919 ms
- 64 bytes from 192.168.157.8: icmp_seq=4 ttl=62 time=0.629 ms
- 64 bytes from 192.168.157.8: icmp_seq=5 ttl=62 time=0.671 ms
-
- --- 192.168.157.8 ping statistics ---
- 5 packets transmitted, 5 received, 0% packet loss, time 4002ms
- rtt min/avg/max/mdev = 0.629/0.776/0.998/0.151 ms
-
-By ping we can know:test1 can ping test2 and test2 can ping test1,then we can check the VyOS:
-
- protocols {
- static {
- route 192.168.157.0/24 {
- next-hop 192.168.10.6 {
- distance 1
- }
- }
- route 192.168.225.0/24 {
- next-hop 192.168.225.2 {
- distance 1
- }
- }
- }
- }
+Set a description for eth0:
+
+ >>> from vymgmt.Router import Router
+ >>> vyos = Router('192.168.225.2','vyos:vyos')
+ >>> vyos.login()
+ 'Result : Login successfully.'
+ >>> vyos.configure()
+ 'Result : Active configure mode successfully.'
+ >>> vyos.set("interfaces ethernet eth0 description 'eth0'")
+ 'Result : Configured successfully'
+ >>> vyos.commit()
+ 'Result : Commit successfully.'
+ >>> vyos.status()
+ {'status': 'login', 'commit': 'Yes', 'save': 'No', 'configure': 'Yes'}
+ >>> vyos.exit()
+ 'Error : You should save first.'
+ >>> vyos.save()
+ 'Result : Save successfully.'
+ >>> vyos.exit()
+ 'Result : Exit configure mode successfully.'
+ >>> vyos.logout()
+ 'Result : Logout successfully.'
Because we have save the configuration,so if you reboot the VyOS system but the static router still works.
@@ -203,129 +83,22 @@ force: True or False
If force=True,this method will execute "exit discard" command and all your changes will lost.
-##lo(lo_addres)
-Add a router loopback address.
-
-Example:
-lo_addres: '1.1.1.1/32'(all parameters are string)
-
-You can use this method to add a new VyOS loopback address for interface "lo".We usually use this new address as router id.
-
-##delete_route(route_type)
-Delete router configurations.
-
-Example:
-route_type: 'rip'/'static'/'ospf'/'bgp'/'all'
-
-The value of "config" just "rip","static","ospf","bgp" and "all".Please remember "all" will delete all configuration in the section "protocols" in VyOS's configuration file.The others will delete the corresponding part of configuration in "protocols" section.
-
-You can use this method to delete router configuration but be careful.
-
-##static_route(network_range, next_hop, distance)
-This method provide a basic static router configuration function,
-and his method equal to "set protocols static route next-hop distance".
-
-Example:
-network_range: '10.20.10.0/24'
-next-hop: '10.20.10.1'
-distance: '1'
-
-You can use this method to configure a static router.
-##rip_route(network_range)
-RIP router network setting,and this method equal to "set protocols rip network".
+##set(config)
+Basic 'set' method,execute the set command in VyOS.
Example:
-network_range: '10.20.10.0/24'
+config: "interfaces ethernet eth0 description 'eth0'"
-You can use this method to add a network.
+The minimal c method.
-##rip_redistribute()
-Execute "set protocols rip redistribute connected" command.
-
-You can use this method to execute routing redistribution.
-
-##ospf_area(area, network_range)
-This method provide a OSPF area configuration function and this method equal to "set protocols ospf area network".
-
-Example:
-area: '0'
-network_range: '192.168.10.0/24'
-
-You can use this method to configure OSPF areas.
-
-##ospf_router_id(router_id)
-This method provide a router id configuration function and this method equal to "set protocols ospf parameters router-id".
-
-Example:
-router_id: '1.1.1.1'
-
-You can use this method to configure router id.
-
-##ospf_redistribute(metric_type)
-OSPF redistribute setting and this method equal to "set protocols ospf redistribute connected metric-type" and "set protocols ospf redistribute connected route-map CONNECT".
-
-Example:
-metric_type: '2'
-
-You can use this method to execute routing redistribution.
-
-##ospf_adjacency()
-This method equal to "set protocols ospf log-adjacency-changes".
-
-##ospf\_default\_route(metric, metric_type)
-This method execute the commands to configure default route and this method equal to "set protocols ospf default-information originate always","set protocols ospf default-information originate metric" and "set protocols ospf default-information originate metric-type".
-
-Example:
-metric: '10'
-metric-type: '2'
-
-You can use this method to configure default route.
-
-##ospf\_route\_map(data)
-VyOS route-map setting when you configure a OSPF router and this method equal to "set policy route-map CONNECT rule action permit" and "set policy route-map CONNECT rule match interface".
-
-Example:
-rule: '10'
-interface: 'lo'
-
-You can use this method to configure route-map.
-
-##bgp_route(self_as, neighbor, multihop, remote_as, update_source)
-VyOS BGP router basic setting and this method equal to "set protocols bgp neighbor ebgp-multihop","set protocols bgp neighbor remote-as" and "set protocols bgp neighbor update-source".
-
-Example:
-self_as: '65538'
-neighbor': '192.168.10.5'
-multihop': '2'
-remote_as': '65537'
-update_source': '192.168.10.6'
-
-You can use this method to configure neighbor,AS,remote-as and update-source and ebgp-multihop when you configure a BGP router.
-
-##bgp_network(self_as, network_range)
-Add a network to BGP router and this method equals to "set protocols bgp network".
-
-Example:
-self_as: '65538'
-router_id: '10.20.10.0'
-
-This method is similar to rip_route.
-
-##bgp\_router\_id(self_as, router_id)
-Set a router id for the router you login and this method equals to set protocols bgp parameters router-id".
+##delete(config)
+Basic 'delete' method,execute the delete command in VyOS.
Example:
-self_as: '65538'
-router_id: '10.20.10.0'
+config: "interfaces ethernet eth0 description 'eth0'"
-This method is similar to ospf\_router\_id.
+The minimal configuration method.
-##bgp\_blackhole\_route(network_range)
-Set a blackhole route and this method equals to "set protocols static route blackhole distance 254".
-
-Example:
-network_range: '10.20.10.0/24'
-You can use this method to configure blackhole route when you configure a BGP router.
diff --git a/setup.py b/setup.py
index 5a5d950..0c2f82e 100644
--- a/setup.py
+++ b/setup.py
@@ -2,17 +2,17 @@
from setuptools import setup, find_packages
setup(
- name="vyroute",
+ name="vymgmt",
version="0.1",
packages=find_packages(),
install_requires=['pexpect'],
- description="A library for VyOS routing setting",
- long_description="A library for VyOS routing setting",
+ description="A library for VyOS configurations",
+ long_description="A library for VyOS configurations",
author="Hochikong",
- author_email="michellehzg@gmail.com",
+ author_email="hochikong@foxmail.com",
license="MIT",
- keywords="A library for VyOS routing setting",
+ keywords="A library for VyOS configurations",
url="https://github.com/vyos/python-vyos-mgmt"
)
diff --git a/vymgmt/Router.py b/vymgmt/Router.py
new file mode 100644
index 0000000..326e025
--- /dev/null
+++ b/vymgmt/Router.py
@@ -0,0 +1,232 @@
+# Copyright (c) 2016 Hochikong
+
+from pxssh import pxssh
+from .mgmt_common import messenger
+
+
+class Router(object):
+ def __init__(self, address, cred):
+ """Initial a router object
+
+ :param address: Router address,example:'192.168.10.10'
+ :param cred: Router user and password,example:'vyos:vyos'
+ """
+ self.__address = address
+ self.__cred = list(cred)
+ self.__divi = self.__cred.index(":")
+ self.__username = ''.join(self.__cred[:self.__divi])
+ self.__passwd = ''.join(self.__cred[self.__divi+1:])
+ self.__conn = pxssh()
+ self.__status = {"status": None, "commit": None, "save": None, "configure": None}
+ self.__basic_string = {0: 'set ', 1: 'delete '}
+
+ def status(self):
+ """Check the router object inner status
+
+ :return: A python dictionary include the status of the router object
+ """
+ return self.__status
+
+ def login(self):
+ """Login the router
+
+ :return: A message or an error
+ """
+ try:
+ if self.__conn.login(self.__address, self.__username, self.__passwd) is True:
+ self.__status["status"] = "login"
+ return "Result : Login successfully."
+ else:
+ return "Error : Connect Failed."
+ except Exception as e:
+ return e
+
+ def logout(self):
+ """Logout the router
+
+ :return: A message or an error
+ """
+ try:
+ self.__conn.close()
+ self.__status["status"] = "logout"
+ self.__status["configure"] = None
+ self.__conn = pxssh()
+ return "Result : Logout successfully."
+ except Exception as e:
+ return e
+
+ def configure(self):
+ """Enter the VyOS configure mode
+
+ :return: A message or an error
+ """
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] is not "Yes":
+ self.__conn.sendline("configure")
+ self.__conn.prompt(0)
+ self.__conn.set_unique_prompt()
+ self.__status["configure"] = "Yes"
+ return "Result : Active configure mode successfully."
+ else:
+ return "Error : In configure mode now!"
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
+
+ def commit(self):
+ """Commit the configuration changes
+
+ :return: A message or an error
+ """
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] == "Yes":
+ if self.__status["commit"] is None:
+ return "Error : You don't need to commit."
+ if self.__status["commit"] == "No":
+ self.__conn.sendline("commit")
+ self.__conn.prompt()
+ self.__status["commit"] = "Yes"
+ return "Result : Commit successfully."
+ else:
+ return "Error : You have committed!"
+ else:
+ return "Error : Router not in configure mode!"
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
+
+ def save(self):
+ """Save the configuration after commit
+
+ :return: A message or an error
+ """
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] == "Yes":
+ if self.__status["commit"] == "Yes":
+ if self.__status["save"] is None:
+ return "Error : You don't need to save."
+ if self.__status["save"] == "No":
+ self.__conn.sendline("save")
+ self.__conn.prompt(0)
+ self.__status["save"] = "Yes"
+ return "Result : Save successfully."
+ else:
+ return "Error : You have saved!"
+ elif self.__status["commit"] is None:
+ return "Error : You don't need to save."
+ else:
+ return "Error : You need to commit first!"
+ else:
+ return "Error : Router not in configure mode!"
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
+
+ def exit(self, force=False):
+ """Exit VyOS configure mode
+
+ :param force: True or False
+ :return: A message or an error
+ """
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] == "Yes":
+ if force is True:
+ self.__conn.sendline("exit discard")
+ self.__conn.prompt()
+ self.__status["configure"] = "No"
+ self.__status["save"] = None
+ self.__status["commit"] = None
+ return "Result : Exit configure mode successfully."
+ else:
+ if self.__status["commit"] == "Yes":
+ if self.__status["save"] == "Yes":
+ self.__conn.sendline("exit")
+ self.__conn.prompt()
+ self.__status["configure"] = "No"
+ self.__status["save"] = None
+ self.__status["commit"] = None
+ return "Result : Exit configure mode successfully."
+ else:
+ return "Error : You should save first."
+ elif self.__status["commit"] is None:
+ self.__conn.sendline("exit")
+ self.__conn.prompt()
+ self.__status['configure'] = "No"
+ return "Result : Exit configure mode successfully."
+ else:
+ return "Error : You should commit first."
+ else:
+ return "Error : You are not in configure mode,need not exit."
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
+
+ def set(self, config):
+ """Basic 'set' method,execute the set command in VyOS
+
+ :param config: A configuration string.
+ e.g. 'protocols static route ... next-hop ... distance ...'
+ :return: A message or an error
+ """
+ full_config = self.__basic_string[0] + config
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] == "Yes":
+ res = messenger(self.__conn, full_config)
+ if "Result" in res:
+ if self.__status["commit"] == "No":
+ pass
+ else:
+ self.__status["commit"] = "No"
+ if self.__status["save"] == "No":
+ pass
+ else:
+ self.__status["save"] = "No"
+ return res
+ else:
+ return res
+ else:
+ return "Error : You are not in configure mode."
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
+
+ def delete(self, config):
+ """Basic 'delete' method,execute the delete command in VyOS
+
+ :param config: A configuration string.
+ e.g. 'protocols static route ... next-hop ... distance ...'
+ :return: A message or an error
+ """
+ full_config = self.__basic_string[1] + config
+ try:
+ if self.__status["status"] == "login":
+ if self.__status["configure"] == "Yes":
+ res = messenger(self.__conn, full_config)
+ if "Result" in res:
+ if self.__status["commit"] == "No":
+ pass
+ else:
+ self.__status["commit"] = "No"
+ if self.__status["save"] == "No":
+ pass
+ else:
+ self.__status["save"] = "No"
+ return res
+ else:
+ return res
+ else:
+ return "Error : You are not in configure mode."
+ else:
+ return "Error : Router object not connect to a router."
+ except Exception as e:
+ return e
diff --git a/vyroute/__init__.py b/vymgmt/__init__.py
index e69de29..e69de29 100644
--- a/vyroute/__init__.py
+++ b/vymgmt/__init__.py
diff --git a/vymgmt/mgmt_common.py b/vymgmt/mgmt_common.py
new file mode 100644
index 0000000..0ed4bf0
--- /dev/null
+++ b/vymgmt/mgmt_common.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2016 Hochikong
+
+
+def messenger(obj, config):
+ """This method used for sending configuration to VyOS
+
+ :param obj: A connection object
+ :param config: A configuration string
+ :return: A message or an error
+ """
+ try:
+ obj.sendline(config)
+ 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/Router.py b/vyroute/Router.py
deleted file mode 100644
index 8dc1606..0000000
--- a/vyroute/Router.py
+++ /dev/null
@@ -1,678 +0,0 @@
-# Copyright (c) 2016 Hochikong
-
-from pxssh import pxssh
-from vyroute.basic_function import Modifylo
-from vyroute.basic_function import StaticRoute
-from vyroute.basic_function import RIPRoute
-from vyroute.basic_function import OSPFRoute
-from vyroute.basic_function import DeleteRoute
-from vyroute.basic_function import BGPRoute
-
-
-class Router(object):
- pass
-
-
-class BasicRouter(Router):
- def __init__(self, address, cred):
- """Initial a router object
-
- :param address: Router address,example:'192.168.10.10'
- :param cred: Router user and password,example:'vyos:vyos'
- """
- self.__address = address
- self.__cred = list(cred)
- self.__divi = self.__cred.index(":")
- self.__username = ''.join(self.__cred[:self.__divi])
- self.__passwd = ''.join(self.__cred[self.__divi+1:])
- self.__conn = pxssh()
- self.__status = {"status": None, "commit": None, "save": None, "configure": None}
-
- def status(self):
- """Check the router object inner status
-
- :return: A python dictionary include the status of the router object
- """
- return self.__status
-
- def login(self):
- """Login the router
-
- :return: A message or an error
- """
- try:
- if self.__conn.login(self.__address, self.__username, self.__passwd) is True:
- self.__status["status"] = "login"
- return "Result : Login successfully."
- else:
- return "Error : Connect Failed."
- except Exception as e:
- return e
-
- def logout(self):
- """Logout the router
-
- :return: A message or an error
- """
- try:
- self.__conn.close()
- self.__status["status"] = "logout"
- self.__status["configure"] = None
- self.__conn = pxssh()
- return "Result : Logout successfully."
- except Exception as e:
- return e
-
- def configure(self):
- """Enter the VyOS configure mode
-
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] is not "Yes":
- self.__conn.sendline("configure")
- self.__conn.prompt(0)
- self.__conn.set_unique_prompt()
- self.__status["configure"] = "Yes"
- return "Result : Active configure mode successfully."
- else:
- return "Error : In configure mode now!"
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def commit(self):
- """Commit the configuration changes
-
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- if self.__status["commit"] is None:
- return "Error : You don't need to commit."
- if self.__status["commit"] == "No":
- self.__conn.sendline("commit")
- self.__conn.prompt()
- self.__status["commit"] = "Yes"
- return "Result : Commit successfully."
- else:
- return "Error : You have committed!"
- else:
- return "Error : Router not in configure mode!"
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def save(self):
- """Save the configuration after commit
-
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- if self.__status["commit"] == "Yes":
- if self.__status["save"] is None:
- return "Error : You don't need to save."
- if self.__status["save"] == "No":
- self.__conn.sendline("save")
- self.__conn.prompt(0)
- self.__status["save"] = "Yes"
- return "Result : Save successfully."
- else:
- return "Error : You have saved!"
- elif self.__status["commit"] is None:
- return "Error : You don't need to save."
- else:
- return "Error : You need to commit first!"
- else:
- return "Error : Router not in configure mode!"
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def exit(self, force=False):
- """Exit VyOS configure mode
-
- :param force: True or False
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- if force is True:
- self.__conn.sendline("exit discard")
- self.__conn.prompt()
- self.__status["configure"] = "No"
- self.__status["save"] = None
- self.__status["commit"] = None
- return "Result : Exit configure mode successfully."
- else:
- if self.__status["commit"] == "Yes":
- if self.__status["save"] == "Yes":
- self.__conn.sendline("exit")
- self.__conn.prompt()
- self.__status["configure"] = "No"
- self.__status["save"] = None
- self.__status["commit"] = None
- return "Result : Exit configure mode successfully."
- else:
- return "Error : You should save first."
- elif self.__status["commit"] is None:
- self.__conn.sendline("exit")
- self.__conn.prompt()
- self.__status['configure'] = "No"
- return "Result : Exit configure mode successfully."
- else:
- return "Error : You should commit first."
- else:
- return "Error : You are not in configure mode,need not exit."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def lo(self, lo_address):
- """Add a router loopback address
-
- Parameter example:
- '1.1.1.1/32'
-
- :param lo_address: The target address you want.Don't forget the netmask
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = Modifylo.modifylo(self.__conn, lo_address)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def delete_route(self, route_type):
- """Delete router configurations
-
- 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 route_type: Route type
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = DeleteRoute.deleteroute(self.__conn, route_type)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def static_route(self, 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 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
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = StaticRoute.staticroute(self.__conn, network_range, next_hop, distance)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def rip_network(self, network_range):
- """RIP router network setting
-
- Parameter example:
- '10.20.10.0/24'
-
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = RIPRoute.rip_network(self.__conn, network_range)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def rip_redistribute(self):
- """Execute 'set protocols rip redistribute connected' command
-
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = RIPRoute.rip_redistribute(self.__conn)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_area(self, area, network_range):
- """This method provide a OSPF area configuration function
-
- Parameter example:
- 'area':'0'
- 'network_range':'192.168.10.0/24'
-
- :param area: The ospf area number
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospfarea(self.__conn, area, network_range)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_router_id(self, router_id):
- """This method provide a router id configuration function
-
- Parameter example:
- '1.1.1.1'
-
- :param router_id: The router id
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospf_router_id(self.__conn, router_id)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_redistribute(self, metric_type):
- """OSPF redistribute setting
-
- Parameter example:
- '2'
-
- :param metric_type: The metric-type
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospf_redistribute(self.__conn, metric_type)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_adjacency(self):
- """Execute 'Set protocols ospf log-adjacency-changes' command
-
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospf_adjacency(self.__conn)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_default_route(self, metric, metric_type):
- """This method execute the commands to configure default route
-
- Parameter example:
- 'metric':'10'
- 'metric-type':'2'
-
- :param metric: The metric,a number
- :param metric_type: The metric-type
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospf_default_route(self.__conn, metric, metric_type)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def ospf_route_map(self, rule, interface):
- """VyOS route-map setting when you configure a OSPF router
-
- Parameter example:
- 'rule':'10'
- 'interface':'lo'
-
- :param rule: The route-map rule number
- :param interface: The interface name
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = OSPFRoute.ospf_route_map(self.__conn, rule, interface)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def bgp_route(self, self_as, neighbor, multihop, remote_as, update_source):
- """VyOS BGP router basic setting
-
- Parameter example:
- 'self_as':'65538'
- 'neighbor':'192.168.10.5'
- 'multihop':'2'
- 'remote_as':'65537'
- 'update_source':'192.168.10.6'
-
- :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
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = BGPRoute.bgp_as(self.__conn, self_as, neighbor, multihop, remote_as, update_source)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def bgp_network(self, self_as, network_range):
- """Add a network to BGP router
-
- Parameter example:
- 'self_as':'65538'
- 'network_range':'10.20.10.0/24'
-
- :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
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = BGPRoute.bgp_network(self.__conn, self_as, network_range)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def bgp_router_id(self, 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 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
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = BGPRoute.bgp_router_id(self.__conn, self_as, router_id)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
-
- def bgp_blackhole_route(self, network_range):
- """Set a blackhole route
-
- Parameter example:
- '10.20.10.0/24'
-
- :param network_range: The target network,don't forget the netmask
- :return: A message or an error
- """
- try:
- if self.__status["status"] == "login":
- if self.__status["configure"] == "Yes":
- res = BGPRoute.bgp_blackhole_route(self.__conn, network_range)
- if "Result" in res:
- if self.__status["commit"] == "No":
- pass
- else:
- self.__status["commit"] = "No"
- if self.__status["save"] == "No":
- pass
- else:
- self.__status["save"] = "No"
- return res
- else:
- return res
- else:
- return "Error : You are not in configure mode."
- else:
- return "Error : Router object not connect to a router."
- except Exception as e:
- return e
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