Skip to content

Commit 131bf8f

Browse files
author
Gabriel Monroy
committed
fix bug with apps:run task dispatch
1 parent f88e782 commit 131bf8f

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

api/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def flat(self):
404404
'proxy': self.layer.proxy,
405405
'ssh_username': self.layer.ssh_username,
406406
'ssh_private_key': self.layer.ssh_private_key,
407+
'ssh_port': self.layer.ssh_port,
407408
'config': dict(self.layer.config),
408409
'provider_id': self.provider_id,
409410
'fqdn': self.fqdn}

client/deis.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,26 @@ def apps_logs(self, args):
507507
else:
508508
raise ResponseError(response)
509509

510+
def apps_run(self, args):
511+
"""
512+
Run a command inside an ephemeral app container
513+
514+
Usage: deis apps:run <command>...
515+
"""
516+
app = self._session.app
517+
body = {'command': ' '.join(sys.argv[2:])}
518+
response = self._dispatch('post',
519+
"/api/apps/{}/run".format(app),
520+
json.dumps(body))
521+
if response.status_code == requests.codes.ok: # @UndefinedVariable
522+
output, rc = json.loads(response.content)
523+
if rc != 0:
524+
print('Warning: non-zero return code {}'.format(rc))
525+
sys.stdout.write(output)
526+
sys.stdout.flush()
527+
else:
528+
raise ResponseError(response)
529+
510530
def auth_register(self, args):
511531
"""
512532
Register a new user with a Deis controller
@@ -1632,6 +1652,7 @@ def parse_args(cmd):
16321652
'calculate': 'apps:calculate',
16331653
'ssh': 'nodes:ssh',
16341654
'logs': 'apps:logs',
1655+
'run': 'apps:run',
16351656
}
16361657
if cmd == 'help':
16371658
cmd = sys.argv[-1]
@@ -1670,13 +1691,13 @@ def main():
16701691
print(trim(getattr(cli, cmd).__doc__))
16711692
return
16721693
docopt(__doc__, argv=['--help'])
1673-
# re-parse docopt with the relevant docstring
16741694
# unless cmd needs to use sys.argv directly
1675-
# if cmd not in ('formations_run', 'ssh'):
1676-
if hasattr(cli, cmd):
1695+
if cmd not in ('apps_run',):
1696+
# re-parse docopt with the relevant docstring
16771697
docstring = trim(getattr(cli, cmd).__doc__)
16781698
if 'Usage: ' in docstring:
16791699
args.update(docopt(docstring))
1700+
if hasattr(cli, cmd):
16801701
method = getattr(cli, cmd)
16811702
else:
16821703
raise DocoptExit('Found no matching command, try `deis help`')

cm/chef.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def converge_node(node):
138138

139139

140140
def run_node(node, command):
141-
ssh = connect_ssh(node.layer.ssh_username,
142-
node.fqdn, 22,
143-
node.layer.ssh_private_key)
141+
ssh = connect_ssh(node['ssh_username'],
142+
node['fqdn'], node['ssh_port'],
143+
node['ssh_private_key'])
144144
output, rc = exec_ssh(ssh, command, pty=True)
145145
return output, rc
146146

deis/tasks.py

Whitespace-only changes.

0 commit comments

Comments
 (0)