Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NETBOX_URL=
NETBOX_TOKEN=
REPO_URL=https://github.com/netbox-community/devicetype-library.git
REPO_BRANCH=master
IGNORE_SSL_ERRORS=False
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ docker build -t netbox-devicetype-import-library .
The container supports the following env var as configuration :

- `REPO_URL`, the repo to look for device types (defaults to _https://github.com/netbox-community/devicetype-library.git_)
- `REPO_BRANCH`, the branch to check out if appropriate, defaults to master.
- `NETBOX_URL`, used to access netbox
- `NETBOX_TOKEN`, token for accessing netbox
- `VENDORS`, a space-separated list of vendors to import (defaults to None)
Expand Down
9 changes: 7 additions & 2 deletions nb-dt-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
counter = Counter(added=0, updated=0, manufacturer=0)


def update_package(path: str):
def update_package(path: str, branch: str):
try:
repo = Repo(path)
if repo.remotes.origin.url.endswith('.git'):
repo.remotes.origin.pull()
repo.git.checkout(branch)
print(f"Pulled Repo {repo.remotes.origin.url}")
except exc.InvalidGitRepositoryError:
pass
Expand Down Expand Up @@ -387,12 +388,16 @@ def main():

VENDORS = settings.VENDORS
REPO_URL = settings.REPO_URL
REPO_BRANCH = settings.REPO_BRANCH


parser = argparse.ArgumentParser(description='Import Netbox Device Types')
parser.add_argument('--vendors', nargs='+', default=VENDORS,
help="List of vendors to import eg. apc cisco")
parser.add_argument('--url', '--git', default=REPO_URL,
help="Git URL with valid Device Type YAML files")
parser.add_argument('--branch', default=REPO_BRANCH,
help="Git branch to use from repo")
args = parser.parse_args()


Expand All @@ -402,7 +407,7 @@ def main():
+ f"updating {os.path.join(cwd, 'repo')}")
update_package('./repo')
else:
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'))
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'), branch=args.branch)
print(f"Package Installed {repo.remotes.origin.url}")
except exc.GitCommandError as error:
print("Couldn't clone {} ({})".format(args.url, error))
Expand Down
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
load_dotenv()

REPO_URL = os.getenv("REPO_URL")
REPO_BRANCH = os.getenv("REPO_BRANCH", "master")
NETBOX_URL = os.getenv("NETBOX_URL")
NETBOX_TOKEN = os.getenv("NETBOX_TOKEN")
IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", "False") == "True")
Expand Down