summaryrefslogtreecommitdiff
path: root/pkg/machine
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2021-03-22 13:23:22 -0400
committerbaude <bbaude@redhat.com>2021-03-25 08:46:43 -0500
commite7661137373b5f87bf6ec45e32326821b172ce7b (patch)
tree34910aceb3e4188f4e66a128eba502e12e659308 /pkg/machine
parentb5f54a9b23e8d9418700494da9aa78d8db354c43 (diff)
downloadpodman-e7661137373b5f87bf6ec45e32326821b172ce7b.tar.gz
podman-e7661137373b5f87bf6ec45e32326821b172ce7b.tar.bz2
podman-e7661137373b5f87bf6ec45e32326821b172ce7b.zip
Add --execute flag to podman machine ssh
--execute, -e allows to execute a command through ssh Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'pkg/machine')
-rw-r--r--pkg/machine/config.go5
-rw-r--r--pkg/machine/qemu/machine.go9
2 files changed, 11 insertions, 3 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 5e90dae51..2a70b8ff7 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -42,7 +42,10 @@ type Download struct {
VMName string
}
-type SSHOptions struct{}
+type SSHOptions struct {
+ Execute bool
+ Args []string
+}
type StartOptions struct{}
type StopOptions struct{}
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 92a16dda7..30d96ce08 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -293,9 +293,14 @@ func (v *MachineVM) SSH(name string, opts machine.SSHOptions) error {
sshDestination := v.RemoteUsername + "@localhost"
port := strconv.Itoa(v.Port)
- fmt.Printf("Connecting to vm %s. To close connection, use `~.` or `exit`\n", v.Name)
+ args := []string{"-i", v.IdentityPath, "-p", port, sshDestination}
+ if opts.Execute {
+ args = append(args, opts.Args...)
+ } else {
+ fmt.Printf("Connecting to vm %s. To close connection, use `~.` or `exit`\n", v.Name)
+ }
- cmd := exec.Command("ssh", "-i", v.IdentityPath, "-p", port, sshDestination)
+ cmd := exec.Command("ssh", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin