Skip to content

Commit f0d478f

Browse files
committed
code review changes, ip address fix
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 83ffb4c commit f0d478f

File tree

19 files changed

+386
-448
lines changed

19 files changed

+386
-448
lines changed

api/src/main/java/com/cloud/vm/UserVmService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.vm;
1818

19-
import java.util.LinkedHashMap;
2019
import java.util.List;
2120
import java.util.Map;
2221

@@ -514,8 +513,8 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
514513

515514
void collectVmNetworkStatistics (UserVm userVm);
516515

517-
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
518-
final long accountId, final long userId, final ServiceOffering serviceOffering, final DiskOffering rootDiskOffering, final String sshPublicKey, final LinkedHashMap<String, NicProfile> networkNicMap,
519-
final String instanceName, final HypervisorType hypervisorType, final Map<String, String> customParameters, final VirtualMachine.PowerState powerState) throws InsufficientCapacityException;
516+
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
517+
final long accountId, final long userId, final ServiceOffering serviceOffering, final DiskOffering rootDiskOffering, final String sshPublicKey,
518+
final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters, final VirtualMachine.PowerState powerState) throws InsufficientCapacityException;
520519

521520
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ public class ApiConstants {
229229
public static final String NETMASK = "netmask";
230230
public static final String NEW_NAME = "newname";
231231
public static final String NIC = "nic";
232+
public static final String NIC_NETWORK_LIST = "nicnetworklist";
233+
public static final String NIC_IP_ADDRESS_LIST = "nicipaddresslist";
232234
public static final String NUM_RETRIES = "numretries";
233235
public static final String OFFER_HA = "offerha";
234236
public static final String IS_SYSTEM_OFFERING = "issystem";

api/src/main/java/org/apache/cloudstack/api/command/admin/ingestion/ImportUnmanageInstanceCmd.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import javax.inject.Inject;
2626

27+
import org.apache.cloudstack.acl.RoleType;
2728
import org.apache.cloudstack.api.ACL;
2829
import org.apache.cloudstack.api.APICommand;
2930
import org.apache.cloudstack.api.ApiConstants;
@@ -39,7 +40,7 @@
3940
import org.apache.cloudstack.api.response.TemplateResponse;
4041
import org.apache.cloudstack.api.response.UserVmResponse;
4142
import org.apache.cloudstack.context.CallContext;
42-
import org.apache.cloudstack.ingestion.VmImportService;
43+
import org.apache.cloudstack.vm.VmImportService;
4344
import org.apache.log4j.Logger;
4445

4546
import com.cloud.event.EventTypes;
@@ -54,13 +55,16 @@
5455
import com.cloud.offering.ServiceOffering;
5556
import com.cloud.org.Cluster;
5657
import com.cloud.user.Account;
58+
import com.cloud.utils.net.NetUtils;
59+
import com.google.common.base.Strings;
5760

5861
@APICommand(name = ImportUnmanageInstanceCmd.API_NAME,
5962
description = "Import unmanaged virtual machine from a given cluster.",
6063
responseObject = UserVmResponse.class,
6164
responseView = ResponseObject.ResponseView.Full,
6265
requestHasSensitiveInfo = false,
63-
responseHasSensitiveInfo = true)
66+
responseHasSensitiveInfo = true,
67+
authorized = {RoleType.Admin})
6468
public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
6569
public static final Logger s_logger = Logger.getLogger(ImportUnmanageInstanceCmd.class);
6670
public static final String API_NAME = "importUnmanagedInstance";
@@ -136,11 +140,16 @@ public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
136140
description = "the ID of the root disk offering for the virtual machine")
137141
private Long diskOfferingId;
138142

139-
@Parameter(name = "nicnetworklist",
143+
@Parameter(name = ApiConstants.NIC_NETWORK_LIST,
140144
type = CommandType.MAP,
141145
description = "VM nic to network id mapping")
142146
private Map nicNetworkList;
143147

148+
@Parameter(name = ApiConstants.NIC_IP_ADDRESS_LIST,
149+
type = CommandType.MAP,
150+
description = "VM nic to ip address mapping")
151+
private Map nicIpAddressList;
152+
144153
@Parameter(name = ApiConstants.DATADISK_OFFERING_LIST,
145154
type = CommandType.MAP,
146155
description = "datadisk template to disk-offering mapping")
@@ -214,6 +223,25 @@ public Map<String, Long> getNicNetworkList() {
214223
return nicNetworkMap;
215224
}
216225

226+
public Map<String, String> getNicIpAddressList() {
227+
Map<String, String> nicIpAddressMap = new HashMap<>();
228+
if (nicIpAddressList != null && !nicIpAddressList.isEmpty()) {
229+
Collection parameterCollection = nicIpAddressList.values();
230+
Iterator iter = parameterCollection.iterator();
231+
while (iter.hasNext()) {
232+
HashMap<String, String> value = (HashMap<String, String>)iter.next();
233+
String nic = value.get("nic");
234+
String ipAddress = value.get("ipAddress");
235+
if (!Strings.isNullOrEmpty(ipAddress) && NetUtils.isValidIp4(ipAddress)) {
236+
nicIpAddressMap.put(nic, ipAddress);
237+
} else {
238+
throw new InvalidParameterValueException(String.format("IP Address: %s for NIC ID: %s is invalid", ipAddress, nic));
239+
}
240+
}
241+
}
242+
return nicIpAddressMap;
243+
}
244+
217245
public Map<String, Long> getDataDiskToDiskOfferingList() {
218246
Map<String, Long> dataDiskToDiskOfferingMap = new HashMap<>();
219247
if (dataDiskToDiskOfferingList != null && !dataDiskToDiskOfferingList.isEmpty()) {

api/src/main/java/org/apache/cloudstack/api/command/admin/ingestion/ListUnmanagedInstancesCmd.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javax.inject.Inject;
2121

22+
import org.apache.cloudstack.acl.RoleType;
2223
import org.apache.cloudstack.api.APICommand;
2324
import org.apache.cloudstack.api.ApiConstants;
2425
import org.apache.cloudstack.api.BaseAsyncCmd;
@@ -30,8 +31,8 @@
3031
import org.apache.cloudstack.api.response.ListResponse;
3132
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
3233
import org.apache.cloudstack.context.CallContext;
33-
import org.apache.cloudstack.ingestion.UnmanagedInstance;
34-
import org.apache.cloudstack.ingestion.VmImportService;
34+
import org.apache.cloudstack.vm.UnmanagedInstance;
35+
import org.apache.cloudstack.vm.VmImportService;
3536
import org.apache.log4j.Logger;
3637

3738
import com.cloud.exception.ConcurrentOperationException;
@@ -46,7 +47,9 @@
4647
responseObject = UnmanagedInstanceResponse.class,
4748
responseView = ResponseObject.ResponseView.Full,
4849
entityType = {UnmanagedInstance.class},
49-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
50+
requestHasSensitiveInfo = false,
51+
responseHasSensitiveInfo = true,
52+
authorized = {RoleType.Admin})
5053
public class ListUnmanagedInstancesCmd extends BaseListCmd {
5154
public static final Logger s_logger = Logger.getLogger(ListUnmanagedInstancesCmd.class.getName());
5255
public static final String API_NAME = "listUnmanagedInstances";

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.cloudstack.api.ApiConstants;
2424
import org.apache.cloudstack.api.BaseResponse;
2525
import org.apache.cloudstack.api.EntityReference;
26-
import org.apache.cloudstack.ingestion.UnmanagedInstance;
26+
import org.apache.cloudstack.vm.UnmanagedInstance;
2727

2828
import com.cloud.serializer.Param;
2929
import com.google.gson.annotations.SerializedName;

api/src/main/java/org/apache/cloudstack/ingestion/UnmanagedInstance.java renamed to api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.apache.cloudstack.ingestion;
18+
package org.apache.cloudstack.vm;
1919

2020
import java.util.List;
2121

api/src/main/java/org/apache/cloudstack/ingestion/VmImportService.java renamed to api/src/main/java/org/apache/cloudstack/vm/VmImportService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.apache.cloudstack.ingestion;
18+
package org.apache.cloudstack.vm;
1919

2020
import org.apache.cloudstack.api.command.admin.ingestion.ImportUnmanageInstanceCmd;
2121
import org.apache.cloudstack.api.command.admin.ingestion.ListUnmanagedInstancesCmd;

core/src/main/java/com/cloud/agent/api/GetUnmanagedInstancesAnswer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.util.HashMap;
2121

22-
import org.apache.cloudstack.ingestion.UnmanagedInstance;
22+
import org.apache.cloudstack.vm.UnmanagedInstance;
2323

2424
@LogLevel(LogLevel.Log4jLevel.Trace)
2525
public class GetUnmanagedInstancesAnswer extends Answer {

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,5 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
314314
*/
315315
void cleanupNicDhcpDnsEntry(Network network, VirtualMachineProfile vmProfile, NicProfile nicProfile);
316316

317-
Pair<NicProfile, Integer> importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm);
317+
Pair<NicProfile, Integer> importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final String ipAddress);
318318
}

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering offerin
128128

129129
void updateVolumeDiskChain(long volumeId, String path, String chainInfo);
130130

131+
/**
132+
* Imports an existing volume for a VM into database. Useful while ingesting an unmanaged VM.
133+
* @param type Type of the volume - ROOT, DATADISK, etc
134+
* @param name Name of the volume
135+
* @param offering DiskOffering for the volume
136+
* @param size DiskOffering for the volume
137+
* @param minIops minimum IOPS for the disk, if not passed DiskOffering value will be used
138+
* @param maxIops maximum IOPS for the disk, if not passed DiskOffering value will be used
139+
* @param vm VirtualMachine this volume is attached to
140+
* @param template Template of the VM of the volume
141+
* @param owner owner Account for the volume
142+
* @param deviceId device ID of the virtual disk
143+
* @param poolId ID of pool in which volume is stored
144+
* @param path image path of the volume
145+
* @param chainInfo chain info for the volume. Hypervisor specific.
146+
* @return DiskProfile of imported volume
147+
*/
131148
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
132149
Account owner, Long deviceId, Long poolId, String path, String chainInfo);
133150
}

0 commit comments

Comments
 (0)