Skip to content

Commit e51064c

Browse files
committed
Merge pull request #107 from opdemand/106-deis-open
find a proxy and use the OS default handler to open the URL fixes #106
2 parents 69526b0 + e71c803 commit e51064c

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

client/deis.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
create create a new container formation
1616
scale scale container types (web=2, worker=1)
1717
logs print most recent logs for the formation
18+
open open a URL for the formation in a browser
1819
info print a representation of the formation
1920
converge force-converge all nodes in the formation
2021
calculate recalculate and update the formation databag
@@ -44,18 +45,19 @@
4445
import glob
4546
import json
4647
import os.path
48+
import random
4749
import re
4850
import subprocess
4951
import sys
5052
import time
5153
import urlparse
54+
import webbrowser
5255
import yaml
5356

5457
from docopt import docopt
5558
from docopt import DocoptExit
5659
import requests
5760

58-
5961
__version__ = '0.0.5'
6062

6163

@@ -1144,6 +1146,28 @@ def providers(self, args):
11441146
"""
11451147
return self.providers_list(args)
11461148

1149+
def open(self, args):
1150+
"""
1151+
Open a URL to the application in a browser
1152+
1153+
Usage: deis open
1154+
"""
1155+
formation = args.get('--formation')
1156+
if not formation:
1157+
formation = self._session.formation
1158+
# TODO: replace with a proxy lookup that doesn't have any side effects
1159+
# this currently recalculates and updates the databag
1160+
response = self._dispatch('post',
1161+
"/api/formations/{}/calculate".format(formation))
1162+
if response.status_code == requests.codes.ok: # @UndefinedVariable
1163+
databag = json.loads(response.content)
1164+
proxy = random.choice(databag['nodes'].get('proxy', {}).values())
1165+
# use the OS's default handler to open this URL
1166+
webbrowser.open('http://{}/'.format(proxy))
1167+
return proxy
1168+
else:
1169+
print('Error!', response.text)
1170+
11471171
def providers_create(self, args):
11481172
"""
11491173
Create a provider for use by Deis

0 commit comments

Comments
 (0)