Skip to content

Commit

Permalink
Merge pull request #12 from netdevops/credential-bugs
Browse files Browse the repository at this point in the history
bug fixes in credentials
  • Loading branch information
jtdub committed Jul 31, 2020
2 parents 302c4eb + 9fdcb28 commit bde89e0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 19 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/python36.yml
@@ -0,0 +1,28 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python3.6

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install dependencies
run: |
python setup.py install
- name: Run tests
run: |
python setup.py test
28 changes: 28 additions & 0 deletions .github/workflows/python37.yml
@@ -0,0 +1,28 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python3.7

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python setup.py install
- name: Run tests
run: |
python setup.py test
28 changes: 28 additions & 0 deletions .github/workflows/python38.yml
@@ -0,0 +1,28 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python3.8

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python setup.py install
- name: Run tests
run: |
python setup.py test
3 changes: 0 additions & 3 deletions .travis.yml
@@ -1,8 +1,6 @@
language: python

python:
- "3.6"
- "3.7"
- "3.8"

install:
Expand Down Expand Up @@ -30,4 +28,3 @@ deploy:
local-dir: "docs"
on:
branch: master
condition: $TRAVIS_PYTHON_VERSION = "3.6"
2 changes: 1 addition & 1 deletion netnir/__init__.py
Expand Up @@ -3,4 +3,4 @@
netnir will create the default config and folders.
"""

__version__ = "0.0.9"
__version__ = "0.0.10"
30 changes: 15 additions & 15 deletions netnir/core/inventory.py
@@ -1,19 +1,9 @@
from netnir.constants import (
HOSTVARS,
GROUPVARS,
TEMPLATES,
DOMAIN,
NETNIR_USER,
NETNIR_PASS,
)
from netnir.helpers import device_mapper
from nornir.core.deserializer.inventory import Inventory
import os
import yaml


"""dynamic inventory builder class
"""
"""dynamic inventory builder class"""


class NornirInventory(Inventory):
Expand All @@ -31,7 +21,13 @@ def __init__(self, **kwargs):
)

def nhosts(self):
from netnir.helpers import device_mapper
from netnir.core.credentials import Credentials
from netnir.constants import (
HOSTVARS,
TEMPLATES,
DOMAIN,
)

"""
load devices from host_vars and load them into the nornir inventory schema
Expand All @@ -48,8 +44,8 @@ def nhosts(self):
)
data[host] = {
"hostname": f"{host}.{domain}" if domain else host,
"username": os.environ.get(NETNIR_USER, creds["username"]),
"password": os.environ.get(NETNIR_PASS, creds["password"]),
"username": creds["username"],
"password": creds["password"],
"port": host_vars.get("port", 22),
"platform": device_mapper(host_vars["os"]),
"groups": host_vars.get("groups", list()),
Expand All @@ -68,8 +64,8 @@ def nhosts(self):
"connection_options": {
"netconf": {
"hostname": f"{host}.{domain}" if domain else host,
"username": os.environ.get(NETNIR_USER, creds["username"]),
"password": os.environ.get(NETNIR_PASS, creds["password"]),
"username": creds["username"],
"password": creds["password"],
"platform": host_vars.get("os"),
"port": host_vars.get("port", 830),
"extras": {"hostkey_verify": False},
Expand All @@ -83,6 +79,8 @@ def ngroups(self):
"""
load groups from group_vars and load them into the nornir inventory schema
"""
from netnir.constants import GROUPVARS

data = dict()
groups = os.listdir(os.path.expanduser(GROUPVARS))
if "all" in groups:
Expand All @@ -101,6 +99,8 @@ def ndefaults(self):
"""
load the defaults from group_vars/all and load them into the nornir inventory schema
"""
from netnir.constants import GROUPVARS

if os.path.isfile(os.path.expanduser(GROUPVARS) + "/all"):
default_vars = yaml.load(
open(os.path.expanduser(GROUPVARS) + "/all"), Loader=yaml.SafeLoader,
Expand Down

0 comments on commit bde89e0

Please sign in to comment.