1) Added VpcVirtualNetworkApplianceService interface

2) Pass dns1/dns2 to setupGuestNetworkCommand
3) Network implement - don't get source nat ip address for Vpc if it already has one
This commit is contained in:
Alena Prokharchyk 2012-06-10 12:24:43 -07:00
parent f1883e991c
commit aa84256542
16 changed files with 229 additions and 73 deletions

View File

@ -66,6 +66,7 @@ public interface VirtualNetworkApplianceService {
* @param router
* @param network
* @param isRedundant TODO
* @param setupDns TODO
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException

View File

@ -0,0 +1,36 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter;
/**
* @author Alena Prokharchyk
*/
public interface VpcVirtualNetworkApplianceService {
/**
* @param router
* @param network
* @param isRedundant
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
}

Binary file not shown.

View File

@ -423,6 +423,14 @@ public interface NetworkManager extends NetworkService {
* @return
*/
NicProfile getNicProfile(VirtualMachine vm, long networkId);
/**
* @param network
* @param provider
* @return
*/
boolean setupDns(Network network, Provider provider);
}

View File

@ -1939,7 +1939,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
@DB
public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
Transaction.currentTxn();
Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
@ -2000,7 +2001,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, NetworkVO network, NetworkOfferingVO offering)
private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context,
NetworkVO network, NetworkOfferingVO offering)
throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
// If this is a 1) guest virtual network 2) network has sourceNat service 3) network offering does not support a
// Shared source NAT rule,
@ -2008,14 +2010,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
boolean sharedSourceNat = offering.getSharedSourceNat();
if (network.getGuestType() == Network.GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat)
if (network.getGuestType() == Network.GuestType.Isolated
&& areServicesSupportedInNetwork(network.getId(), Service.SourceNat)
&& !sharedSourceNat) {
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
List<IPAddressVO> ips = null;
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcMgr.getVpc(network.getVpcId());
ips = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true);
} else {
ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
}
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for " + network);
String target = vpc != null ? vpc.toString() : network.toString();
s_logger.debug("Creating a source nat ip for " + target);
Account owner = _accountMgr.getAccount(network.getAccountId());
assignSourceNatIpAddressToGuestNetwork(owner, network);
if (vpc != null) {
assignSourceNatIpAddressToVpc(owner, vpc);
} else {
assignSourceNatIpAddressToGuestNetwork(owner, network);
}
}
}
@ -2119,14 +2136,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
@DB
public NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination
dest, ReservationContext context, long nicId, NetworkVO network)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName());
NicVO nic = _nicDao.findById(nicId);
@ -2174,7 +2188,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
}
prepareElement(element, network, profile, vmProfile, dest, context);
prepareElement(element, network, profile, vmProfile, dest, context);
}
profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network));
@ -7094,4 +7108,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return privateNetwork;
}
@Override
public boolean setupDns(Network network, Provider provider) {
boolean dnsProvided = isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider );
boolean dhcpProvided =isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp,
provider);
boolean setupDns = dnsProvided || dhcpProvided;
return setupDns;
}
}

View File

@ -129,8 +129,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
if (physicalNetworkId == null) {
return false;
}
if (network.getVpcId() != null) {
return false;
}
if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, "VirtualRouter")) {
if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, Network.Provider.VirtualRouter.getName())) {
return false;
}
@ -170,18 +174,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
DataCenter.class, network.getDataCenterId());
}
boolean success = true;
for (VirtualRouter router : routers) {
//Add router to guest network
success = success && _routerMgr.addRouterToGuestNetwork(router, network, false);
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router router " + router);
if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router);
s_logger.debug("Successfully added router " + router + " to guest network " + network);
}
}
return success;
return true;
}
@Override
@ -214,18 +216,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
DataCenter.class, network.getDataCenterId());
}
boolean success = true;
for (VirtualRouter router : routers) {
//Add router to guest network
success = success && _routerMgr.addRouterToGuestNetwork(router, network, false);
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router);
if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router);
s_logger.debug("Successfully added router " + router + " to guest network " + network);
}
}
return success;
return true;
}
@Override

View File

@ -31,12 +31,14 @@ 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.offering.NetworkOffering;
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;
@ -53,6 +55,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
NetworkService _ntwkService;
@Inject
VpcService _vpcService;
@Inject
VpcVirtualNetworkApplianceService _vpcMgr;
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -60,6 +64,39 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
@Inject
VpcVirtualNetworkApplianceManager _vpcRouterMgr;
@Override
protected boolean canHandle(Network network, Service service) {
Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network);
if (physicalNetworkId == null) {
return false;
}
if (network.getVpcId() == null) {
return false;
}
if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, Network.Provider.VPCVirtualRouter.getName())) {
return false;
}
if (service == null) {
if (!_networkMgr.isProviderForNetwork(getProvider(), network.getId())) {
s_logger.trace("Element " + getProvider().getName() + " is not a provider for the network " + network);
return false;
}
} else {
if (!_networkMgr.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) {
s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName()
+ " in the network " + network);
return false;
}
}
return true;
}
@Override
public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
@ -111,19 +148,16 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
DataCenter.class, network.getDataCenterId());
}
boolean success = true;
for (VirtualRouter router : routers) {
//Add router to guest network
success = success && _routerMgr.addRouterToGuestNetwork(router, network, false);
//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 (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
return success;
return true;
}
@Override
@ -153,18 +187,16 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
DataCenter.class, network.getDataCenterId());
}
boolean success = true;
for (VirtualRouter router : routers) {
//2) Add router to guest network
success = success && _routerMgr.addRouterToGuestNetwork(router, network, false);
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router);
//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 plugged nic in network " + network + " for virtual router " + router);
s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
}
}
return success;
return true;
}
@Override

View File

@ -93,4 +93,5 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile<UserVm> vm, DeployDestination dest,
List<DomainRouterVO> routers) throws ResourceUnavailableException;
}

View File

@ -1949,7 +1949,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
try {
//add router to public and guest networks
//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(),
@ -1959,9 +1959,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
}
for (Nic guestNic : guestNics.keySet()) {
for (Nic guestNic : guestNics.keySet()) {
Network guestNtwk = guestNics.get(guestNic);
if (!addRouterToGuestNetwork(router, guestNtwk, false)) {
//FIXME - move vpc code to the vpc manager
boolean setupDnsRouter = _networkMgr.setupDns(guestNtwk, Provider.VirtualRouter);
boolean setupDnsVpc = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter);
boolean setupDns = setupDnsRouter ? setupDnsRouter : setupDnsVpc;
if (!addRouterToGuestNetwork(router, guestNtwk, false, setupDns)) {
s_logger.warn("Failed to plug nic " + guestNic + " to router " + router);
return false;
}
@ -1969,8 +1975,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
} catch (Exception ex) {
s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex);
return false;
}
}
return result;
}
@ -3058,7 +3063,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
protected boolean setupGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant,
NicProfile guestNic)
NicProfile guestNic, boolean setupDns)
throws ConcurrentOperationException, ResourceUnavailableException{
String networkDomain = network.getNetworkDomain();
@ -3082,16 +3087,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String defaultDns1 = null;
String defaultDns2 = null;
boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter);
boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter);
if (guestNic.isDefaultNic() && (dnsProvided || dhcpProvided)) {
if (setupDns) {
defaultDns1 = guestNic.getDns1();
defaultDns2 = guestNic.getDns2();
}
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), router.getId()),
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
_networkMgr.getNetworkRate(network.getId(), router.getId()),
_networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network));
SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority,
@ -3116,10 +3119,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return result;
}
@Override
public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
boolean setupDns = _networkMgr.setupDns(network, Provider.VirtualRouter);
return addRouterToGuestNetwork(router, network, isRedundant, setupDns);
}
protected boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (network.getTrafficType() != TrafficType.Guest) {
s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
@ -3129,19 +3141,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//Add router to the Guest network
boolean result = true;
try {
DomainRouterVO routerVO = _routerDao.findById(router.getId());
s_logger.debug("Plugging nic for vpc virtual router " + router + " in network " + network);
_routerDao.addRouterToGuestNetwork(routerVO, network);
if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
DomainRouterVO routerVO = _routerDao.findById(router.getId());
s_logger.debug("Plugging nic for virtual router " + router + " in network " + network);
_routerDao.addRouterToGuestNetwork(routerVO, network);
}
NicProfile guestNic = _itMgr.addVmToNetwork(router, network);
//setup guest network
if (guestNic != null) {
result = setupGuestNetwork(network, router, true, isRedundant, guestNic);
result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns);
} else {
s_logger.warn("Failed to add router " + router + " to guest network " + network);
result = false;
}
} catch (Exception ex) {
s_logger.warn("Failed to add router " + router + " to network " + network);
s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex);
result = false;
} finally {
if (!result) {
@ -3157,7 +3172,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return result;
}
@Override
public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException {
@ -3166,13 +3180,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return false;
}
//check if router is already part of network
if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is not a part of guest network " + network + "; no need to unplug guest nic");
return true;
}
//Check if router is a part of the Guest network
if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is not a part of the Guest network " + network);
return true;
}
boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()));
boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false);
if (!result) {
s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
return false;
@ -3204,6 +3224,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork);
//setup public network
if (publicNic != null) {
publicNic.setDefaultNic(true);
if (publicIpAddr != null) {
IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId());
PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()),
@ -3215,7 +3236,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork);
}
} catch (Exception ex) {
s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork);
s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork + " due to ", ex);
} finally {
if (!result) {
s_logger.debug("Removing the router " + router + " from public network " + publicNetwork + " as a part of cleanup");

View File

@ -19,6 +19,7 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.vpc.Vpc;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
@ -27,7 +28,7 @@ import com.cloud.vm.VirtualMachineProfile.Param;
/**
* @author Alena Prokharchyk
*/
public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{
public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{
/**
* @param vpc

View File

@ -19,17 +19,23 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import sun.security.jca.ProviderList;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkService;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.vpc.Vpc;
@ -47,7 +53,7 @@ import com.cloud.vm.VirtualMachineProfile.Param;
* @author Alena Prokharchyk
*/
@Local(value = {VpcVirtualNetworkApplianceManager.class})
@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class})
public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{
private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class);
@ -139,4 +145,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
}
@Override
public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VPCVirtualRouter);
boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp,
Provider.VPCVirtualRouter);
boolean setupDns = dnsProvided || dhcpProvided;
return super.addRouterToGuestNetwork(router, network, isRedundant, setupDns);
}
}

View File

@ -2432,7 +2432,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
@Override
@DB
public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
@ -2451,27 +2450,27 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
NicProfile nic = null;
NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
if (nicVO != null) {
nic = new NicProfile(nicVO, network, nicVO.getBroadcastUri(), nicVO.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), vm.getId()),
_networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(vm.getHypervisorType(), network));
nic = _networkMgr.getNicProfile(vm, network.getId());
}
if (nic == null) {
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
Transaction txn = Transaction.currentTxn();
txn.start();
//1) allocate nic and prepare nic if needed
int deviceId = _nicsDao.countNics(vm.getId());
nic = _networkMgr.allocateNic(null, network, false,
deviceId, vmProfile).first();
if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
}
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
txn.commit();
}
//2) Convert vmProfile to vmTO

View File

@ -123,5 +123,12 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
* @param guestNetworkId
*/
void removeRouterFromNetwork(long routerId, long guestNetworkId);
/**
* @param routerId
* @param guestNetworkId
* @return
*/
boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId);
}

View File

@ -309,5 +309,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("role", Role.VIRTUAL_ROUTER);
return listBy(sc);
}
@Override
public boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId) {
RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId);
return routerNtwkMap != null;
}
}

View File

@ -2197,7 +2197,8 @@ CREATE TABLE `cloud`.`router_network_ref` (
`guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated',
PRIMARY KEY (`id`),
CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE
CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE,
UNIQUE `i_router_network_ref__router_id__network_id`(`router_id`, `network_id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -4,7 +4,8 @@
# the following two variables are used by the target "waf dist"
# 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-08T01:50:26Z'
VERSION = '3.0.3.2012-06-10T19:26:47Z'
APPNAME = 'cloud'
import shutil,os