Skip to content

Commit 43aaf11

Browse files
committed
Fix a lint bug to tag beta 7
1 parent 9f24ecd commit 43aaf11

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

Sources/hostmgr/HostMgrCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import libhostmgr
55
@main
66
struct Hostmgr: AsyncParsableCommand {
77

8-
private static var appVersion = "0.15.0-beta.6"
8+
private static var appVersion = "0.15.0-beta.7"
99

1010
static var configuration = CommandConfiguration(
1111
abstract: "A utility for managing VM hosts",

Sources/libhostmgr/libhostmgr.swift

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ public func startVM(name: String) async throws {
198198
}
199199

200200
let destination = FileManager.default.temporaryFilePath(named: name + ".tmp.pvm")
201-
202201
try FileManager.default.removeItemIfExists(at: destination)
203202
try FileManager.default.copyItem(at: sourceVM.path, to: destination)
204203
Console.info("Created temporary VM at \(destination)")
@@ -209,37 +208,14 @@ public func startVM(name: String) async throws {
209208

210209
Console.success("Successfully Imported \(parallelsVM.name) with UUID \(parallelsVM.uuid)")
211210

212-
Console.info("Applying VM Settings")
213-
214-
// Always leave 4GB available to the VM host – the VM can have the rest
215-
let vmAvailableMemory = ProcessInfo().physicalMemory - (4096 * 1024 * 1024)
216-
let cpuCoreCount = ProcessInfo().physicalProcessorCount
217-
218-
Console.printTable(data: [
219-
["Total System Memory", Format.memoryBytes(ProcessInfo().physicalMemory)],
220-
["VM System Memory", Format.memoryBytes(vmAvailableMemory)],
221-
["VM CPU Cores", "\(cpuCoreCount)"],
222-
["Hypervisor Type", "apple"],
223-
["Networking Type", "bridged"]
224-
])
225-
226-
try [
227-
.memorySize(Int(vmAvailableMemory / 1024 / 1024)),
211+
try applyVMSettings([
212+
.memorySize(Int(ProcessInfo().physicalMemory - 4096)), // This is a hack, we should make this configurable
228213
.cpuCount(ProcessInfo().physicalProcessorCount),
229214
.hypervisorType(.apple),
230215
.networkType(.shared),
231216
.isolateVM(.on),
232217
.sharedCamera(.off)
233-
].forEach { try parallelsVM.set($0) }
234-
235-
// These are optional, and it's possible they've already been removed, so they may fail
236-
do {
237-
try parallelsVM.set(.withoutSoundDevice())
238-
try parallelsVM.set(.withoutCDROMDevice())
239-
} catch {
240-
Console.warn("Unable to remove device: \(error.localizedDescription)")
241-
}
242-
218+
], to: parallelsVM)
243219
try parallelsVM.start()
244220

245221
let _: Void = try await withCheckedThrowingContinuation { continuation in
@@ -305,3 +281,31 @@ func waitForVMStartup(_ parallelsVirtualMachine: StoppedVM) throws {
305281
.filter { $0.uuid == parallelsVirtualMachine.uuid && $0.hasIpV4Address }
306282
.isEmpty
307283
}
284+
285+
func applyVMSettings(_ settings: [StoppedVM.VMOption], to parallelsVM: StoppedVM) throws {
286+
Console.info("Applying VM Settings")
287+
288+
// Always leave 4GB available to the VM host – the VM can have the rest
289+
let dedicatedMemoryForVM = ProcessInfo().physicalMemory - 4096 // This is a hack, we should make this configurable
290+
let cpuCoreCount = ProcessInfo().physicalProcessorCount
291+
292+
Console.printTable(data: [
293+
["Total System Memory", Format.memoryBytes(ProcessInfo().physicalMemory)],
294+
["VM System Memory", Format.memoryBytes(dedicatedMemoryForVM)],
295+
["VM CPU Cores", "\(cpuCoreCount)"],
296+
["Hypervisor Type", "apple"],
297+
["Networking Type", "bridged"]
298+
])
299+
300+
for setting in settings {
301+
try parallelsVM.set(setting)
302+
}
303+
304+
// These are optional, and it's possible they've already been removed, so they may fail
305+
do {
306+
try parallelsVM.set(.withoutSoundDevice())
307+
try parallelsVM.set(.withoutCDROMDevice())
308+
} catch {
309+
Console.warn("Unable to remove device: \(error.localizedDescription)")
310+
}
311+
}

0 commit comments

Comments
 (0)