Skip to content

Commit

Permalink
Move ssh config generation to new function
Browse files Browse the repository at this point in the history
Prepare for moving into a more central place.

[NO NEW TESTS NEEDED]

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Dec 30, 2021
1 parent 911a03c commit fb469cd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/machine/qemu/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,24 +647,29 @@ func (v *MachineVM) SSH(name string, opts machine.SSHOptions) error {
return cmd.Run()
}

// SSHocker does a reverse sshfs mount over a SSH connection.
func (v *MachineVM) SSHocker(name string, source, target string, readonly bool) error {
volumeDefinition := source + ":" + target
if readonly {
volumeDefinition += ":ro"
}

func (v *MachineVM) sshConfig() string {
config := fmt.Sprintf("Host %s\n", v.Name)
config += fmt.Sprintf(" IdentityFile %s\n", v.IdentityPath)
config += fmt.Sprintf(" User %s\n", v.RemoteUsername)
config += fmt.Sprintf(" Hostname %s\n", "localhost")
config += fmt.Sprintf(" Port %d\n", v.Port)
config += fmt.Sprintf(" UserKnownHostsFile %s\n", "/dev/null")
config += fmt.Sprintf(" StrictHostKeyChecking %s\n", "no")
return config
}

// SSHocker does a reverse sshfs mount over a SSH connection.
func (v *MachineVM) SSHocker(name string, source, target string, readonly bool) error {
volumeDefinition := source + ":" + target
if readonly {
volumeDefinition += ":ro"
}

vmConfigDir, err := machine.GetConfDir(vmtype)
if err != nil {
return err
}
config := v.sshConfig()
sshConfigFile := filepath.Join(vmConfigDir, v.Name+".config")
err = ioutil.WriteFile(sshConfigFile, []byte(config), 0666)
if err != nil {
Expand Down

0 comments on commit fb469cd

Please sign in to comment.