Add support for CDROM drives.

This commit is contained in:
Michael Lipp 2023-08-07 17:26:16 +02:00
parent cc7037be0b
commit a28ccfc8e0
5 changed files with 32 additions and 9 deletions

View file

@ -431,13 +431,13 @@ spec:
type: string
type: object
type: object
cdromImage:
cdrom:
type: object
properties:
path:
image:
type: string
required:
- path
- image
bootindex:
type: integer
oneOf:
@ -446,9 +446,9 @@ spec:
required:
- volumeClaimTemplate
- properties:
cdromImage:
cdrom:
required:
- cdromImage
- cdrom
default: []
display:
type: object

View file

@ -151,9 +151,9 @@ data:
</#if>
<#assign drvCounter = drvCounter + 1/>
</#if>
<#if disk.cdromImage??>
<#if disk.cdrom??>
- type: ide-cd
file: "${ disk.cdromImage.path.asString }"
file: "${ disk.cdrom.image.asString }"
<#if disk.bootindex??>
bootindex: ${ disk.bootindex.asInt?c }
</#if>

View file

@ -32,7 +32,7 @@ spec:
- name: vm-data
mountPath: /var/local/vm-data
- name: vmop-image-repository
mountPath: /var/local/vmop-image-repository
mountPath: ${ constants.IMAGE_REPO_PATH }
volumeDevices:
<#assign diskCounter = 0/>
<#list cr.spec.vm.disks.asList() as disk>

View file

@ -41,4 +41,7 @@ public class Constants {
/** The Constant STATE_STOPPED. */
public static final String STATE_STOPPED = "Stopped";
/** The Constant IMAGE_REPO_PATH. */
public static final String IMAGE_REPO_PATH
= "/var/local/vmop-image-repository";
}

View file

@ -18,6 +18,8 @@
package org.jdrupes.vmoperator.manager;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import freemarker.core.ParseException;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapperBuilder;
@ -108,7 +110,7 @@ public class Reconciler extends Component {
// Prepare Freemarker model
model = new HashMap<>();
model.put("cr", vmDef.getRaw());
model.put("cr", patchCr(vmDef.getRaw().deepCopy()));
model.put("constants",
(TemplateHashModel) new DefaultObjectWrapperBuilder(
Configuration.VERSION_2_3_32)
@ -130,4 +132,22 @@ public class Reconciler extends Component {
}
}
private Object patchCr(JsonObject vmDef) {
// Adjust cdromImage path
var disks
= GsonPtr.to(vmDef).to("spec", "vm", "disks").get(JsonArray.class);
for (var disk : disks) {
var cdrom = (JsonObject) ((JsonObject) disk).get("cdrom");
if (cdrom == null) {
continue;
}
String image = cdrom.get("image").getAsString();
if (!image.contains("/")) {
cdrom.addProperty("image",
Constants.IMAGE_REPO_PATH + "/" + image);
}
}
return vmDef;
}
}