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

@ -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
}