Browse Source

Merge pull request #6741 from naveenrajm7/qemu-args

scripting: add qemu additional arguments
pull/6904/head
osy 8 months ago
committed by GitHub
parent
commit
8a35d037bc
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      Scripting/UTM.sdef
  2. 25
      Scripting/UTMScriptingConfigImpl.swift

10
Scripting/UTM.sdef

@ -444,6 +444,11 @@
description="List of serial configuration."> description="List of serial configuration.">
<type type="qemu serial configuration" list="yes"/> <type type="qemu serial configuration" list="yes"/>
</property> </property>
<property name="qemu additional arguments" code="QeAd"
description="List of qemu arguments.">
<type type="qemu argument" list="yes"/>
</property>
</record-type> </record-type>
<enumeration name="qemu directory share mode" code="QeSm" description="Method for sharing directory in QEMU."> <enumeration name="qemu directory share mode" code="QeSm" description="Method for sharing directory in QEMU.">
@ -553,6 +558,11 @@
description="The port number to listen on when the interface is a TCP server."/> description="The port number to listen on when the interface is a TCP server."/>
</record-type> </record-type>
<record-type name="qemu argument" code="QeAr" description="QEMU argument configuration.">
<property name="argument string" code="ArSt" type="text"
description="The QEMU argument as a string."/>
</record-type>
<record-type name="apple configuration" code="ApCf" description="Apple virtual machine configuration."> <record-type name="apple configuration" code="ApCf" description="Apple virtual machine configuration.">
<property name="name" code="pnam" type="text" <property name="name" code="pnam" type="text"
description="Virtual machine name."/> description="Virtual machine name."/>

25
Scripting/UTMScriptingConfigImpl.swift

@ -107,6 +107,7 @@ extension UTMScriptingConfigImpl {
"drives": config.drives.map({ serializeQemuDriveExisting($0) }), "drives": config.drives.map({ serializeQemuDriveExisting($0) }),
"networkInterfaces": config.networks.enumerated().map({ serializeQemuNetwork($1, index: $0) }), "networkInterfaces": config.networks.enumerated().map({ serializeQemuNetwork($1, index: $0) }),
"serialPorts": config.serials.enumerated().map({ serializeQemuSerial($1, index: $0) }), "serialPorts": config.serials.enumerated().map({ serializeQemuSerial($1, index: $0) }),
"qemuAdditionalArguments": config.qemu.additionalArguments.map({ serializeQemuAdditionalArgument($0)}),
] ]
} }
@ -188,6 +189,14 @@ extension UTMScriptingConfigImpl {
] ]
} }
private func serializeQemuAdditionalArgument(_ argument: QEMUArgument) -> [AnyHashable: Any] {
var serializedArgument: [AnyHashable: Any] = [
"argumentString": argument.string
]
return serializedArgument
}
private func serializeAppleConfiguration(_ config: UTMAppleConfiguration) -> [AnyHashable : Any] { private func serializeAppleConfiguration(_ config: UTMAppleConfiguration) -> [AnyHashable : Any] {
[ [
"name": config.information.name, "name": config.information.name,
@ -338,6 +347,9 @@ extension UTMScriptingConfigImpl {
if let serialPorts = record["serialPorts"] as? [[AnyHashable : Any]] { if let serialPorts = record["serialPorts"] as? [[AnyHashable : Any]] {
try updateQemuSerials(from: serialPorts) try updateQemuSerials(from: serialPorts)
} }
if let qemuAdditionalArguments = record["qemuAdditionalArguments"] as? [[AnyHashable: Any]] {
try updateQemuAdditionalArguments(from: qemuAdditionalArguments)
}
} }
private func parseQemuDriveInterface(_ value: AEKeyword?) -> QEMUDriveInterface? { private func parseQemuDriveInterface(_ value: AEKeyword?) -> QEMUDriveInterface? {
@ -500,6 +512,19 @@ extension UTMScriptingConfigImpl {
} }
} }
private func updateQemuAdditionalArguments(from records: [[AnyHashable: Any]]) throws {
let config = config as! UTMQemuConfiguration
let additionalArguments = records.compactMap { record -> QEMUArgument? in
guard let argumentString = record["argumentString"] as? String else { return nil }
var argument = QEMUArgument(argumentString)
return argument
}
// Update entire additional arguments with new one.
config.qemu.additionalArguments = additionalArguments
}
private func updateAppleConfiguration(from record: [AnyHashable : Any]) throws { private func updateAppleConfiguration(from record: [AnyHashable : Any]) throws {
let config = config as! UTMAppleConfiguration let config = config as! UTMAppleConfiguration
if let name = record["name"] as? String, !name.isEmpty { if let name = record["name"] as? String, !name.isEmpty {

Loading…
Cancel
Save