diff --git a/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml b/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml index a798b6e..8ecddf3 100644 --- a/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml +++ b/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml @@ -83,11 +83,14 @@ # There are no default drives. The supported types are "ide-cd" # and "raw". All types support a "bootindex" property. # Type "raw" can have a property "file" (if backed by a file on - # the host) or a property "device" (if backed by a device). + # the host) or a property "device" (if backed by a device). + # Alternatively you can use "resource", which automatically be + # interpreted as file or device as appropriate + # (see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#isRegularFile(java.nio.file.Path,java.nio.file.LinkOption...)). # "drives": # - "type": "ide-cd" # "bootindex": (undefined) - # "file": (undefined) + # "resource": (undefined) # "spice": # "port": 5900 diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java index 5b6fae8..ce7e8b3 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java @@ -132,7 +132,7 @@ class Configuration implements Dto { public String rtcClock = "rt"; public int powerdownTimeout = 900; public Network[] network = { new Network() }; - public Drive[] drives; + public Drive[] drives = new Drive[0]; public Spice spice; /** @@ -173,6 +173,7 @@ class Configuration implements Dto { public Integer bootindex; public String device; public String file; + public String resource; } /** @@ -202,9 +203,29 @@ class Configuration implements Dto { vm.maximumCpus = vm.currentCpus; } + checkDrives(); + return true; } + private void checkDrives() { + for (Drive drive : vm.drives) { + if (drive.file != null || drive.device != null) { + continue; + } + if (drive.resource == null) { + logger.severe( + () -> "Drive configuration is missing its resource."); + + } + if (Files.isRegularFile(Path.of(drive.resource))) { + drive.file = drive.resource; + } else { + drive.device = drive.resource; + } + } + } + @SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts") private boolean checkRuntimeDir() { // Runtime directory (sockets)