You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by li...@apache.org on 2013/04/26 01:25:43 UTC
[2/7] git commit: updated refs/heads/dedicate-guest-vlan-ranges to
5f15f38
guest-vlan: dedicate
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/75b1105a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/75b1105a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/75b1105a
Branch: refs/heads/dedicate-guest-vlan-ranges
Commit: 75b1105a7b4e9aa267053a3104c3ab5b496b6de1
Parents: 7e5fd88
Author: Likitha Shetty <li...@citrix.com>
Authored: Sat Apr 20 05:56:32 2013 +0530
Committer: Likitha Shetty <li...@citrix.com>
Committed: Wed Apr 24 22:42:58 2013 +0530
----------------------------------------------------------------------
api/src/com/cloud/network/GuestVlan.java | 31 +++
api/src/com/cloud/network/NetworkService.java | 4 +
.../org/apache/cloudstack/api/ApiConstants.java | 2 +
.../apache/cloudstack/api/ResponseGenerator.java | 2 +
.../admin/network/DedicateGuestVlanRangeCmd.java | 109 +++++++++++
.../api/response/GuestVlanRangeResponse.java | 80 ++++++++
client/tomcatconf/applicationContext.xml.in | 1 +
server/src/com/cloud/api/ApiDBUtils.java | 14 ++
server/src/com/cloud/api/ApiResponseHelper.java | 19 ++
.../src/com/cloud/network/NetworkServiceImpl.java | 149 +++++++++++++++
.../cloud/network/dao/AccountGuestVlanMapDao.java | 32 +++
.../network/dao/AccountGuestVlanMapDaoImpl.java | 76 ++++++++
.../cloud/network/dao/AccountGuestVlanMapVO.java | 94 +++++++++
.../src/com/cloud/server/ManagementServerImpl.java | 1 +
.../com/cloud/network/MockNetworkManagerImpl.java | 8 +
.../test/com/cloud/vpc/MockNetworkManagerImpl.java | 10 +-
setup/db/db/schema-410to420.sql | 15 ++
17 files changed, 644 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/com/cloud/network/GuestVlan.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/GuestVlan.java b/api/src/com/cloud/network/GuestVlan.java
new file mode 100755
index 0000000..0f346b2
--- /dev/null
+++ b/api/src/com/cloud/network/GuestVlan.java
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+public interface GuestVlan extends InternalIdentity, Identity {
+
+ public long getId();
+
+ public long getAccountId();
+
+ public String getGuestVlanRange();
+
+ public long getPhysicalNetworkId();
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/com/cloud/network/NetworkService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java
index 5a6054d..54c7c6b 100755
--- a/api/src/com/cloud/network/NetworkService.java
+++ b/api/src/com/cloud/network/NetworkService.java
@@ -18,6 +18,7 @@ package com.cloud.network;
import java.util.List;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
@@ -29,6 +30,7 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.GuestVlan;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.user.Account;
@@ -114,6 +116,8 @@ public interface NetworkService {
boolean deletePhysicalNetworkTrafficType(Long id);
+ GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd);
+
Pair<List<? extends PhysicalNetworkTrafficType>, Integer> listTrafficTypes(Long physicalNetworkId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 1165c7b..bf7f615 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -85,6 +85,7 @@ public class ApiConstants {
public static final String GSLB_SERVICE_TYPE = "gslbservicetype";
public static final String GSLB_STICKY_SESSION_METHOD = "gslbstickysessionmethodname";
public static final String GUEST_CIDR_ADDRESS = "guestcidraddress";
+ public static final String GUEST_VLAN_RANGE = "guestvlanrange";
public static final String HA_ENABLE = "haenable";
public static final String HOST_ID = "hostid";
public static final String HOST_NAME = "hostname";
@@ -221,6 +222,7 @@ public class ApiConstants {
public static final String VIRTUAL_MACHINE_ID = "virtualmachineid";
public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
public static final String VLAN = "vlan";
+ public static final String VLAN = "vlanrange";
public static final String REMOVE_VLAN="removevlan";
public static final String VLAN_ID = "vlanid";
public static final String VM_AVAILABLE = "vmavailable";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
old mode 100644
new mode 100755
index a3aa9de..0429d9e
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -197,6 +197,8 @@ public interface ResponseGenerator {
IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
+ GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan result);
+
GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBalancerRule globalLoadBalancerRule);
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java
new file mode 100755
index 0000000..61524a9
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java
@@ -0,0 +1,109 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.network;
+
+import com.cloud.dc.Vlan;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.GuestVlan;
+import com.cloud.user.Account;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.*;
+import org.apache.log4j.Logger;
+
+@APICommand(name = "dedicateGuestVlanRange", description="Dedicates a guest vlan range to an account", responseObject=GuestVlanRangeResponse.class)
+public class DedicateGuestVlanRangeCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(DedicateGuestVlanRangeCmd.class.getName());
+
+ private static final String s_name = "dedicateguestvlanrangeresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.VLAN_RANGE, type=CommandType.STRING, required=true,
+ description="guest vlan range to be dedicated")
+ private String vlan;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true,
+ description="account who will own the VLAN")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ description="project who will own the VLAN")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
+ required=true, description="domain ID of the account owning a VLAN")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class,
+ required=true, description="physical network ID of the vlan")
+ private Long physicalNetworkId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getVlan() {
+ return vlan;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public Long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException, ResourceAllocationException {
+ GuestVlan result = _networkService.dedicateGuestVlanRange(this);
+ if (result != null) {
+ GuestVlanRangeResponse response = _responseGenerator.createDedicatedGuestVlanRangeResponse(result);
+ response.setResponseName(getCommandName());
+ response.setObjectName("dedicatedguestvlanrange");
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate guest vlan range");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/api/src/org/apache/cloudstack/api/response/GuestVlanRangeResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/GuestVlanRangeResponse.java b/api/src/org/apache/cloudstack/api/response/GuestVlanRangeResponse.java
new file mode 100755
index 0000000..2c4432c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/GuestVlanRangeResponse.java
@@ -0,0 +1,80 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+
+import com.cloud.network.GuestVlan;
+
+@EntityReference(value=GuestVlan.class)
+@SuppressWarnings("unused")
+public class GuestVlanRangeResponse extends BaseResponse implements ControlledEntityResponse {
+ @SerializedName(ApiConstants.ID) @Param(description="the ID of the guest VLAN range")
+ private Long id;
+
+ @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account of the guest VLAN range")
+ private String accountName;
+
+ @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID of the guest VLAN range")
+ private String domainId;
+
+ @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the guest VLAN range")
+ private String domainName;
+
+ @SerializedName(ApiConstants.GUEST_VLAN_RANGE) @Param(description="the guest VLAN range")
+ private String guestVlanRange;
+
+ @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the guest vlan range")
+ private String projectId;
+
+ @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the guest vlan range")
+ private String projectName;
+
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ public void setDomainId(String domainId) {
+ this.domainId = domainId;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public void setGuestVlanRange(String guestVlanRange) {
+ this.guestVlanRange = guestVlanRange;
+ }
+
+ public void setProjectId(String projectId) {
+ this.projectId = projectId;
+ }
+
+ public void setProjectName(String projectName) {
+ this.projectName = projectName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index d2ea380..f9506f0 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -165,6 +165,7 @@
<bean id="accountDaoImpl" class="com.cloud.user.dao.AccountDaoImpl" />
<bean id="accountDetailsDaoImpl" class="com.cloud.user.AccountDetailsDaoImpl" />
<bean id="accountJoinDaoImpl" class="com.cloud.api.query.dao.AccountJoinDaoImpl" />
+ <bean id="accountGuestVlanMapDaoImpl" class="com.cloud.network.dao.AccountGuestVlanMapDaoImpl" />
<bean id="accountVlanMapDaoImpl" class="com.cloud.dc.dao.AccountVlanMapDaoImpl" />
<bean id="agentUpgradeDaoImpl" class="com.cloud.maint.dao.AgentUpgradeDaoImpl" />
<bean id="alertDaoImpl" class="com.cloud.alert.dao.AlertDaoImpl" />
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 21ce63b..0fbf5e7 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -130,6 +130,8 @@ import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
@@ -309,6 +311,7 @@ public class ApiDBUtils {
static GuestOSDao _guestOSDao;
static GuestOSCategoryDao _guestOSCategoryDao;
static HostDao _hostDao;
+ static AccountGuestVlanMapDao _accountGuestVlanMapDao;
static IPAddressDao _ipAddressDao;
static LoadBalancerDao _loadBalancerDao;
static SecurityGroupDao _securityGroupDao;
@@ -416,6 +419,7 @@ public class ApiDBUtils {
@Inject private GuestOSDao guestOSDao;
@Inject private GuestOSCategoryDao guestOSCategoryDao;
@Inject private HostDao hostDao;
+ @Inject private AccountGuestVlanMapDao accountGuestVlanMapDao;
@Inject private IPAddressDao ipAddressDao;
@Inject private LoadBalancerDao loadBalancerDao;
@Inject private SecurityGroupDao securityGroupDao;
@@ -512,6 +516,7 @@ public class ApiDBUtils {
_templateMgr = templateMgr;
_accountDao = accountDao;
+ _accountGuestVlanMapDao = accountGuestVlanMapDao;
_accountVlanMapDao = accountVlanMapDao;
_clusterDao = clusterDao;
_capacityDao = capacityDao;
@@ -945,6 +950,15 @@ public class ApiDBUtils {
}
}
+ public static Long getAccountIdForGuestVlan(long vlanDbId) {
+ List<AccountGuestVlanMapVO> accountGuestVlanMaps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByVlan(vlanDbId);
+ if (accountGuestVlanMaps.isEmpty()) {
+ return null;
+ } else {
+ return accountGuestVlanMaps.get(0).getAccountId();
+ }
+ }
+
public static HypervisorType getVolumeHyperType(long volumeId) {
return _volumeDao.getHypervisorType(volumeId);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 894ec8d..b508058 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -179,7 +179,9 @@ import com.cloud.event.Event;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.HypervisorCapabilities;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
import com.cloud.network.IpAddress;
+import com.cloud.network.GuestVlan;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
@@ -2733,6 +2735,23 @@ public class ApiResponseHelper implements ResponseGenerator {
}
@Override
+ public GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan vlan) {
+ GuestVlanRangeResponse guestVlanRangeResponse = new GuestVlanRangeResponse();
+
+ guestVlanRangeResponse.setId(vlan.getId());
+ // set uuid
+ Long accountId= ApiDBUtils.getAccountIdForGuestVlan(vlan.getId());
+ Account owner = ApiDBUtils.findAccountById(accountId);
+ if (owner != null) {
+ populateAccount(guestVlanRangeResponse, owner.getId());
+ populateDomain(guestVlanRangeResponse, owner.getDomainId());
+ }
+ guestVlanRangeResponse.setGuestVlanRange(vlan.getGuestVlanRange());
+
+ return guestVlanRangeResponse;
+ }
+
+ @Override
public ServiceResponse createNetworkServiceResponse(Service service) {
ServiceResponse response = new ServiceResponse();
response.setName(service.getName());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 7653a08..ef74a00 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -85,6 +85,7 @@ import com.cloud.vm.dao.*;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@@ -203,6 +204,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
HostPodDao _hostPodDao;
@Inject
DataCenterVnetDao _datacneter_vnet;
+ @Inject
+ AccountGuestVlanMapDao _accountGuestVlanMapDao;
int _cidrLimit;
boolean _allowSubdomainNetworkAccess;
@@ -2686,6 +2689,152 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
@Override
+ @DB
+ // Generate action events
+ public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) {
+ String vlan = cmd.getVlan();
+ String accountName = cmd.getAccountName();
+ Long domainId = cmd.getDomainId();
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ Long projectId = cmd.getProjectId();
+
+ int startVlan, endVlan;
+ String updatedVlanRange = null;
+ long guestVlanMapId = 0;
+ long guestVlanMapAccountId = 0;
+
+ // Verify account is valid
+ Account vlanOwner = null;
+ if (projectId != null) {
+ if (accountName != null) {
+ throw new InvalidParameterValueException("accountName and projectId are mutually exclusive");
+ }
+ Project project = _projectMgr.getProject(projectId);
+ if (project == null) {
+ throw new InvalidParameterValueException("Unable to find project by id " + projectId);
+ }
+ vlanOwner = _accountMgr.getAccount(project.getProjectAccountId());
+ }
+
+ if ((accountName != null) && (domainId != null)) {
+ vlanOwner = _accountDao.findActiveAccount(accountName, domainId);
+ if (vlanOwner == null) {
+ throw new InvalidParameterValueException("Unable to find account by name " + accountName);
+ }
+ }
+
+ // Get the start and end vlan
+ String[] vlanRange = vlan.split("-");
+ if (vlanRange.length != 2) {
+ throw new InvalidParameterValueException("Invalid format for parameter value vlan " + vlan + " .Vlan should be specified as 'startvlan-endvlan'");
+ }
+
+ try {
+ startVlan = Integer.parseInt(vlanRange[0]);
+ endVlan = Integer.parseInt(vlanRange[1]);
+ } catch (NumberFormatException e) {
+ s_logger.warn("Unable to parse guest vlan range:", e);
+ throw new InvalidParameterValueException("Please provide valid guest vlan range");
+ }
+
+ // Verify guest vlan range exists in the system
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ List <Pair <Integer,Integer>> existingRanges = physicalNetwork.getVnet();
+ Boolean exists = false;
+ if (!existingRanges.isEmpty()) {
+ for (int i=0 ; i < existingRanges.size(); i++){
+ int existingStartVlan = existingRanges.get(i).first();
+ int existingEndVlan = existingRanges.get(i).second();
+ if (startVlan >= existingStartVlan && endVlan <= existingEndVlan) {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists) {
+ throw new InvalidParameterValueException("Unable to find guest vlan by range " + vlan);
+ }
+ }
+
+ // Verify guest vlans in the range don't belong to a network of a different account
+ for (int i = startVlan; i <= endVlan; i++) {
+ List<DataCenterVnetVO> allocatedVlans = _datacneter_vnet.listAllocatedVnetsInRange(physicalNetwork.getDataCenterId(), physicalNetwork.getId(), startVlan, endVlan);
+ if (!allocatedVlans.isEmpty()){
+ for (DataCenterVnetVO allocatedVlan : allocatedVlans) {
+ if (allocatedVlan.getAccountId() != vlanOwner.getAccountId()) {
+ throw new InvalidParameterValueException("Guest vlan from this range " + allocatedVlan.getVnet() + " is allocated to a different account." +
+ " Can only dedicate a range which has no allocated vlans or vlans allocated to the same account ");
+ }
+ }
+ }
+ }
+
+
+ List<AccountGuestVlanMapVO> guestVlanMaps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(physicalNetworkId);
+ for (AccountGuestVlanMapVO guestVlanMap : guestVlanMaps) {
+ List<Integer> vlanTokens = getVlanFromRange(guestVlanMap.getGuestVlanRange());
+ int dedicatedStartVlan = vlanTokens.get(0).intValue();
+ int dedicatedEndVlan = vlanTokens.get(1).intValue();
+ guestVlanMapId = guestVlanMap.getId();
+ guestVlanMapAccountId = guestVlanMap.getAccountId();
+
+ // Verify if range is already dedicated
+ if (startVlan >= dedicatedStartVlan && endVlan <= dedicatedEndVlan) {
+ if (guestVlanMap.getAccountId() != vlanOwner.getAccountId()) {
+ throw new InvalidParameterValueException("Vlan range is already dedicated to another account. Cannot dedicate guest vlan range " + vlan);
+ } else {
+ s_logger.debug("Vlan range " + vlan +" is already dedicated to the specified account" + accountName);
+ return guestVlanMap;
+ }
+ }
+ // Verify if range overlaps with an existing range
+ if (startVlan < dedicatedStartVlan & endVlan+1 >= dedicatedStartVlan & endVlan <= dedicatedEndVlan) { // extend to the left
+ updatedVlanRange = startVlan + "-" + dedicatedEndVlan;
+ break;
+ } else if (startVlan >= dedicatedStartVlan & startVlan-1 <= dedicatedEndVlan & endVlan > dedicatedEndVlan) { // extend to right
+ updatedVlanRange = dedicatedStartVlan + "-" + endVlan;
+ break;
+ } else if (startVlan < dedicatedStartVlan & endVlan > dedicatedEndVlan){ // extend to the left and right
+ updatedVlanRange = startVlan + "-" + endVlan;
+ break;
+ }
+ }
+
+
+ if (updatedVlanRange != null) {
+ if (guestVlanMapAccountId != vlanOwner.getAccountId()) {
+ throw new InvalidParameterValueException("Vlan range is partially dedicated to another account. Cannot dedicate guest vlan range " + vlan);
+ }
+ AccountGuestVlanMapVO accountGuestVlanMapVO = _accountGuestVlanMapDao.findById(guestVlanMapId);
+ accountGuestVlanMapVO.setGuestVlanRange(updatedVlanRange);
+ _accountGuestVlanMapDao.update(guestVlanMapId, accountGuestVlanMapVO);
+ return accountGuestVlanMapVO;
+ } else {
+ Transaction txn = Transaction.currentTxn();
+ AccountGuestVlanMapVO accountGuestVlanMapVO = new AccountGuestVlanMapVO(vlanOwner.getAccountId(), physicalNetworkId);
+ accountGuestVlanMapVO.setGuestVlanRange(startVlan + "-" + endVlan);
+ _accountGuestVlanMapDao.persist(accountGuestVlanMapVO);
+ txn.commit();
+ return accountGuestVlanMapVO;
+ }
+ }
+
+ private List<Integer> getVlanFromRange(String vlanRange) {
+ // Get the start and end vlan
+ String[] vlanTokens = vlanRange.split("-");
+ List<Integer> tokens = new ArrayList<Integer>();
+ try {
+ int startVlan = Integer.parseInt(vlanTokens[0]);
+ int endVlan = Integer.parseInt(vlanTokens[1]);
+ tokens.add(startVlan);
+ tokens.add(endVlan);
+ } catch (NumberFormatException e) {
+ s_logger.warn("Unable to parse guest vlan range:", e);
+ throw new InvalidParameterValueException("Please provide valid guest vlan range");
+ }
+ return tokens;
+ }
+
+ @Override
public List<? extends Service> listNetworkServices(String providerName) {
Provider provider = null;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/network/dao/AccountGuestVlanMapDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/AccountGuestVlanMapDao.java b/server/src/com/cloud/network/dao/AccountGuestVlanMapDao.java
new file mode 100755
index 0000000..57e1187
--- /dev/null
+++ b/server/src/com/cloud/network/dao/AccountGuestVlanMapDao.java
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.dao;
+
+import com.cloud.network.dao.AccountGuestVlanMapVO;
+import com.cloud.utils.db.GenericDao;
+
+import java.util.List;
+
+public interface AccountGuestVlanMapDao extends GenericDao<AccountGuestVlanMapVO, Long> {
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByAccount(long accountId);
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByVlan(long guestVlanId);
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByPhysicalNetwork(long physicalNetworkId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java b/server/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
new file mode 100755
index 0000000..05b92c5
--- /dev/null
+++ b/server/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
@@ -0,0 +1,76 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.dao;
+
+import com.cloud.network.dao.AccountGuestVlanMapVO;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+
+import java.util.List;
+import javax.ejb.Local;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value={AccountGuestVlanMapDao.class})
+@DB(txn=false)
+public class AccountGuestVlanMapDaoImpl extends GenericDaoBase<AccountGuestVlanMapVO, Long> implements AccountGuestVlanMapDao {
+
+ protected SearchBuilder<AccountGuestVlanMapVO> AccountSearch;
+ protected SearchBuilder<AccountGuestVlanMapVO> GuestVlanSearch;
+ protected SearchBuilder<AccountGuestVlanMapVO> PhysicalNetworkSearch;
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByAccount(long accountId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = AccountSearch.create();
+ sc.setParameters("accountId", accountId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByVlan(long guestVlanId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = GuestVlanSearch.create();
+ sc.setParameters("guestVlanId", guestVlanId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByPhysicalNetwork(long physicalNetworkId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = GuestVlanSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ public AccountGuestVlanMapDaoImpl() {
+ super();
+ AccountSearch = createSearchBuilder();
+ AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+ AccountSearch.done();
+
+ GuestVlanSearch = createSearchBuilder();
+ GuestVlanSearch.and("guestVlanId", GuestVlanSearch.entity().getId(), SearchCriteria.Op.EQ);
+ GuestVlanSearch.done();
+
+ PhysicalNetworkSearch = createSearchBuilder();
+ PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getId(), SearchCriteria.Op.EQ);
+ PhysicalNetworkSearch.done();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/AccountGuestVlanMapVO.java b/server/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
new file mode 100755
index 0000000..db6ecda
--- /dev/null
+++ b/server/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
@@ -0,0 +1,94 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.dao;
+
+import com.cloud.network.GuestVlan;
+
+import javax.persistence.*;
+import java.util.UUID;
+
+@Entity
+@Table(name="account_guest_vlan_map")
+public class AccountGuestVlanMapVO implements GuestVlan {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="account_id")
+ private long accountId;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name="guest_vlan_range")
+ private String guestVlanRange;
+
+ @Column(name="physical_network_id")
+ private long physicalNetworkId;
+
+ public AccountGuestVlanMapVO(long accountId,long physicalNetworkId) {
+ this.accountId = accountId;
+ this.physicalNetworkId = physicalNetworkId;
+ this.guestVlanRange = null;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public AccountGuestVlanMapVO() {
+
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public String getGuestVlanRange() {
+ return guestVlanRange;
+ }
+
+
+ public void setGuestVlanRange(String guestVlanRange) {
+ this.guestVlanRange = guestVlanRange;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ @Override
+ public long getPhysicalNetworkId() {
+ return this.physicalNetworkId;
+ }
+
+ public void setPhysicalNetworkId(long physicalNetworkId) {
+ this.physicalNetworkId = physicalNetworkId;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 16127a2..d3b35c1 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -2194,6 +2194,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
cmdList.add(UpdateNetworkServiceProviderCmd.class);
cmdList.add(UpdatePhysicalNetworkCmd.class);
cmdList.add(UpdateStorageNetworkIpRangeCmd.class);
+ cmdList.add(DedicateGuestVlanRangeCmd.class);
cmdList.add(CreateDiskOfferingCmd.class);
cmdList.add(CreateServiceOfferingCmd.class);
cmdList.add(DeleteDiskOfferingCmd.class);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index 6a0263e..498ec2b 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -29,6 +29,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.GuestVlan;
import com.cloud.network.element.LoadBalancingServiceProvider;
import com.cloud.network.element.StaticNatServiceProvider;
import com.cloud.network.element.UserDataServiceProvider;
@@ -54,6 +55,7 @@ import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@@ -334,6 +336,12 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
}
@Override
+ public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
public List<? extends Service> listNetworkServices(String providerName) {
// TODO Auto-generated method stub
return null;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
old mode 100644
new mode 100755
index bfcccf5..0af299b
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -28,6 +28,7 @@ import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NetworkVO;
@@ -58,6 +59,7 @@ import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@@ -346,9 +348,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
return false;
}
-
-
-
+ @Override
+ public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) {
+ // TODO Auto-generated method stub
+ return null;
+ }
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#listNetworkServices(java.lang.String)
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75b1105a/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 78444fd..c5b4d8f 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1109,4 +1109,19 @@ CREATE VIEW `cloud`.`account_view` AS
and async_job.instance_type = 'Account'
and async_job.job_status = 0;
+
alter table `cloud_usage`.`usage_network_offering` add column nic_id bigint(20) unsigned NOT NULL;
+
+CREATE TABLE `cloud`.`account_guest_vlan_map` (
+ `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
+ `uuid` varchar(255) UNIQUE,
+ `guest_vlan_range` varchar(255) NOT NULL COMMENT 'dedicated guest vlan range',
+ `account_id` bigint unsigned NOT NULL COMMENT 'account id. foreign key to account table',
+ `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id. foreign key to the the physical network table',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `fk_account_guest_vlan_map__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network` (`id`) ON DELETE CASCADE,
+ INDEX `i_account_guest_vlan_map__physical_network_id`(`physical_network_id`),
+ CONSTRAINT `fk_account_guest_vlan_map__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE,
+ INDEX `i_account_guest_vlan_map__account_id`(`account_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+