asd
This commit is contained in:
1 parent
d3df425784
commit
b65494c2c8
7 files changed
+509
-25
No files matched your search
+35
-11
@@ -1,3 +1,7 @@
|
||||
# TODO check common API
|
||||
# TODO install pyEOS
|
||||
|
||||
|
||||
class NetworkDriver:
|
||||
def __init__(self, hostname, user, password):
|
||||
"""
|
||||
@@ -27,22 +31,34 @@ class NetworkDriver:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def compare_configuration(self, candidate):
|
||||
def load_candidate_config(self, filename=None, config=None):
|
||||
"""
|
||||
Compares the running configuration with a candidate configuration.
|
||||
:param candidate: (str) Configuration you want to compare with.
|
||||
:return: A string showing the difference between the running configuration and the candidate configuration.
|
||||
Populates the attribute candidate_config with the desired configuration. You can populate it from a file or
|
||||
from a string. If you send both a filename and a string containing the configuration, the file takes precedence.
|
||||
|
||||
:param filename: Path to the file containing the desired configuration. By default is None.
|
||||
:param config: String containing the desired configuration.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def replace_configuration(self, candidate):
|
||||
def compare_config(self):
|
||||
"""
|
||||
Replaces the running configuration with the candidate configuration.
|
||||
:param candidate: (str) Configuration you want to have on the device.
|
||||
:return: None
|
||||
:raises SyntacticError: If configuration syntax was incorrect.
|
||||
:raises SemanticError: If the device reported semantic errors on the configuration.
|
||||
:raises UnknownConfigurationError: If none of the above.
|
||||
|
||||
:return: A string showing the difference between the running_config and the candidate_config. The running_config is
|
||||
loaded automatically just before doing the comparison so there is no neeed for you to do it.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def replace_config(self):
|
||||
"""
|
||||
Applies the configuration loaded with the method load_candidate_config on the device. Note that the current
|
||||
configuration of the device is replaced with the new configuration.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def rollback(self):
|
||||
"""
|
||||
If changes have been made, revert changes to the original state.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -60,6 +76,14 @@ class NetworkDriver:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_interface(self, name):
|
||||
"""
|
||||
Retrieves information from the available interfaces on the device.
|
||||
:param name: (string) Interface name of the interface you want to get.
|
||||
:return: (list of Interface) List of Interface from the device.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_interfaces(self):
|
||||
"""
|
||||
Retrieves information from the available interfaces on the device.
|
||||
|
||||
+75
-2
@@ -1,8 +1,43 @@
|
||||
# Copyright 2014 Spotify AB. All rights reserved.
|
||||
#
|
||||
# The contents of this file are licensed under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations under
|
||||
# the License.
|
||||
|
||||
from pyEOS import EOS
|
||||
|
||||
from base import NetworkDriver
|
||||
from objects.facts import Facts
|
||||
from objects.bgp import BGPInstance, BGPNeighbor
|
||||
from objects.interface import Interface, InterfaceStatus
|
||||
from objects.lldp import LLDPNeighbor
|
||||
|
||||
def _process_interface(interface):
|
||||
name = interface['name']
|
||||
|
||||
if interface['interfaceStatus'] == u'notconnect':
|
||||
status = InterfaceStatus.OPER_DOWN
|
||||
elif interface['interfaceStatus'] == u'connected':
|
||||
status = InterfaceStatus.UP
|
||||
elif interface['interfaceStatus'] == u'disabled':
|
||||
status = InterfaceStatus.ADMIN_DOWN
|
||||
else:
|
||||
raise Exception('Unknown interface status: %s, %s' % (name, interface['interfaceStatus']))
|
||||
|
||||
return Interface(
|
||||
name,
|
||||
interface['bandwidth'],
|
||||
status
|
||||
)
|
||||
|
||||
|
||||
class EOSDriver(NetworkDriver):
|
||||
|
||||
@@ -12,13 +47,24 @@ class EOSDriver(NetworkDriver):
|
||||
self.password = password
|
||||
self.device = EOS(hostname, user, password, use_ssl=True)
|
||||
|
||||
|
||||
def open(self):
|
||||
self.device.open()
|
||||
|
||||
def close(self):
|
||||
self.device.close()
|
||||
|
||||
def load_candidate_config(self, filename=None, config=None):
|
||||
self.device.load_candidate_config(filename=filename, config=config)
|
||||
|
||||
def compare_config(self):
|
||||
return self.device.compare_config()
|
||||
|
||||
def replace_config(self):
|
||||
self.device.replace_config()
|
||||
|
||||
def rollback(self):
|
||||
self.device.rollback()
|
||||
|
||||
def get_facts(self):
|
||||
hostname = self.device.show_hostname()
|
||||
sv = self.device.show_version()
|
||||
@@ -58,4 +104,31 @@ class EOSDriver(NetworkDriver):
|
||||
bgp_neighbors = list_peers,
|
||||
)
|
||||
bgp_table.append(bgp_instance)
|
||||
return bgp_table
|
||||
return bgp_table
|
||||
|
||||
def get_interface(self, name):
|
||||
interfaces = self.device.show_interfaces()
|
||||
interface = interfaces['interfaces'][name]
|
||||
return _process_interface(interface)
|
||||
|
||||
def get_interfaces(self):
|
||||
interfaces = list()
|
||||
|
||||
for interface in self.device.show_interfaces()['interfaces'].values():
|
||||
interfaces.append(_process_interface(interface))
|
||||
|
||||
return interfaces
|
||||
|
||||
def get_lldp_neighbors(self):
|
||||
neighbors = list()
|
||||
|
||||
for n in self.device.show_lldp_neighbors()['lldpNeighbors']:
|
||||
neighbors.append(
|
||||
LLDPNeighbor(
|
||||
n['neighborDevice'],
|
||||
n['port'],
|
||||
n['neighborPort']
|
||||
)
|
||||
)
|
||||
|
||||
return neighbors
|
||||
Reference in new issue
Block a user