Renaming drivers to napalm for the sake of clarity when importing

This commit is contained in:
David Barroso committed 2015-03-16 14:15:18 +01:00
1 parent a82fec74a6
commit ff9365b476
5 files changed
-335

No files matched your search

View File
Whitespace-only changes.
-106
View File
@@ -1,106 +0,0 @@
# TODO check common API
# TODO install pyEOS
class NetworkDriver:
def __init__(self, hostname, user, password):
"""
This is the base class you have to inherit from when writing your own Network Driver to manage any device. You
will, in addition, have to override all the methods specified on this class. Make sure you follow the guidelines
for every method and that you return the correct data.
:param hostname: (str) IP or FQDN of the device you want to connect to.
:param user: (str) Username you want to use
:param password: (str) Password
:return:
"""
raise NotImplementedError
def open(self):
"""
Opens a connection to the device.
:return: None
"""
raise NotImplementedError
def close(self):
"""
Closes the connection to the device.
:return: None
"""
raise NotImplementedError
def load_candidate_config(self, filename=None, config=None):
"""
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 compare_config(self):
"""
: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 commit_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 discard_config(self):
"""
Discards the configuration loaded into the candidate.
"""
raise NotImplementedError
def rollback(self):
"""
If changes have been made, revert changes to the original state.
"""
raise NotImplementedError
def get_facts(self):
"""
Retrieves facts from the device.
:return: (Facts) Facts from the device.
"""
raise NotImplementedError
def get_bgp_neighbors(self):
"""
Retrieves BGP neighbors information from the device.
:return: (list of BGPNeighbor) List of BGPNeighbor from the device.
"""
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.
:return: (list of Interface) List of Interface from the device.
"""
raise NotImplementedError
def get_lldp_neighbors(self):
"""
Retrieves LLDP information from the device.
:return: (list of LLDPNeighbor) List of LLDPNeighbor.
"""
raise NotImplementedError
-137
View File
@@ -1,137 +0,0 @@
# 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):
def __init__(self, hostname, user, password):
self.hostname = hostname
self.user = user
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 commit_config(self):
self.device.replace_config()
def discard_config(self):
pass
def rollback(self):
self.device.rollback()
def get_facts(self):
hostname = self.device.show_hostname()
sv = self.device.show_version()
return Facts(
vendor = 'Arista',
hostname = hostname['hostname'],
fqdn = hostname['fqdn'],
hardware_model = sv['modelName'],
serial_number = sv['serialNumber'],
os_version = sv['version'],
interfaces = self.device.show_interfaces()['interfaces'].keys(),
)
def get_bgp_neighbors(self):
output = self.device.show_ip_bgp_summary_vrf_all()
bgp_table = list()
for vrf, bgp in output['vrfs'].iteritems():
list_peers = list()
for peer, values in bgp['peers'].iteritems():
p = BGPNeighbor(
ip = peer,
remote_as = int(values['asn']),
state = values['peerState'],
time = int(values['upDownTime']),
prefixes_accepted = int(values['prefixAccepted']),
)
list_peers.append(p)
bgp_instance = BGPInstance(
vrf = vrf,
asn = int(bgp['asn']),
router_id = bgp['routerId'],
bgp_neighbors = list_peers,
)
bgp_table.append(bgp_instance)
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
-48
View File
@@ -1,48 +0,0 @@
# 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 pyIOSXR import IOSXR
from base import NetworkDriver
class IOSXRDriver(NetworkDriver):
def __init__(self, hostname, username, password):
self.hostname = hostname
self.username = username
self.password = password
self.device = IOSXR(hostname, username, password)
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 commit_config(self):
self.device.commit_config()
def discard_config(self):
self.device.discard_config()
def rollback(self):
self.device.rollback()
-44
View File
@@ -1,44 +0,0 @@
from base import NetworkDriver
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
class JunOSDriver(NetworkDriver):
def __init__(self, hostname, user, password):
self.hostname = hostname
self.user = user
self.password = password
self.device = Device(hostname, user=user, password=password)
def open(self):
self.device.open()
self.device.bind(cu=Config)
self.device.cu.lock()
def close(self):
self.device.cu.unlock()
self.device.close()
def load_candidate_config(self, filename=None, config=None):
if filename is None:
configuration = config
else:
with open(filename) as f:
configuration = f.read()
self.device.cu.load(configuration, format='text', overwrite=True)
def compare_config(self):
return self.device.cu.diff()
def commit_config(self):
self.device.cu.commit()
def discard_config(self):
self.device.cu.rollback(rb_id=0)
def rollback(self):
self.device.cu.rollback(rb_id=1)
self.commit_config()