Skip to content

Commit 770cf02

Browse files
author
Likitha Shetty
committed
Global config to disable an account from acquiring public ips and guest vlans from the system if the account
has dedicated resources and the dedicated resources have all been consumed - use.system.public.ips and use.system.guest.vlans Both configs are configurable at the account level too.
1 parent 28b598b commit 770cf02

9 files changed

Lines changed: 41 additions & 12 deletions

File tree

engine/schema/src/com/cloud/dc/dao/DataCenterDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface DataCenterDao extends GenericDao<DataCenterVO, Long> {
3636
Pair<String, Long> allocatePrivateIpAddress(long id, long podId, long instanceId, String reservationId);
3737
DataCenterIpAddressVO allocatePrivateIpAddress(long id, String reservationId);
3838
String allocateLinkLocalIpAddress(long id, long podId, long instanceId, String reservationId);
39-
String allocateVnet(long dcId, long physicalNetworkId, long accountId, String reservationId);
39+
String allocateVnet(long dcId, long physicalNetworkId, long accountId, String reservationId, boolean canUseSystemGuestVlans);
4040

4141
void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId);
4242
void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId);

engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,27 @@ public boolean deleteLinkLocalIpAddressByPod(long podId) {
192192
}
193193

194194
@Override
195-
public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId) {
195+
public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId,
196+
boolean canUseSystemGuestVlans) {
196197
ArrayList<Long> dedicatedVlanDbIds = new ArrayList<Long>();
198+
boolean useDedicatedGuestVlans = false;
197199
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId);
198200
for (AccountGuestVlanMapVO map : maps) {
199201
dedicatedVlanDbIds.add(map.getId());
200202
}
201203
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
204+
useDedicatedGuestVlans = true;
202205
DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds);
203206
if (vo != null)
204207
return vo.getVnet();
205208
}
206-
DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null);
207-
if (vo == null) {
208-
return null;
209+
if (!useDedicatedGuestVlans || (useDedicatedGuestVlans && canUseSystemGuestVlans)) {
210+
DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null);
211+
if (vo != null) {
212+
return vo.getVnet();
213+
}
209214
}
210-
return vo.getVnet();
215+
return null;
211216
}
212217

213218
@Override

plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Network implement(Network network, NetworkOffering offering,
162162
}
163163

164164
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId,
165-
network.getAccountId(), context.getReservationId());
165+
network.getAccountId(), context.getReservationId(), canUseSystemGuestVlan(network.getAccountId()));
166166
if (vnet == null) {
167167
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " +
168168
"part of network " + network + " implement ", DataCenter.class, dcId);

plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
9494
protected void allocateVnet(Network network, NetworkVO implemented, long dcId,
9595
long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException {
9696
if (network.getBroadcastUri() == null) {
97-
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId);
97+
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId,
98+
canUseSystemGuestVlan(network.getAccountId()));
9899
if (vnet == null) {
99100
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId);
100101
}

server/src/com/cloud/configuration/Config.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,14 @@ public enum Config {
216216
AlertPurgeInterval("Advanced", ManagementServer.class, Integer.class, "alert.purge.interval", "86400", "The interval (in seconds) to wait before running the alert purge thread", null),
217217
AlertPurgeDelay("Advanced", ManagementServer.class, Integer.class, "alert.purge.delay", "0", "Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts", null),
218218
HostReservationReleasePeriod("Advanced", ManagementServer.class, Integer.class, "host.reservation.release.period", "300000", "The interval in milliseconds between host reservation release checks", null),
219-
219+
UseSystemPublicIps("Advanced", ManagementServer.class, Boolean.class, "use.system.public.ips", "true",
220+
"If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been" +
221+
" consumed ips will be acquired from the system pool",
222+
null, ConfigurationParameterScope.account.toString()),
223+
UseSystemGuestVlans("Advanced", ManagementServer.class, Boolean.class, "use.system.guest.vlans", "true",
224+
"If true, when account has dedicated guest vlan range(s), once the vlans dedicated to the account have been" +
225+
" consumed vlans will be allocated from the system pool",
226+
null, ConfigurationParameterScope.account.toString()),
220227

221228
// LB HealthCheck Interval.
222229
LBHealthCheck("Advanced", ManagementServer.class, String.class, "healthcheck.update.interval", "600",

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,10 @@ public PublicIp fetchNewPublicIp(long dcId, Long podId, List<Long> vlanDbIds, Ac
445445

446446
// If all the dedicated IPs of the owner are in use fetch an IP from the system pool
447447
if (addrs.size() == 0 && fetchFromDedicatedRange) {
448-
if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
448+
// Verify if account is allowed to acquire IPs from the system
449+
boolean useSystemIps = Boolean.parseBoolean(_configServer.getConfigValue(Config.UseSystemPublicIps.key(),
450+
Config.ConfigurationParameterScope.account.toString(), owner.getId()));
451+
if(useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
449452
fetchFromDedicatedRange = false;
450453
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
451454
errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());

server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
130130
// Get a vlan tag
131131
int vlanTag;
132132
if (config.getBroadcastUri() == null) {
133-
String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), context.getReservationId());
133+
String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(),
134+
context.getReservationId(), canUseSystemGuestVlan(config.getAccountId()));
134135

135136
try {
136137
vlanTag = Integer.parseInt(vnet);

server/src/com/cloud/network/guru/GuestNetworkGuru.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.inject.Inject;
2727

2828
import com.cloud.event.ActionEventUtils;
29+
import com.cloud.server.ConfigurationServer;
2930
import com.cloud.utils.Pair;
3031
import org.apache.log4j.Logger;
3132

@@ -98,6 +99,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
9899
IPAddressDao _ipAddressDao;
99100
@Inject
100101
protected PhysicalNetworkDao _physicalNetworkDao;
102+
@Inject
103+
ConfigurationServer _configServer;
101104
Random _rand = new Random(System.currentTimeMillis());
102105

103106
private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@@ -155,6 +158,11 @@ public IsolationMethod[] getIsolationMethods() {
155158
return _isolationMethods;
156159
}
157160

161+
public boolean canUseSystemGuestVlan(long accountId) {
162+
return Boolean.parseBoolean(_configServer.getConfigValue(Config.UseSystemGuestVlans.key(),
163+
Config.ConfigurationParameterScope.account.toString(), accountId));
164+
}
165+
158166
protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork);
159167

160168
@Override
@@ -260,7 +268,8 @@ public int getGloballyConfiguredCidrSize() {
260268
protected void allocateVnet(Network network, NetworkVO implemented, long dcId,
261269
long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException {
262270
if (network.getBroadcastUri() == null) {
263-
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId);
271+
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId,
272+
canUseSystemGuestVlan(network.getAccountId()));
264273
if (vnet == null) {
265274
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " +
266275
"part of network " + network + " implement ", DataCenter.class, dcId);

setup/db/db/schema-410to420.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,3 +1854,6 @@ SET foreign_key_checks = 1;
18541854
UPDATE `cloud`.`snapshot_policy` set uuid=id WHERE uuid is NULL;
18551855
#update shared sg enabled network with not null name in Advance Security Group enabled network
18561856
UPDATE `cloud`.`networks` set name='Shared SG enabled network', display_text='Shared SG enabled network' WHERE name IS null AND traffic_type='Guest' AND data_center_id IN (select id from data_center where networktype='Advanced' and is_security_group_enabled=1) AND acl_type='Domain';
1857+
1858+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'use.system.public.ips', 'true', 'If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been consumed ips will be acquired from the system pool');
1859+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'use.system.guest.vlans', 'true', 'If true, when account has dedicated guest vlan range(s), once the vlans dedicated to the account have been consumed vlans will be allocated from the system pool');

0 commit comments

Comments
 (0)