Skip to content

Commit eb7067f

Browse files
author
Gabriel Monroy
committed
move open to apps:open
1 parent a05b5c8 commit eb7067f

1 file changed

Lines changed: 27 additions & 39 deletions

File tree

client/deis.py

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,6 @@ def _dispatch(self, method, path, body=None,
320320
response = func(url, data=body, headers=headers)
321321
return response
322322

323-
def attach(self, args):
324-
"""
325-
Attach session to an application or formation
326-
327-
Uses DEIS_APPLICATION and DEIS_FORMATION environment
328-
variables to store state in the terminal session.
329-
330-
Usage: deis attach --formation=<formation> | --app=<app>
331-
"""
332-
formation = args.get('--formation')
333-
if formation:
334-
os.environ['DEIS_FORMATION'] = formation
335-
336323
def apps(self, args):
337324
"""
338325
Valid commands for apps:
@@ -482,6 +469,32 @@ def apps_list(self, args):
482469
else:
483470
raise ResponseError(response)
484471

472+
def apps_open(self, args):
473+
"""
474+
Open a URL to the application in a browser
475+
476+
Usage: deis apps:open [--app=<app>]
477+
"""
478+
app = args.get('--app')
479+
if not app:
480+
app = self._session.app
481+
# TODO: replace with a proxy lookup that doesn't have any side effects
482+
# this currently recalculates and updates the databag
483+
response = self._dispatch('post',
484+
"/api/apps/{}/calculate".format(app))
485+
if response.status_code == requests.codes.ok: # @UndefinedVariable
486+
databag = json.loads(response.content)
487+
domains = databag.get('domains', [])
488+
if domains:
489+
domain = random.choice(domains)
490+
# use the OS's default handler to open this URL
491+
webbrowser.open('http://{}/'.format(domain))
492+
return domain
493+
else:
494+
print('No proxies found. Use `deis layers:scale proxy=1` to scale up.')
495+
else:
496+
raise ResponseError(response)
497+
485498
def apps_logs(self, args):
486499
"""
487500
Retrieve the most recent log events
@@ -1467,32 +1480,6 @@ def providers(self, args):
14671480
"""
14681481
return self.providers_list(args)
14691482

1470-
def open(self, args):
1471-
"""
1472-
Open a URL to the application in a browser
1473-
1474-
Usage: deis open
1475-
"""
1476-
app = args.get('--app')
1477-
if not app:
1478-
app = self._session.app
1479-
# TODO: replace with a proxy lookup that doesn't have any side effects
1480-
# this currently recalculates and updates the databag
1481-
response = self._dispatch('post',
1482-
"/api/apps/{}/calculate".format(app))
1483-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1484-
databag = json.loads(response.content)
1485-
proxies = databag.get('proxies', [])
1486-
if proxies:
1487-
proxy = random.choice(proxies)
1488-
# use the OS's default handler to open this URL
1489-
webbrowser.open('http://{}/'.format(proxy))
1490-
return proxy
1491-
else:
1492-
print('No proxies found. Use `deis layers:scale proxy=1` to scale up.')
1493-
else:
1494-
raise ResponseError(response)
1495-
14961483
def providers_create(self, args):
14971484
"""
14981485
Create a provider for use by Deis
@@ -1661,6 +1648,7 @@ def parse_args(cmd):
16611648
'converge': 'formations:converge',
16621649
'calculate': 'apps:calculate',
16631650
'ssh': 'nodes:ssh',
1651+
'open': 'apps:open',
16641652
'logs': 'apps:logs',
16651653
'run': 'apps:run',
16661654
}

0 commit comments

Comments
 (0)