|
24 | 24 |
|
25 | 25 | import javax.inject.Inject; |
26 | 26 |
|
| 27 | +import org.apache.cloudstack.acl.RoleType; |
27 | 28 | import org.apache.cloudstack.api.ACL; |
28 | 29 | import org.apache.cloudstack.api.APICommand; |
29 | 30 | import org.apache.cloudstack.api.ApiConstants; |
|
39 | 40 | import org.apache.cloudstack.api.response.TemplateResponse; |
40 | 41 | import org.apache.cloudstack.api.response.UserVmResponse; |
41 | 42 | import org.apache.cloudstack.context.CallContext; |
42 | | -import org.apache.cloudstack.ingestion.VmImportService; |
| 43 | +import org.apache.cloudstack.vm.VmImportService; |
43 | 44 | import org.apache.log4j.Logger; |
44 | 45 |
|
45 | 46 | import com.cloud.event.EventTypes; |
|
54 | 55 | import com.cloud.offering.ServiceOffering; |
55 | 56 | import com.cloud.org.Cluster; |
56 | 57 | import com.cloud.user.Account; |
| 58 | +import com.cloud.utils.net.NetUtils; |
| 59 | +import com.google.common.base.Strings; |
57 | 60 |
|
58 | 61 | @APICommand(name = ImportUnmanageInstanceCmd.API_NAME, |
59 | 62 | description = "Import unmanaged virtual machine from a given cluster.", |
60 | 63 | responseObject = UserVmResponse.class, |
61 | 64 | responseView = ResponseObject.ResponseView.Full, |
62 | 65 | requestHasSensitiveInfo = false, |
63 | | - responseHasSensitiveInfo = true) |
| 66 | + responseHasSensitiveInfo = true, |
| 67 | + authorized = {RoleType.Admin}) |
64 | 68 | public class ImportUnmanageInstanceCmd extends BaseAsyncCmd { |
65 | 69 | public static final Logger s_logger = Logger.getLogger(ImportUnmanageInstanceCmd.class); |
66 | 70 | public static final String API_NAME = "importUnmanagedInstance"; |
@@ -136,11 +140,16 @@ public class ImportUnmanageInstanceCmd extends BaseAsyncCmd { |
136 | 140 | description = "the ID of the root disk offering for the virtual machine") |
137 | 141 | private Long diskOfferingId; |
138 | 142 |
|
139 | | - @Parameter(name = "nicnetworklist", |
| 143 | + @Parameter(name = ApiConstants.NIC_NETWORK_LIST, |
140 | 144 | type = CommandType.MAP, |
141 | 145 | description = "VM nic to network id mapping") |
142 | 146 | private Map nicNetworkList; |
143 | 147 |
|
| 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 | + |
144 | 153 | @Parameter(name = ApiConstants.DATADISK_OFFERING_LIST, |
145 | 154 | type = CommandType.MAP, |
146 | 155 | description = "datadisk template to disk-offering mapping") |
@@ -214,6 +223,25 @@ public Map<String, Long> getNicNetworkList() { |
214 | 223 | return nicNetworkMap; |
215 | 224 | } |
216 | 225 |
|
| 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 | + |
217 | 245 | public Map<String, Long> getDataDiskToDiskOfferingList() { |
218 | 246 | Map<String, Long> dataDiskToDiskOfferingMap = new HashMap<>(); |
219 | 247 | if (dataDiskToDiskOfferingList != null && !dataDiskToDiskOfferingList.isEmpty()) { |
|
0 commit comments