Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Add task to pop open web browser to nautobot page #211

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion nautobot-app/{{ cookiecutter.project_slug }}/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
"""

import os
import platform
import re
import sys
from pathlib import Path
from time import sleep

from invoke.collection import Collection
from invoke.exceptions import Exit, UnexpectedExit
from invoke.exceptions import Exit, Failure, UnexpectedExit
from invoke.tasks import task as invoke_task


Expand Down Expand Up @@ -651,6 +652,22 @@ def backup_db(context, db_name="", output_file="dump.sql", readable=True):
print(50 * "=")


@task
def open_nautobot_web(context):
"""Open Nautobot web interface in the default browser."""
nautobot_raw_uri = docker_compose(context, "port nautobot 8080").stdout.rstrip()
nautobot_url = f"http://{nautobot_raw_uri}"

if platform.system() == "Darwin":
open_cmd = "open"
else:
open_cmd = "xdg-open"
try:
context.run(f"{open_cmd} {nautobot_url}", hide="err")
except Failure:
print(f"Unable to open browser. Nautobot interface at {nautobot_url}")


# ------------------------------------------------------------------------------
# DOCS
# ------------------------------------------------------------------------------
Expand Down