1) Added guestIpType to the network offering; create/listNetworkOffering apis got changed accordingly.

2) Set traffic Type to be Guest for Direct/Virtual non-system default network offerings. Use this guestIpType during the network creation/implementation
This commit is contained in:
alena 2011-02-24 15:33:29 -08:00
parent 2e91b702fc
commit 039b11b9ba
16 changed files with 105 additions and 35 deletions

View File

@ -192,5 +192,6 @@ public class ApiConstants {
public static final String IS_SYSTEM = "issystem";
public static final String AVAILABILITY = "availability";
public static final String NETWORKRATE = "networkrate";
public static final String GUEST_IP_TYPE = "guestiptype";
}

View File

@ -25,7 +25,6 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.NetworkResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;

View File

@ -47,6 +47,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.")
private String traffictype;
@Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, required=true, description="the guest ip type for the network offering, supported types are Direct and Virtual.")
private String guestIpType;
@Parameter(name=ApiConstants.MAX_CONNECTIONS, type=CommandType.INTEGER, description="maximum number of concurrent connections supported by the network offering")
private Integer maxConnections;
@ -99,6 +102,10 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
return networkRate;
}
public String getGuestIpType() {
return guestIpType;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -62,7 +62,11 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
private Boolean isShared;
@Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Required")
private String availability;
private String availability;
@Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, description="the guest ip type for the network offering, supported types are Direct and Virtual.")
private String guestIpType;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -100,6 +104,10 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
return availability;
}
public String getGuestIpType() {
return guestIpType;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -37,6 +37,9 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName("availability") @Param(description="availability of the network offering")
private String availability;
@SerializedName(ApiConstants.GUEST_IP_TYPE) @Param(description="guest ip type of the network offering")
private String guestIpType;
@SerializedName(ApiConstants.NETWORKRATE) @Param(description="data transfer rate in megabits per second allowed.")
private Integer networkRate;
@ -135,4 +138,14 @@ public class NetworkOfferingResponse extends BaseResponse{
public void setNetworkRate(Integer networkRate) {
this.networkRate = networkRate;
}
public String getGuestIpType() {
return guestIpType;
}
public void setGuestIpType(String guestIpType) {
this.guestIpType = guestIpType;
}
}

View File

@ -17,6 +17,7 @@
*/
package com.cloud.offering;
import com.cloud.network.Network.GuestIpType;
import com.cloud.network.Networks.TrafficType;
/**
@ -94,4 +95,6 @@ public interface NetworkOffering {
boolean isVpnService();
boolean isDhcpService();
GuestIpType getGuestType();
}

View File

@ -2241,6 +2241,11 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setSpecifyVlan(offering.getSpecifyVlan());
response.setAvailability(offering.getAvailability().toString());
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
if (offering.getGuestType() != null) {
response.setGuestIpType(offering.getGuestType().toString());
}
response.setObjectName("networkoffering");
return response;
}

View File

@ -31,6 +31,7 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.network.Network.GuestIpType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering.Availability;
@ -165,11 +166,12 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* @param trafficType
* @param tags
* @param maxConnections
* @param guestIpType TODO
* @param id
* @param specifyVlan;
* @return network offering object
*/
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability);
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, GuestIpType guestIpType);
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;

View File

@ -2411,8 +2411,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String trafficTypeString = cmd.getTraffictype();
Boolean specifyVlan = cmd.getSpecifyVlan();
String availabilityStr = cmd.getAvailability();
String guestIpTypeString = cmd.getGuestIpType();
TrafficType trafficType = null;
GuestIpType guestIpType = null;
Availability availability = null;
@ -2420,12 +2422,27 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
for (TrafficType tType : TrafficType.values()) {
if (tType.name().equalsIgnoreCase(trafficTypeString)) {
trafficType = tType;
break;
}
}
if (trafficType == null) {
throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
}
//Verify guest ip type
for (GuestIpType gType : GuestIpType.values()) {
if (gType.name().equalsIgnoreCase(guestIpTypeString)) {
guestIpType = gType;
break;
}
}
if (guestIpType == null) {
throw new InvalidParameterValueException("Invalid guest IP type; can have Direct or Virtual value");
}
//Verify availability
for (Availability avlb : Availability.values()) {
if (avlb.name().equalsIgnoreCase(availabilityStr)) {
@ -2438,11 +2455,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
Integer maxConnections = cmd.getMaxconnections();
return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability);
return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, guestIpType);
}
@Override
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability) {
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, GuestIpType guestIpType) {
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
@ -2461,7 +2478,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
gatewayService = true;
}
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, true, true, true, gatewayService, firewallService, lbService, vpnService);
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, true, true, true, gatewayService, firewallService, lbService, vpnService, guestIpType);
if ((offering = _networkOfferingDao.persist(offering)) != null) {
return offering;
@ -2483,6 +2500,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
Object specifyVlan = cmd.getSpecifyVlan();
Object isShared = cmd.getIsShared();
Object availability = cmd.getAvailability();
Object guestIpType = cmd.getGuestIpType();
Object keyword = cmd.getKeyword();
@ -2497,6 +2515,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (guestIpType != null) {
sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType);
}
if (name != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}

View File

@ -690,7 +690,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
true,
Availability.Required,
//services - all true except for firewall/lb/vpn and gateway services
true, true, true, false, false,false, false);
true, true, true, false, false,false, false, GuestIpType.Direct);
guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemGuestNetwork, guestNetworkOffering);
@ -706,13 +706,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
true,
Availability.Required,
//services
true, true, true, true,true, true, true);
true, true, true, true,true, true, true, GuestIpType.Virtual);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(
NetworkOffering.DefaultDirectNetworkOffering,
"Direct",
TrafficType.Public,
TrafficType.Guest,
false,
false,
null,
@ -721,7 +721,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
true,
Availability.Required,
//services - all true except for firewall/lb/vpn and gateway services
true, true, true, false, false,false, false);
true, true, true, false, false,false, false, GuestIpType.Direct);
defaultGuestDirectNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
AccountsUsingNetworkSearch = _accountDao.createSearchBuilder();
@ -1456,10 +1456,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
throw new InvalidParameterValueException("Unable to find network offeirng by id " + networkOfferingId);
}
// allow isDefault to be set only for Virtual network
if (networkOffering.getTrafficType() == TrafficType.Guest) {
// allow isDefault to be set only for Direct network
if (networkOffering.getGuestType() == GuestIpType.Virtual) {
if (isDefault != null) {
throw new InvalidParameterValueException("Can specify isDefault parameter only for Public network. ");
throw new InvalidParameterValueException("Can specify isDefault parameter only for Direct network.");
} else {
isDefault = true;
}

View File

@ -75,7 +75,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
return null;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), null, Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), plan.getDataCenterId(), Network.State.Setup);
NetworkVO config = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), plan.getDataCenterId(), Network.State.Setup);
config.setCidr(_cidr);
config.setGateway(_gateway);

View File

@ -68,11 +68,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject NetworkOfferingDao _networkOfferingDao;
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//this guru handles only non-system Public network
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Public && !offering.isSystemOnly()) {
//this guru handles only non-system network with guestIpType = Direct
if (dc.getNetworkType() == NetworkType.Advanced && offering.getGuestType() == GuestIpType.Direct && offering.getTrafficType() == TrafficType.Guest && !offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of Public Direct networks");
s_logger.trace("We only take care of Guest Direct networks");
return false;
}
}
@ -90,7 +90,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
state = State.Setup;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), GuestIpType.Direct, Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), state);
NetworkVO config = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), state);
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||

View File

@ -78,10 +78,10 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//This guru handles only non-system Guest network
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && !offering.isSystemOnly()) {
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == GuestIpType.Virtual && !offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of Guest networks in zone of type " + NetworkType.Advanced);
s_logger.trace("We only take care of Guest Virtual networks in zone of type " + NetworkType.Advanced);
return false;
}
}
@ -93,7 +93,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
return null;
}
NetworkVO network = new NetworkVO(offering.getTrafficType(), GuestIpType.Virtual, Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated);
NetworkVO network = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated);
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {

View File

@ -28,9 +28,9 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.network.Network.GuestIpType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.GenericDao;
@Entity
@ -106,6 +106,9 @@ public class NetworkOfferingVO implements NetworkOffering {
@Column(name="dhcp_service")
boolean dhcpService;
@Column(name="guest_type")
GuestIpType guestType;
@Override
public String getDisplayText() {
@ -292,8 +295,17 @@ public class NetworkOfferingVO implements NetworkOffering {
public void setDhcpService(boolean dhcpService) {
this.dhcpService = dhcpService;
}
@Override
public GuestIpType getGuestType() {
return guestType;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean dhcpService, boolean dnsService, boolean userDataService, boolean gatewayService, boolean firewallService, boolean lbService, boolean vpnService) {
public void setGuestType(GuestIpType guestType) {
this.guestType = guestType;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean dhcpService, boolean dnsService, boolean userDataService, boolean gatewayService, boolean firewallService, boolean lbService, boolean vpnService, GuestIpType guestIpType) {
this.name = name;
this.displayText = displayText;
this.rateMbps = rateMbps;
@ -310,22 +322,17 @@ public class NetworkOfferingVO implements NetworkOffering {
this.gatewayService = gatewayService;
this.firewallService = firewallService;
this.lbService = lbService;
this.vpnService = vpnService;
this.vpnService = vpnService;
this.guestType = guestIpType;
}
public NetworkOfferingVO(ServiceOfferingVO offering) {
this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false, Availability.Required, false, false, false, false, false, false, false);
this.serviceOfferingId = offering.getId();
}
/**
* Network Offering for all system vms.
* @param name
* @param trafficType
*/
public NetworkOfferingVO(String name, TrafficType trafficType) {
this(name, "System Offering for " + name, trafficType, true, false, null, null, null, false, Availability.Required, false, false, false, false, false, false, false);
this(name, "System Offering for " + name, trafficType, true, false, null, null, null, false, Availability.Required, false, false, false, false, false, false, false, null);
}
@Override

View File

@ -57,6 +57,7 @@ import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.Network.GuestIpType;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.BroadcastDomainType;
@ -735,7 +736,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
true, false, null, null, null, true,
Availability.Required,
true, true, true, //services - all true except for firewall/lb/vpn and gateway
false, false, false, false);
false, false, false, false, GuestIpType.Direct);
guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering);
@ -746,16 +747,16 @@ public class ConfigurationServerImpl implements ConfigurationServer {
false, false, null, null, null, true,
Availability.Required,
true, true, true, //services
true, true, true, true);
true, true, true, true, GuestIpType.Virtual);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(
NetworkOffering.DefaultDirectNetworkOffering,
"Direct",
TrafficType.Public,
TrafficType.Guest,
false, false, null, null, null, true,
Availability.Required,
true, true, true, //services - all true except for firewall/lb/vpn and gateway
false, false, false, false);
false, false, false, false, GuestIpType.Direct);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
}

View File

@ -258,6 +258,7 @@ CREATE TABLE `cloud`.`network_offerings` (
`userdata_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides user data service',
`vpn_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides vpn service',
`dhcp_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides dhcp service',
`guest_type` char(32) COMMENT 'guest ip type of network offering',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;