summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJonathan Bauer2018-04-19 13:18:26 +0200
committerJonathan Bauer2018-04-19 13:18:26 +0200
commitb2a22b23561c33559eea533f696b1b355aab93fa (patch)
tree3fdb186da91ba21af65d0a48abb71d3d3484b6d9 /core
parent[vbox-src] support SHARE_REMAP_MODE (diff)
downloadmltk-b2a22b23561c33559eea533f696b1b355aab93fa.tar.gz
mltk-b2a22b23561c33559eea533f696b1b355aab93fa.tar.xz
mltk-b2a22b23561c33559eea533f696b1b355aab93fa.zip
[vbox-src] finalize xml: split into functions
Diffstat (limited to 'core')
-rwxr-xr-xcore/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc91
1 files changed, 61 insertions, 30 deletions
diff --git a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc
index 9eab913a..d0e4f75f 100755
--- a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc
+++ b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/finalize_machine_config.inc
@@ -1,11 +1,8 @@
################################################################################
# Include: write final machine configuration file #
################################################################################
-finalize_machine_config() {
-
- # set the generated machine uuid
- set_attr "/VirtualBox/Machine" "uuid" "{${MACHINE_UUID}}"
+setup_disk_image() {
# set read-only image path and uuid
set_attr \
"/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk" \
@@ -14,10 +11,8 @@ finalize_machine_config() {
"/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk" \
"uuid" "{${HDD_UUID}}"
- # set snapshot dir
- set_attr "/VirtualBox/Machine" "snapshotFolder" "${VBOX_SNAPSHOT_DIR}"
- # Add a HardDisk node for the snapshot
+ # add a HardDisk node for the snapshot
add_node \
"/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk" "HardDisk" \
"uuid={${SNAPSHOT_UUID}}" \
@@ -25,12 +20,19 @@ finalize_machine_config() {
"format=VDI" \
"type=Normal"
- # set snapshot uuid to the storage controller
+ # set snapshot dir
+ set_attr "/VirtualBox/Machine" "snapshotFolder" "${VBOX_SNAPSHOT_DIR}"
+
+ # set snapshot uuid
+ # there should only be exactly one <AttachedDevice> node from the xml
+ # retrieved from the server
+
set_attr \
"/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice/Image" \
"uuid" "{${SNAPSHOT_UUID}}"
+}
-
+setup_floppies() {
# add storage controller and 2 floppies to it
add_node \
"/VirtualBox/Machine/StorageControllers" "StorageController" \
@@ -55,27 +57,31 @@ finalize_machine_config() {
add_node \
'/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice[@device="1"]' "Image" \
"uuid={${SLX_FLOPPY_UUID}}"
+}
+setup_shared_folders() {
+ # TODO common share through shared folders?
+ if isempty SHARED_FOLDERS HOME_SHARE_NAME HOME_SHARE_PATH; then
+ writelog "Missing information to setup shared folders."
+ return 1
+ fi
+ add_node \
+ "/VirtualBox/Machine/Hardware/SharedFolders" "SharedFolder" \
+ "name=${HOME_SHARE_NAME}" \
+ "hostPath=${HOME_SHARE_PATH}" \
+ "writable=true" \
+ "autoMount=true"
+}
- setup_shared_folders() {
- # TODO common share through shared folders?
- if isempty SHARED_FOLDERS HOME_SHARE_NAME HOME_SHARE_PATH; then
- writelog "Missing information to setup shared folders."
- return 1
- fi
- add_node \
- "/VirtualBox/Machine/Hardware/SharedFolders" "SharedFolder" \
- "name=${HOME_SHARE_NAME}" \
- "hostPath=${HOME_SHARE_PATH}" \
- "writable=true" \
- "autoMount=true"
- }
- notempty VBOX_SHARED_FOLDERS && setup_shared_folders
-
+setup_ethernet() {
# remove ':' from MAC address and set it to the main network adapter
VM_MAC_ADDR="$(sed 's/://g' <<< ${VM_MAC_ADDR})"
set_attr "/VirtualBox/Machine/Hardware/Network/Adapter" "MACAddress" "${VM_MAC_ADDR}"
+ # TODO bridge other nics
+}
+
+setup_cpu_ram() {
# set vm's memory
set_attr "/VirtualBox/Machine/Hardware/Memory" "RAMSize" "${VM_MEM}"
@@ -106,19 +112,44 @@ finalize_machine_config() {
local PSE_SUPPORT="false"
detect_cpu_flag "pse" && PSE_SUPPORT="true"
set_attr "/VirtualBox/Machine/Hardware/CPU/HardwareVirtExLargePages" "enabled" "${PSE_SUPPORT}"
+}
- # EXPERIMENTAL: check for USB 3 support
+setup_usb() {
+ ## Currently not used
+ # EXPERIMENTAL: check for USB 3 support and activate it
local XHCI_OK="$(lsusb -t | grep xhci)"
if [ -n "$XHCI_OK" ]; then
- del_node "/VirtualBox/Machine/Hardware/USB"
- add_node "/VirtualBox/Machine/Hardware/USB/Controllers" "Controller" "name=xHCI" "type=XHCI"
+ # Afaik, there is no way to configure more than one USB controller
+ # through the GUI, but it is technically possible through xml editing.
+ # To avoid potential problems, we only add a xHCI controller
+ # and delete the others, just as the GUI would configure it.
+ if node_exists "/VirtualBox/Machine/Hardware/USB"; then
+ del_node "/VirtualBox/Machine/Hardware/USB"
+ add_node "/VirtualBox/Machine/Hardware/USB/Controllers" "Controller" "name=xHCI" "type=XHCI"
+ fi
fi
+}
- # EXPERIMENTAL: ALSA-driven sound is buggy as of vbox 5.2.8
- # we still force alsa as we only have this driver in the current minilinux
+setup_sound() {
+ # force ALSA driver for now and change when others become available
set_attr "/VirtualBox/Machine/Hardware/AudioAdapter" "driver" "ALSA"
+}
- cp $TMPCONFIG $VBOX_MACHINE_CONFIG
+finalize_machine_config() {
+
+ # set the generated machine uuid
+ set_attr "/VirtualBox/Machine" "uuid" "{${MACHINE_UUID}}"
+
+ setup_disk_image
+ setup_floppies
+ setup_ethernet
+ setup_cpu_ram
+ setup_sound
+ notempty VBOX_SHARED_FOLDERS && setup_shared_folders
+
+ if ! cp -p "$TMPCONFIG" "$VBOX_MACHINE_CONFIG"; then
+ writelog "Could not copy '$TMPCONFIG' to '$VBOX_MACHINE_CONFIG'!"
+ fi
}
call_post_source finalize_machine_config