mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
VPC: added vif info to ipassoc command
Conflicts: server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java server/src/com/cloud/vm/VirtualMachineManagerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java
This commit is contained in:
parent
a39fd61249
commit
110903a91a
@ -419,9 +419,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);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -2354,8 +2354,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());
|
||||
|
||||
@ -7454,16 +7459,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;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -285,7 +285,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;
|
||||
@ -438,7 +438,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()));
|
||||
@ -455,7 +455,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;
|
||||
@ -487,9 +487,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());
|
||||
@ -522,8 +524,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());
|
||||
}
|
||||
@ -598,12 +600,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);
|
||||
}
|
||||
});
|
||||
@ -690,8 +712,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);
|
||||
@ -720,16 +741,21 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
||||
finalizeSshAndVersionAndNetworkUsageOnStart(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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -737,8 +763,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());
|
||||
|
||||
@ -756,32 +783,33 @@ 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());
|
||||
@ -834,13 +862,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;
|
||||
@ -949,7 +978,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;
|
||||
@ -964,10 +993,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;
|
||||
}
|
||||
|
||||
@ -976,7 +1005,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1262,7 +1291,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) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -53,7 +53,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);
|
||||
}
|
||||
|
||||
@ -173,7 +173,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);
|
||||
|
||||
@ -930,15 +930,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType)
|
||||
*/
|
||||
@Override
|
||||
public String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#getElementImplementingProvider(java.lang.String)
|
||||
*/
|
||||
@ -1001,14 +992,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#getNicProfile(com.cloud.vm.VirtualMachine, long)
|
||||
*/
|
||||
@Override
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#setupDns(com.cloud.network.Network, com.cloud.network.Network.Provider)
|
||||
@ -1138,4 +1121,31 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType)
|
||||
*/
|
||||
@Override
|
||||
public String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#getNicProfile(com.cloud.vm.VirtualMachine, long, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.NetworkManager#assignVpnGatewayIpAddress(long, com.cloud.user.Account, long)
|
||||
*/
|
||||
@Override
|
||||
public PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user