Skip to content

Commit

Permalink
remote: add mount support tools command
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Feb 21, 2024
1 parent ea4576b commit 7b9b3a5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ class UTMRemoteData: UTMData {
}

override func mountSupportTools(for vm: any UTMVirtualMachine) async throws {
throw UTMDataError.notImplemented
try await remoteClient.server.mountGuestToolsOnVirtualMachine(id: vm.id)
}
}
#endif
9 changes: 9 additions & 0 deletions Remote/UTMRemoteClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ extension UTMRemoteClient {
try await _deletePackageFile(parameters: .init(id: id, relativePathComponents: relativePathComponents))
}

func mountGuestToolsOnVirtualMachine(id: UUID) async throws {
try await _mountGuestToolsOnVirtualMachine(parameters: .init(id: id))
}

func startVirtualMachine(id: UUID, options: UTMVirtualMachineStartOptions) async throws -> UTMRemoteMessageServer.StartVirtualMachine.ServerInformation {
return try await _startVirtualMachine(parameters: .init(id: id, options: options)).serverInfo
}
Expand Down Expand Up @@ -485,6 +489,11 @@ extension UTMRemoteClient {
try await M.DeletePackageFile.send(parameters, to: peer)
}

@discardableResult
private func _mountGuestToolsOnVirtualMachine(parameters: M.MountGuestToolsOnVirtualMachine.Request) async throws -> M.MountGuestToolsOnVirtualMachine.Reply {
try await M.MountGuestToolsOnVirtualMachine.send(parameters, to: peer)
}

private func _startVirtualMachine(parameters: M.StartVirtualMachine.Request) async throws -> M.StartVirtualMachine.Reply {
try await M.StartVirtualMachine.send(parameters, to: peer)
}
Expand Down
11 changes: 11 additions & 0 deletions Remote/UTMRemoteMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum UTMRemoteMessageServer: UInt8, MessageID {
case getPackageFile
case sendPackageFile
case deletePackageFile
case mountGuestToolsOnVirtualMachine
case startVirtualMachine
case stopVirtualMachine
case restartVirtualMachine
Expand Down Expand Up @@ -174,6 +175,16 @@ extension UTMRemoteMessageServer {
struct Reply: Serializable, Codable {}
}

struct MountGuestToolsOnVirtualMachine: Message {
static let id = UTMRemoteMessageServer.mountGuestToolsOnVirtualMachine

struct Request: Serializable, Codable {
let id: UUID
}

struct Reply: Serializable, Codable {}
}

struct StartVirtualMachine: Message {
static let id = UTMRemoteMessageServer.startVirtualMachine

Expand Down
10 changes: 10 additions & 0 deletions Remote/UTMRemoteServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ extension UTMRemoteServer {
return try await _sendPackageFile(parameters: .decode(data)).encode()
case .deletePackageFile:
return try await _deletePackageFile(parameters: .decode(data)).encode()
case .mountGuestToolsOnVirtualMachine:
return try await _mountGuestToolsOnVirtualMachine(parameters: .decode(data)).encode()
case .startVirtualMachine:
return try await _startVirtualMachine(parameters: .decode(data)).encode()
case .stopVirtualMachine:
Expand Down Expand Up @@ -774,6 +776,14 @@ extension UTMRemoteServer {
return .init()
}

private func _mountGuestToolsOnVirtualMachine(parameters: M.MountGuestToolsOnVirtualMachine.Request) async throws -> M.MountGuestToolsOnVirtualMachine.Reply {
let vm = try await findVM(withId: parameters.id)
if let wrapped = await vm.wrapped {
try await data.mountSupportTools(for: wrapped)
}
return .init()
}

private func _startVirtualMachine(parameters: M.StartVirtualMachine.Request) async throws -> M.StartVirtualMachine.Reply {
let vm = try await findVM(withId: parameters.id)
let serverInfo = try await data.startRemote(vm: vm, options: parameters.options, forClient: client)
Expand Down

0 comments on commit 7b9b3a5

Please sign in to comment.