From e7661137373b5f87bf6ec45e32326821b172ce7b Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Mon, 22 Mar 2021 13:23:22 -0400 Subject: Add --execute flag to podman machine ssh --execute, -e allows to execute a command through ssh Signed-off-by: Ashley Cui --- pkg/machine/config.go | 5 ++++- pkg/machine/qemu/machine.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'pkg') 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 -- cgit v1.2.3-54-g00ecf