Skip to content

Commit eaf8f03

Browse files
authored
Merge pull request #36 from dmcken/add-repo-branch-option
Add repo branch option
2 parents 3aaf98b + 58be612 commit eaf8f03

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
counter = Counter(added=0, updated=0, manufacturer=0)
1414

1515

16-
def update_package(path: str):
16+
def update_package(path: str, branch: str):
1717
try:
1818
repo = Repo(path)
1919
if repo.remotes.origin.url.endswith('.git'):
2020
repo.remotes.origin.pull()
21+
repo.git.checkout(branch)
2122
print(f"Pulled Repo {repo.remotes.origin.url}")
2223
except exc.InvalidGitRepositoryError:
2324
pass
@@ -387,12 +388,16 @@ def main():
387388

388389
VENDORS = settings.VENDORS
389390
REPO_URL = settings.REPO_URL
391+
REPO_BRANCH = settings.REPO_BRANCH
392+
390393

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

398403

@@ -402,7 +407,7 @@ def main():
402407
+ f"updating {os.path.join(cwd, 'repo')}")
403408
update_package('./repo')
404409
else:
405-
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'))
410+
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'), branch=args.branch)
406411
print(f"Package Installed {repo.remotes.origin.url}")
407412
except exc.GitCommandError as error:
408413
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)