Get started with vmop-agent.

This commit is contained in:
Michael Lipp 2025-02-25 15:43:47 +01:00
parent d2c39dc06a
commit 4a7a309f07
6 changed files with 95 additions and 7 deletions

View file

@ -47,6 +47,7 @@ import org.jdrupes.vmoperator.runner.qemu.events.OsinfoEvent;
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange;
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
import org.jdrupes.vmoperator.runner.qemu.events.ShutdownEvent;
import org.jdrupes.vmoperator.runner.qemu.events.VmopAgentConnected;
import org.jdrupes.vmoperator.util.GsonPtr;
import org.jgrapes.core.Channel;
import org.jgrapes.core.annotation.Handler;
@ -192,20 +193,21 @@ public class StatusUpdater extends VmDefUpdater {
status.addProperty("ram", GsonPtr.to(from.data())
.getAsString("spec", "vm", "maximumRam").orElse("0"));
status.addProperty("cpus", 1);
// In case we had an irregular shutdown
status.remove("osinfo");
} else if (event.runState() == RunState.STOPPED) {
status.addProperty("ram", "0");
status.addProperty("cpus", 0);
status.remove("osinfo");
}
// In case console connection was still present
if (!running) {
// In case console connection was still present
status.addProperty("consoleClient", "");
updateCondition(from, status, "ConsoleConnected", false,
"VmStopped", "The VM has been shut down");
"VmStopped", "The VM is not running");
// In case we had an irregular shutdown
status.remove("osinfo");
updateCondition(vmDef, vmDef.statusJson(), "VmopAgentConnected",
false, "VmStopped", "The VM is not running");
}
return status;
});
@ -322,4 +324,24 @@ public class StatusUpdater extends VmDefUpdater {
});
}
/**
* @param event the event
* @throws ApiException
*/
@Handler
@SuppressWarnings("PMD.AssignmentInOperand")
public void onVmopAgentConnected(VmopAgentConnected event)
throws ApiException {
VmDefinition vmDef;
if (vmStub == null || (vmDef = vmStub.model().orElse(null)) == null) {
return;
}
vmStub.updateStatus(from -> {
JsonObject status = from.statusJson();
updateCondition(vmDef, status, "VmopAgentConnected",
true, "VmopAgentStarted", "The VM operator agent is running");
return status;
});
}
}

View file

@ -19,6 +19,7 @@
package org.jdrupes.vmoperator.runner.qemu;
import java.io.IOException;
import org.jdrupes.vmoperator.runner.qemu.events.VmopAgentConnected;
import org.jgrapes.core.Channel;
/**
@ -42,7 +43,9 @@ public class VmopAgentClient extends AgentConnector {
@Override
protected void processInput(String line) throws IOException {
// TODO Auto-generated method stub
if (line.startsWith("220 ")) {
rep().fire(new VmopAgentConnected());
}
}
}

View file

@ -0,0 +1,27 @@
/*
* VM-Operator
* Copyright (C) 2025 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.events;
import org.jgrapes.core.Event;
/**
* Signals information about the guest OS.
*/
public class VmopAgentConnected extends Event<Void> {
}