Set balloon on startup.
This commit is contained in:
parent
15e83c082e
commit
3587e91150
2 changed files with 18 additions and 3 deletions
|
|
@ -68,7 +68,9 @@ public class QemuMonitor extends Component {
|
|||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
private final Map<String, String> monitorMessages = new HashMap<>(Map.of(
|
||||
"connect", "{ \"execute\": \"qmp_capabilities\" }",
|
||||
"powerdown", "{ \"execute\": \"system_powerdown\" }"));
|
||||
"powerdown", "{ \"execute\": \"system_powerdown\" }",
|
||||
"setBalloon", "{ \"execute\": \"balloon\", \"arguments\": "
|
||||
+ "{ \"value\": %d } }"));
|
||||
|
||||
private Path socketPath;
|
||||
private int powerdownTimeout;
|
||||
|
|
@ -185,6 +187,16 @@ public class QemuMonitor extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current ram.
|
||||
*
|
||||
* @param amount the new current ram
|
||||
*/
|
||||
public void setCurrentRam(Number amount) {
|
||||
writeToMonitor(
|
||||
String.format(monitorMessages.get("setBalloon"), amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle data from qemu monitor connection.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ import org.jgrapes.util.events.WatchFile;
|
|||
* qemu --> monitor : FileChanged[monitor socket created]
|
||||
*
|
||||
* monitor: entry/fire OpenSocketConnection
|
||||
* monitor --> success: ClientConnected[for monitor]
|
||||
* monitor --> success: ClientConnected[for monitor]/set balloon value
|
||||
* monitor -> error: ConnectError[for monitor]
|
||||
* }
|
||||
*
|
||||
|
|
@ -129,7 +129,7 @@ import org.jgrapes.util.events.WatchFile;
|
|||
*
|
||||
* qemuPowerdown: entry/suspend Stop, send powerdown to qemu, start timer
|
||||
*
|
||||
* qemuPowerdown --> terminateProcesses: Closed[for monitor]/resume Stop
|
||||
* qemuPowerdown --> terminateProcesses: Closed[for monitor]/resume Stop,\ncancel Timer
|
||||
* qemuPowerdown --> terminateProcesses: Timeout/resume Stop
|
||||
* terminateProcesses --> terminated
|
||||
* }
|
||||
|
|
@ -445,6 +445,9 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onQemuMonitorOpened(QemuMonitorOpened event) {
|
||||
Optional.ofNullable(config.vm.currentRam)
|
||||
.map(Configuration::parseMemory)
|
||||
.ifPresent(qemuMonitor::setCurrentRam);
|
||||
state.set(State.RUNNING);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue