|
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:: |
@@ -711,6 +712,7 @@ def formations(self, args): |
711 | 712 | formations:converge force-converge all nodes in the formation |
712 | 713 | formations:calculate recalculate and update the formation databag |
713 | 714 | formations:logs view aggregated log info for the formation |
| 715 | + formations:run run a command on a remote container |
714 | 716 | formations:destroy destroy a container formation |
715 | 717 |
|
716 | 718 | Use `deis help [command]` to learn more |
@@ -910,6 +912,29 @@ def formations_converge(self, args): |
910 | 912 | else: |
911 | 913 | print('Error!', response.text) |
912 | 914 |
|
| 915 | + def formations_run(self, args): |
| 916 | + """ |
| 917 | + Run a command on a remote node. |
| 918 | +
|
| 919 | + Usage: deis formations:run <command>... |
| 920 | + """ |
| 921 | + formation = args.get('--formation') |
| 922 | + if not formation: |
| 923 | + formation = self._session.formation |
| 924 | + body = {'commands': sys.argv[2:]} |
| 925 | + response = self._dispatch('post', |
| 926 | + "/api/formations/{}/run".format(formation), |
| 927 | + json.dumps(body)) |
| 928 | + if response.status_code == requests.codes.ok: # @UndefinedVariable |
| 929 | + output, rc = json.loads(response.content) |
| 930 | + if rc == 0: |
| 931 | + sys.stdout.write(output) |
| 932 | + sys.stdout.flush() |
| 933 | + else: |
| 934 | + print('Error!\n{}'.format(output)) |
| 935 | + else: |
| 936 | + print('Error!', response.text) |
| 937 | + |
913 | 938 | def keys(self, args): |
914 | 939 | """ |
915 | 940 | Valid commands for SSH keys: |
@@ -1426,6 +1451,7 @@ def parse_args(cmd): |
1426 | 1451 | 'calculate': 'formations:calculate', |
1427 | 1452 | 'converge': 'formations:converge', |
1428 | 1453 | 'destroy': 'formations:destroy', |
| 1454 | + 'run': 'formations:run', |
1429 | 1455 | 'scale': 'containers:scale', |
1430 | 1456 | 'ps': 'containers:list', |
1431 | 1457 | } |
@@ -1467,7 +1493,8 @@ def main(): |
1467 | 1493 | return |
1468 | 1494 | docopt(__doc__, argv=['--help']) |
1469 | 1495 | # re-parse docopt with the relevant docstring |
1470 | | - if cmd in dir(cli): |
| 1496 | + # unless cmd is formations_run, which needs to use sys.argv directly |
| 1497 | + if not cmd == 'formations_run' and cmd in dir(cli): |
1471 | 1498 | docstring = trim(getattr(cli, cmd).__doc__) |
1472 | 1499 | if 'Usage: ' in docstring: |
1473 | 1500 | args.update(docopt(docstring)) |
|
0 commit comments