add nicmacaddresslist parameter to importUnmanagedInstance and importVM APIs#13414
Open
prashanthr2 wants to merge 10 commits into
Open
add nicmacaddresslist parameter to importUnmanagedInstance and importVM APIs#13414prashanthr2 wants to merge 10 commits into
prashanthr2 wants to merge 10 commits into
Conversation
added 10 commits
June 11, 2026 20:32
…importVM APIs Allow callers to specify per-NIC MAC addresses when importing a VM into CloudStack management, overriding the MAC address reported by the hypervisor. Problem ------- importUnmanagedInstance and importVM always used the MAC address reported by the hypervisor. There was no way to supply a specific MAC at import time. The only control was 'forced': reject conflicting MAC or silently replace it. Solution -------- Add new MAP parameter 'nicmacaddresslist' to ImportUnmanagedInstanceCmd (inherited by ImportVmCmd), following the pattern of 'nicnetworklist' and 'nicipaddresslist'. nicmacaddresslist[0].nic=nic1&nicmacaddresslist[0].mac=aa:bb:cc:dd:ee:ff nicmacaddresslist[1].nic=nic2&nicmacaddresslist[1].mac=aa:bb:cc:dd:ee:02 NICs not listed keep their hypervisor-reported MAC (backward compatible). Changes ------- - ApiConstants: add NIC_MAC_ADDRESS_LIST = "nicmacaddresslist" - VmDetailConstants: add NIC_MAC_ADDRESS = "mac" (map entry key) - ImportUnmanagedInstanceCmd: add @parameter nicmacaddresslist with getNicMacAddressList() validation (isValidMac + isUnicastMac + standardizeMacAddress), matching BaseDeployVMCmd / AddNicToVMCmd - UnmanagedVMsManagerImpl: * mergeNicMacAddresses() merges caller MACs into the IpAddresses map * baseImportInstance() and importVm() call mergeNicMacAddresses() * importNic() prefers ipAddresses.getMacAddress() (caller) over nic.getMacAddress() (hypervisor) when non-empty * importNic() changed private -> protected for testability Tests ----- - ImportUnmanagedInstanceCmdTest: MAC format/unicast/empty validation - UnmanagedVMsManagerImplTest: mergeNicMacAddresses() edge cases + importNic() MAC selection (caller preferred, fallback to hypervisor)
…xception Remove test-specific stubs for dataCenterDao and networkOrchestrationService.importNic that duplicate the setUp() stubs. With Mockito 5 strict stubs, test-method stubs that don't get invoked (because setUp's broader nullable() stubs match first) trigger UnnecessaryStubbingException. Rely on setUp's stubs and only verify the MAC argument.
Normalize all changed files to LF line endings, strip trailing whitespace, and ensure a single newline at end of file to pass pre-commit hooks: end-of-file-fixer, mixed-line-ending, trailing-whitespace.
…ody with MAC address changes
…istency with ip4Address
…ct macAddress value
… filesystem truncation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for specifying per-NIC MAC addresses when importing a VM into CloudStack via
importUnmanagedInstanceandimportVMAPIs.Problem
Both APIs always used the MAC address reported by the hypervisor. The only MAC control was the
forcedboolean — which either rejected a conflict or silently generated a new MAC. There was no way to supply a specific MAC at import time, which is needed for migration scenarios requiring MAC preservation.Solution
New MAP parameter
nicmacaddresslistfollowing the same pattern asnicnetworklistandnicipaddresslist:```
nicmacaddresslist[0].nic=nic1&nicmacaddresslist[0].mac=aa:bb:cc:dd:ee:ff
nicmacaddresslist[1].nic=nic2&nicmacaddresslist[1].mac=aa:bb:cc:dd:ee:02
```
NICs not listed keep their hypervisor-reported MAC — fully backward compatible.
Changes
ApiConstants: addNIC_MAC_ADDRESS_LIST = "nicmacaddresslist"VmDetailConstants: addNIC_MAC_ADDRESS = "macAddress"ImportUnmanagedInstanceCmd: new@Parameter nicmacaddresslistwithgetNicMacAddressList()—isValidMac+isUnicastMac+standardizeMacAddressvalidationUnmanagedVMsManagerImpl:mergeNicMacAddresses(): merges caller MACs into theIpAddressesmapbaseImportInstance()+importVm(): callmergeNicMacAddresses()importNic(): prefers caller-supplied MAC over hypervisor-reported MACimportNic():private→protectedfor testabilityTests
ImportUnmanagedInstanceCmdTest(new): 9 tests — MAC format, unicast, empty/null validationUnmanagedVMsManagerImplTest: 8 new tests —mergeNicMacAddresses()edge cases +importNic()MAC selection