Merge pull request #20115 from baude/hypervstarting

hyperv: set more realistic starting state
This commit is contained in:
OpenShift Merge Robot
2023-09-24 19:24:50 -04:00
committed by GitHub
3 changed files with 21 additions and 7 deletions

View File

@ -200,12 +200,12 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*entities.ListReporter, error
response.Name = vm.Name
}
switch {
case vm.Running:
response.LastUp = "Currently running"
response.Running = true
case vm.Starting:
response.LastUp = "Currently starting"
response.Starting = true
case vm.Running:
response.LastUp = "Currently running"
response.Running = true
default:
response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago"
}

View File

@ -84,7 +84,7 @@ func (v HyperVVirtualization) List(opts machine.ListOptions) ([]*machine.ListRes
CreatedAt: mm.Created,
LastUp: mm.LastUp,
Running: vm.State() == hypervctl.Enabled,
Starting: vm.IsStarting(),
Starting: mm.isStarting(),
Stream: mm.ImageStream,
VMType: machine.HyperVVirt.String(),
CPUs: mm.CPUs,

View File

@ -479,6 +479,14 @@ func (m *HyperVMachine) Start(name string, opts machine.StartOptions) error {
if err != nil {
return fmt.Errorf("unable to start host networking: %q", err)
}
// The "starting" status from hyper v is a very small windows and not really
// the same as what we want. so modeling starting behaviour after qemu
m.Starting = true
if err := m.writeConfig(); err != nil {
return fmt.Errorf("writing JSON file: %w", err)
}
if err := vm.Start(); err != nil {
return err
}
@ -487,16 +495,18 @@ func (m *HyperVMachine) Start(name string, opts machine.StartOptions) error {
return err
}
// set starting back false now that we are running
m.Starting = false
if m.HostUser.Modified {
if machine.UpdatePodmanDockerSockService(m, name, m.UID, m.Rootful) == nil {
// Reset modification state if there are no errors, otherwise ignore errors
// which are already logged
m.HostUser.Modified = false
_ = m.writeConfig()
}
}
return nil
// Write the config with updated starting status and hostuser modification
return m.writeConfig()
}
func (m *HyperVMachine) State(_ bool) (machine.Status, error) {
@ -718,3 +728,7 @@ func (m *HyperVMachine) resizeDisk(newSize strongunits.GiB) error {
}
return nil
}
func (m *HyperVMachine) isStarting() bool {
return m.Starting
}