diff --git a/machine/machine.py b/machine/machine.py index 76e0418..a0c56e1 100644 --- a/machine/machine.py +++ b/machine/machine.py @@ -364,3 +364,18 @@ def scp(self, source, destination, recursive=False): cmd = ["scp"] + r + [source, destination] stdout, _, _ = self._run(cmd) return stdout.split() + + def ssh(self, machine, cmd): + """ + Run a command on a machine through docker-machine ssh + + Args: + machine (str): machine name + cmd (str): command to run + + Returns: + List[str]: output of the ssh command + """ + ssh_cmd = ['ssh', machine, cmd] + stdout, _, _ = self._run(ssh_cmd) + return stdout.split() diff --git a/tests/test_commands.py b/tests/test_commands.py index 80ea1e0..08400fa 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -33,7 +33,7 @@ def tearDownClass(cls): cls.machine.rm(machine=TEMPORARY_MACHINE) except RuntimeError: pass - + def setUp(self): if not self.machine.status(machine=TEST_MACHINE): self.machine.start(machine=TEST_MACHINE) @@ -81,6 +81,10 @@ def test_scp(self): destination = "%s:." % TEST_MACHINE self.machine.scp(source, destination) + def test_ssh_echo(self): + self.assertTrue(self.machine.exists(machine=TEST_MACHINE)) + self.assertEqual(self.machine.ssh(TEST_MACHINE, 'echo \"Hi\"'), ['Hi']) + def test_start(self): self.machine.stop(machine=TEST_MACHINE) self.machine.start(machine=TEST_MACHINE)