Skip to content

Commit

Permalink
Merge pull request #63 from spotify/0.2
Browse files Browse the repository at this point in the history
0.2
  • Loading branch information
dbarrosop committed Oct 1, 2015
2 parents 88f0a61 + bb42127 commit 1318008
Show file tree
Hide file tree
Showing 39 changed files with 1,469 additions and 526 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ docs/_build/

.idea
.DS_Store

env
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
David Barroso <dbarroso@spotify.com>
<<<<<<< HEAD
Elisa Jasinska <elisa@bigwaveit.org>
=======
Elisa Jasinska <elisa@bigwaveit.com>
>>>>>>> master
3 changes: 2 additions & 1 deletion Manifest.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include requirements.txt
include requirements.txt
include utils/*.yml
66 changes: 66 additions & 0 deletions ansible/napalm_get_facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 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.


"""
"""

import ast
import logging

logger = logging.getLogger('eos_install_config')

DOCUMENTATION = '''
'''

EXAMPLES = '''
'''


def main():
module = AnsibleModule(
argument_spec=dict(
hostname=dict(required=True),
username=dict(required=True),
password=dict(required=True),
dev_os=dict(required=True),
),
supports_check_mode=True
)

hostname = module.params['hostname']
username = module.params['username']
dev_os = module.params['dev_os']
password = module.params['password']


network_driver = get_network_driver(dev_os)

device = network_driver(hostname, username, password)
device.open()

facts = device.get_facts()
facts['interface_details'] = device.get_interfaces()

device.close()

module.exit_json(ansible_facts=facts)

from ansible.module_utils.basic import *
from napalm import get_network_driver

main()
2 changes: 1 addition & 1 deletion napalm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_network_driver(vendor):
'IOSXR': IOSXRDriver,
'JUNOS': JunOSDriver,
'JUNIPER': JunOSDriver,
'fortios': FortiOSDriver,
'FORTIOS': FortiOSDriver,
}
try:
return driver_mapping[vendor.upper()]
Expand Down
208 changes: 204 additions & 4 deletions napalm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def load_merge_candidate(self, filename=None, config=None):

def compare_config(self):
"""
:return: A string showing the difference between the running configuration and the candidate configuration. The
:return: A string showing the difference between the running configuration and the candidate configuration. The\
running_config is loaded automatically just before doing the comparison so there is no need for you to do it.
"""
raise NotImplementedError
Expand All @@ -94,16 +93,217 @@ def rollback(self):
"""
raise NotImplementedError

'''
def get_facts(self):
"""
Returns a dictionary containing the following information:
* uptime - Uptime of the device in seconds.
* vendor - Manufacturer of the device.
* model - Device model.
* hostname - Hostname of the device
* fqdn - Fqdn of the device
* os_version - String with the OS version running on the device.
* serial_number - Serial number of the device
* interface_list - List of the interfaces of the device
For example::
{
'uptime': 151005.57332897186,
'vendor': u'Arista',
'os_version': u'4.14.3-2329074.gaatlantarel',
'serial_number': u'SN0123A34AS',
'model': u'vEOS',
'hostname': u'eos-router',
'fqdn': u'eos-router',
'interface_list': [u'Ethernet2', u'Management1', u'Ethernet1', u'Ethernet3']
}
"""


raise NotImplementedError
'''

def get_interfaces(self):
"""
Returns a dictionary of dictionaries. The keys for the first dictionary will be the interfaces in the devices.\
The inner dictionary will containing the following data for each interface:
* is_up (True/False)
* is_enabled (True/False)
* description (string)
* last_flapped (int in seconds)
* speed (int in Mbit)
* mac_address (string)
For example::
{
u'Management1':
{
'is_up': False,
'is_enabled': False,
'description': u'',
'last_flapped': -1,
'speed': 1000,
'mac_address': u'dead:beef:dead',
},
u'Ethernet1':
{
'is_up': True,
'is_enabled': True,
'description': u'foo',
'last_flapped': 1429978575.1554043,
'speed': 1000,
'mac_address': u'beef:dead:beef',
},
u'Ethernet2':
{
'is_up': True,
'is_enabled': True,
'description': u'bla',
'last_flapped': 1429978575.1555667,
'speed': 1000,
'mac_address': u'beef:beef:beef',
},
u'Ethernet3':
{
'is_up': False,
'is_enabled': True,
'description': u'bar',
'last_flapped': -1,
'speed': 1000,
'mac_address': u'dead:dead:dead',
}
}
"""
raise NotImplementedError

def get_lldp_neighbors(self):
"""
Returns a dictionary where the keys are local ports and the value is a list of dictionaries with the following \
information:
* hostname
* port
For example::
{
u'Ethernet2':
[
{
'hostname': u'junos-unittest',
'port': u'520',
}
],
u'Ethernet3':
[
{
'hostname': u'junos-unittest',
'port': u'522',
}
],
u'Ethernet1':
[
{
'hostname': u'junos-unittest',
'port': u'519',
},
{
'hostname': u'ios-xrv-unittest',
'port': u'Gi0/0/0/0',
}
],
u'Management1':
[
{
'hostname': u'junos-unittest',
'port': u'508',
}
]
}
"""
raise NotImplementedError

# def get_bgp_neighbors(self):
# """
# Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf (global if no vrf).\
# The inner dictionary will containg the following data for each vrf:
# * local_as (int)
# * router_id
# * peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. The inner keys are:
# * is_up (True/False)
# * is_enabled (True/False)
# * remote_as (int)
# * description (string)
# * uptime (int in seconds)
# * received_prefixes (int)
# * accepted_prefixes (int)
# * sent_prefixes (int)
#
# For example:
#
# {
# u'default':
# {
# 'router_id': u'192.168.0.1',
# 'local_as': 65000,
# 'peers':
# {
# u'10.0.0.11':
# {
# 'is_up': True,
# 'is_enabled': True,
# 'uptime': 1429978587.950959,
# 'description': u'',
# 'received_prefixes': 2,
# 'sent_prefixes': 3,
# 'accepted_prefixes': 0,
# 'remote_as': 65001
# },
# u'1.1.1.1':
# {
# 'is_up': False,
# 'is_enabled': False,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 1
# }
# }
# },
# u'vrfA':
# {
# 'router_id': u'10.0.1.10',
# 'local_as': 65010,
# 'peers':
# {
# u'10.0.1.12':
# {
# 'is_up': False,
# 'is_enabled': True,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 65012
# },
# u'10.0.1.13':
# {
# 'is_up': False,
# 'is_enabled': True,
# 'uptime': -1,
# 'description': u'',
# 'received_prefixes': 0,
# 'sent_prefixes': 0,
# 'accepted_prefixes': 0,
# 'remote_as': 65013
# }
# }
# }
# }
#
#
# """
# raise NotImplementedError

0 comments on commit 1318008

Please sign in to comment.