shwstppr commented on a change in pull request #3606: [WIP DO NOT MERGE] VM
ingestion
URL: https://github.com/apache/cloudstack/pull/3606#discussion_r347229249
##########
File path:
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
##########
@@ -3950,6 +3950,61 @@ public NicVO savePlaceholderNic(final Network network,
final String ip4Address,
return _nicDao.persist(nic);
}
+ @DB
+ @Override
+ public Pair<NicProfile, Integer> importNic(final String macAddress, int
deviceId, final Network network, final Boolean isDefaultNic, final
VirtualMachine vm, final Network.IpAddresses ipAddresses)
+ throws ConcurrentOperationException,
InsufficientVirtualNetworkCapacityException,
InsufficientAddressCapacityException {
+ s_logger.debug("Allocating nic for vm " + vm.getUuid() + " in network
" + network + " during import");
+ String guestIp = null;
+ if (ipAddresses != null &&
!Strings.isNullOrEmpty(ipAddresses.getIp4Address())) {
+ if (ipAddresses.getIp4Address().equals("auto")) {
+ ipAddresses.setIp4Address(null);
+ }
+ if (network.getGuestType() != GuestType.L2) {
+ guestIp = _ipAddrMgr.acquireGuestIpAddress(network,
ipAddresses.getIp4Address());
+ } else {
+ guestIp = null;
+ }
+ if (guestIp == null && network.getGuestType() != GuestType.L2 &&
!_networkModel.listNetworkOfferingServices(network.getNetworkOfferingId()).isEmpty())
{
+ throw new InsufficientVirtualNetworkCapacityException("Unable
to acquire Guest IP address for network " + network, DataCenter.class,
+ network.getDataCenterId());
+ }
+ }
+ final String finalGuestIp = guestIp;
+ NicVO vo = Transaction.execute(new TransactionCallback<NicVO>() {
+ @Override
+ public NicVO doInTransaction(TransactionStatus status) {
+ NicVO vo = new NicVO(network.getGuruName(), vm.getId(),
network.getId(), vm.getType());
+ vo.setMacAddress(macAddress);
+ vo.setAddressFormat(Networks.AddressFormat.Ip4);
+ if (NetUtils.isValidIp4(finalGuestIp) &&
!Strings.isNullOrEmpty(network.getGateway())) {
+ vo.setIPv4Address(finalGuestIp);
+ vo.setIPv4Gateway(network.getGateway());
+ if (!Strings.isNullOrEmpty(network.getCidr())) {
+
vo.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
+ }
+ }
+ vo.setBroadcastUri(network.getBroadcastUri());
+ vo.setMode(network.getMode());
+ vo.setState(Nic.State.Reserved);
+ vo.setReservationStrategy(ReservationStrategy.Start);
+ vo.setReservationId(UUID.randomUUID().toString());
+ vo.setIsolationUri(network.getBroadcastUri());
+ vo.setDeviceId(deviceId);
+ vo.setDefaultNic(isDefaultNic);
+ vo = _nicDao.persist(vo);
+ return vo;
+ }
+ });
+ updateNic(vo, network.getId(), 1);
Review comment:
Refactored, please check once @DaanHoogland
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services