Skip to content

Commit

Permalink
Merge pull request #3 from cblackcom/pr/mac-address-argument
Browse files Browse the repository at this point in the history
MAC address argument
  • Loading branch information
azenla authored Nov 28, 2020
2 parents 811ab8e + e9218df commit 737516e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Mac junk
.DS_Store

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
Expand Down
4 changes: 4 additions & 0 deletions virtual/VirtualCommandRun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ struct VirtualCommandRun: ParsableCommand {
@Flag(name: .shortAndLong, help: "Enable NAT Networking")
var network: Bool = false

// if not specified, will generate at random
@Option(name: [.customShort("a"), .long], help: "MAC Address")
var macaddr: String = ""

@Flag(name: .long, help: "Show Version Information")
var version: Bool = false

Expand Down
9 changes: 8 additions & 1 deletion virtual/VirtualSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class VirtualSystem: NSObject, VZVirtualMachineDelegate {
var storage: [VZStorageDeviceConfiguration] = []
if !command.disk.isEmpty {
for disk in command.disk {
let blockAttachment = try VZDiskImageStorageDeviceAttachment(url: URL(fileURLWithPath: disk).absoluteURL, readOnly: true)
let blockAttachment = try VZDiskImageStorageDeviceAttachment(url: URL(fileURLWithPath: disk).absoluteURL, readOnly: false)
let blockDevice = VZVirtioBlockDeviceConfiguration(attachment: blockAttachment)
storage.append(blockDevice)
}
Expand All @@ -50,6 +50,13 @@ class VirtualSystem: NSObject, VZVirtualMachineDelegate {

if command.network {
let networkDevice = VZVirtioNetworkDeviceConfiguration()
if !command.macaddr.isEmpty {
if let macAddress = VZMACAddress(string: command.macaddr) {
networkDevice.macAddress = macAddress
} else {
NSLog("Ignoring MAC Address: was not in acceptable format e.g. 01:23:45:ab:cd:ef")
}
}
networkDevice.attachment = VZNATNetworkDeviceAttachment()
network.append(networkDevice)
}
Expand Down

0 comments on commit 737516e

Please sign in to comment.