Introduce a new singleton 'PVE.qemu.Architecture', that contains nearly all
architecture specific settings such as renderers, defaults and filters.

This provides a single place to modify architecture specific behavior,
or add new architectures the gui should handle.

Signed-off-by: Dominik Csapak <[email protected]>
---
 www/manager6/Makefile             |   1 +
 www/manager6/qemu/Architecture.js | 104 ++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+)
 create mode 100644 www/manager6/qemu/Architecture.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 8857045c..8f9c53c4 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -5,6 +5,7 @@ BIOME ?= proxmox-biome
 JSSRC=                                                         \
        Parser.js                                       \
        StateProvider.js                                \
+       qemu/Architecture.js                            \
        Utils.js                                        \
        UIOptions.js                                    \
        Toolkit.js                                      \
diff --git a/www/manager6/qemu/Architecture.js 
b/www/manager6/qemu/Architecture.js
new file mode 100644
index 00000000..21aabd26
--- /dev/null
+++ b/www/manager6/qemu/Architecture.js
@@ -0,0 +1,104 @@
+/* This file defines the helpers, defaults and limtis for various vCPU 
architectures, such
+ * as x86_64, and aarch64.
+ *
+ * To add a new architecture, add the respective entry in the 
defaults/renderers and selection.
+ */
+Ext.define('PVE.qemu.Architecture', {
+    singleton: true,
+
+    selection: [
+        ['__default__', `${Proxmox.Utils.defaultText} (${gettext('Host 
Architecture')})`],
+        ['x86_64', gettext('x86 (64-bit)')],
+        ['aarch64', gettext('ARM (64-bit)')],
+    ],
+
+    // filter for PVE.Utils.kvm_ostypes
+    kvmOSTypes: {
+        x86_64: {
+            bases: undefined, // include all
+            ostypes: undefined, // include all
+        },
+        aarch64: {
+            bases: ['Linux', 'Other'],
+            ostypes: ['l26', 'other'],
+        },
+    },
+
+    defaultProcessorModel: {
+        x86_64: 'x86-64-v2-AES',
+        aarch64: 'cortex-a57',
+    },
+
+    defaultMachines: {
+        x86_64: 'pc',
+        aarch64: 'virt',
+    },
+
+    defaultCDDrive: {
+        x86_64: ['ide', 2],
+        aarch64: ['scsi', 2],
+    },
+
+    allowedScsiHw: {
+        x86_64: [
+            '__default__',
+            'lsi',
+            'lsi53c810',
+            'megasas',
+            'virtio-scsi-pci',
+            'virtio-scsi-single',
+            'pvscsi',
+        ],
+        aarch64: ['virtio-scsi-pci', 'virtio-scsi-single'],
+    },
+
+    allowedMachines: {
+        x86_64: ['__default__', 'q35'], // __default__ is i440fx
+        aarch64: ['__default__'], // __default__ is virt
+    },
+
+    allowedBusses: {
+        x86_64: ['ide', 'sata', 'virtio', 'scsi', 'unused'],
+        aarch64: ['sata', 'virtio', 'scsi', 'unused'],
+    },
+
+    allowedFirmware: {
+        x86_64: ['__default__', 'seabios', 'ovmf'], // default is seabios
+        aarch64: ['ovmf'],
+    },
+
+    render_vcpu_architecture: function (value) {
+        switch (value ?? '') {
+            case '':
+            case 'x86_64':
+                return gettext('x86 (64-bit)');
+            case 'aarch64':
+                return gettext('ARM (64-bit)');
+            default:
+                return Proxmox.Utils.unknownText;
+        }
+    },
+
+    // returns the resulting architecture from a given arch and
+    // the nodename, in case the architecture is set to default or empty
+    getNodeArchitecture: function (architecture, nodename) {
+        if (architecture === '__default__') {
+            architecture = undefined;
+        }
+
+        let hostArchitecture = 
PVE.data.ResourceStore.getNodeById(nodename)?.data.architecture;
+
+        return architecture ?? hostArchitecture ?? 'x86_64';
+    },
+
+    // returns if the given architecture is the native host architecture of 
the given nodename
+    isHostArchitecture: function (architecture, nodename) {
+        if (architecture === '__default__') {
+            architecture = undefined;
+        }
+
+        let hostArchitecture = 
PVE.data.ResourceStore.getNodeById(nodename)?.data.architecture;
+
+        return (architecture ?? 'x86_64') === (hostArchitecture ?? 'x86_64');
+    },
+});
-- 
2.47.3




Reply via email to