Skip to content

Commit b2c20b2

Browse files
authored
Merge branch 'master' into master
2 parents 8160b6c + eaf8f03 commit b2c20b2

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
NETBOX_URL=
22
NETBOX_TOKEN=
33
REPO_URL=https://github.com/netbox-community/devicetype-library.git
4+
REPO_BRANCH=master
45
IGNORE_SSL_ERRORS=False
56
#SLUGS=c9300-48u isr4431 isr4331

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ docker build -t netbox-devicetype-import-library .
7777
The container supports the following env var as configuration :
7878

7979
- `REPO_URL`, the repo to look for device types (defaults to _https://github.com/netbox-community/devicetype-library.git_)
80+
- `REPO_BRANCH`, the branch to check out if appropriate, defaults to master.
8081
- `NETBOX_URL`, used to access netbox
8182
- `NETBOX_TOKEN`, token for accessing netbox
8283
- `VENDORS`, a space-separated list of vendors to import (defaults to None)

nb-dt-import.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
counter = Counter(added=0, updated=0, manufacturer=0)
1515

1616

17-
def update_package(path: str):
17+
def update_package(path: str, branch: str):
1818
try:
1919
repo = Repo(path)
2020
if repo.remotes.origin.url.endswith('.git'):
2121
repo.remotes.origin.pull()
22+
repo.git.checkout(branch)
2223
print(f"Pulled Repo {repo.remotes.origin.url}")
2324
except exc.InvalidGitRepositoryError:
2425
pass
@@ -394,7 +395,9 @@ def main():
394395

395396
VENDORS = settings.VENDORS
396397
REPO_URL = settings.REPO_URL
398+
397399
SLUGS = settings.SLUGS
400+
REPO_BRANCH = settings.REPO_BRANCH
398401

399402
parser = argparse.ArgumentParser(description='Import Netbox Device Types')
400403
parser.add_argument('--vendors', nargs='+', default=VENDORS,
@@ -403,7 +406,8 @@ def main():
403406
help="Git URL with valid Device Type YAML files")
404407
parser.add_argument('--slugs', nargs='+', default=SLUGS,
405408
help="List of device-type slugs to import eg. ap4431 ws-c3850-24t-l")
406-
409+
parser.add_argument('--branch', default=REPO_BRANCH,
410+
help="Git branch to use from repo")
407411
args = parser.parse_args()
408412

409413
try:
@@ -412,7 +416,7 @@ def main():
412416
+ f"updating {os.path.join(cwd, 'repo')}")
413417
update_package('./repo')
414418
else:
415-
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'))
419+
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'), branch=args.branch)
416420
print(f"Package Installed {repo.remotes.origin.url}")
417421
except exc.GitCommandError as error:
418422
print("Couldn't clone {} ({})".format(args.url, error))

settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load_dotenv()
44

55
REPO_URL = os.getenv("REPO_URL")
6+
REPO_BRANCH = os.getenv("REPO_BRANCH", "master")
67
NETBOX_URL = os.getenv("NETBOX_URL")
78
NETBOX_TOKEN = os.getenv("NETBOX_TOKEN")
89
IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", "False") == "True")

0 commit comments

Comments
 (0)