diff options
Diffstat (limited to 'pkg/machine')
-rw-r--r-- | pkg/machine/config.go | 3 | ||||
-rw-r--r-- | pkg/machine/ignition.go | 14 | ||||
-rw-r--r-- | pkg/machine/qemu/machine.go | 30 |
3 files changed, 39 insertions, 8 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 554ea7c97..32b3b5c2b 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -56,8 +56,7 @@ type ListResponse struct { } type SSHOptions struct { - Execute bool - Args []string + Args []string } type StartOptions struct{} diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go index a68d68ac3..cc5c01de6 100644 --- a/pkg/machine/ignition.go +++ b/pkg/machine/ignition.go @@ -55,10 +55,16 @@ func NewIgnitionFile(ign DynamicIgnition) error { } ignPassword := Passwd{ - Users: []PasswdUser{{ - Name: ign.Name, - SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)}, - }}, + Users: []PasswdUser{ + { + Name: ign.Name, + SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)}, + }, + { + Name: "root", + SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)}, + }, + }, } ignStorage := Storage{ diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index b48926524..fd22f465b 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -168,6 +168,11 @@ func (v *MachineVM) Init(opts machine.InitOptions) error { if err := machine.AddConnection(&uri, v.Name, filepath.Join(sshDir, v.Name), opts.IsDefault); err != nil { return err } + + uriRoot := machine.SSHRemoteConnection.MakeSSHURL("localhost", "/run/podman/podman.sock", strconv.Itoa(v.Port), "root") + if err := machine.AddConnection(&uriRoot, v.Name+"-root", filepath.Join(sshDir, v.Name), opts.IsDefault); err != nil { + return err + } } else { fmt.Println("An ignition path was provided. No SSH connection was added to Podman") } @@ -357,6 +362,10 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun if err := machine.RemoveConnection(v.Name); err != nil { logrus.Error(err) } + if err := machine.RemoveConnection(v.Name + "-root"); err != nil { + logrus.Error(err) + } + vmConfigDir, err := machine.GetConfDir(vmtype) if err != nil { return "", nil, err @@ -400,7 +409,7 @@ func (v *MachineVM) SSH(name string, opts machine.SSHOptions) error { port := strconv.Itoa(v.Port) args := []string{"-i", v.IdentityPath, "-p", port, sshDestination} - if opts.Execute { + if len(opts.Args) > 0 { args = append(args, opts.Args...) } else { fmt.Printf("Connecting to vm %s. To close connection, use `~.` or `exit`\n", v.Name) @@ -446,7 +455,11 @@ func getDiskSize(path string) (uint64, error) { } // List lists all vm's that use qemu virtualization -func List(opts machine.ListOptions) ([]*machine.ListResponse, error) { +func List(_ machine.ListOptions) ([]*machine.ListResponse, error) { + return GetVMInfos() +} + +func GetVMInfos() ([]*machine.ListResponse, error) { vmConfigDir, err := machine.GetConfDir(vmtype) if err != nil { return nil, err @@ -493,3 +506,16 @@ func List(opts machine.ListOptions) ([]*machine.ListResponse, error) { } return listed, err } + +func IsValidVMName(name string) (bool, error) { + infos, err := GetVMInfos() + if err != nil { + return false, err + } + for _, vm := range infos { + if vm.Name == name { + return true, nil + } + } + return false, nil +} |