mirror of https://github.com/containers/podman.git
Merge pull request #14469 from shanesmith/prevent-simultaneous-machine-starts
Prevent simultaneous machine starts
This commit is contained in:
commit
f808907d85
|
@ -48,6 +48,7 @@ type ListReporter struct {
|
||||||
Default bool
|
Default bool
|
||||||
Created string
|
Created string
|
||||||
Running bool
|
Running bool
|
||||||
|
Starting bool
|
||||||
LastUp string
|
LastUp string
|
||||||
Stream string
|
Stream string
|
||||||
VMType string
|
VMType string
|
||||||
|
@ -224,10 +225,14 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*ListReporter, error) {
|
||||||
} else {
|
} else {
|
||||||
response.Name = vm.Name
|
response.Name = vm.Name
|
||||||
}
|
}
|
||||||
if vm.Running {
|
switch {
|
||||||
|
case vm.Running:
|
||||||
response.LastUp = "Currently running"
|
response.LastUp = "Currently running"
|
||||||
response.Running = true
|
response.Running = true
|
||||||
} else {
|
case vm.Starting:
|
||||||
|
response.LastUp = "Currently starting"
|
||||||
|
response.Starting = true
|
||||||
|
default:
|
||||||
response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago"
|
response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago"
|
||||||
}
|
}
|
||||||
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
|
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
|
||||||
|
|
|
@ -56,7 +56,7 @@ func start(_ *cobra.Command, args []string) error {
|
||||||
if vmName == activeName {
|
if vmName == activeName {
|
||||||
return errors.Wrapf(machine.ErrVMAlreadyRunning, "cannot start VM %s", vmName)
|
return errors.Wrapf(machine.ErrVMAlreadyRunning, "cannot start VM %s", vmName)
|
||||||
}
|
}
|
||||||
return errors.Wrapf(machine.ErrMultipleActiveVM, "cannot start VM %s. VM %s is currently running", vmName, activeName)
|
return errors.Wrapf(machine.ErrMultipleActiveVM, "cannot start VM %s. VM %s is currently running or starting", vmName, activeName)
|
||||||
}
|
}
|
||||||
fmt.Printf("Starting machine %q\n", vmName)
|
fmt.Printf("Starting machine %q\n", vmName)
|
||||||
if err := vm.Start(vmName, machine.StartOptions{}); err != nil {
|
if err := vm.Start(vmName, machine.StartOptions{}); err != nil {
|
||||||
|
|
|
@ -42,7 +42,9 @@ const (
|
||||||
// Running indicates the qemu vm is running.
|
// Running indicates the qemu vm is running.
|
||||||
Running Status = "running"
|
Running Status = "running"
|
||||||
// Stopped indicates the vm has stopped.
|
// Stopped indicates the vm has stopped.
|
||||||
Stopped Status = "stopped"
|
Stopped Status = "stopped"
|
||||||
|
// Starting indicated the vm is in the process of starting
|
||||||
|
Starting Status = "starting"
|
||||||
DefaultMachineName string = "podman-machine-default"
|
DefaultMachineName string = "podman-machine-default"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ var (
|
||||||
DefaultIgnitionUserName = "core"
|
DefaultIgnitionUserName = "core"
|
||||||
ErrNoSuchVM = errors.New("VM does not exist")
|
ErrNoSuchVM = errors.New("VM does not exist")
|
||||||
ErrVMAlreadyExists = errors.New("VM already exists")
|
ErrVMAlreadyExists = errors.New("VM already exists")
|
||||||
ErrVMAlreadyRunning = errors.New("VM already running")
|
ErrVMAlreadyRunning = errors.New("VM already running or starting")
|
||||||
ErrMultipleActiveVM = errors.New("only one VM can be active at a time")
|
ErrMultipleActiveVM = errors.New("only one VM can be active at a time")
|
||||||
ForwarderBinaryName = "gvproxy"
|
ForwarderBinaryName = "gvproxy"
|
||||||
)
|
)
|
||||||
|
@ -88,6 +90,7 @@ type ListResponse struct {
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
LastUp time.Time
|
LastUp time.Time
|
||||||
Running bool
|
Running bool
|
||||||
|
Starting bool
|
||||||
Stream string
|
Stream string
|
||||||
VMType string
|
VMType string
|
||||||
CPUs uint64
|
CPUs uint64
|
||||||
|
|
|
@ -910,7 +910,7 @@ func (v *MachineVM) State(bypass bool) (machine.Status, error) {
|
||||||
}
|
}
|
||||||
// Check if we can dial it
|
// Check if we can dial it
|
||||||
if v.Starting && !bypass {
|
if v.Starting && !bypass {
|
||||||
return "", nil
|
return machine.Starting, nil
|
||||||
}
|
}
|
||||||
monitor, err := qmp.NewSocketMonitor(v.QMPMonitor.Network, v.QMPMonitor.Address.GetPath(), v.QMPMonitor.Timeout)
|
monitor, err := qmp.NewSocketMonitor(v.QMPMonitor.Network, v.QMPMonitor.Address.GetPath(), v.QMPMonitor.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1081,8 +1081,11 @@ func getVMInfos() ([]*machine.ListResponse, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if state == machine.Running {
|
switch state {
|
||||||
|
case machine.Running:
|
||||||
listEntry.Running = true
|
listEntry.Running = true
|
||||||
|
case machine.Starting:
|
||||||
|
listEntry.Starting = true
|
||||||
}
|
}
|
||||||
|
|
||||||
listed = append(listed, listEntry)
|
listed = append(listed, listEntry)
|
||||||
|
@ -1115,7 +1118,7 @@ func (p *Provider) CheckExclusiveActiveVM() (bool, string, error) {
|
||||||
return false, "", errors.Wrap(err, "error checking VM active")
|
return false, "", errors.Wrap(err, "error checking VM active")
|
||||||
}
|
}
|
||||||
for _, vm := range vms {
|
for _, vm := range vms {
|
||||||
if vm.Running {
|
if vm.Running || vm.Starting {
|
||||||
return true, vm.Name, nil
|
return true, vm.Name, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1312,6 +1312,7 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
|
||||||
listEntry.RemoteUsername = vm.RemoteUsername
|
listEntry.RemoteUsername = vm.RemoteUsername
|
||||||
listEntry.Port = vm.Port
|
listEntry.Port = vm.Port
|
||||||
listEntry.IdentityPath = vm.IdentityPath
|
listEntry.IdentityPath = vm.IdentityPath
|
||||||
|
listEntry.Starting = false
|
||||||
|
|
||||||
running := vm.isRunning()
|
running := vm.isRunning()
|
||||||
listEntry.CreatedAt, listEntry.LastUp, _ = vm.updateTimeStamps(running)
|
listEntry.CreatedAt, listEntry.LastUp, _ = vm.updateTimeStamps(running)
|
||||||
|
|
Loading…
Reference in New Issue