for (String networkName : networkNames) {
NetworkEntity networkEntity =
networkMgr.getNetworkEntityByName(networkName);
if (needAllocIp) {
NetworkAdd network = new NetworkAdd();
network.setPortGroup(networkEntity.getPortGroup());
network.setName(networkName);
network
.setDhcp(networkEntity.getAllocType() == NetworkEntity.AllocType.DHCP);
if (!network.getIsDhcp()) {
logger.debug("using static ip.");
List<IpBlockEntity> ipBlockEntities =
networkMgr.getAllocatedIpBlocks(networkEntity,
clusterEntity.getId());
long allocatedIpNum = IpBlockEntity.count(ipBlockEntities);
if (allocatedIpNum < instanceNum) {
long newNum = instanceNum - allocatedIpNum;
List<IpBlockEntity> newIpBlockEntities =
networkMgr.alloc(networkEntity, clusterEntity.getId(),
newNum);
ipBlockEntities.addAll(newIpBlockEntities);
}
network.setDns1(networkEntity.getDns1());
network.setDns2(networkEntity.getDns2());
network.setGateway(networkEntity.getGateway());
network.setNetmask(networkEntity.getNetmask());
List<IpBlock> ips = new ArrayList<IpBlock>();
for (IpBlockEntity ipBlockEntity : ipBlockEntities) {
IpBlock ip = new IpBlock();
ip.setBeginIp(ipBlockEntity.getBeginAddress());
ip.setEndIp(ipBlockEntity.getEndAddress());
ips.add(ip);
}
network.setIpBlocks(ips);
}
networkings.add(network);
}
}
return networkings;