Move some logic of setRootful to a common file

Moves most of the logic of `setRootful` to the common file
`pkg/machine/machine_common.go`.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
Jake Correnti
2023-08-01 19:49:26 -04:00
parent 98cf8462ad
commit 597ccff0bc
4 changed files with 24 additions and 39 deletions

View File

@ -692,22 +692,10 @@ func (m *HyperVMachine) writeConfig() error {
}
func (m *HyperVMachine) setRootful(rootful bool) error {
changeCon, err := machine.AnyConnectionDefault(m.Name, m.Name+"-root")
if err != nil {
if err := machine.SetRootful(rootful, m.Name, m.Name+"-root"); err != nil {
return err
}
if changeCon {
newDefault := m.Name
if rootful {
newDefault += "-root"
}
err := machine.ChangeDefault(newDefault)
if err != nil {
return err
}
}
m.HostUser.Modified = true
return nil
}

View File

@ -122,3 +122,24 @@ func WaitAPIAndPrintInfo(forwardState APIForwardingState, name, helper, forwardS
}
}
}
// SetRootful modifies the machine's default connection to be either rootful or
// rootless
func SetRootful(rootful bool, name, rootfulName string) error {
changeCon, err := AnyConnectionDefault(name, rootfulName)
if err != nil {
return err
}
if changeCon {
newDefault := name
if rootful {
newDefault += "-root"
}
err := ChangeDefault(newDefault)
if err != nil {
return err
}
}
return nil
}

View File

@ -1607,22 +1607,10 @@ func (v *MachineVM) resizeDisk(diskSize uint64, oldSize uint64) error {
}
func (v *MachineVM) setRootful(rootful bool) error {
changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root")
if err != nil {
if err := machine.SetRootful(rootful, v.Name, v.Name+"-root"); err != nil {
return err
}
if changeCon {
newDefault := v.Name
if rootful {
newDefault += "-root"
}
err := machine.ChangeDefault(newDefault)
if err != nil {
return err
}
}
v.HostUser.Modified = true
return nil
}

View File

@ -1525,22 +1525,10 @@ func getMem(vm *MachineVM) (uint64, error) {
}
func (v *MachineVM) setRootful(rootful bool) error {
changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root")
if err != nil {
if err := machine.SetRootful(rootful, v.Name, v.Name+"-root"); err != nil {
return err
}
if changeCon {
newDefault := v.Name
if rootful {
newDefault += "-root"
}
err := machine.ChangeDefault(newDefault)
if err != nil {
return err
}
}
dist := toDist(v.Name)
return v.setupPodmanDockerSock(dist, rootful)
}