mirror of https://github.com/apache/cloudstack.git
VPC: added vif info to ipassoc command
This commit is contained in:
parent
cedf128ae4
commit
f6041de179
|
|
@ -411,9 +411,10 @@ public interface NetworkManager extends NetworkService {
|
|||
/**
|
||||
* @param vm
|
||||
* @param networkId
|
||||
* @param broadcastUri TODO
|
||||
* @return
|
||||
*/
|
||||
NicProfile getNicProfile(VirtualMachine vm, long networkId);
|
||||
NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2351,8 +2351,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
@Override
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId) {
|
||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId());
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) {
|
||||
NicVO nic = null;
|
||||
if (broadcastUri != null) {
|
||||
nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(networkId, vm.getId(), broadcastUri);
|
||||
} else {
|
||||
nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId());
|
||||
}
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
|
||||
|
||||
|
|
@ -7426,16 +7431,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
if (requested != null && requested.getBroadCastUri() != null) {
|
||||
String broadcastUri = requested.getBroadCastUri().toString();
|
||||
String ipAddress = requested.getIp4Address();
|
||||
NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
|
||||
NicVO nicVO = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
|
||||
if (nicVO != null) {
|
||||
if (ipAddress == null || nicVO.getIp4Address().equals(ipAddress)) {
|
||||
nic = getNicProfile(vm, network.getId());
|
||||
nic = getNicProfile(vm, network.getId(), broadcastUri);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
|
||||
if (nicVO != null) {
|
||||
nic = getNicProfile(vm, network.getId());
|
||||
nic = getNicProfile(vm, network.getId(), null);
|
||||
}
|
||||
}
|
||||
return nic;
|
||||
|
|
|
|||
|
|
@ -1868,7 +1868,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
|
||||
for (Long guestNetworkId : routerGuestNtwkIds) {
|
||||
if (reprogramGuestNtwks) {
|
||||
finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId);
|
||||
finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, null);
|
||||
finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
|
||||
}
|
||||
|
||||
|
|
@ -2024,7 +2024,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
}
|
||||
|
||||
protected void finalizeIpAssocForNetwork(Commands cmds, VirtualRouter router, Provider provider,
|
||||
Long guestNetworkId) {
|
||||
Long guestNetworkId, Map<String, String> vlanMacAddress) {
|
||||
|
||||
ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(router, provider, guestNetworkId);
|
||||
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return true;
|
||||
}
|
||||
|
||||
boolean result = setupVpcGuestNetwork(network, router, false, _networkMgr.getNicProfile(router, network.getId()));
|
||||
boolean result = setupVpcGuestNetwork(network, router, false, _networkMgr.getNicProfile(router, network.getId(), null));
|
||||
if (!result) {
|
||||
s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
|
||||
return false;
|
||||
|
|
@ -439,7 +439,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
String networkDomain = network.getNetworkDomain();
|
||||
String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
|
||||
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(router, nic.getNetworkId());
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(router, nic.getNetworkId(), null);
|
||||
|
||||
SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, false, null,
|
||||
defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
|
||||
|
|
@ -456,7 +456,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
|
||||
private void createVpcAssociatePublicIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips,
|
||||
Commands cmds) {
|
||||
Commands cmds, Map<String, String> vlanMacAddress) {
|
||||
|
||||
Pair<IpAddressTO, Long> sourceNatIpAdd = null;
|
||||
Boolean addSourceNat = null;
|
||||
|
|
@ -488,9 +488,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
|
||||
for (final PublicIpAddress ipAddr : ipAddrList) {
|
||||
boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true);
|
||||
|
||||
|
||||
String macAddress = vlanMacAddress.get(ipAddr.getVlanTag());
|
||||
|
||||
IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false,
|
||||
ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(), ipAddr.getNetmask(), ipAddr.getMacAddress(),
|
||||
ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(), ipAddr.getNetmask(), macAddress,
|
||||
null, networkRate, ipAddr.isOneToOneNat());
|
||||
|
||||
ip.setTrafficType(network.getTrafficType());
|
||||
|
|
@ -523,8 +525,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
protected NicTO getNicTO(final VirtualRouter router, Long guestNetworkId) {
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(router, guestNetworkId);
|
||||
protected NicTO getNicTO(final VirtualRouter router, Long networkId, String broadcastUri) {
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(router, networkId, broadcastUri);
|
||||
|
||||
return _itMgr.toNicTO(nicProfile, router.getHypervisorType());
|
||||
}
|
||||
|
|
@ -599,12 +601,32 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
//3) apply the ips
|
||||
//3) apply the rules
|
||||
boolean result = applyRules(network, routers, "vpc ip association", false, null, false, new RuleApplier() {
|
||||
@Override
|
||||
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
createVpcAssociatePublicIPCommands(router, ipAddress, cmds);
|
||||
Map<String, String> vlanMacAddress = new HashMap<String, String>();
|
||||
for (PublicIpAddress ipAddr : ipAddress) {
|
||||
|
||||
String broadcastURI = BroadcastDomainType.Vlan.toUri(ipAddr.getVlanTag()).toString();
|
||||
Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ipAddr.getNetworkId(),
|
||||
router.getId(), broadcastURI);
|
||||
|
||||
String macAddress = null;
|
||||
if (nic == null) {
|
||||
if (ipAddr.getState() != IpAddress.State.Releasing) {
|
||||
throw new CloudRuntimeException("Unable to find the nic in network " + ipAddr.getNetworkId() +
|
||||
" to apply the ip address " + ipAddr + " for");
|
||||
}
|
||||
macAddress = ipAddr.getMacAddress();
|
||||
} else {
|
||||
macAddress = nic.getMacAddress();
|
||||
}
|
||||
|
||||
vlanMacAddress.put(ipAddr.getVlanTag(), macAddress);
|
||||
}
|
||||
createVpcAssociatePublicIPCommands(router, ipAddress, cmds, vlanMacAddress);
|
||||
return sendCommandsToRouter(router, cmds);
|
||||
}
|
||||
});
|
||||
|
|
@ -691,8 +713,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
SetNetworkACLCommand cmd = new SetNetworkACLCommand(rulesTO, getNicTO(router, guestNetworkId));
|
||||
SetNetworkACLCommand cmd = new SetNetworkACLCommand(rulesTO, getNicTO(router, guestNetworkId, null));
|
||||
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
|
||||
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId()));
|
||||
cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, guestVlan);
|
||||
|
|
@ -731,16 +752,21 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
finalizeSshAndVersionOnStart(cmds, profile, router, controlNic);
|
||||
|
||||
//2) FORM PLUG NIC COMMANDS
|
||||
Map<Nic, Network> guestNics = new HashMap<Nic, Network>();
|
||||
Map<Nic, Network> publicNics = new HashMap<Nic, Network>();
|
||||
List<Pair<Nic, Network>> guestNics = new ArrayList<Pair<Nic, Network>>();
|
||||
List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic, Network>>();
|
||||
Map<String, String> vlanMacAddress = new HashMap<String, String>();
|
||||
|
||||
List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
|
||||
for (Nic routerNic : routerNics) {
|
||||
Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Guest) {
|
||||
guestNics.put(routerNic, network);
|
||||
Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic, network);
|
||||
guestNics.add(guestNic);
|
||||
} else if (network.getTrafficType() == TrafficType.Public) {
|
||||
publicNics.put(routerNic, network);
|
||||
Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic, network);
|
||||
publicNics.add(publicNic);
|
||||
String vlanTag = routerNic.getBroadcastUri().getHost();
|
||||
vlanMacAddress.put(vlanTag, routerNic.getMacAddress());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -748,8 +774,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
try {
|
||||
//add VPC router to public networks
|
||||
List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
|
||||
for (Nic publicNic : publicNics.keySet()) {
|
||||
Network publicNtwk = publicNics.get(publicNic);
|
||||
for (Pair<Nic, Network> nicNtwk : publicNics) {
|
||||
Nic publicNic = nicNtwk.first();
|
||||
Network publicNtwk = nicNtwk.second();
|
||||
IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
|
||||
publicNic.getIp4Address());
|
||||
|
||||
|
|
@ -767,31 +794,32 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, publicNic.getNetworkId()));
|
||||
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()));
|
||||
cmds.addCommand(plugNicCmd);
|
||||
}
|
||||
|
||||
// create ip assoc for source nat
|
||||
if (!sourceNat.isEmpty()) {
|
||||
createVpcAssociatePublicIPCommands(router, sourceNat, cmds);
|
||||
createVpcAssociatePublicIPCommands(router, sourceNat, cmds, vlanMacAddress);
|
||||
}
|
||||
|
||||
//add VPC router to guest networks
|
||||
for (Nic nic : guestNics.keySet()) {
|
||||
for (Pair<Nic, Network> nicNtwk : guestNics) {
|
||||
Nic guestNic = nicNtwk.first();
|
||||
//plug guest nic
|
||||
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, nic.getNetworkId()));
|
||||
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, guestNic.getNetworkId(), null));
|
||||
cmds.addCommand(plugNicCmd);
|
||||
|
||||
if (!_networkMgr.isPrivateGateway(nic)) {
|
||||
if (!_networkMgr.isPrivateGateway(guestNic)) {
|
||||
//set guest network
|
||||
VirtualMachine vm = _vmDao.findById(router.getId());
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(vm, nic.getNetworkId());
|
||||
NicProfile nicProfile = _networkMgr.getNicProfile(vm, guestNic.getNetworkId(), null);
|
||||
SetupGuestNetworkCommand setupCmd = createSetupGuestNetworkCommand(router, true, nicProfile);
|
||||
cmds.addCommand(setupCmd);
|
||||
} else {
|
||||
//set private network
|
||||
PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
|
||||
Network network = _networkDao.findById(nic.getNetworkId());
|
||||
PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(), guestNic.getIp4Address());
|
||||
Network network = _networkDao.findById(guestNic.getNetworkId());
|
||||
String vlanTag = network.getBroadcastUri().getHost();
|
||||
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
||||
PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, ipVO.getMacAddress());
|
||||
|
|
@ -844,13 +872,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString());
|
||||
}
|
||||
|
||||
for (Nic nic : guestNics.keySet()) {
|
||||
for (Pair<Nic, Network> nicNtwk : guestNics) {
|
||||
Nic guestNic = nicNtwk.first();
|
||||
if (reprogramGuestNtwks) {
|
||||
finalizeIpAssocForNetwork(cmds, router, provider, nic.getNetworkId());
|
||||
finalizeNetworkRulesForNetwork(cmds, router, provider, nic.getNetworkId());
|
||||
finalizeIpAssocForNetwork(cmds, router, provider, guestNic.getNetworkId(), vlanMacAddress);
|
||||
finalizeNetworkRulesForNetwork(cmds, router, provider, guestNic.getNetworkId());
|
||||
}
|
||||
|
||||
finalizeUserDataAndDhcpOnStart(cmds, router, provider, nic.getNetworkId());
|
||||
finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNic.getNetworkId());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -959,7 +988,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
Network privateNetwork = _networkMgr.getNetwork(gateway.getNetworkId());
|
||||
|
||||
s_logger.debug("Releasing private ip for gateway " + gateway + " from " + router);
|
||||
boolean result = setupVpcPrivateNetwork(router, false, _networkMgr.getNicProfile(router, privateNetwork.getId()));
|
||||
boolean result = setupVpcPrivateNetwork(router, false, _networkMgr.getNicProfile(router, privateNetwork.getId(), null));
|
||||
if (!result) {
|
||||
s_logger.warn("Failed to release private ip for gateway " + gateway + " on router " + router);
|
||||
return false;
|
||||
|
|
@ -974,10 +1003,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
|
||||
@Override
|
||||
protected void finalizeIpAssocForNetwork(Commands cmds, VirtualRouter router, Provider provider,
|
||||
Long guestNetworkId) {
|
||||
Long guestNetworkId, Map<String, String> vlanMacAddress) {
|
||||
|
||||
if (router.getVpcId() == null) {
|
||||
super.finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId);
|
||||
super.finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, vlanMacAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -986,7 +1015,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
if (publicIps != null && !publicIps.isEmpty()) {
|
||||
s_logger.debug("Found " + publicIps.size() + " ip(s) to apply as a part of domR " + router + " start.");
|
||||
// Re-apply public ip addresses - should come before PF/LB/VPN
|
||||
createVpcAssociatePublicIPCommands(router, publicIps, cmds);
|
||||
createVpcAssociatePublicIPCommands(router, publicIps, cmds, vlanMacAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1272,7 +1301,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
|
||||
if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) {
|
||||
//nic has to be plugged only when there are no nics for this vlan tag exist on VR
|
||||
Nic nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(publicNtwkId, router.getId(),
|
||||
Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(publicNtwkId, router.getId(),
|
||||
broadcastUri.toString());
|
||||
|
||||
if ((nic == null && nicsToPlug.get(ip.getVlanTag()) == null) || nicsToUnplug.get(ip.getVlanTag()) != null) {
|
||||
|
|
|
|||
|
|
@ -2527,7 +2527,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
Nic nic = null;
|
||||
|
||||
if (broadcastUri != null) {
|
||||
nic = _nicsDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.toString());
|
||||
nic = _nicsDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.toString());
|
||||
} else {
|
||||
nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||
|
||||
int countNics(long instanceId);
|
||||
|
||||
NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri);
|
||||
NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri);
|
||||
|
||||
NicVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, long instanceId, String ip4Address);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||
|
||||
|
||||
@Override
|
||||
public NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri) {
|
||||
public NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri) {
|
||||
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("instance", instanceId);
|
||||
|
|
|
|||
|
|
@ -959,7 +959,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
|||
* @see com.cloud.network.NetworkManager#getNicProfile(com.cloud.vm.VirtualMachine, long)
|
||||
*/
|
||||
@Override
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId) {
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue