Fixed addDhcpEntry/userdata/password in VPC setup

This commit is contained in:
Alena Prokharchyk 2012-06-11 13:37:38 -07:00
parent ebbbb3b343
commit 3b943d84dd
10 changed files with 122 additions and 137 deletions

View File

@ -3371,7 +3371,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
private boolean shutdownNetworkElementsAndResources(ReservationContext context, boolean cleanupElements, NetworkVO network) {
// 1) Cleanup all the rules for the network. If it fails, just log the failure and proceed with shutting down
// the elements
// the elements
boolean cleanupResult = true;
try {
cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId());

View File

@ -80,6 +80,7 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
@ -174,15 +175,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
DataCenter.class, network.getDataCenterId());
}
for (VirtualRouter router : routers) {
//Add router to guest network
if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added router " + router + " to guest network " + network);
}
}
return true;
}
@ -216,12 +208,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
DataCenter.class, network.getDataCenterId());
}
for (VirtualRouter router : routers) {
//Add router to guest network
if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added router " + router + " to guest network " + network);
if (vm.getType() == Type.User) {
for (VirtualRouter router : routers) {
if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
//Add router to guest network
if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added router " + router + " to guest network " + network);
}
}
}
}
@ -790,35 +786,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
boolean publicNetwork = false;
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
publicNetwork = true;
}
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic
|| _networkMgr.isSecurityGroupSupportedInNetwork(network)) &&
network.getTrafficType() == TrafficType.Guest;
List<DomainRouterVO> routers;
if (publicNetwork) {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
} else {
Long podId = dest.getPod().getId();
if (isPodBased) {
routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER);
} else {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
}
}
// for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when
// network.dns.basiczone.updates is set to "all"
Long podId = dest.getPod().getId();
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(),
podId, State.Running, Role.VIRTUAL_ROUTER);
routers.addAll(allRunningRoutersOutsideThePod);
}
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
@ -841,35 +809,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
boolean publicNetwork = false;
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
publicNetwork = true;
}
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic
|| _networkMgr.isSecurityGroupSupportedInNetwork(network)) &&
network.getTrafficType() == TrafficType.Guest;
List<DomainRouterVO> routers;
if (publicNetwork) {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
} else {
Long podId = dest.getPod().getId();
if (isPodBased) {
routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER);
} else {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
}
}
// for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when
// network.dns.basiczone.updates is set to "all"
Long podId = dest.getPod().getId();
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(),
podId, State.Running, Role.VIRTUAL_ROUTER);
routers.addAll(allRunningRoutersOutsideThePod);
}
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
@ -880,6 +820,39 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
return false;
}
protected List<DomainRouterVO> getRouters(Network network, DeployDestination dest) {
boolean publicNetwork = false;
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
publicNetwork = true;
}
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic
|| _networkMgr.isSecurityGroupSupportedInNetwork(network)) &&
network.getTrafficType() == TrafficType.Guest;
List<DomainRouterVO> routers;
if (publicNetwork) {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
} else {
Long podId = dest.getPod().getId();
if (isPodBased) {
routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER);
} else {
routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
}
}
// for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when
// network.dns.basiczone.updates is set to "all"
Long podId = dest.getPod().getId();
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(),
podId, State.Running, Role.VIRTUAL_ROUTER);
routers.addAll(allRunningRoutersOutsideThePod);
}
return routers;
}
@Override
public List<? extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd) {
Long id = cmd.getId();

View File

@ -31,18 +31,19 @@ import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkService;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcService;
import com.cloud.network.vpc.VpcManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
/**
@ -54,15 +55,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
@Inject
NetworkService _ntwkService;
@Inject
VpcService _vpcService;
VpcManager _vpcMgr;
@Inject
VpcVirtualNetworkApplianceService _vpcMgr;
VpcVirtualNetworkApplianceManager _vpcRouterMgr;
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@Inject
VpcVirtualNetworkApplianceManager _vpcRouterMgr;
@Override
@ -133,7 +131,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return false;
}
Vpc vpc = _vpcService.getActiveVpc(vpcId);
Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
@ -148,15 +146,6 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
DataCenter.class, network.getDataCenterId());
}
for (VirtualRouter router : routers) {
//Add router to guest network
if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
}
}
return true;
}
@ -171,7 +160,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return false;
}
Vpc vpc = _vpcService.getActiveVpc(vpcId);
Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
@ -187,14 +176,18 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
DataCenter.class, network.getDataCenterId());
}
for (VirtualRouter router : routers) {
//Add router to guest network
if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
if (vm.getType() == Type.User) {
for (VirtualRouter router : routers) {
//Add router to guest network
if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
}
}
}
}
}
return true;
}
@ -202,30 +195,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
throws ConcurrentOperationException, ResourceUnavailableException {
boolean success = true;
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is not a part the network " + network);
continue;
}
//2) Call unplugNics in the network service
success = success && _vpcRouterMgr.removeRouterFromGuestNetwork(router, network, false);
if (!success) {
s_logger.warn("Failed to unplug nic in network " + network + " for virtual router " + router);
} else {
s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router " + router);
}
}
return success;
return true;
}
@Override
@ -299,5 +269,13 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
//TODO - add implementation here
return true;
}
@Override
protected List<DomainRouterVO> getRouters(Network network, DeployDestination dest) {
return _vpcMgr.getVpcRouters(network.getVpcId());
}
}

View File

@ -128,6 +128,8 @@ import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
@ -1951,8 +1953,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//add router to public and guest networks
for (Nic publicNic : publicNics.keySet()) {
Network publicNtwk = publicNics.get(publicNic);
if (!addRouterToPublicNetwork(router, publicNtwk, _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
publicNic.getIp4Address()))) {
IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
publicNic.getIp4Address());
PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
if (!addRouterToPublicNetwork(router, publicNtwk, publicIp)) {
s_logger.warn("Failed to plug nic " + publicNic + " to router " + router);
return false;
}
@ -2108,7 +2113,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
@Override
public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile, DeployDestination dest, List<DomainRouterVO> routers)
public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile,
DeployDestination dest, List<DomainRouterVO> routers)
throws ResourceUnavailableException {
_userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine());
@ -3146,7 +3152,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
_routerDao.addRouterToGuestNetwork(routerVO, network);
}
NicProfile guestNic = _itMgr.addVmToNetwork(router, network);
NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
//setup guest network
if (guestNic != null) {
result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns);
@ -3208,7 +3214,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return result;
}
protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress publicIpAddr)
protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, PublicIp sourceNatIp)
throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException {
if (publicNetwork.getTrafficType() != TrafficType.Public) {
@ -3219,13 +3225,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//Add router to the Public network
boolean result = true;
try {
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
defaultNic.setGateway(sourceNatIp.getGateway());
defaultNic.setNetmask(sourceNatIp.getNetmask());
defaultNic.setMacAddress(sourceNatIp.getMacAddress());
defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork);
NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic);
//setup public network
if (publicNic != null) {
publicNic.setDefaultNic(true);
if (publicIpAddr != null) {
IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId());
if (sourceNatIp != null) {
IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()),
NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
result = setupPublicNetwork(publicNetwork, router, false, publicIp);

View File

@ -24,6 +24,7 @@ import com.cloud.network.element.VpcProvider;
import com.cloud.network.vpc.VpcOffering.State;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
/**
@ -89,4 +90,10 @@ public interface VpcManager extends VpcService{
* @throws ResourceUnavailableException
*/
boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* @param vpcId
* @return
*/
List<DomainRouterVO> getVpcRouters(long vpcId);
}

View File

@ -65,8 +65,10 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.ReservationContextImpl;
import com.cloud.vm.dao.DomainRouterDao;
/**
* @author Alena Prokharchyk
@ -93,6 +95,8 @@ public class VpcManagerImpl implements VpcManager, Manager{
NetworkManager _ntwkMgr;
@Inject
IPAddressDao _ipAddressDao;
@Inject
DomainRouterDao _routerDao;
private VpcProvider vpcElement = null;
@ -907,4 +911,9 @@ public class VpcManagerImpl implements VpcManager, Manager{
_vpcDao.update(vpc.getId(), vpc);
}
}
@Override
public List<DomainRouterVO> getVpcRouters(long vpcId) {
return _routerDao.listRoutersByVpcId(vpcId);
}
}

View File

@ -138,12 +138,13 @@ public interface VirtualMachineManager extends Manager {
/**
* @param vm
* @param network
* @param requested TODO
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException;
/**

View File

@ -2432,9 +2432,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
@Override
public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("Adding vm " + vm + " to network " + network);
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
NetworkVO networkVO = _networkDao.findById(network.getId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
@ -2458,7 +2459,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
//1) allocate nic and prepare nic if needed
int deviceId = _nicsDao.countNics(vm.getId());
nic = _networkMgr.allocateNic(null, network, false,
nic = _networkMgr.allocateNic(requested, network, false,
deviceId, vmProfile).first();
if (nic == null) {
@ -2470,7 +2471,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
}
//2) Convert vmProfile to vmTO

View File

@ -240,7 +240,7 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager {
* @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
*/
@Override
public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
// TODO Auto-generated method stub
return false;
}

View File

@ -5,7 +5,7 @@
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
VERSION = '3.0.3.2012-06-11T16:40:18Z'
VERSION = '3.0.3.2012-06-11T20:32:53Z'
APPNAME = 'cloud'
import shutil,os