bug 12869: more changes to NAAS feature

This commit is contained in:
Alena Prokharchyk 2012-01-20 14:13:52 -08:00
parent d9a2ed664d
commit 8bcf30da85
25 changed files with 267 additions and 231 deletions

View File

@ -324,6 +324,7 @@ public class ApiConstants {
public static final String KEYWORD = "keyword";
public static final String LIST_ALL = "listall";
public static final String IS_ELASTIC = "iselastic";
public static final String SPECIFY_IP_RANGES = "specifyipranges";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -89,6 +89,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
private Map serviceCapabilitystList;
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to false if not specified")
private Boolean specifyIpRanges;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -137,6 +140,10 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public String getGuestIpType() {
return guestIptype;
}
public Boolean getSpecifyIpRanges() {
return specifyIpRanges == null ? false : specifyIpRanges;
}
public Boolean getConserveMode() {
if (conserveMode == null) {

View File

@ -28,6 +28,7 @@ import com.cloud.api.BaseListCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.NetworkOfferingResponse;
import com.cloud.offering.NetworkOffering;
@ -85,6 +86,9 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only network offerings which support specifying ip ranges")
private Boolean specifyIpRanges;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -140,6 +144,10 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
public Boolean getSourceNatSupported() {
return sourceNatSupported;
}
public Boolean getSpecifyIpRanges() {
return specifyIpRanges;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -28,6 +28,7 @@ import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.NetworkResponse;
import com.cloud.network.Network;
@ -70,6 +71,9 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
@Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list network offerings by restartRequired option")
private Boolean restartRequired;
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges")
private Boolean specifyIpRanges;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -110,6 +114,10 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
public Boolean getRestartRequired() {
return restartRequired;
}
public Boolean getSpecifyIpRanges() {
return specifyIpRanges;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -54,6 +54,9 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName(ApiConstants.CONSERVE_MODE) @Param(description="true if network offering is ip conserve mode enabled")
private Boolean conserveMode;
@SerializedName(ApiConstants.SPECIFY_IP_RANGES) @Param(description="true if network offering supports specifying ip ranges, false otherwise")
private Boolean specifyIpRanges;
@SerializedName(ApiConstants.AVAILABILITY) @Param(description="availability of the network offering")
private String availability;
@ -72,6 +75,7 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class)
private List<ServiceResponse> services;
public void setId(Long id) {
this.id.setValue(id);
@ -132,4 +136,12 @@ public class NetworkOfferingResponse extends BaseResponse{
public void setServiceOfferingId(Long serviceOfferingId) {
this.serviceOfferingId.setValue(serviceOfferingId);
}
public void setServiceOfferingId(IdentityProxy serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}
public void setSpecifyIpRanges(Boolean specifyIpRanges) {
this.specifyIpRanges = specifyIpRanges;
}
}

View File

@ -130,6 +130,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
@SerializedName(ApiConstants.RESTART_REQUIRED) @Param(description="true network requires restart")
private Boolean restartRequired;
@SerializedName(ApiConstants.SPECIFY_IP_RANGES) @Param(description="true if network supports specifying ip ranges, false otherwise")
private Boolean specifyIpRanges;
public void setId(Long id) {
this.id.setValue(id);
}
@ -267,4 +270,8 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
public void setRestartRequired(Boolean restartRequired) {
this.restartRequired = restartRequired;
}
public void setSpecifyIpRanges(Boolean specifyIpRanges) {
this.specifyIpRanges = specifyIpRanges;
}
}

View File

@ -289,4 +289,6 @@ public interface Network extends ControlledEntity {
boolean isSpecifiedCidr();
boolean isRestartRequired();
boolean getSpecifyIpRanges();
}

View File

@ -50,6 +50,7 @@ public class NetworkProfile implements Network {
private ACLType aclType;
private boolean specifiedCidr;
private boolean restartRequired;
private boolean specifyIpRanges;
public NetworkProfile(Network network) {
this.id = network.getId();
@ -74,6 +75,7 @@ public class NetworkProfile implements Network {
this.aclType = network.getAclType();
this.specifiedCidr = network.isSpecifiedCidr();
this.restartRequired = network.isRestartRequired();
this.specifyIpRanges = network.getSpecifyIpRanges();
}
public String getDns1() {
@ -216,4 +218,10 @@ public class NetworkProfile implements Network {
return false;
}
@Override
public boolean getSpecifyIpRanges() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -32,7 +32,6 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
import com.cloud.utils.net.Ip4Address;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
@ -137,25 +136,6 @@ public interface NetworkGuru extends Adapter {
* to be assigned.
*/
NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* NetworkGuru is asked to acquire an IPv4 address.
* @param network guest network that this IPv4 address is acquired in.
* @param requestedIp ip address that is being requested.
* @param reservationId id used to refer to this reservation.
* @return Ip4Address ipv4 address
*/
Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException;
/**
* Release the IPv4 address acquired.
*
* @param network guest network that it was acquired in.
* @param reservationId reservation id that it was acquired in.
* @return true if release was successful; false if not.
*/
boolean releaseIp4Address(Network network, String reservationId);
/**
* Once a guest network is implemented, then the virtual machine must

View File

@ -102,4 +102,6 @@ public interface NetworkOffering {
boolean getElasticIp();
boolean getElasticLb();
boolean getSpecifyIpRanges();
}

View File

@ -2585,6 +2585,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setIsDefault(offering.isDefault());
response.setSpecifyVlan(offering.getSpecifyVlan());
response.setConserveMode(offering.isConserveMode());
response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
response.setAvailability(offering.getAvailability().toString());
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
if (offering.getServiceOfferingId() != null) {
@ -2771,6 +2772,8 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setDomainId(dedicatedDomainId);
response.setDomainName(domain.getName());
}
response.setSpecifyIpRanges(network.getSpecifyIpRanges());
response.setObjectName("network");
return response;

View File

@ -180,15 +180,16 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* @param type TODO
* @param systemOnly TODO
* @param serviceOfferingId
* @param specifyIpRanges TODO
* @param id
* @param specifyVlan;
* @param conserveMode;
* @return network offering object
*/
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap);
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges);
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId, Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, long networkId, Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException;

View File

@ -2035,7 +2035,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (forVirtualNetwork) {
//default physical network with public traffic in the zone
physicalNetworkId = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId();
}else{
} else {
if (zone.getNetworkType() == DataCenter.NetworkType.Basic) {
//default physical network with guest traffic in the zone
physicalNetworkId = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
@ -2084,6 +2084,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + " with type: " + network.getGuestType());
}
}
if (network == null) {
network = _networkMgr.getNetwork(networkId);
}
//Can add vlan range only to the network which allows it
if (!network.getSpecifyIpRanges()) {
throw new InvalidParameterValueException("Network " + network + " doesn't support adding multiple ip ranges");
}
// if end ip is not specified, default it to startIp
if (endIP == null && startIP != null) {
@ -2195,7 +2204,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@Override
@DB
public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId,
Account account, Long networkId, Long physicalNetworkId) {
Account account, long networkId, Long physicalNetworkId) {
// Check that the pod ID is valid
if (podId != null && ((_podDao.findById(podId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid pod.");
@ -2898,6 +2907,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
TrafficType trafficType = null;
Availability availability = null;
Network.GuestType guestType = null;
boolean specifyIpRanges = cmd.getSpecifyIpRanges();
// Verify traffic type
for (TrafficType tType : TrafficType.values()) {
@ -3048,7 +3058,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap);
return createNetworkOffering(userId, name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType,
false, serviceOfferingId, conserveMode, serviceCapabilityMap);
false, serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges);
}
void validateLoadBalancerServiceCapabilities(Map<Capability, String> lbServiceCapabilityMap) {
@ -3131,7 +3141,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@DB
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability,
Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly,
Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap) {
Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges) {
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
@ -3195,7 +3205,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
}
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb);
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges);
if (serviceOfferingId != null) {
offering.setServiceOfferingId(serviceOfferingId);
@ -3251,6 +3261,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
Long networkId = cmd.getNetworkId();
String guestIpType = cmd.getGuestIpType();
List<String> supportedServicesStr = cmd.getSupportedServices();
Object specifyIpRanges = cmd.getSpecifyIpRanges();
if (zoneId != null) {
zone = getZone(zoneId);
@ -3300,6 +3311,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (state != null) {
sc.addAnd("state", SearchCriteria.Op.EQ, state);
}
if (specifyIpRanges != null) {
sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
}
if (zone != null) {
if (zone.getNetworkType() == NetworkType.Basic) {

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set;
import com.cloud.acl.ControlledEntity.ACLType;
import com.cloud.dc.DataCenter;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.deploy.DataCenterDeployment;
@ -33,6 +34,7 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.Capability;
@ -287,4 +289,10 @@ public interface NetworkManager extends NetworkService {
boolean handleElasticIpRelease(IpAddress ip);
void checkNetworkPermissions(Account owner, Network network);
void allocateDirectIp(NicProfile nic, DataCenter dc,
VirtualMachineProfile<? extends VirtualMachine> vm,
Network network, String requestedIp)
throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException;
}

View File

@ -95,6 +95,7 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
@ -111,6 +112,7 @@ import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
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.BroadcastDomainRange;
import com.cloud.network.addr.PublicIp;
@ -1136,16 +1138,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
_cidrLimit = NumbersUtil.parseInt(_configs.get(Config.NetworkGuestCidrLimit.key()), 22);
_networkLockTimeout = NumbersUtil.parseInt(_configs.get(Config.NetworkLockTimeout.key()), 600);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, true);
publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemPublicNetwork, publicNetworkOffering);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, false);
managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemManagementNetwork, managementNetworkOffering);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, false);
controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemControlNetwork, controlNetworkOffering);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, true);
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemStorageNetwork, storageNetworkOffering);
@ -1188,25 +1190,25 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkOfferingVO offering = null;
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null);
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null);
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) {
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null);
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) {
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null);
offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1405,7 +1407,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
txn.start();
NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, predefined.getNetworkDomain(),
offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType);
offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges());
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
if (domainId != null && aclType == ACLType.Domain) {
@ -2127,8 +2129,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
throw new InvalidParameterValueException("AclType should be " + ACLType.Account + " for network of type " + Network.GuestType.Isolated);
}
} else if (networkOffering.getGuestType() == GuestType.Shared) {
if (aclType != ACLType.Domain) {
throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " for network of type " + Network.GuestType.Shared);
if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) {
throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + ACLType.Account + " for network of type " + Network.GuestType.Shared);
}
}
} else {
@ -2137,7 +2139,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} else if (networkOffering.getGuestType() == GuestType.Shared) {
aclType = ACLType.Domain;
}
}
}
//Only Admin can create Shared networks
if (networkOffering.getGuestType() == GuestType.Shared && !_accountMgr.isAdmin(caller.getType())) {
throw new InvalidParameterValueException("Only Admins can create network with guest type " + GuestType.Shared);
}
// Check if the network is domain specific
if (aclType == ACLType.Domain) {
@ -2236,6 +2243,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (cidr != null) {
checkVirtualNetworkCidrOverlap(zoneId, cidr);
}
//Vlan is created in 2 cases - works in Advance zone only:
//1) GuestType is Shared
//2) GuestType is Isolated, but SourceNat service is disabled
boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced
&& ((networkOffering.getGuestType() == Network.GuestType.Shared)
|| (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))));
//Can add vlan range only to the network which allows it
if (createVlan && !networkOffering.getSpecifyIpRanges()) {
throw new InvalidParameterValueException("Network offering " + networkOffering + " doesn't support adding multiple ip ranges");
}
Transaction txn = Transaction.currentTxn();
txn.start();
@ -2256,13 +2274,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
Network network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, false, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess);
//Vlan is created in 2 cases - works in Advance zone only:
//1) GuestType is Shared
//2) GuestType is Isolated, but SourceNat service is disabled
boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced
&& ((network.getGuestType() == Network.GuestType.Shared)
|| (network.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))));
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
// Create vlan ip range
_configMgr.createVlanAndPublicIpRange(userId, pNtwk.getDataCenterId(), null, startIP, endIP, gateway, netmask, false, vlanId, null, network.getId(), physicalNetworkId);
@ -2343,8 +2355,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
// VlanId can be specified only when network offering supports it
if (vlanId != null && !networkOffering.getSpecifyVlan()) {
throw new InvalidParameterValueException("Can't specify vlan because network offering doesn't support it");
boolean vlanSpecified = (vlanId != null);
if (vlanSpecified != networkOffering.getSpecifyVlan()) {
if (vlanSpecified) {
throw new InvalidParameterValueException("Can't specify vlan; corresponding offering says specifyVlan=false");
} else {
throw new InvalidParameterValueException("Vlan has to be specified; corresponding offering says specifyVlan=true");
}
}
// Don't allow to create network with vlan that already exists in the system
@ -2474,6 +2491,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Boolean restartRequired= cmd.getRestartRequired();
boolean listAll = cmd.listAll();
boolean isRecursive = cmd.isRecursive();
Boolean specifyIpRanges = cmd.getSpecifyIpRanges();
//1) default is system to false if not specified
//2) reset parameter to false if it's specified by the regular user
@ -2563,17 +2581,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (isSystem == null || !isSystem) {
//Get domain level networks
if (domainId != null) {
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, domainId));
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, domainId));
}
if (!permittedAccounts.isEmpty()) {
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, permittedAccounts));
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, permittedAccounts));
} else if (domainId == null){
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, path, isRecursive));
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, path, isRecursive));
}
} else {
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired), searchFilter);
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter);
}
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
@ -2602,7 +2619,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired) {
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges) {
SearchCriteria<NetworkVO> sc = sb.create();
if (isSystem != null) {
@ -2646,6 +2663,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (restartRequired != null) {
sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired);
}
if (specifyIpRanges != null) {
sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
}
return sc;
}
@ -4193,6 +4214,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return false;
}
//specify vlan should be the same
if (oldNetworkOffering.getSpecifyVlan() != newNetworkOffering.getSpecifyVlan()) {
s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different values for specifyVlan, can't upgrade");
return false;
}
//specify ipRanges should be the same
if (oldNetworkOffering.getSpecifyIpRanges() != newNetworkOffering.getSpecifyIpRanges()) {
s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different values for specifyIpRangess, can't upgrade");
return false;
}
//Check all ips
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
List<PublicIp> publicIps = new ArrayList<PublicIp>();
@ -5908,7 +5941,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (network.getGuestType() != Network.GuestType.Shared) {
List<NetworkVO> networkMap = _networksDao.listBy(owner.getId(), network.getId());
if (networkMap == null || networkMap.isEmpty()) {
throw new PermissionDeniedException("Unable to create a vm using network with id " + network.getId() + ", permission denied");
throw new PermissionDeniedException("Unable to use network with id= " + network.getId() + ", permission denied");
}
} else {
if (!isNetworkAvailableInDomain(network.getId(), owner.getDomainId())) {
@ -5916,5 +5949,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
}
public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
if (nic.getIp4Address() == null) {
PublicIp ip = assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIp, false);
nic.setIp4Address(ip.getAddress().toString());
nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask());
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
}
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
}
}

View File

@ -148,6 +148,9 @@ public class NetworkVO implements Network, Identity {
@Column(name="restart_required")
boolean restartRequired = false;
@Column(name="specify_ip_ranges")
boolean specifyIpRanges = false;
public NetworkVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -175,12 +178,11 @@ public class NetworkVO implements Network, Identity {
this.state = state;
}
this.id = -1;
this.guestType = guestType;
this.uuid = UUID.randomUUID().toString();
}
public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType) {
this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, related, name, displayText, networkDomain,guestType, dcId, physicalNetworkId, aclType);
public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) {
this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges);
this.gateway = that.getGateway();
this.cidr = that.getCidr();
this.broadcastUri = that.getBroadcastUri();
@ -207,11 +209,12 @@ public class NetworkVO implements Network, Identity {
* @param networkDomain
* @param guestType TODO
* @param aclType TODO
* @param specifyIpRanges TODO
* @param isShared TODO
* @param isShared
* @param dataCenterId
*/
public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType) {
public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) {
this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId);
this.domainId = domainId;
this.accountId = accountId;
@ -224,6 +227,7 @@ public class NetworkVO implements Network, Identity {
this.uuid = UUID.randomUUID().toString();
this.guestType = guestType;
this.specifiedCidr = false;
this.specifyIpRanges = specifyIpRanges;
}
@Override
@ -485,4 +489,9 @@ public class NetworkVO implements Network, Identity {
public boolean isRestartRequired() {
return restartRequired;
}
@Override
public boolean getSpecifyIpRanges() {
return specifyIpRanges;
}
}

View File

@ -23,7 +23,6 @@ import org.apache.log4j.Logger;
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;
import com.cloud.deploy.DeployDestination;
@ -34,17 +33,15 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Service;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkProfile;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.AddressFormat;
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.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -53,7 +50,6 @@ import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.Ip4Address;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@ -94,10 +90,10 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
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 && !_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)&& isMyTrafficType(offering.getTrafficType())) {
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == GuestType.Shared) {
return true;
} else {
s_logger.trace("We only take care of Guest Direct networks");
s_logger.trace("We only take care of Guest networks of type " + GuestType.Shared);
return false;
}
}
@ -151,25 +147,6 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
super();
}
protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
if (nic.getIp4Address() == null) {
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIp, false);
nic.setIp4Address(ip.getAddress().toString());
nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask());
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
}
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
}
@Override
public void updateNicProfile(NicProfile profile, Network network) {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
@ -193,7 +170,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setStrategy(ReservationStrategy.Create);
}
getIp(nic, dc, vm, network, nic.getRequestedIp());
_networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
nic.setStrategy(ReservationStrategy.Create);
return nic;
@ -203,7 +180,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
if (nic.getIp4Address() == null) {
getIp(nic, dest.getDataCenter(), vm, network, null);
_networkMgr.allocateDirectIp(nic, dest.getDataCenter(), vm, network, null);
nic.setStrategy(ReservationStrategy.Create);
}
}
@ -221,7 +198,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @DB
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("direct network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
}
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
@ -250,14 +227,4 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2());
}
@Override public Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException {
// TODO Auto-generated method stub
return null;
}
@Override public boolean releaseIp4Address(Network network, String reservationId) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -39,7 +39,6 @@ import com.cloud.network.Network.State;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkVO;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.PhysicalNetworkDao;
@ -51,6 +50,7 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
@ -89,9 +89,6 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner);
if (config == null) {
return null;
} else {
/* In order to revert userSpecified network setup */
config.setState(State.Allocated);
}
return config;
@ -223,7 +220,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
return profile;
}
@Override
@Override @DB
public void deallocate(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
super.deallocate(config, nic, vm);

View File

@ -17,10 +17,7 @@
*/
package com.cloud.network.guru;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import javax.ejb.Local;
@ -38,8 +35,9 @@ import com.cloud.event.EventVO;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.Network.Service;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkProfile;
@ -48,13 +46,15 @@ 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.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.utils.net.Ip4Address;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
@ -76,6 +76,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
protected NicDao _nicDao;
@Inject
protected NetworkDao _networkDao;
@Inject
IPAddressDao _ipAddressDao;
Random _rand = new Random(System.currentTimeMillis());
private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@ -104,10 +106,10 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// This guru handles only Guest Isolated network that supports Source nat service
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)) {
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated) {
return true;
} else {
s_logger.trace("We only take care of Guest networks with service " + Service.SourceNat + " enabled in zone of type " + NetworkType.Advanced);
s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced);
return false;
}
}
@ -132,7 +134,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
network.setSpecifiedCidr(true);
}
if (userSpecified.getBroadcastUri() != null) {
if (offering.getSpecifyVlan()) {
network.setBroadcastUri(userSpecified.getBroadcastUri());
network.setState(State.Setup);
}
@ -141,8 +143,23 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
return network;
}
@Override
@Override @DB
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
if (network.getSpecifyIpRanges()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
}
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null) {
Transaction txn = Transaction.currentTxn();
txn.start();
_networkMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
txn.commit();
}
nic.deallocate();
}
}
@Override
@ -196,19 +213,24 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setIsolationUri(network.getBroadcastUri());
nic.setGateway(network.getGateway());
String guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to acquire guest IP address for network " + network, DataCenter.class, dc.getId());
String guestIp = null;
if (network.getSpecifyIpRanges()) {
_networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
} else {
guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP address for network " + network, DataCenter.class, dc.getId());
}
nic.setIp4Address(guestIp);
nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
nic.setFormat(AddressFormat.Ip4);
}
nic.setIp4Address(guestIp);
nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
}
nic.setFormat(AddressFormat.Ip4);
}
}
nic.setStrategy(ReservationStrategy.Start);
@ -250,7 +272,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
s_logger.debug("Releasing vnet for the network id=" + profile.getId());
if (profile.getBroadcastUri() != null) {
if (profile.getBroadcastUri() != null && !offering.getSpecifyVlan()) {
_dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId());
EventUtils.saveEvent(UserContext.current().getCallerUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: "
+profile.getBroadcastUri().getHost()+" for Network: "+profile.getId(), 0);
@ -269,50 +291,4 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2());
}
@Override
public Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException {
assert requestedIp == null || requestedIp.equals(reservationId) : "The GuestNetworkGuru relies on the fact that the reservationId is always the same as the requestedIp because at this point, there's no way for the GuestNetworkGuru to record down the reservation id. It can be done but I'm just lazy so don't you be lazy when you hit this assert!";
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
String[] cidr = network.getCidr().split("/");
Set<Long> usedIps = new TreeSet<Long>();
int size = Integer.parseInt(cidr[1]);
// Let's prepare the list of ips already taken.
usedIps.add(NetUtils.ip2Long(network.getGateway()));
for (String ip : ips) {
usedIps.add(NetUtils.ip2Long(ip));
}
if (requestedIp != null) { // Make sure requestedIp is not already taken.
if (usedIps.contains(requestedIp)) {
throw new InsufficientAddressCapacityException("The ip requested " + requestedIp + " is already assigned within " + network, DataCenter.class, network.getDataCenterId());
}
if (!NetUtils.sameSubnetCIDR(requestedIp, cidr[0], size)) {
throw new IllegalArgumentException("The ip requested " + requestedIp + " does not match the cidr, " + network.getCidr() + ", of " + network);
}
return new Ip4Address(requestedIp);
}
long base = NetUtils.ip2Long(cidr[0]);
int diff = 1 << size - usedIps.size();
for (diff = 1 << size - usedIps.size(); diff > 0; diff--) {
long nextIp = _rand.nextInt(1 << size);
nextIp += base;
if (!usedIps.contains(nextIp)) {
return new Ip4Address(nextIp);
}
}
throw new InsufficientAddressCapacityException("Unable to map more ip addresses into a cidr of " + network.getCidr(), DataCenter.class, network.getDataCenterId());
}
@Override public boolean releaseIp4Address(Network network, String reservationId) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -36,18 +36,17 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkProfile;
import com.cloud.network.NetworkVO;
import com.cloud.network.StorageNetworkManager;
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.StorageNetworkManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip4Address;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
@ -176,14 +175,4 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
public boolean trash(Network config, NetworkOffering offering, Account owner) {
return true;
}
@Override public boolean releaseIp4Address(Network network, String reservationId) {
// TODO Auto-generated method stub
return false;
}
@Override public Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -221,14 +221,4 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2());
}
@Override public Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException {
// TODO Auto-generated method stub
return null;
}
@Override public boolean releaseIp4Address(Network network, String reservationId) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -102,18 +102,6 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
return new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
@Override
public Ip4Address acquireIp4Address(Network network, String requestedIp, String reservationId) throws InsufficientAddressCapacityException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean releaseIp4Address(Network network, String reservationId) {
// TODO Auto-generated method stub
return false;
}
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {

View File

@ -102,6 +102,9 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
@Column(name="shared_source_nat_service")
boolean sharedSourceNat;
@Column(name="specify_ip_ranges")
boolean specifyIpRanges = false;
@Column(name="sort_key")
int sortKey;
@ -260,7 +263,7 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode) {
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges) {
this.name = name;
this.displayText = displayText;
this.rateMbps = rateMbps;
@ -280,11 +283,12 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
this.redundantRouter = false;
this.elasticIp = false;
this.elasticLb = false;
this.specifyIpRanges = specifyIpRanges;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode);
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb, boolean specifyIpRanges) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges);
this.dedicatedLB = dedicatedLb;
this.sharedSourceNat = sharedSourceNat;
this.redundantRouter = redundantRouter;
@ -299,9 +303,10 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
* Network Offering for all system vms.
* @param name
* @param trafficType
* @param specifyIpRanges TODO
*/
public NetworkOfferingVO(String name, TrafficType trafficType) {
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true);
public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges);
this.state = State.Enabled;
}
@ -346,4 +351,9 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
public boolean getElasticLb() {
return elasticLb;
}
@Override
public boolean getSpecifyIpRanges() {
return specifyIpRanges;
}
}

View File

@ -830,13 +830,13 @@ public class ConfigurationServerImpl implements ConfigurationServer {
@DB
protected void createDefaultNetworkOfferings() {
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, true);
publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, false);
managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, false);
controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, true);
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
//populate providers
@ -884,7 +884,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
"Offering for Shared Security group enabled networks",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true);
null, Network.GuestType.Shared, true, true);
deafultSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled);
deafultSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(deafultSharedSGNetworkOffering);
@ -901,7 +901,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
"Offering for Shared networks",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true);
null, Network.GuestType.Shared, true, true);
defaultSharedNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultSharedNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedNetworkOffering);
@ -918,7 +918,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
"Offering for Isolated networks with Source Nat service enabled",
TrafficType.Guest,
false, false, null, null, true, Availability.Required,
null, Network.GuestType.Isolated, true);
null, Network.GuestType.Isolated, true, false);
defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering);
@ -936,7 +936,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
"Offering for Isolated networks with no Source Nat service",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Isolated, true);
null, Network.GuestType.Isolated, true, true);
defaultIsolatedEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultIsolatedEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedEnabledNetworkOffering);
@ -953,7 +953,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
"Offering for Shared networks with Elastic IP and Elastic LB capabilities",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true, false, false, false, true, true);
null, Network.GuestType.Shared, true, false, false, false, true, true, true);
defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering);
@ -999,32 +999,26 @@ public class ConfigurationServerImpl implements ConfigurationServer {
BroadcastDomainType broadcastDomainType = null;
TrafficType trafficType= offering.getTrafficType();
boolean isNetworkDefault = false;
boolean specifyIpRanges = false;
if (trafficType == TrafficType.Management) {
broadcastDomainType = BroadcastDomainType.Native;
} else if (trafficType == TrafficType.Storage) {
broadcastDomainType = BroadcastDomainType.Native;
specifyIpRanges = true;
} else if (trafficType == TrafficType.Control) {
broadcastDomainType = BroadcastDomainType.LinkLocal;
} else if (offering.getTrafficType() == TrafficType.Public) {
if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
specifyIpRanges = true;
broadcastDomainType = BroadcastDomainType.Vlan;
} else {
continue;
}
} else if (offering.getTrafficType() == TrafficType.Guest) {
if (zone.getNetworkType() == NetworkType.Basic) {
isNetworkDefault = true;
broadcastDomainType = BroadcastDomainType.Native;
} else {
continue;
}
networkDomain = "cs" + Long.toHexString(Account.ACCOUNT_ID_SYSTEM) + _domainSuffix;
} else if (offering.getTrafficType() == TrafficType.Storage) {
broadcastDomainType = BroadcastDomainType.Storage;
}
if (broadcastDomainType != null) {
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null);
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges);
network.setGuruName(guruNames.get(network.getTrafficType()));
network.setDns1(zone.getDns1());
network.setDns2(zone.getDns2());

View File

@ -212,6 +212,7 @@ CREATE TABLE `cloud`.`networks` (
`restart_required` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if restart is required for the network',
`created` datetime NOT NULL COMMENT 'date created',
`removed` datetime COMMENT 'date removed if not null',
`specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network provides an ability to define ip ranges',
PRIMARY KEY (`id`),
CONSTRAINT `fk_networks__network_offering_id` FOREIGN KEY (`network_offering_id`) REFERENCES `network_offerings`(`id`),
CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE,
@ -289,6 +290,7 @@ CREATE TABLE `cloud`.`network_offerings` (
`guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated',
`elastic_ip_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides elastic ip service',
`elastic_lb_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides elastic lb service',
`specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides an ability to define ip ranges',
PRIMARY KEY (`id`),
INDEX `i_network_offerings__system_only`(`system_only`),
INDEX `i_network_offerings__removed`(`removed`),