Skip to content

Commit b278bc8

Browse files
committed
Preserve N2K source MAC for Cloud imports
1 parent a4d3f05 commit b278bc8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/n2k/target_cloud.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,27 @@ n2k_cloud_target_source_deploy_params_json() {
225225
elif ($s | test("scsi|lsilogic|pvscsi|buslogic")) then "scsi"
226226
else "" end;
227227
228+
def source_mac($vm):
229+
(($vm.nics // [])
230+
| map(.mac // .macAddress // .mac_address // "")
231+
| map((. // "") | tostring | ascii_downcase)
232+
| map(select(test("^([0-9a-f]{2}:){5}[0-9a-f]{2}$")))
233+
| first) // "";
234+
228235
(.source.vm // {}) as $vm
229236
| (($vm.cpu // 0) | tonumber? // 0) as $cpu
230237
| (($vm.memory_mb // 0) | tonumber? // 0) as $memory_mb
231238
| ((.target.cloud.cpu_speed // "1000") | tostring) as $cpu_speed
232239
| (($vm.firmware // "") | tostring | ascii_downcase) as $firmware
233240
| (($vm.secure_boot // false) == true) as $secure_boot
241+
| (source_mac($vm)) as $source_mac
234242
| (controller(.disks[0].controller.type // "")) as $root_controller
235243
| (controller((.disks[1:] // [] | map(.controller.type // "") | map(select((. | tostring | length) > 0)) | first) // "")) as $data_controller
236244
| {}
237245
+ (if $cpu > 0 then {"details[0].cpuNumber": ($cpu | floor | tostring)} else {} end)
238246
+ {"details[0].cpuSpeed": $cpu_speed}
239247
+ (if $memory_mb > 0 then {"details[0].memory": ($memory_mb | floor | tostring)} else {} end)
248+
+ (if ($source_mac | length) > 0 then {macaddress:$source_mac} else {} end)
240249
+ (if ($root_controller | length) > 0 then {"details[0].rootDiskController": $root_controller} else {} end)
241250
+ (if ($data_controller | length) > 0 then {"details[0].dataDiskController": $data_controller} else {} end)
242251
+ (

0 commit comments

Comments
 (0)