Add support for CDROM drives.
This commit is contained in:
parent
cc7037be0b
commit
a28ccfc8e0
5 changed files with 32 additions and 9 deletions
|
|
@ -431,13 +431,13 @@ spec:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
type: object
|
type: object
|
||||||
cdromImage:
|
cdrom:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
path:
|
image:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- path
|
- image
|
||||||
bootindex:
|
bootindex:
|
||||||
type: integer
|
type: integer
|
||||||
oneOf:
|
oneOf:
|
||||||
|
|
@ -446,9 +446,9 @@ spec:
|
||||||
required:
|
required:
|
||||||
- volumeClaimTemplate
|
- volumeClaimTemplate
|
||||||
- properties:
|
- properties:
|
||||||
cdromImage:
|
cdrom:
|
||||||
required:
|
required:
|
||||||
- cdromImage
|
- cdrom
|
||||||
default: []
|
default: []
|
||||||
display:
|
display:
|
||||||
type: object
|
type: object
|
||||||
|
|
|
||||||
|
|
@ -151,9 +151,9 @@ data:
|
||||||
</#if>
|
</#if>
|
||||||
<#assign drvCounter = drvCounter + 1/>
|
<#assign drvCounter = drvCounter + 1/>
|
||||||
</#if>
|
</#if>
|
||||||
<#if disk.cdromImage??>
|
<#if disk.cdrom??>
|
||||||
- type: ide-cd
|
- type: ide-cd
|
||||||
file: "${ disk.cdromImage.path.asString }"
|
file: "${ disk.cdrom.image.asString }"
|
||||||
<#if disk.bootindex??>
|
<#if disk.bootindex??>
|
||||||
bootindex: ${ disk.bootindex.asInt?c }
|
bootindex: ${ disk.bootindex.asInt?c }
|
||||||
</#if>
|
</#if>
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ spec:
|
||||||
- name: vm-data
|
- name: vm-data
|
||||||
mountPath: /var/local/vm-data
|
mountPath: /var/local/vm-data
|
||||||
- name: vmop-image-repository
|
- name: vmop-image-repository
|
||||||
mountPath: /var/local/vmop-image-repository
|
mountPath: ${ constants.IMAGE_REPO_PATH }
|
||||||
volumeDevices:
|
volumeDevices:
|
||||||
<#assign diskCounter = 0/>
|
<#assign diskCounter = 0/>
|
||||||
<#list cr.spec.vm.disks.asList() as disk>
|
<#list cr.spec.vm.disks.asList() as disk>
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,7 @@ public class Constants {
|
||||||
/** The Constant STATE_STOPPED. */
|
/** The Constant STATE_STOPPED. */
|
||||||
public static final String STATE_STOPPED = "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";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package org.jdrupes.vmoperator.manager;
|
package org.jdrupes.vmoperator.manager;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import freemarker.core.ParseException;
|
import freemarker.core.ParseException;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.DefaultObjectWrapperBuilder;
|
import freemarker.template.DefaultObjectWrapperBuilder;
|
||||||
|
|
@ -108,7 +110,7 @@ public class Reconciler extends Component {
|
||||||
|
|
||||||
// Prepare Freemarker model
|
// Prepare Freemarker model
|
||||||
model = new HashMap<>();
|
model = new HashMap<>();
|
||||||
model.put("cr", vmDef.getRaw());
|
model.put("cr", patchCr(vmDef.getRaw().deepCopy()));
|
||||||
model.put("constants",
|
model.put("constants",
|
||||||
(TemplateHashModel) new DefaultObjectWrapperBuilder(
|
(TemplateHashModel) new DefaultObjectWrapperBuilder(
|
||||||
Configuration.VERSION_2_3_32)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue