NaaS: Discard DhcpElement

VirtualRouterElement would do all the job. The difference would be public
network enabled or not.
This commit is contained in:
Sheng Yang 2011-11-04 14:07:28 -07:00
parent 523da327c6
commit 3051dc2621
18 changed files with 120 additions and 583 deletions

View File

@ -1,127 +0,0 @@
/**
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.PlugService;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.network.element.DhcpElementService;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(responseObject=SuccessResponse.class, description="Configures a dhcp element.")
public class ConfigureDhcpElementCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ConfigureDhcpElementCmd.class.getName());
private static final String s_name = "configuredhcpelementresponse";
@PlugService
private DhcpElementService _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the network service provider ID of the virtual router element")
private Long nspId;
@Parameter(name=ApiConstants.ENABLED, type=CommandType.BOOLEAN, required=true, description="Enabled/Disabled the service provider")
private Boolean enabled;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public void setNspId(Long nspId) {
this.nspId = nspId;
}
public Long getNspId() {
return nspId;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Boolean getEnabled() {
return enabled;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "boolean";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
}
@Override
public String getEventDescription() {
return "configuring dhcp element: " + _service.getIdByNspId(nspId);
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.None;
}
public Long getInstanceId() {
return _service.getIdByNspId(nspId);
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Dhcp element: " + _service.getIdByNspId(nspId));
Boolean result = _service.configure(this);
if (result){
SuccessResponse response = new SuccessResponse();
response.setResponseName(getCommandName());
response.setSuccess(result);
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the dhcp element");
}
}
}

View File

@ -1,112 +0,0 @@
/**
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.PlugService;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.element.DhcpElementService;
import com.cloud.event.EventTypes;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(responseObject=SuccessResponse.class, description="Create a dhcp element.")
public class CreateDhcpElementCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateDhcpElementCmd.class.getName());
private static final String s_name = "createdhcpelementresponse";
@PlugService
private DhcpElementService _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.LONG, required=true, description="the network service provider ID of the dhcp element")
private Long nspId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public void setNspId(Long nspId) {
this.nspId = nspId;
}
public Long getNspId() {
return nspId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
UserContext.current().setEventDetails("DHCP element Id: "+getEntityId());
VirtualRouterProvider result = _service.getCreatedElement(getEntityId());
if (result != null) {
SuccessResponse response = new SuccessResponse();
response.setResponseName(getCommandName());
response.setSuccess(true);
this.setResponseObject(response);
}else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
}
}
@Override
public void create() throws ResourceAllocationException {
VirtualRouterProvider result = _service.addElement(getNspId());
if (result != null) {
setEntityId(result.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_SERVICE_PROVIDER_CREATE;
}
@Override
public String getEventDescription() {
return "Adding physical network ServiceProvider Dhcp server: " + getEntityId();
}
}

View File

@ -113,7 +113,6 @@ public interface Network extends ControlledEntity {
public static final Provider VirtualRouter = new Provider("VirtualRouter", false);
public static final Provider DhcpServer = new Provider("DhcpServer", false);
public static final Provider JuniperSRX = new Provider("JuniperSRX", true);
public static final Provider F5BigIp = new Provider("F5BigIp", true);
public static final Provider Netscaler = new Provider("Netscaler", true);

View File

@ -20,7 +20,6 @@ package com.cloud.network;
public interface VirtualRouterProvider {
public enum VirtualRouterProviderType {
DhcpElement,
VirtualRouterElement,
RedundantVirtualRouterElement,
}

View File

@ -1,12 +0,0 @@
package com.cloud.network.element;
import com.cloud.api.commands.ConfigureDhcpElementCmd;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.utils.component.PluggableService;
public interface DhcpElementService extends PluggableService{
boolean configure(ConfigureDhcpElementCmd cmd);
VirtualRouterProvider addElement(Long nspId);
Long getIdByNspId(Long nspId);
VirtualRouterProvider getCreatedElement(long id);
}

View File

@ -1,7 +1,12 @@
package com.cloud.network.element;
import com.cloud.api.commands.ConfigureVirtualRouterElementCmd;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.utils.component.PluggableService;
public interface VirtualRouterElementService extends DhcpElementService {
public interface VirtualRouterElementService extends PluggableService{
boolean configure(ConfigureVirtualRouterElementCmd cmd);
VirtualRouterProvider addElement(Long nspId);
Long getIdByNspId(Long nspId);
VirtualRouterProvider getCreatedElement(long id);
}

View File

@ -25,7 +25,6 @@
<adapter name="F5ExternalLoadBalancer" class="com.cloud.network.element.F5ExternalLoadBalancerElement"/>
<adapter name="DomainRouter" class="com.cloud.network.element.VirtualRouterElement"/>
<adapter name="RedundantVirtualRouter" class="com.cloud.network.element.RedundantVirtualRouterElement"/>
<adapter name="Dhcp" class="com.cloud.network.element.DhcpElement"/>
<adapter name="Ovs" class="com.cloud.network.element.OvsElement"/>
<adapter name="ExternalDhcp" class="com.cloud.network.element.ExternalDhcpElement"/>
<adapter name="BareMetal" class="com.cloud.network.element.BareMetalElement"/>

View File

@ -95,7 +95,6 @@
</adapters>
<adapters key="com.cloud.network.element.NetworkElement">
<adapter name="DomainRouter" class="com.cloud.network.element.VirtualRouterElement"/>
<adapter name="Dhcp" class="com.cloud.network.element.DhcpElement"/>
<adapter name="Ovs" class="com.cloud.network.element.OvsElement"/>
<adapter name="ElasticLoadBalancer" class="com.cloud.network.element.ElasticLoadBalancerElement"/>
@ -107,7 +106,6 @@
<adapter name="ClusterBasedAgentLbPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner"/>
</adapters>
<pluggableservice name="DhcpElementService" key="com.cloud.network.element.DhcpElementService" class="com.cloud.network.element.DhcpElement"/>
<pluggableservice name="VirtualRouterElementService" key="com.cloud.network.element.VirtualRouterElementService" class="com.cloud.network.element.VirtualRouterElement"/>
<pluggableservice name="RedundantVirtualRouterElementService" key="com.cloud.network.element.RedundantVirtualRouterElementService" class="com.cloud.network.element.RedundantVirtualRouterElement"/>
</management-server>

View File

@ -3,8 +3,6 @@
#### router commands
createVirtualRouterElement=com.cloud.api.commands.CreateVirtualRouterElementCmd;7
createDhcpElement=com.cloud.api.commands.CreateDhcpElementCmd;7
createRedundantVirtualRouterElement=com.cloud.api.commands.CreateRedundantVirtualRouterElementCmd;7
configureDhcpElement=com.cloud.api.commands.ConfigureDhcpElementCmd;7
configureVirtualRouterElement=com.cloud.api.commands.ConfigureVirtualRouterElementCmd;7
configureRedundantVirtualRouterElement=com.cloud.api.commands.ConfigureRedundantVirtualRouterElementCmd;7

View File

@ -89,8 +89,6 @@ import com.cloud.network.dao.PhysicalNetworkTrafficTypeDaoImpl;
import com.cloud.network.dao.RemoteAccessVpnDaoImpl;
import com.cloud.network.dao.VirtualRouterProviderDaoImpl;
import com.cloud.network.dao.VpnUserDaoImpl;
import com.cloud.network.element.DhcpElement;
import com.cloud.network.element.DhcpElementService;
import com.cloud.network.element.RedundantVirtualRouterElement;
import com.cloud.network.element.RedundantVirtualRouterElementService;
import com.cloud.network.element.VirtualRouterElement;
@ -390,7 +388,6 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
}
protected void populateServices() {
addService("DhcpElementService", DhcpElementService.class, DhcpElement.class);
addService("VirtualRouterElementService", VirtualRouterElementService.class, VirtualRouterElement.class);
addService("RedundantVirtualRouterElementService", RedundantVirtualRouterElementService.class, RedundantVirtualRouterElement.class);
}

View File

@ -199,9 +199,9 @@ public class DataCenterVO implements DataCenter {
vpnProvider = Provider.VirtualRouter.getName();
userDataProvider = Provider.VirtualRouter.getName();
} else if (zoneType == NetworkType.Basic){
dhcpProvider = Provider.DhcpServer.getName();
dnsProvider = Provider.DhcpServer.getName();
userDataProvider = Provider.DhcpServer.getName();
dhcpProvider = Provider.VirtualRouter.getName();
dnsProvider = Provider.VirtualRouter.getName();
userDataProvider = Provider.VirtualRouter.getName();
loadBalancerProvider = Provider.ElasticLoadBalancerVm.getName();
}

View File

@ -854,7 +854,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//populate providers
Map<Network.Service, Set<Network.Provider>> defaultDirectNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
defaultProviders.add(Network.Provider.DhcpServer);
defaultProviders.add(Network.Provider.VirtualRouter);
defaultDirectNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
defaultDirectNetworkOfferingProviders.put(Service.Dns, defaultProviders);
defaultDirectNetworkOfferingProviders.put(Service.UserData, defaultProviders);

View File

@ -1,289 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.commands.ConfigureDhcpElementCmd;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.dao.HostDao;
import com.cloud.network.Network;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkManager;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.AccountManager;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
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.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
@Local(value=NetworkElement.class)
public class DhcpElement extends AdapterBase implements DhcpElementService, UserDataServiceProvider {
private static final Logger s_logger = Logger.getLogger(DhcpElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@Inject NetworkDao _networkConfigDao;
@Inject NetworkManager _networkMgr;
@Inject VirtualNetworkApplianceManager _routerMgr;
@Inject UserVmManager _userVmMgr;
@Inject UserVmDao _userVmDao;
@Inject DomainRouterDao _routerDao;
@Inject ConfigurationManager _configMgr;
@Inject HostPodDao _podDao;
@Inject AccountManager _accountMgr;
@Inject HostDao _hostDao;
@Inject VirtualRouterProviderDao _vrProviderDao;
private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType, long offeringId) {
if (_networkMgr.isProviderSupported(offeringId, Service.Gateway, Provider.JuniperSRX) && networkType == Network.GuestType.Isolated) {
return true;
} else if (dest.getPod() != null && dest.getPod().getExternalDhcp()){
//This pod is using external DHCP server
return false;
} else {
return (networkType == Network.GuestType.Shared);
}
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
if (!canHandle(dest, offering.getTrafficType(), network.getGuestType(), network.getNetworkOfferingId())) {
return false;
}
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramNetwork, true);
_routerMgr.deployDhcp(network, dest, _accountMgr.getAccount(network.getAccountId()), params);
return true;
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(dest, network.getTrafficType(), network.getGuestType(), network.getNetworkOfferingId())) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramNetwork, true);
List<DomainRouterVO> routers = _routerMgr.deployDhcp(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters());
//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();
DataCenter dc = dest.getDataCenter();
boolean isPodBased = (dc.getNetworkType() == NetworkType.Basic || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && network.getTrafficType() == TrafficType.Guest;
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.DHCP_USERDATA);
routers.addAll(allRunningRoutersOutsideThePod);
}
List<VirtualRouter> rets = _routerMgr.addVirtualMachineIntoNetwork(network, nic, uservm, dest, context, routers);
return (rets != null) && (!rets.isEmpty());
} else {
return false;
}
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) {
return true;
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
boolean result = true;
for (DomainRouterVO router : routers) {
result = result && _routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null;
}
return result;
}
@Override
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
boolean result = true;
for (DomainRouterVO router : routers) {
result = result && (_routerMgr.destroyRouter(router.getId()) != null);
}
return result;
}
@Override
public Provider getProvider() {
return Provider.DhcpServer;
}
@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
return capabilities;
}
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
Map<Capability, String> dnsCapabilities = new HashMap<Capability, String>();
dnsCapabilities.put(Capability.AllowDnsSuffixModification, "true");
capabilities.put(Service.Dns, dnsCapabilities);
capabilities.put(Service.UserData, null);
capabilities.put(Service.Dhcp, null);
return capabilities;
}
@Override
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.trace("Can't find dhcp element in network " + network.getId());
return true;
}
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
}
@Override
public String getPropertiesFile() {
return "virtualrouter_commands.properties";
}
@Override
public boolean configure(ConfigureDhcpElementCmd cmd) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(cmd.getNspId(), VirtualRouterProviderType.DhcpElement);
if (element == null) {
s_logger.trace("Can't find element with network service provider ID " + cmd.getNspId());
return false;
}
element.setEnabled(cmd.getEnabled());
_vrProviderDao.persist(element);
return true;
}
@Override
public VirtualRouterProvider addElement(Long nspId) {
long serviceOfferingId = _routerMgr.getDefaultVirtualRouterServiceOfferingId();
if (serviceOfferingId == 0) {
return null;
}
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.DhcpElement);
if (element != null) {
s_logger.trace("There is already a dhcp element with service provider id " + nspId);
return null;
}
element = new VirtualRouterProviderVO(nspId, null, VirtualRouterProviderType.DhcpElement);
_vrProviderDao.persist(element);
return element;
}
@Override
public Long getIdByNspId(Long nspId) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.DhcpElement);
return element.getId();
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderType.DhcpElement);
if (element == null) {
return false;
}
return element.isEnabled();
}
@Override
public VirtualRouterProvider getCreatedElement(long id) {
return _vrProviderDao.findById(id);
}
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context, boolean forceShutdown) throws ConcurrentOperationException,
ResourceUnavailableException {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderType.DhcpElement);
if (element == null) {
return true;
}
//Find domain routers
long elementId = element.getId();
List<DomainRouterVO> routers = _routerDao.listByElementId(elementId);
boolean result = true;
for (DomainRouterVO router : routers) {
if (forceShutdown) {
result = result && (_routerMgr.stopRouter(router.getId(), true) != null);
}
result = result && (_routerMgr.destroyRouter(router.getId()) != null);
}
return result;
}
@Override
public boolean canEnableIndividualServices() {
return false;
}
}

View File

@ -50,6 +50,7 @@ public class RedundantVirtualRouterElement extends VirtualRouterElement implemen
}
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramNetwork, true);
_routerMgr.deployVirtualRouter(guestConfig, dest, _accountMgr.getAccount(guestConfig.getAccountId()), params, true);

View File

@ -22,12 +22,15 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.api.commands.ConfigureVirtualRouterElementCmd;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -38,6 +41,7 @@ import com.cloud.network.Network.Capability;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.NetworkManager;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
@ -59,7 +63,9 @@ import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.user.AccountManager;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DomainRouterVO;
@ -68,12 +74,13 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
@Local(value=NetworkElement.class)
public class VirtualRouterElement extends DhcpElement implements VirtualRouterElementService, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider {
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider {
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -90,11 +97,17 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
@Inject DomainRouterDao _routerDao;
@Inject LoadBalancerDao _lbDao;
@Inject HostDao _hostDao;
@Inject AccountManager _accountMgr;
@Inject ConfigurationDao _configDao;
@Inject VirtualRouterProviderDao _vrProviderDao;
protected boolean canHandle(GuestType networkType, long offeringId, Service service) {
boolean result = (networkType == Network.GuestType.Isolated && _networkMgr.isProviderSupported(offeringId, service, getProvider()));
boolean result = false;
if (_networkMgr.isProviderSupported(offeringId, service, getProvider())) {
result = true;
}
if (!result) {
s_logger.trace("Virtual router element only takes care of type " + Network.GuestType.Isolated + " for provider " + getProvider().getName());
}
@ -108,6 +121,7 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
}
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramNetwork, true);
_routerMgr.deployVirtualRouter(guestConfig, dest, _accountMgr.getAccount(guestConfig.getAccountId()), params, false);
@ -117,7 +131,7 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network.getGuestType(), network.getNetworkOfferingId(), Service.Gateway)) {
if (canHandle(network.getGuestType(), network.getNetworkOfferingId(), Service.Dhcp)) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
@ -128,6 +142,16 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
if ((routers == null) || (routers.size() == 0)) {
throw new ResourceUnavailableException("Can't find at least one running router!", this.getClass(), 0);
}
//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();
DataCenter dc = dest.getDataCenter();
boolean isPodBased = (dc.getNetworkType() == NetworkType.Basic || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && network.getTrafficType() == TrafficType.Guest;
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.DHCP_USERDATA);
routers.addAll(allRunningRoutersOutsideThePod);
}
List<VirtualRouter> rets = _routerMgr.addVirtualMachineIntoNetwork(network, nic, uservm, dest, context, routers);
return (rets != null) && (!rets.isEmpty());
} else {
@ -444,4 +468,15 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.VirtualRouterElement);
return vr.getId();
}
@Override
public VirtualRouterProvider getCreatedElement(long id) {
return _vrProviderDao.findById(id);
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
return true;
}
}

View File

@ -70,7 +70,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
List<DomainRouterVO> deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
//List<DomainRouterVO> deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
List<VirtualRouter> addVirtualMachineIntoNetwork(Network config, NicProfile nic, VirtualMachineProfile<UserVm> vm, DeployDestination dest, ReservationContext context, List<DomainRouterVO> routers) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;

View File

@ -1031,8 +1031,28 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
long dcId = dest.getDataCenter().getId();
DataCenterDeployment plan = new DataCenterDeployment(dcId);
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMgr.isServiceSupportedByNetworkOffering(guestNetwork.getNetworkOfferingId(), Service.SecurityGroup)) && guestNetwork.getTrafficType() == TrafficType.Guest;
boolean publicNetwork = false;
if (_networkMgr.isServiceSupportedByNetworkOffering(guestNetwork.getNetworkOfferingId(), Service.SourceNat)) {
publicNetwork = true;
}
if (isRedundant && !publicNetwork) {
s_logger.error("Didn't support redundant virtual router without public network!");
return null;
}
List<DomainRouterVO> routers;
if (publicNetwork) {
routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
} else {
Long podId = dest.getPod().getId();
if (isPodBased) {
routers = _routerDao.listByNetworkAndPodAndRole(guestNetwork.getId(), podId, Role.DHCP_USERDATA);
plan = new DataCenterDeployment(dcId, podId, null, null, null, null);
} else {
routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.DHCP_USERDATA);
plan = new DataCenterDeployment(dcId);
}
}
try {
int routerCount = 1;
@ -1058,7 +1078,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
NicProfile defaultNic = new NicProfile();
//if source nat service is supported by the network, get the source nat ip address
if (_networkMgr.isServiceSupportedByNetworkOffering(guestNetwork.getNetworkOfferingId(), Service.SourceNat)) {
if (publicNetwork) {
PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountService.getSystemUser().getId());
defaultNic.setDefaultNic(true);
defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
@ -1086,21 +1106,38 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false, false).get(0);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
List<NetworkVO> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false, false);
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), defaultNic));
NicProfile gatewayNic = new NicProfile();
if (isRedundant) {
gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null));
} else {
gatewayNic.setIp4Address(guestNetwork.getGateway());
if (publicNetwork) {
NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
List<NetworkVO> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false, false);
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), defaultNic));
}
String defaultNetworkStartIp = null;
if (guestNetwork.getCidr() != null && !publicNetwork) {
String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId());
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
defaultNetworkStartIp = startIp;
} else if (s_logger.isDebugEnabled()){
s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ip address from the range");
}
}
NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp);
if (publicNetwork) {
if (isRedundant) {
gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null));
} else {
gatewayNic.setIp4Address(guestNetwork.getGateway());
}
gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
gatewayNic.setMode(guestNetwork.getMode());
String gatewayCidr = guestNetwork.getCidr();
gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
} else {
gatewayNic.setDefaultNic(true);
}
gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
gatewayNic.setMode(guestNetwork.getMode());
String gatewayCidr = guestNetwork.getCidr();
gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
@ -1135,6 +1172,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, routerOffering.getOfferHA(), false);
if (!publicNetwork) {
router.setRole(Role.DHCP_USERDATA);
}
router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner);
break;
} catch (InsufficientCapacityException ex) {
@ -1236,6 +1276,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
@Override
public List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params, boolean isRedundant) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(guestNetwork.getNetworkOfferingId());
if (offering.isSystemOnly() || guestNetwork.getGuestType() == Network.GuestType.Shared) {
owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Starting a router for " + guestNetwork + " in " + dest);
}
@ -1272,6 +1317,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return runningRouters;
}
/*
List<DomainRouterVO> findOrCreateDhcpServers(Network guestNetwork, DeployDestination dest, Account owner) throws ConcurrentOperationException, InsufficientCapacityException {
Network network = _networkDao.acquireInLockTable(guestNetwork.getId());
if (network == null) {
@ -1340,7 +1386,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
for (HypervisorType hType : supportedHypervisors) {
try {
s_logger.debug("Allocating the domR with the hypervisor type " + hType);
/* Before starting router, already know the hypervisor type */
VMTemplateVO template = _templateDao.findRoutingTemplate(hType);
//physical network id can be null in Guest Network in Basic zone, so locate the physical network
@ -1421,6 +1466,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return runningRouters;
}
*/
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {

View File

@ -834,14 +834,14 @@ public class ConfigurationServerImpl implements ConfigurationServer {
//populate providers
Map<Network.Service, Network.Provider> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
defaultSharedNetworkOfferingProviders.put(Service.Dhcp, Provider.DhcpServer);
defaultSharedNetworkOfferingProviders.put(Service.Dns, Provider.DhcpServer);
defaultSharedNetworkOfferingProviders.put(Service.UserData, Provider.DhcpServer);
defaultSharedNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
defaultSharedNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
defaultSharedNetworkOfferingProviders.put(Service.UserData, Provider.VirtualRouter);
Map<Network.Service, Network.Provider> defaultSharedSGNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
defaultSharedSGNetworkOfferingProviders.put(Service.Dhcp, Provider.DhcpServer);
defaultSharedSGNetworkOfferingProviders.put(Service.Dns, Provider.DhcpServer);
defaultSharedSGNetworkOfferingProviders.put(Service.UserData, Provider.DhcpServer);
defaultSharedSGNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
defaultSharedSGNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
defaultSharedSGNetworkOfferingProviders.put(Service.UserData, Provider.VirtualRouter);
defaultSharedSGNetworkOfferingProviders.put(Service.SecurityGroup, Provider.SecurityGroupProvider);
Map<Network.Service, Network.Provider> defaultIsolatedNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();