mirror of https://github.com/apache/cloudstack.git
1) Don't allow to delete a vlan if it has network associated with it. Also don't show such vlans in listIpRanges command.
2) Return vlan in create/list networks command. 3) Implemented list networks by type. 4) Changed listVlanIpRanges to return start/endIps in separate tags instead of returning them in description.
This commit is contained in:
parent
e0c3c96b0b
commit
5571b444f2
|
|
@ -43,7 +43,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
|
|||
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network offering")
|
||||
private String displayText;
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, required=true, description="type of the network. Supported types Virtualized, DirectSingle, DirectDual")
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, required=true, description="type of the network. Supported types Virtual, Direct, DirectPodBased")
|
||||
private String type;
|
||||
|
||||
@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.")
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
|||
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the VLAN IP range")
|
||||
private String endIp;
|
||||
|
||||
// @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="true if VLAN is of Virtual type, false if Direct")
|
||||
// private Boolean forVirtualNetwork;
|
||||
@Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="true if VLAN is of Virtual type, false if Direct")
|
||||
private Boolean forVirtualNetwork;
|
||||
|
||||
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the VLAN IP range")
|
||||
private String gateway;
|
||||
|
|
@ -86,9 +86,9 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
|||
return endIp;
|
||||
}
|
||||
|
||||
// public Boolean isForVirtualNetwork() {
|
||||
// return forVirtualNetwork;
|
||||
// }
|
||||
public Boolean isForVirtualNetwork() {
|
||||
return forVirtualNetwork == null ? true : forVirtualNetwork;
|
||||
}
|
||||
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
|||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="availability zone for the virtual machine")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name=ApiConstants.NETWORK_IDS, type=CommandType.LIST, required=true, collectionType=CommandType.LONG, description="list of network ids used by virtual machine")
|
||||
@Parameter(name=ApiConstants.NETWORK_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="list of network ids used by virtual machine")
|
||||
private List<Long> networkIds;
|
||||
|
||||
// unexposed parameter needed for serializing/deserializing the command
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.cloud.api.ApiConstants;
|
|||
import com.cloud.api.BaseListCmd;
|
||||
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;
|
||||
|
|
@ -52,6 +51,9 @@ public class ListNetworksCmd extends BaseListCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID of the network")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="the type of the network")
|
||||
private String type;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -73,6 +75,10 @@ public class ListNetworksCmd extends BaseListCmd {
|
|||
return zoneId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ public class NetworkResponse extends BaseResponse{
|
|||
@SerializedName("type")
|
||||
private String type;
|
||||
|
||||
//TODO - add description
|
||||
@SerializedName("vlan")
|
||||
private String vlan;
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the account associated with the network")
|
||||
private String accountName;
|
||||
|
||||
|
|
@ -264,4 +268,12 @@ public class NetworkResponse extends BaseResponse{
|
|||
public void setEndIp(String endIp) {
|
||||
this.endIp = endIp;
|
||||
}
|
||||
|
||||
public String getVlan() {
|
||||
return vlan;
|
||||
}
|
||||
|
||||
public void setVlan(String vlan) {
|
||||
this.vlan = vlan;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public interface NetworkOffering {
|
|||
public enum GuestIpType {
|
||||
Virtual,
|
||||
Direct,
|
||||
DirectPodBased,
|
||||
}
|
||||
|
||||
public final String DefaultVirtualizedNetworkOffering = "DefaultVirtualizedNetworkOffering";
|
||||
|
|
|
|||
|
|
@ -759,7 +759,13 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
vlanResponse.setGateway(vlan.getVlanGateway());
|
||||
vlanResponse.setNetmask(vlan.getVlanNetmask());
|
||||
vlanResponse.setDescription(vlan.getIpRange());
|
||||
|
||||
//get start ip and end ip of corresponding vlan
|
||||
String ipRange = vlan.getIpRange();
|
||||
String[] range = ipRange.split("-");
|
||||
vlanResponse.setStartIp(range[0]);
|
||||
vlanResponse.setEndIp(range[1]);
|
||||
|
||||
vlanResponse.setNetworkId(vlan.getNetworkId());
|
||||
vlanResponse.setObjectName("vlan");
|
||||
|
||||
|
|
@ -2370,9 +2376,9 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
response.setEndIp(range[1]);
|
||||
response.setGateway(singleVlan.getVlanGateway());
|
||||
response.setNetmask(singleVlan.getVlanNetmask());
|
||||
response.setVlan(singleVlan.getVlanId());
|
||||
}
|
||||
|
||||
|
||||
response.setZoneId(network.getDataCenterId());
|
||||
|
||||
//populate network offering information
|
||||
|
|
|
|||
|
|
@ -1436,6 +1436,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
String vlanNetmask = cmd.getNetmask();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
String vlanId = cmd.getVlan();
|
||||
Boolean forVirtualNetwork = cmd.isForVirtualNetwork();
|
||||
// If an account name and domain ID are specified, look up the account
|
||||
String accountName = cmd.getAccountName();
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
|
@ -1446,7 +1447,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid account.");
|
||||
}
|
||||
}
|
||||
return createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, vlanGateway, vlanNetmask, true, vlanId, account, null);
|
||||
|
||||
return createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, vlanGateway, vlanNetmask, forVirtualNetwork, vlanId, account, null);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1780,6 +1782,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
throw new InvalidParameterValueException("Please specify a valid IP range id.");
|
||||
}
|
||||
|
||||
if (vlan.getNetworkId() != null) {
|
||||
throw new InvalidParameterValueException("Fail to delete a vlan range as there are networks associated with it");
|
||||
}
|
||||
|
||||
// Check if the VLAN has any allocated public IPs
|
||||
if (_publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true) > 0) {
|
||||
throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses.");
|
||||
|
|
@ -2416,7 +2422,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
}
|
||||
}
|
||||
if (type == null) {
|
||||
throw new InvalidParameterValueException("Invalid value for type. Supported types: Virtualized, DirectSingle, DirectDual");
|
||||
throw new InvalidParameterValueException("Invalid value for type. Supported types: Virtual, Direct, DirectPerPod");
|
||||
}
|
||||
|
||||
if (specifyVlan == null) {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ import com.cloud.dc.dao.VlanDao;
|
|||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventUtils;
|
||||
|
|
@ -89,6 +90,7 @@ import com.cloud.exception.ResourceUnavailableException;
|
|||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.configuration.NetworkGuru;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
|
|
@ -1845,6 +1847,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
owner = ctxAccount;
|
||||
}
|
||||
|
||||
//if VlanId is Direct untagged, verify if there is already network of this type in the zone
|
||||
if (networkOffering.getGuestIpType() == GuestIpType.DirectPodBased && vlanId != null && vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
|
||||
SearchBuilder<NetworkVO> sb = _networkConfigDao.createSearchBuilder();
|
||||
sb.and("broadcastDomainType", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
SearchCriteria<NetworkVO> sc = sb.create();
|
||||
sc.setParameters("broadcastDomainType", BroadcastDomainType.Native);
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
|
||||
List<NetworkVO> networks = _networkConfigDao.search(sc, null);
|
||||
if (networks!= null && !networks.isEmpty()) {
|
||||
throw new InvalidParameterValueException("Network with untagged vlan already exists for the zone " + zoneId);
|
||||
}
|
||||
}
|
||||
|
||||
//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");
|
||||
|
|
@ -1868,6 +1885,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
userNetwork.setGateway(gateway);
|
||||
if (vlanId != null) {
|
||||
userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId));
|
||||
if (vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
|
||||
userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
|
||||
} else {
|
||||
userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1913,6 +1935,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
Account account = UserContext.current().getAccount();
|
||||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
String type = cmd.getType();
|
||||
Long accountId = null;
|
||||
|
||||
if (isAdmin(account.getType())) {
|
||||
|
|
@ -1961,6 +1984,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
sc.addAnd("guestType", SearchCriteria.Op.EQ, type);
|
||||
}
|
||||
|
||||
SearchCriteria<NetworkVO> ssc = _networkConfigDao.createSearchCriteria();
|
||||
ssc.addOr("accountId", SearchCriteria.Op.EQ, accountId);
|
||||
if (accountName == null && domainId == null) {
|
||||
|
|
|
|||
|
|
@ -1403,6 +1403,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlan", sb.entity().getVlanId(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.NULL);
|
||||
|
||||
if (accountId != null) {
|
||||
SearchBuilder<AccountVlanMapVO> accountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();
|
||||
|
|
@ -1442,6 +1443,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
if (podId != null) {
|
||||
sc.setJoinParameters("podVlanMapSearch", "podId", podId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return _vlanDao.search(sc, searchFilter);
|
||||
|
|
|
|||
Loading…
Reference in New Issue