return false;
}
}
OvsVpcPhysicalTopologyConfigCommand prepareVpcTopologyUpdate(long vpcId) {
VpcVO vpc = _vpcDao.findById(vpcId);
assert (vpc != null): "invalid vpc id";
List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
List<Long> hostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
List<Long> vmIds = _ovsNetworkToplogyGuru.getAllActiveVmsInVpc(vpcId);
List<OvsVpcPhysicalTopologyConfigCommand.Host> hosts = new ArrayList<>();
List<OvsVpcPhysicalTopologyConfigCommand.Tier> tiers = new ArrayList<>();
List<OvsVpcPhysicalTopologyConfigCommand.Vm> vms = new ArrayList<>();
for (Long hostId : hostIds) {
HostVO hostDetails = _hostDao.findById(hostId);
String remoteIp = null;
for (Network network: vpcNetworks) {
try {
remoteIp = getGreEndpointIP(hostDetails, network);
} catch (Exception e) {
}
}
OvsVpcPhysicalTopologyConfigCommand.Host host = new OvsVpcPhysicalTopologyConfigCommand.Host(hostId, remoteIp);
hosts.add(host);
}
for (Network network: vpcNetworks) {
String key = network.getBroadcastUri().getAuthority();
long gre_key;
if (key.contains(".")) {
String[] parts = key.split("\\.");
gre_key = Long.parseLong(parts[1]);
} else {
try {
gre_key = Long.parseLong(BroadcastDomainType.getValue(key));
} catch (Exception e) {
return null;
}
}
NicVO nic = _nicDao.findByIp4AddressAndNetworkId(network.getGateway(), network.getId());
OvsVpcPhysicalTopologyConfigCommand.Tier tier = new OvsVpcPhysicalTopologyConfigCommand.Tier(gre_key,
network.getUuid(), network.getGateway(), nic.getMacAddress(), network.getCidr());
tiers.add(tier);
}
for (long vmId: vmIds) {
VirtualMachine vmInstance = _vmInstanceDao.findById(vmId);
List<OvsVpcPhysicalTopologyConfigCommand.Nic> vmNics = new ArrayList<OvsVpcPhysicalTopologyConfigCommand.Nic>();
for (Nic vmNic :_nicDao.listByVmId(vmId)) {
Network network = _networkDao.findById(vmNic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest) {
OvsVpcPhysicalTopologyConfigCommand.Nic nic = new OvsVpcPhysicalTopologyConfigCommand.Nic(
vmNic.getIp4Address(), vmNic.getMacAddress(), network.getUuid());
vmNics.add(nic);
}
}
OvsVpcPhysicalTopologyConfigCommand.Vm vm = new OvsVpcPhysicalTopologyConfigCommand.Vm(
vmInstance.getHostId(), vmNics.toArray(new OvsVpcPhysicalTopologyConfigCommand.Nic[vmNics.size()]));
vms.add(vm);
}
return new OvsVpcPhysicalTopologyConfigCommand(
hosts.toArray(new OvsVpcPhysicalTopologyConfigCommand.Host[hosts.size()]),
tiers.toArray(new OvsVpcPhysicalTopologyConfigCommand.Tier[tiers.size()]),
vms.toArray(new OvsVpcPhysicalTopologyConfigCommand.Vm[vms.size()]),
vpc.getCidr());
}