Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit f4c9f65

Browse files
committed
Add --dashboard
Opens the dashboard URL specified in `SUPERNOVA_DASHBOARD_URL` in a web browser. e.g.: If you have in your config: [dfw] SUPERNOVA_DASHBOARD_URL=https://dfw.dashboard.rackspacecloud.com/ ... snip ... Then: $ supernova --dashboard dfw would open https://dfw.dashboard.rackspacecloud.com/ in a web browser.
1 parent 3cd5294 commit f4c9f65

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

.supernova

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This is an example config for use with tests
22
[dfw]
3+
SUPERNOVA_DASHBOARD_URL=https://dfw.dashboard.rackspacecloud.com/
34
SUPERNOVA_GROUP=raxusa
45
OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/
56
OS_AUTH_SYSTEM=rackspace

supernova/executable.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
to run
1919
"""
2020
import sys
21+
import webbrowser
2122

2223

2324
import click
@@ -93,6 +94,8 @@ def print_env_short_list(ctx, param, value):
9394
help="Display the least amount of output possible")
9495
@click.option('--echo', '-e', default=None, is_flag=True,
9596
help="Print the specified environment and exit")
97+
@click.option('--dashboard', '-D', default=None, is_flag=True,
98+
help="Open dashboard in browser for specified environment")
9699
@click.argument('environment', nargs=1)
97100
@click.argument('command', nargs=-1)
98101
@click.version_option()
@@ -104,7 +107,7 @@ def print_env_short_list(ctx, param, value):
104107
help="List all configured environments in shorter format")
105108
@click.pass_context
106109
def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
107-
echo):
110+
echo, dashboard):
108111
"""
109112
You can use supernova with many OpenStack clients and avoid the pain of
110113
managing multiple sets of environment variables. Getting started is easy
@@ -154,6 +157,7 @@ def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
154157
'executable': executable,
155158
'quiet': quiet,
156159
'echo': echo,
160+
'dashboard': dashboard,
157161
}
158162

159163
# If the user specified a single environment, we need to verify that the
@@ -176,6 +180,21 @@ def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
176180
click.echo('{0}={1}'.format(k, env[k]))
177181
ctx.exit(0)
178182

183+
if supernova_args['dashboard']:
184+
if len(envs) > 1:
185+
msg = ("\nCan't open dashboard for a group of environments.\n"
186+
"Specify a single environment when using --dashboard.")
187+
click.echo(msg)
188+
ctx.exit(1)
189+
url = nova_creds[envs[0]].get('SUPERNOVA_DASHBOARD_URL')
190+
if url is None:
191+
msg = ("\nNo SUPERNOVA_DASHBOARD_URL specified "
192+
"for environment: %s" % envs[0])
193+
click.echo(msg)
194+
ctx.exit(1)
195+
webbrowser.open(url)
196+
ctx.exit(0)
197+
179198
if len(command) == 0:
180199
msg = ("\nMissing arguments to pass to executable Run supernova "
181200
"--help for examples.\n".format(envs[0]))

tests/test_executable.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import webbrowser
2+
13
from click.testing import CliRunner
24

35

@@ -111,6 +113,26 @@ def test_broken_configuration_file(self):
111113
assert result.exit_code != 0
112114
assert "There's an error in your configuration file" in result.output
113115

116+
def test_dashboard(self, monkeypatch):
117+
def mockreturn(url):
118+
return False
119+
monkeypatch.setattr(webbrowser, "open", mockreturn)
120+
runner = CliRunner()
121+
result = runner.invoke(executable.run_supernova, ['--dashboard', 'dfw'])
122+
assert result.exit_code == 0
123+
124+
def test_dashboard_group(self):
125+
runner = CliRunner()
126+
result = runner.invoke(executable.run_supernova, ['--dashboard', 'raxusa'])
127+
assert result.exit_code == 1
128+
assert 'group of environments' in result.output
129+
130+
def test_dashboard_no_url(self):
131+
runner = CliRunner()
132+
result = runner.invoke(executable.run_supernova, ['--dashboard', 'hkg'])
133+
assert result.exit_code == 1
134+
assert 'No SUPERNOVA_DASHBOARD_URL' in result.output
135+
114136
def test_echo(self):
115137
runner = CliRunner()
116138
result = runner.invoke(executable.run_supernova, ['--echo', 'hkg'])

0 commit comments

Comments
 (0)