Implement reset.
This commit is contained in:
parent
f20e61d57c
commit
92c9c6df9c
4 changed files with 72 additions and 1 deletions
|
|
@ -45,6 +45,12 @@
|
||||||
# property in the CRD.
|
# property in the CRD.
|
||||||
# "guestShutdownStops":
|
# "guestShutdownStops":
|
||||||
# false
|
# false
|
||||||
|
|
||||||
|
# When incremented, the VM is reset. The value has no default value,
|
||||||
|
# i.e. if you start the VM without a value for this property, and
|
||||||
|
# decide to trigger a reset later, you have to first set the value
|
||||||
|
# and then inrement it.
|
||||||
|
# "resetCounter": 1
|
||||||
|
|
||||||
# Define the VM (required)
|
# Define the VM (required)
|
||||||
"vm":
|
"vm":
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,9 @@ public class Configuration implements Dto {
|
||||||
/** If guest shutdown changes CRD .vm.state to "Stopped". */
|
/** If guest shutdown changes CRD .vm.state to "Stopped". */
|
||||||
public boolean guestShutdownStops;
|
public boolean guestShutdownStops;
|
||||||
|
|
||||||
|
/** Increments of the reset counter trigger a reset of the VM. */
|
||||||
|
public Integer resetCounter;
|
||||||
|
|
||||||
/** The vm. */
|
/** The vm. */
|
||||||
@SuppressWarnings("PMD.ShortVariable")
|
@SuppressWarnings("PMD.ShortVariable")
|
||||||
public Vm vm;
|
public Vm vm;
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ import org.apache.commons.cli.Option;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont;
|
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont;
|
||||||
|
import org.jdrupes.vmoperator.runner.qemu.commands.QmpReset;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.events.Exit;
|
import org.jdrupes.vmoperator.runner.qemu.events.Exit;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
||||||
|
|
@ -215,6 +216,7 @@ public class Runner extends Component {
|
||||||
private CommandDefinition cloudInitImgDefinition;
|
private CommandDefinition cloudInitImgDefinition;
|
||||||
private CommandDefinition qemuDefinition;
|
private CommandDefinition qemuDefinition;
|
||||||
private final QemuMonitor qemuMonitor;
|
private final QemuMonitor qemuMonitor;
|
||||||
|
private Integer resetCounter;
|
||||||
private State state = State.INITIALIZING;
|
private State state = State.INITIALIZING;
|
||||||
|
|
||||||
/** Preparatory actions for QEMU start */
|
/** Preparatory actions for QEMU start */
|
||||||
|
|
@ -615,7 +617,7 @@ public class Runner extends Component {
|
||||||
* @param event the event
|
* @param event the event
|
||||||
*/
|
*/
|
||||||
@Handler(priority = -1000)
|
@Handler(priority = -1000)
|
||||||
public void onConfigureQemu(ConfigureQemu event) {
|
public void onConfigureQemuFinal(ConfigureQemu event) {
|
||||||
if (state == State.STARTING) {
|
if (state == State.STARTING) {
|
||||||
fire(new MonitorCommand(new QmpCont()));
|
fire(new MonitorCommand(new QmpCont()));
|
||||||
state = State.RUNNING;
|
state = State.RUNNING;
|
||||||
|
|
@ -624,6 +626,23 @@ public class Runner extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On configure qemu.
|
||||||
|
*
|
||||||
|
* @param event the event
|
||||||
|
*/
|
||||||
|
@Handler
|
||||||
|
public void onConfigureQemu(ConfigureQemu event) {
|
||||||
|
if (state == State.RUNNING) {
|
||||||
|
if (resetCounter != null
|
||||||
|
&& event.configuration().resetCounter != null
|
||||||
|
&& event.configuration().resetCounter > resetCounter) {
|
||||||
|
fire(new MonitorCommand(new QmpReset()));
|
||||||
|
}
|
||||||
|
resetCounter = event.configuration().resetCounter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On process exited.
|
* On process exited.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* VM-Operator
|
||||||
|
* Copyright (C) 2023 Michael N. Lipp
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jdrupes.vmoperator.runner.qemu.commands;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link QmpCommand} that send a system_reset to the VM.
|
||||||
|
*/
|
||||||
|
public class QmpReset extends QmpCommand {
|
||||||
|
|
||||||
|
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||||
|
"PMD.VariableNamingConventions" })
|
||||||
|
private static final JsonNode jsonTemplate
|
||||||
|
= parseJson("{ \"execute\": \"system_reset\" }");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonNode toJson() {
|
||||||
|
return jsonTemplate.deepCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "QmpReset()";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue