Make the changes to the core networks to support the capabilities.

This commit is contained in:
Hugo Trippaers 2013-10-29 17:35:42 +01:00
parent e1aba6aea3
commit 7c2077ff91
8 changed files with 468 additions and 188 deletions

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
@ -37,12 +40,14 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.NetworkModel;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
@ -57,6 +62,16 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value={NetworkGuru.class})
public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Basic, NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated, GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN,
IsolationMethod.NONE);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Control);
@Inject DataCenterDao _dcDao;
@Inject ConfigurationDao _configDao;
@Inject NetworkModel _networkMgr;
@ -236,4 +251,24 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
return true;
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,12 +16,15 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import com.cloud.dc.DataCenter;
@ -46,6 +49,7 @@ import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkVO;
@ -57,7 +61,6 @@ import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionCallbackWithException;
import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.ExceptionUtil;
@ -75,6 +78,14 @@ import com.cloud.vm.dao.NicSecondaryIpDao;
public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(DirectNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Guest);
@Inject
DataCenterDao _dcDao;
@Inject
@ -99,22 +110,22 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
IpAddressManager _ipAddrMgr;
private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// this guru handles only Guest networks in Advance zone with source nat service disabled
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == GuestType.Shared) {
@ -171,9 +182,9 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
boolean isSecurityGroupEnabled = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.SecurityGroup);
if (isSecurityGroupEnabled) {
if (userSpecified.getIp6Cidr() != null) {
if (userSpecified.getIp6Cidr() != null) {
throw new InvalidParameterValueException("Didn't support security group with IPv6");
}
}
config.setName("SecurityGroupEnabledNetwork");
config.setDisplayText("SecurityGroupEnabledNetwork");
}
@ -198,7 +209,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
@ -271,11 +282,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @DB
public void deallocate(final Network network, final NicProfile nic, VirtualMachineProfile vm) {
if (s_logger.isDebugEnabled()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
}
if (nic.getIp4Address() != null) {
if (nic.getIp4Address() != null) {
final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null) {
Transaction.execute(new TransactionCallbackNoReturn() {
@ -289,7 +300,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
}
//unassign nic secondary ip address
s_logger.debug("remove nic " + nic.getId() + " secondary ip ");
List<String> nicSecIps = null;
@ -302,11 +313,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
}
});
}
}
if (nic.getIp6Address() != null) {
_ipv6Mgr.revokeDirectIpv6Address(nic.getNetworkId(), nic.getIp6Address());
}
}
if (nic.getIp6Address() != null) {
_ipv6Mgr.revokeDirectIpv6Address(nic.getNetworkId(), nic.getIp6Address());
}
nic.deallocate();
}
@ -344,4 +355,25 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2());
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -17,12 +17,15 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import com.cloud.configuration.ZoneConfig;
@ -42,9 +45,12 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.IpAddressManager;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
@ -67,6 +73,15 @@ import com.cloud.vm.VirtualMachineProfile;
public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
private static final Logger s_logger = Logger.getLogger(DirectPodBasedNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Basic);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated, GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN,
IsolationMethod.NONE);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Guest);
@Inject
DataCenterDao _dcDao;
@Inject
@ -95,7 +110,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenterVO dc = _dcDao.findById(network.getDataCenterId());
ReservationStrategy rsStrategy = ReservationStrategy.Start;
@ -127,10 +142,10 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
@Override @DB
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
String oldIp = nic.getIp4Address();
boolean getNewIp = false;
if (oldIp == null) {
getNewIp = true;
} else {
@ -166,7 +181,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
@DB
protected void getIp(final NicProfile nic, final Pod pod, final VirtualMachineProfile vm, final Network network) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
InsufficientAddressCapacityException, ConcurrentOperationException {
final DataCenter dc = _dcDao.findById(pod.getDataCenterId());
if (nic.getIp4Address() == null) {
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {
@ -187,11 +202,11 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
s_logger.debug("Nic got an ip address " + placeholderNic.getIp4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
}
}
if (ip == null) {
ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
}
nic.setIp4Address(ip.getAddress().toString());
nic.setFormat(AddressFormat.Ip4);
nic.setGateway(ip.getGateway());
@ -203,7 +218,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
}
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
//save the placeholder nic if the vm is the Virtual router
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
@ -219,4 +234,24 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
nic.setDns2(dc.getDns2());
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
@ -42,6 +44,7 @@ import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.State;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.IPAddressDao;
@ -65,6 +68,16 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class)
public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
private static final Logger s_logger = Logger.getLogger(ExternalGuestNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.GRE, IsolationMethod.L3,
IsolationMethod.VLAN);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Guest);
@Inject
NetworkOrchestrationService _networkMgr;
@Inject
@ -139,11 +152,11 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
int vlanTag;
if (config.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), context.getReservationId(),
UseSystemGuestVlans.valueIn(config.getAccountId()));
UseSystemGuestVlans.valueIn(config.getAccountId()));
try {
// when supporting more types of networks this need to become
// int vlantag = Integer.parseInt(BroadcastDomainType.getValue(vnet));
// int vlantag = Integer.parseInt(BroadcastDomainType.getValue(vnet));
vlanTag = Integer.parseInt(vnet);
} catch (NumberFormatException e) {
throw new CloudRuntimeException("Obtained an invalid guest vlan tag. Exception: " + e.getMessage());
@ -219,7 +232,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
@Override
public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
InsufficientAddressCapacityException {
if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId()) && nic != null && nic.getRequestedIpv4() != null) {
throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
@ -318,4 +331,24 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
return NetUtils.ip2Long(ipAddress) & ~(0xffffffffffffffffl << (32 - cidrSize));
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import javax.ejb.Local;
@ -23,6 +26,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Pod;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DeployDestination;
@ -30,13 +34,15 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.StorageNetworkManager;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@ -46,45 +52,54 @@ import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value={NetworkGuru.class})
public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(PodBasedNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Basic, NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated, GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN,
IsolationMethod.NONE);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Management);
@Inject DataCenterDao _dcDao;
@Inject StorageNetworkManager _sNwMgr;
Random _rand = new Random(System.currentTimeMillis());
private static final TrafficType[] _trafficTypes = {TrafficType.Management};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
return _trafficTypes;
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
TrafficType type = offering.getTrafficType();
if (!isMyTrafficType(type)) {
return null;
}
NetworkVO config = new NetworkVO(type, Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup, plan.getDataCenterId(), plan.getPhysicalNetworkId());
return config;
}
protected PodBasedNetworkGuru() {
super();
}
@ -92,13 +107,13 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) {
}
@Override
public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
InsufficientAddressCapacityException {
TrafficType trafficType = config.getTrafficType();
assert trafficType == TrafficType.Management || trafficType == TrafficType.Storage: "Well, I can't take care of this config now can I? " + config;
assert trafficType == TrafficType.Management || trafficType == TrafficType.Storage: "Well, I can't take care of this config now can I? " + config;
if (nic != null) {
if (nic.getRequestedIpv4() != null) {
throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
@ -106,21 +121,21 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setStrategy(nic.getIp4Address() != null ? ReservationStrategy.Create : ReservationStrategy.Start);
} else {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
}
return nic;
}
@Override
public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
InsufficientAddressCapacityException {
Pod pod = dest.getPod();
Pair<String, Long> ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId());
if (ip == null) {
throw new InsufficientAddressCapacityException("Unable to get a management ip address", Pod.class, pod.getId());
}
nic.setIp4Address(ip.first());
nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.second())));
nic.setGateway(pod.getGateway());
@ -130,29 +145,29 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setBroadcastType(BroadcastDomainType.Native);
nic.setBroadcastUri(null);
nic.setIsolationUri(null);
s_logger.debug("Allocated a nic " + nic + " for " + vm);
}
@Override
public void updateNicProfile(NicProfile profile, Network network) {
}
@Override
public void updateNetworkProfile(NetworkProfile networkProfile) {
}
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
_dcDao.releasePrivateIpAddress(nic.getId(), nic.getReservationId());
nic.deallocate();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Released nic: " + nic);
}
return true;
}
@ -160,13 +175,34 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
return config;
}
@Override
public void shutdown(NetworkProfile config, NetworkOffering offering) {
}
@Override
public boolean trash(Network config, NetworkOffering offering) {
return true;
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,6 +16,10 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
@ -39,6 +43,7 @@ import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.vpc.PrivateIpAddress;
import com.cloud.network.vpc.PrivateIpVO;
@ -57,6 +62,15 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class)
public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(PrivateNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Guest);
@Inject
protected ConfigurationManager _configMgr;
@Inject
@ -222,7 +236,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm,
DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
if (nic.getIp4Address() == null) {
getIp(nic, _entityMgr.findById(DataCenter.class, network.getDataCenterId()), network);
nic.setStrategy(ReservationStrategy.Create);
@ -250,4 +264,25 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2());
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,13 +16,19 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
@ -33,6 +39,7 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.IpAddressManager;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.AddressFormat;
@ -40,6 +47,7 @@ import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
@ -62,6 +70,15 @@ import com.cloud.vm.VirtualMachineProfile;
public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(PublicNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Basic, NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated, GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN,
IsolationMethod.NONE);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Public);
@Inject
DataCenterDao _dcDao;
@Inject
@ -143,7 +160,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
@ -204,7 +221,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
});
}
nic.deallocate();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deallocated nic: " + nic);
}
@ -226,4 +243,24 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns2(dc.getDns2());
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}

View File

@ -16,11 +16,16 @@
// under the License.
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Pod;
import com.cloud.dc.StorageNetworkIpAddressVO;
import com.cloud.deploy.DeployDestination;
@ -28,164 +33,196 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.StorageNetworkManager;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.Nic.ReservationStrategy;
@Local(value = NetworkGuru.class)
public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(StorageNetworkGuru.class);
@Inject StorageNetworkManager _sNwMgr;
@Inject NetworkDao _nwDao;
protected StorageNetworkGuru() {
super();
}
private static final Logger s_logger = Logger.getLogger(StorageNetworkGuru.class);
/**
* The supported networking configs
*/
private static final EnumSet<NetworkType> _supportedNetworkTypes = EnumSet.of(NetworkType.Basic, NetworkType.Advanced);
private static final EnumSet<GuestType> _supportedGuestTypes = EnumSet.of(GuestType.Isolated, GuestType.Shared);
private static final EnumSet<IsolationMethod> _supportedIsolationMethods = EnumSet.of(IsolationMethod.VLAN,
IsolationMethod.NONE);
private static final EnumSet<TrafficType> _supportedTrafficTypes = EnumSet.of(TrafficType.Storage);
@Inject
StorageNetworkManager _sNwMgr;
@Inject NetworkDao _nwDao;
protected StorageNetworkGuru() {
super();
}
private static final TrafficType[] _trafficTypes = {TrafficType.Storage};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering) {
if (isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("It's not storage network offering, skip it.");
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
if (!canHandle(offering)) {
return null;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup,
plan.getDataCenterId(), plan.getPhysicalNetworkId());
return config;
}
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException {
assert network.getTrafficType() == TrafficType.Storage : "Why are you sending this configuration to me " + network;
if (!_sNwMgr.isStorageIpRangeAvailable(destination.getDataCenter().getId())) {
return super.implement(network, offering, destination, context);
}
return network;
}
protected boolean canHandle(NetworkOffering offering) {
if (isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("It's not storage network offering, skip it.");
return false;
}
}
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Storage : "Well, I can't take care of this config now can I? " + network;
if (!_sNwMgr.isStorageIpRangeAvailable(network.getDataCenterId())) {
return super.allocate(network, nic, vm);
}
return new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
if (!canHandle(offering)) {
return null;
}
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) {
super.reserve(nic, network, vm, dest, context);
return;
}
Pod pod = dest.getPod();
Integer vlan = null;
StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
if (ip == null) {
throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
}
vlan = ip.getVlan();
nic.setIp4Address(ip.getIpAddress());
nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac())));
nic.setFormat(AddressFormat.Ip4);
nic.setNetmask(ip.getNetmask());
nic.setBroadcastType(BroadcastDomainType.Storage);
nic.setGateway(ip.getGateway());
if (vlan != null) {
nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
} else {
nic.setBroadcastUri(null);
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup,
plan.getDataCenterId(), plan.getPhysicalNetworkId());
return config;
}
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException {
assert network.getTrafficType() == TrafficType.Storage : "Why are you sending this configuration to me " + network;
if (!_sNwMgr.isStorageIpRangeAvailable(destination.getDataCenter().getId())) {
return super.implement(network, offering, destination, context);
}
return network;
}
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Storage : "Well, I can't take care of this config now can I? " + network;
if (!_sNwMgr.isStorageIpRangeAvailable(network.getDataCenterId())) {
return super.allocate(network, nic, vm);
}
return new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) {
super.reserve(nic, network, vm, dest, context);
return;
}
Pod pod = dest.getPod();
Integer vlan = null;
StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
if (ip == null) {
throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
}
vlan = ip.getVlan();
nic.setIp4Address(ip.getIpAddress());
nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac())));
nic.setFormat(AddressFormat.Ip4);
nic.setNetmask(ip.getNetmask());
nic.setBroadcastType(BroadcastDomainType.Storage);
nic.setGateway(ip.getGateway());
if (vlan != null) {
nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
} else {
nic.setBroadcastUri(null);
}
nic.setIsolationUri(null);
s_logger.debug("Allocated a storage nic " + nic + " for " + vm);
}
}
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
Network nw = _nwDao.findById(nic.getNetworkId());
if (!_sNwMgr.isStorageIpRangeAvailable(nw.getDataCenterId())) {
return super.release(nic, vm, reservationId);
}
_sNwMgr.releaseIpAddress(nic.getIp4Address());
s_logger.debug("Release an storage ip " + nic.getIp4Address());
nic.deallocate();
return true;
}
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
Network nw = _nwDao.findById(nic.getNetworkId());
if (!_sNwMgr.isStorageIpRangeAvailable(nw.getDataCenterId())) {
return super.release(nic, vm, reservationId);
}
@Override
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
// TODO Auto-generated method stub
_sNwMgr.releaseIpAddress(nic.getIp4Address());
s_logger.debug("Release an storage ip " + nic.getIp4Address());
nic.deallocate();
return true;
}
}
@Override
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
// TODO Auto-generated method stub
@Override
public void updateNicProfile(NicProfile profile, Network network) {
// TODO Auto-generated method stub
}
}
@Override
public void updateNicProfile(NicProfile profile, Network network) {
// TODO Auto-generated method stub
@Override
public void shutdown(NetworkProfile network, NetworkOffering offering) {
// TODO Auto-generated method stub
}
}
@Override
public void shutdown(NetworkProfile network, NetworkOffering offering) {
// TODO Auto-generated method stub
@Override
public boolean trash(Network network, NetworkOffering offering) {
// TODO Auto-generated method stub
return false;
}
}
@Override
public void updateNetworkProfile(NetworkProfile networkProfile) {
// TODO Auto-generated method stub
@Override
public boolean trash(Network network, NetworkOffering offering) {
// TODO Auto-generated method stub
return false;
}
}
@Override
public void updateNetworkProfile(NetworkProfile networkProfile) {
// TODO Auto-generated method stub
}
@Override
public List<NetworkType> getSupportedNetworkTypes() {
return new ArrayList<NetworkType>(_supportedNetworkTypes);
}
@Override
public List<TrafficType> getSupportedTrafficTypes() {
return new ArrayList<TrafficType>(_supportedTrafficTypes);
}
@Override
public List<GuestType> getSupportedGuestTypes() {
return new ArrayList<GuestType>(_supportedGuestTypes);
}
@Override
public List<IsolationMethod> getSupportedIsolationMethods() {
return new ArrayList<IsolationMethod>(_supportedIsolationMethods);
}
}