summaryrefslogtreecommitdiff
path: root/vyroute/basic_function/OSPFRoute.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/OSPFRoute.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/OSPFRoute.py')
-rw-r--r--vyroute/basic_function/OSPFRoute.py178
1 files changed, 0 insertions, 178 deletions
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