|
15 | 15 | create create a new container formation |
16 | 16 | scale scale container types (web=2, worker=1) |
17 | 17 | logs print most recent logs for the formation |
| 18 | + open open a URL for the formation in a browser |
18 | 19 | info print a representation of the formation |
19 | 20 | converge force-converge all nodes in the formation |
20 | 21 | calculate recalculate and update the formation databag |
|
44 | 45 | import glob |
45 | 46 | import json |
46 | 47 | import os.path |
| 48 | +import random |
47 | 49 | import re |
48 | 50 | import subprocess |
49 | 51 | import sys |
50 | 52 | import time |
51 | 53 | import urlparse |
| 54 | +import webbrowser |
52 | 55 | import yaml |
53 | 56 |
|
54 | 57 | from docopt import docopt |
55 | 58 | from docopt import DocoptExit |
56 | 59 | import requests |
57 | 60 |
|
58 | | - |
59 | 61 | __version__ = '0.0.5' |
60 | 62 |
|
61 | 63 |
|
@@ -1144,6 +1146,28 @@ def providers(self, args): |
1144 | 1146 | """ |
1145 | 1147 | return self.providers_list(args) |
1146 | 1148 |
|
| 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 | + |
1147 | 1171 | def providers_create(self, args): |
1148 | 1172 | """ |
1149 | 1173 | Create a provider for use by Deis |
|
0 commit comments