|
19 | 19 | converge force-converge all nodes in the formation |
20 | 20 | calculate recalculate and update the formation databag |
21 | 21 | logs view aggregated log info for the formation |
| 22 | + run run a command on a remote container |
22 | 23 | destroy destroy a container formation |
23 | 24 |
|
24 | 25 | Subcommands, use ``deis help [subcommand]`` to learn more:: |
@@ -644,6 +645,7 @@ def formations(self, args): |
644 | 645 | formations:converge force-converge all nodes in the formation |
645 | 646 | formations:calculate recalculate and update the formation databag |
646 | 647 | formations:logs view aggregated log info for the formation |
| 648 | + formations:run run a command on a remote container |
647 | 649 | formations:destroy destroy a container formation |
648 | 650 |
|
649 | 651 | Use `deis help [command]` to learn more |
@@ -835,6 +837,29 @@ def formations_converge(self, args): |
835 | 837 | else: |
836 | 838 | print('Error!', response.text) |
837 | 839 |
|
| 840 | + def formations_run(self, args): |
| 841 | + """ |
| 842 | + Run a command on a remote node. |
| 843 | +
|
| 844 | + Usage: deis formations:run <command>... |
| 845 | + """ |
| 846 | + formation = args.get('--formation') |
| 847 | + if not formation: |
| 848 | + formation = self._session.formation |
| 849 | + body = {'commands': sys.argv[2:]} |
| 850 | + response = self._dispatch('post', |
| 851 | + "/api/formations/{}/run".format(formation), |
| 852 | + json.dumps(body)) |
| 853 | + if response.status_code == requests.codes.ok: # @UndefinedVariable |
| 854 | + output, rc = json.loads(response.content) |
| 855 | + if rc == 0: |
| 856 | + sys.stdout.write(output) |
| 857 | + sys.stdout.flush() |
| 858 | + else: |
| 859 | + print('Error!\n{}'.format(output)) |
| 860 | + else: |
| 861 | + print('Error!', response.text) |
| 862 | + |
838 | 863 | def keys(self, args): |
839 | 864 | """ |
840 | 865 | Valid commands for SSH keys: |
@@ -1335,6 +1360,7 @@ def parse_args(cmd): |
1335 | 1360 | 'calculate': 'formations:calculate', |
1336 | 1361 | 'converge': 'formations:converge', |
1337 | 1362 | 'destroy': 'formations:destroy', |
| 1363 | + 'run': 'formations:run', |
1338 | 1364 | 'scale': 'containers:scale', |
1339 | 1365 | 'ps': 'containers:list', |
1340 | 1366 | } |
@@ -1376,7 +1402,8 @@ def main(): |
1376 | 1402 | return |
1377 | 1403 | docopt(__doc__, argv=['--help']) |
1378 | 1404 | # re-parse docopt with the relevant docstring |
1379 | | - if cmd in dir(cli): |
| 1405 | + # unless cmd is formations_run, which needs to use sys.argv directly |
| 1406 | + if not cmd == 'formations_run' and cmd in dir(cli): |
1380 | 1407 | docstring = trim(getattr(cli, cmd).__doc__) |
1381 | 1408 | if 'Usage: ' in docstring: |
1382 | 1409 | args.update(docopt(docstring)) |
|
0 commit comments