mirror of
https://github.com/containers/podman.git
synced 2025-07-02 08:47:43 +08:00
pkg/machine/vmconfigs: simplify IsFirstBoot
This is faster and, to my best knowledge, is equivalent to the old code. Remove the error return (as we don't guarantee stable API here), and simplify callers. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@ -216,11 +216,6 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
|
|||||||
|
|
||||||
cmd.Args = append(cmd.Args, endpointArgs...)
|
cmd.Args = append(cmd.Args, endpointArgs...)
|
||||||
|
|
||||||
firstBoot, err := mc.IsFirstBoot()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if logrus.IsLevelEnabled(logrus.DebugLevel) {
|
if logrus.IsLevelEnabled(logrus.DebugLevel) {
|
||||||
debugDevArgs, err := GetDebugDevicesCMDArgs()
|
debugDevArgs, err := GetDebugDevicesCMDArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -230,7 +225,7 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
|
|||||||
cmd.Args = append(cmd.Args, "--gui") // add command line switch to pop the gui open
|
cmd.Args = append(cmd.Args, "--gui") // add command line switch to pop the gui open
|
||||||
}
|
}
|
||||||
|
|
||||||
if firstBoot {
|
if mc.IsFirstBoot() {
|
||||||
// If this is the first boot of the vm, we need to add the vsock
|
// If this is the first boot of the vm, we need to add the vsock
|
||||||
// device to vfkit so we can inject the ignition file
|
// device to vfkit so we can inject the ignition file
|
||||||
socketName := fmt.Sprintf("%s-%s", mc.Name, ignitionSocketName)
|
socketName := fmt.Sprintf("%s-%s", mc.Name, ignitionSocketName)
|
||||||
|
@ -182,12 +182,7 @@ func (h HyperVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func(
|
|||||||
defer callbackFuncs.CleanIfErr(&err)
|
defer callbackFuncs.CleanIfErr(&err)
|
||||||
go callbackFuncs.CleanOnSignal()
|
go callbackFuncs.CleanOnSignal()
|
||||||
|
|
||||||
firstBoot, err := mc.IsFirstBoot()
|
if mc.IsFirstBoot() {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if firstBoot {
|
|
||||||
// Add ignition entries to windows registry
|
// Add ignition entries to windows registry
|
||||||
// for first boot only
|
// for first boot only
|
||||||
if err := readAndSplitIgnition(mc, vm); err != nil {
|
if err := readAndSplitIgnition(mc, vm); err != nil {
|
||||||
|
@ -578,11 +578,7 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirstBoot, err := mc.IsFirstBoot()
|
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && mc.IsFirstBoot() {
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if mp.VMType() == machineDefine.WSLVirt && mc.Ansible != nil && isFirstBoot {
|
|
||||||
if err := machine.CommonSSHSilent(mc.Ansible.User, mc.SSH.IdentityPath, mc.Name, mc.SSH.Port, []string{"ansible-playbook", mc.Ansible.PlaybookPath}); err != nil {
|
if err := machine.CommonSSHSilent(mc.Ansible.User, mc.SSH.IdentityPath, mc.Name, mc.SSH.Port, []string{"ansible-playbook", mc.Ansible.PlaybookPath}); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -303,12 +303,8 @@ func (mc *MachineConfig) LogFile() (*define.VMFile, error) {
|
|||||||
return rtDir.AppendToNewVMFile(mc.Name+".log", nil)
|
return rtDir.AppendToNewVMFile(mc.Name+".log", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MachineConfig) IsFirstBoot() (bool, error) {
|
func (mc *MachineConfig) IsFirstBoot() bool {
|
||||||
never, err := time.Parse(time.RFC3339, "0001-01-01T00:00:00Z")
|
return mc.LastUp.IsZero()
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return mc.LastUp == never, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {
|
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {
|
||||||
|
Reference in New Issue
Block a user