Skip to content

Commit ca9b052

Browse files
author
Prashanth Reddy
committed
feat: add nicmacaddresslist parameter to importUnmanagedInstance and 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)
1 parent b0601e5 commit ca9b052

6 files changed

Lines changed: 6958 additions & 6680 deletions

File tree

Lines changed: 139 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,140 @@
1-
// Licensed to the Apache Software Foundation (ASF) under one
2-
// or more contributor license agreements. See the NOTICE file
3-
// distributed with this work for additional information
4-
// regarding copyright ownership. The ASF licenses this file
5-
// to you under the Apache License, Version 2.0 (the
6-
// "License"); you may not use this file except in compliance
7-
// with the License. You may obtain a copy of the License at
8-
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
11-
// Unless required by applicable law or agreed to in writing,
12-
// software distributed under the License is distributed on an
13-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
// KIND, either express or implied. See the License for the
15-
// specific language governing permissions and limitations
16-
// under the License.
17-
package com.cloud.vm;
18-
19-
public interface VmDetailConstants {
20-
String KEYBOARD = "keyboard";
21-
String CPU_CORE_PER_SOCKET = "cpu.corespersocket";
22-
String CPU_THREAD_PER_CORE = "cpu.threadspercore";
23-
String ROOT_DISK_SIZE = "rootdisksize";
24-
String BOOT_MODE = "boot.mode";
25-
String NAME_ON_HYPERVISOR= "nameonhypervisor";
26-
27-
// VMware specific
28-
String NIC_ADAPTER = "nicAdapter";
29-
String ROOT_DISK_CONTROLLER = "rootDiskController";
30-
String DATA_DISK_CONTROLLER = "dataDiskController";
31-
String SVGA_VRAM_SIZE = "svga.vramSize";
32-
String NESTED_VIRTUALIZATION_FLAG = "nestedVirtualizationFlag";
33-
String RAM_RESERVATION = "ramReservation";
34-
35-
// XenServer specific (internal)
36-
String HYPERVISOR_TOOLS_VERSION = "hypervisortoolsversion";
37-
String PLATFORM = "platform";
38-
String TIME_OFFSET = "timeoffset";
39-
40-
// KVM specific (internal)
41-
String KVM_VNC_PORT = "kvm.vnc.port";
42-
String KVM_VNC_ADDRESS = "kvm.vnc.address";
43-
String KVM_VNC_PASSWORD = "kvm.vnc.password";
44-
String KVM_GUEST_OS_MACHINE_TYPE = "kvm.guest.os.machine.type";
45-
46-
// KVM specific, custom virtual GPU hardware
47-
String VIDEO_HARDWARE = "video.hardware";
48-
String VIDEO_RAM = "video.ram";
49-
50-
//KVM specific, loop threads for block IO requests
51-
String IOTHREADS = "iothreads";
52-
String IO_POLICY = "io.policy";
53-
54-
// KVM specific, the number of queues for multiqueue NICs
55-
String NIC_MULTIQUEUE_NUMBER = "nic.multiqueue.number";
56-
String NIC_PACKED_VIRTQUEUES_ENABLED = "nic.packed.virtqueues.enabled";
57-
58-
// KVM specific, disk controllers
59-
String KVM_SKIP_FORCE_DISK_CONTROLLER = "skip.force.disk.controller";
60-
61-
// Mac OSX guest specific (internal)
62-
String SMC_PRESENT = "smc.present";
63-
String FIRMWARE = "firmware";
64-
65-
// VM deployment with custom compute offering params
66-
String CPU_NUMBER = "cpuNumber";
67-
String CPU_SPEED = "cpuSpeed";
68-
String MEMORY = "memory";
69-
70-
// Misc details for internal usage (not to be set/changed by user or admin)
71-
String CPU_OVER_COMMIT_RATIO = "cpuOvercommitRatio";
72-
String MEMORY_OVER_COMMIT_RATIO = "memoryOvercommitRatio";
73-
String MESSAGE_RESERVED_CAPACITY_FREED_FLAG = "Message.ReservedCapacityFreed.Flag";
74-
String DEPLOY_VM = "deployvm";
75-
String SSH_PUBLIC_KEY = "SSH.PublicKey";
76-
String SSH_KEY_PAIR_NAMES = "SSH.KeyPairNames";
77-
String PASSWORD = "password";
78-
String ENCRYPTED_PASSWORD = "Encrypted.Password";
79-
80-
String CONFIG_DRIVE_LOCATION = "configDriveLocation";
81-
String LAST_CONFIG_DRIVE_LOCATION = "lastConfigDriveLocation";
82-
83-
String SKIP_DRS = "skipFromDRS";
84-
85-
// VM import with nic, disk and custom params for custom compute offering
86-
String NIC = "nic";
87-
String NETWORK = "network";
88-
String IP4_ADDRESS = "ip4Address";
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.vm;
18+
19+
public interface VmDetailConstants {
20+
String KEYBOARD = "keyboard";
21+
String CPU_CORE_PER_SOCKET = "cpu.corespersocket";
22+
String CPU_THREAD_PER_CORE = "cpu.threadspercore";
23+
String ROOT_DISK_SIZE = "rootdisksize";
24+
String BOOT_MODE = "boot.mode";
25+
String NAME_ON_HYPERVISOR= "nameonhypervisor";
26+
27+
// VMware specific
28+
String NIC_ADAPTER = "nicAdapter";
29+
String ROOT_DISK_CONTROLLER = "rootDiskController";
30+
String DATA_DISK_CONTROLLER = "dataDiskController";
31+
String SVGA_VRAM_SIZE = "svga.vramSize";
32+
String NESTED_VIRTUALIZATION_FLAG = "nestedVirtualizationFlag";
33+
String RAM_RESERVATION = "ramReservation";
34+
35+
// XenServer specific (internal)
36+
String HYPERVISOR_TOOLS_VERSION = "hypervisortoolsversion";
37+
String PLATFORM = "platform";
38+
String TIME_OFFSET = "timeoffset";
39+
40+
// KVM specific (internal)
41+
String KVM_VNC_PORT = "kvm.vnc.port";
42+
String KVM_VNC_ADDRESS = "kvm.vnc.address";
43+
String KVM_VNC_PASSWORD = "kvm.vnc.password";
44+
String KVM_GUEST_OS_MACHINE_TYPE = "kvm.guest.os.machine.type";
45+
46+
// KVM specific, custom virtual GPU hardware
47+
String VIDEO_HARDWARE = "video.hardware";
48+
String VIDEO_RAM = "video.ram";
49+
50+
//KVM specific, loop threads for block IO requests
51+
String IOTHREADS = "iothreads";
52+
String IO_POLICY = "io.policy";
53+
54+
// KVM specific, the number of queues for multiqueue NICs
55+
String NIC_MULTIQUEUE_NUMBER = "nic.multiqueue.number";
56+
String NIC_PACKED_VIRTQUEUES_ENABLED = "nic.packed.virtqueues.enabled";
57+
58+
// KVM specific, disk controllers
59+
String KVM_SKIP_FORCE_DISK_CONTROLLER = "skip.force.disk.controller";
60+
61+
// Mac OSX guest specific (internal)
62+
String SMC_PRESENT = "smc.present";
63+
String FIRMWARE = "firmware";
64+
65+
// VM deployment with custom compute offering params
66+
String CPU_NUMBER = "cpuNumber";
67+
String CPU_SPEED = "cpuSpeed";
68+
String MEMORY = "memory";
69+
70+
// Misc details for internal usage (not to be set/changed by user or admin)
71+
String CPU_OVER_COMMIT_RATIO = "cpuOvercommitRatio";
72+
String MEMORY_OVER_COMMIT_RATIO = "memoryOvercommitRatio";
73+
String MESSAGE_RESERVED_CAPACITY_FREED_FLAG = "Message.ReservedCapacityFreed.Flag";
74+
String DEPLOY_VM = "deployvm";
75+
String SSH_PUBLIC_KEY = "SSH.PublicKey";
76+
String SSH_KEY_PAIR_NAMES = "SSH.KeyPairNames";
77+
String PASSWORD = "password";
78+
String ENCRYPTED_PASSWORD = "Encrypted.Password";
79+
80+
String CONFIG_DRIVE_LOCATION = "configDriveLocation";
81+
String LAST_CONFIG_DRIVE_LOCATION = "lastConfigDriveLocation";
82+
83+
String SKIP_DRS = "skipFromDRS";
84+
85+
// VM import with nic, disk and custom params for custom compute offering
86+
String NIC = "nic";
87+
String NETWORK = "network";
88+
String IP4_ADDRESS = "ip4Address";
8989
String IP6_ADDRESS = "ip6Address";
90-
String DISK = "disk";
91-
String DISK_OFFERING = "diskOffering";
92-
93-
String DEPLOY_AS_IS_CONFIGURATION = "configurationId";
94-
String KEY_PAIR_NAMES = "keypairnames";
95-
String CKS_CONTROL_NODE_LOGIN_USER = "controlNodeLoginUser";
96-
String CKS_NODE_TYPE = "node";
97-
String OFFERING = "offering";
98-
String TEMPLATE = "template";
99-
String AFFINITY_GROUP = "affinitygroup";
100-
101-
// VMware to KVM VM migrations specific
102-
String VMWARE_TO_KVM_PREFIX = "vmware-to-kvm";
103-
String VMWARE_VCENTER_HOST = String.format("%s-vcenter", VMWARE_TO_KVM_PREFIX);
104-
String VMWARE_DATACENTER_NAME = String.format("%s-datacenter", VMWARE_TO_KVM_PREFIX);
105-
String VMWARE_CLUSTER_NAME = String.format("%s-cluster", VMWARE_TO_KVM_PREFIX);
106-
String VMWARE_VCENTER_USERNAME = String.format("%s-username", VMWARE_TO_KVM_PREFIX);
107-
String VMWARE_VCENTER_PASSWORD = String.format("%s-password", VMWARE_TO_KVM_PREFIX);
108-
String VMWARE_VM_NAME = String.format("%s-vmname", VMWARE_TO_KVM_PREFIX);
109-
String VMWARE_HOST_NAME = String.format("%s-host", VMWARE_TO_KVM_PREFIX);
110-
String VMWARE_DISK = String.format("%s-disk", VMWARE_TO_KVM_PREFIX);
111-
String VMWARE_MAC_ADDRESSES = String.format("%s-mac-addresses", VMWARE_TO_KVM_PREFIX);
112-
113-
// TPM
114-
String VIRTUAL_TPM_ENABLED = "virtual.tpm.enabled";
115-
String VIRTUAL_TPM_MODEL = "virtual.tpm.model";
116-
String VIRTUAL_TPM_VERSION = "virtual.tpm.version";
117-
118-
// CPU mode and model, ADMIN only
119-
String GUEST_CPU_MODE = "guest.cpu.mode";
120-
String GUEST_CPU_MODEL = "guest.cpu.model";
121-
122-
// Lease related
123-
String INSTANCE_LEASE_EXPIRY_DATE = "leaseexpirydate";
124-
String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
125-
String INSTANCE_LEASE_EXECUTION = "leaseactionexecution";
126-
127-
// External orchestrator related
128-
String MAC_ADDRESS = "mac_address";
129-
String EXPUNGE_EXTERNAL_VM = "expunge.external.vm";
130-
String EXTERNAL_DETAIL_PREFIX = "External:";
131-
String CLOUDSTACK_VM_DETAILS = "cloudstack.vm.details";
132-
String CLOUDSTACK_VLAN = "cloudstack.vlan";
133-
134-
// KVM Checkpoints related
135-
String ACTIVE_CHECKPOINT_ID = "active.checkpoint.id";
136-
String ACTIVE_CHECKPOINT_CREATE_TIME = "active.checkpoint.create.time";
137-
String LAST_CHECKPOINT_ID = "last.checkpoint.id";
138-
String LAST_CHECKPOINT_CREATE_TIME = "last.checkpoint.create.time";
139-
}
90+
String NIC_MAC_ADDRESS = "mac";
91+
String DISK = "disk";
92+
String DISK_OFFERING = "diskOffering";
93+
94+
String DEPLOY_AS_IS_CONFIGURATION = "configurationId";
95+
String KEY_PAIR_NAMES = "keypairnames";
96+
String CKS_CONTROL_NODE_LOGIN_USER = "controlNodeLoginUser";
97+
String CKS_NODE_TYPE = "node";
98+
String OFFERING = "offering";
99+
String TEMPLATE = "template";
100+
String AFFINITY_GROUP = "affinitygroup";
101+
102+
// VMware to KVM VM migrations specific
103+
String VMWARE_TO_KVM_PREFIX = "vmware-to-kvm";
104+
String VMWARE_VCENTER_HOST = String.format("%s-vcenter", VMWARE_TO_KVM_PREFIX);
105+
String VMWARE_DATACENTER_NAME = String.format("%s-datacenter", VMWARE_TO_KVM_PREFIX);
106+
String VMWARE_CLUSTER_NAME = String.format("%s-cluster", VMWARE_TO_KVM_PREFIX);
107+
String VMWARE_VCENTER_USERNAME = String.format("%s-username", VMWARE_TO_KVM_PREFIX);
108+
String VMWARE_VCENTER_PASSWORD = String.format("%s-password", VMWARE_TO_KVM_PREFIX);
109+
String VMWARE_VM_NAME = String.format("%s-vmname", VMWARE_TO_KVM_PREFIX);
110+
String VMWARE_HOST_NAME = String.format("%s-host", VMWARE_TO_KVM_PREFIX);
111+
String VMWARE_DISK = String.format("%s-disk", VMWARE_TO_KVM_PREFIX);
112+
String VMWARE_MAC_ADDRESSES = String.format("%s-mac-addresses", VMWARE_TO_KVM_PREFIX);
113+
114+
// TPM
115+
String VIRTUAL_TPM_ENABLED = "virtual.tpm.enabled";
116+
String VIRTUAL_TPM_MODEL = "virtual.tpm.model";
117+
String VIRTUAL_TPM_VERSION = "virtual.tpm.version";
118+
119+
// CPU mode and model, ADMIN only
120+
String GUEST_CPU_MODE = "guest.cpu.mode";
121+
String GUEST_CPU_MODEL = "guest.cpu.model";
122+
123+
// Lease related
124+
String INSTANCE_LEASE_EXPIRY_DATE = "leaseexpirydate";
125+
String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
126+
String INSTANCE_LEASE_EXECUTION = "leaseactionexecution";
127+
128+
// External orchestrator related
129+
String MAC_ADDRESS = "mac_address";
130+
String EXPUNGE_EXTERNAL_VM = "expunge.external.vm";
131+
String EXTERNAL_DETAIL_PREFIX = "External:";
132+
String CLOUDSTACK_VM_DETAILS = "cloudstack.vm.details";
133+
String CLOUDSTACK_VLAN = "cloudstack.vlan";
134+
135+
// KVM Checkpoints related
136+
String ACTIVE_CHECKPOINT_ID = "active.checkpoint.id";
137+
String ACTIVE_CHECKPOINT_CREATE_TIME = "active.checkpoint.create.time";
138+
String LAST_CHECKPOINT_ID = "last.checkpoint.id";
139+
String LAST_CHECKPOINT_CREATE_TIME = "last.checkpoint.create.time";
140+
}

0 commit comments

Comments
 (0)