Skip to content

Commit 87f5150

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
Basic zone is fixed and works with new NaaS now
1 parent f4136bf commit 87f5150

10 files changed

Lines changed: 106 additions & 103 deletions

File tree

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,11 +1429,6 @@ public void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled, l
14291429
// the zone creation
14301430
if (zone != null) {
14311431
List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
1432-
1433-
//for Advance security group enabled zone and Basic zone we have to find only one guest network offering enabled in the system
1434-
if (zone.getNetworkType() == NetworkType.Basic || isSecurityGroupEnabled) {
1435-
ntwkOff.add(_networkMgr.getExclusiveGuestNetworkOffering());
1436-
}
14371432

14381433
for (NetworkOfferingVO offering : ntwkOff) {
14391434
DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
@@ -1453,20 +1448,8 @@ public void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled, l
14531448
} else {
14541449
continue;
14551450
}
1456-
} else if (offering.getTrafficType() == TrafficType.Guest) {
1457-
if (zone.getNetworkType() == NetworkType.Basic) {
1458-
isNetworkDefault = true;
1459-
broadcastDomainType = BroadcastDomainType.Native;
1460-
//set physicalnetworkId to the default Guest network in a basic Zone.
1461-
plan = new DataCenterDeployment(zone.getId(), null, null, null, null, physicalNetworkId);
1462-
} else if (offering.getGuestType() == GuestType.Shared && isSecurityGroupEnabled) {
1463-
isNetworkDefault = true;
1464-
} else {
1465-
continue;
1466-
}
1467-
1468-
networkDomain = "cs" + Long.toHexString(Account.ACCOUNT_ID_SYSTEM) + _networkMgr.getGlobalGuestDomainSuffix();
14691451
}
1452+
14701453
userNetwork.setBroadcastDomainType(broadcastDomainType);
14711454
userNetwork.setNetworkDomain(networkDomain);
14721455
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, Domain.ROOT_DOMAIN, null);

‎server/src/com/cloud/configuration/DefaultComponentLibrary.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import com.cloud.identity.IdentityServiceImpl;
26+
import com.cloud.identity.dao.IdentityDaoImpl;
2527
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
2628
import com.cloud.alert.AlertManagerImpl;
2729
import com.cloud.alert.dao.AlertDaoImpl;
@@ -65,8 +67,6 @@
6567
import com.cloud.host.dao.HostTagsDaoImpl;
6668
import com.cloud.hypervisor.HypervisorGuruManagerImpl;
6769
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDaoImpl;
68-
import com.cloud.identity.IdentityServiceImpl;
69-
import com.cloud.identity.dao.IdentityDaoImpl;
7070
import com.cloud.keystore.KeystoreDaoImpl;
7171
import com.cloud.keystore.KeystoreManagerImpl;
7272
import com.cloud.maint.UpgradeManagerImpl;

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.apache.log4j.Logger;
3434

35+
import com.cloud.identity.dao.IdentityDao;
3536
import com.cloud.agent.AgentManager;
3637
import com.cloud.agent.api.AgentControlAnswer;
3738
import com.cloud.agent.api.Answer;
@@ -69,12 +70,11 @@
6970
import com.cloud.exception.OperationTimedoutException;
7071
import com.cloud.exception.ResourceUnavailableException;
7172
import com.cloud.exception.StorageUnavailableException;
72-
import com.cloud.host.Host.Type;
7373
import com.cloud.host.Host;
74+
import com.cloud.host.Host.Type;
7475
import com.cloud.host.HostVO;
7576
import com.cloud.host.dao.HostDao;
7677
import com.cloud.hypervisor.Hypervisor.HypervisorType;
77-
import com.cloud.identity.dao.IdentityDao;
7878
import com.cloud.info.ConsoleProxyConnectionInfo;
7979
import com.cloud.info.ConsoleProxyInfo;
8080
import com.cloud.info.ConsoleProxyLoadInfo;
@@ -88,6 +88,7 @@
8888
import com.cloud.network.NetworkManager;
8989
import com.cloud.network.NetworkVO;
9090
import com.cloud.network.Networks.TrafficType;
91+
import com.cloud.network.dao.NetworkDao;
9192
import com.cloud.offerings.NetworkOfferingVO;
9293
import com.cloud.offerings.dao.NetworkOfferingDao;
9394
import com.cloud.resource.ResourceManager;
@@ -118,10 +119,10 @@
118119
import com.cloud.utils.component.Manager;
119120
import com.cloud.utils.db.DB;
120121
import com.cloud.utils.db.GlobalLock;
122+
import com.cloud.utils.db.SearchCriteria.Op;
121123
import com.cloud.utils.db.SearchCriteria2;
122124
import com.cloud.utils.db.SearchCriteriaService;
123125
import com.cloud.utils.db.Transaction;
124-
import com.cloud.utils.db.SearchCriteria.Op;
125126
import com.cloud.utils.events.SubscriptionMgr;
126127
import com.cloud.utils.exception.CloudRuntimeException;
127128
import com.cloud.utils.net.NetUtils;
@@ -208,10 +209,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
208209
@Inject
209210
UserVmDetailsDao _vmDetailsDao;
210211
@Inject
211-
ResourceManager _resourceMgr;
212-
212+
ResourceManager _resourceMgr;
213213
@Inject
214214
IdentityDao _identityDao;
215+
@Inject
216+
NetworkDao _networkDao;
215217

216218
private ConsoleProxyListener _listener;
217219

@@ -220,6 +222,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
220222
NetworkOfferingVO _publicNetworkOffering;
221223
NetworkOfferingVO _managementNetworkOffering;
222224
NetworkOfferingVO _linkLocalNetworkOffering;
225+
223226

224227
@Inject
225228
private VirtualMachineManager _itMgr;
@@ -560,18 +563,28 @@ protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorT
560563
Account systemAcct = _accountMgr.getSystemAccount();
561564

562565
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
563-
NetworkOfferingVO defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
564-
566+
567+
TrafficType defaultTrafficType = TrafficType.Public;
565568
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
566-
defaultOffering = _networkMgr.getExclusiveGuestNetworkOffering();
569+
defaultTrafficType = TrafficType.Guest;
567570
}
571+
572+
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
573+
574+
if (defaultNetworks.size() != 1) {
575+
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
576+
}
577+
578+
NetworkVO defaultNetwork = defaultNetworks.get(0);
568579

569580
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
570581
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
571582
NicProfile defaultNic = new NicProfile();
572583
defaultNic.setDefaultNic(true);
573584
defaultNic.setDeviceId(2);
574-
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering, plan, null, null, false).get(0), defaultNic));
585+
586+
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), null, plan, null, null, false, false, null, null).get(0), defaultNic));
587+
575588
for (NetworkOfferingVO offering : offerings) {
576589
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
577590
}

‎server/src/com/cloud/network/NetworkManager.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId
235235
List<Service> getElementServices(Provider provider);
236236

237237
boolean canElementEnableIndividualServices(Provider provider);
238-
239-
NetworkOfferingVO getExclusiveGuestNetworkOffering();
240238

241239
PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId);
242240

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

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,22 +1148,6 @@ public List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeri
11481148
}
11491149
return offerings;
11501150
}
1151-
1152-
1153-
@Override
1154-
public NetworkOfferingVO getExclusiveGuestNetworkOffering() {
1155-
//this method should return Guest network offering in Enabled state; and this network offering should be unique, otherwise Runtime exception is going to be thrown
1156-
List<NetworkOfferingVO> offerings = _networkOfferingDao.listByTrafficTypeGuestTypeAndState(NetworkOffering.State.Enabled, TrafficType.Guest, GuestType.Shared);
1157-
if (offerings.isEmpty()) {
1158-
throw new CloudRuntimeException("Unable to find network offering in state " + NetworkOffering.State.Enabled + ", traffic type " + TrafficType.Guest + " and guest type " + GuestType.Shared);
1159-
}
1160-
1161-
if (offerings.size() > 1) {
1162-
throw new CloudRuntimeException("Found more than 1 network offering in state " + NetworkOffering.State.Enabled + ", traffic type " + TrafficType.Guest + " and guest type " + GuestType.Shared);
1163-
1164-
}
1165-
return offerings.get(0);
1166-
}
11671151

11681152
@Override
11691153
@DB
@@ -1886,12 +1870,12 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
18861870

18871871
Network network = createNetwork(networkOfferingId, name, displayText, isDefault, gateway, cidr, vlanId, networkDomain, owner, false, sharedDomainId, pNtwk, zoneId, aclType);
18881872

1889-
//Vlan is created in 2 cases:
1873+
//Vlan is created in 2 cases - works in Advance zone only:
18901874
//1) GuestType is Shared
18911875
//2) GuestType is Isolated, but SourceNat service is disabled
18921876
boolean createVlan = ((network.getGuestType() == Network.GuestType.Shared) || (network.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
18931877

1894-
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan && defineNetworkConfig) {
1878+
if (zone.getNetworkType() == NetworkType.Advanced && caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan && defineNetworkConfig) {
18951879
// Create vlan ip range
18961880
_configMgr.createVlanAndPublicIpRange(userId, pNtwk.getDataCenterId(), null, startIP, endIP, gateway, netmask, false, vlanId, null, network.getId(), physicalNetworkId);
18971881
}
@@ -1908,44 +1892,43 @@ public Network createNetwork(long networkOfferingId, String name, String display
19081892

19091893
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
19101894
DataCenterVO zone = _dcDao.findById(zoneId);
1911-
// removed during the merge for network as service
1912-
// Only Direct Account specific networks can be created in Advanced Security Group enabled zone
1913-
// if (zone.isSecurityGroupEnabled() && (networkOffering.getGuestType() == GuestIpType.Virtual || (isShared != null && isShared))) {
1914-
// throw new InvalidParameterValueException("Virtual Network and Direct Shared Network creation is not allowed if zone is security group enabled");
1915-
// }
1916-
//
1917-
// if (zone.getNetworkType() == NetworkType.Basic) {
1918-
// throw new InvalidParameterValueException("Network creation is not allowed in zone with network type " + NetworkType.Basic);
1919-
// }
1920-
//
1921-
1922-
//Only one guest network is supported in Basic zone
1895+
1896+
19231897
if (zone.getNetworkType() == NetworkType.Basic) {
1924-
throw new InvalidParameterValueException("Network creation is not allowed in zone with network type " + NetworkType.Basic);
1898+
//Only one guest network is supported in Basic zone
1899+
List<NetworkVO> guestNetworks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Guest);
1900+
if (!guestNetworks.isEmpty()) {
1901+
throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " + NetworkType.Basic);
1902+
}
1903+
1904+
//if zone is basic, only Shared network offerings w/o source nat service are allowed
1905+
if (!(networkOffering.getGuestType() == GuestType.Shared && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))) {
1906+
throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() + " service are allowed");
1907+
}
1908+
1909+
} else if (zone.isSecurityGroupEnabled()) {
1910+
//Only Account specific Isolated network with sourceNat service disabled are allowed in security group enabled zone
1911+
boolean allowCreation = (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat));
1912+
if (!allowCreation) {
1913+
throw new InvalidParameterValueException("Only Account specific Isolated network with sourceNat service disabled are allowed in security group enabled zone");
1914+
}
19251915
}
1926-
1916+
19271917

19281918
// allow isDefault to be set only for Shared network and Isolated networks with source nat disabled service
1929-
boolean allowSettingDefault = (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
1919+
boolean allowSettingDefault = (zone.getNetworkType() == NetworkType.Advanced && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))));
19301920
if (allowSettingDefault) {
19311921
if (isDefault == null) {
19321922
isDefault = false;
19331923
}
19341924
} else {
19351925
if (isDefault == null) {
19361926
isDefault = true;
1927+
} else {
1928+
throw new InvalidParameterValueException("isDefault parameter can be passed in only for network creation of guestType Shared or Isolated with source nat service disabled; and only in Advance zone");
19371929
}
19381930
}
1939-
1940-
// Don't allow to create network with vlan that already exists in the system
1941-
if (vlanId != null) {
1942-
String uri = "vlan://" + vlanId;
1943-
List<NetworkVO> networks = _networksDao.listBy(zoneId, uri);
1944-
if ((networks != null && !networks.isEmpty())) {
1945-
throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
1946-
}
1947-
}
1948-
1931+
19491932
// VlanId can be specified only when network offering supports it
19501933
if (vlanId != null && !networkOffering.getSpecifyVlan()) {
19511934
throw new InvalidParameterValueException("Can't specify vlan because network offering doesn't support it");
@@ -1962,6 +1945,16 @@ public Network createNetwork(long networkOfferingId, String name, String display
19621945
}
19631946
}
19641947

1948+
// Don't allow to create network with vlan that already exists in the system
1949+
if (vlanId != null) {
1950+
String uri = "vlan://" + vlanId;
1951+
List<NetworkVO> networks = _networksDao.listBy(zoneId, uri);
1952+
if ((networks != null && !networks.isEmpty())) {
1953+
throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
1954+
}
1955+
}
1956+
1957+
19651958
// If networkDomain is not specified, take it from the global configuration
19661959
if (areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) {
19671960
Map<Network.Capability, String> dnsCapabilities = getNetworkOfferingServiceCapabilities(_configMgr.getNetworkOffering(networkOfferingId), Service.Dns);
@@ -1995,11 +1988,16 @@ public Network createNetwork(long networkOfferingId, String name, String display
19951988
}
19961989
}
19971990

1998-
// Cidr for Shared networks and Isolated networks w/o source nat service can't be NULL - 2.2.x limitation, remove after we introduce support for multiple ip ranges
1991+
// In Advance zone Cidr for Shared networks and Isolated networks w/o source nat service can't be NULL - 2.2.x limitation, remove after we introduce support for multiple ip ranges
19991992
// with different Cidrs for the same Shared network
2000-
boolean cidrRequired = networkOffering.getTrafficType() == TrafficType.Guest && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
1993+
boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && networkOffering.getTrafficType() == TrafficType.Guest && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
20011994
if (cidr == null && cidrRequired) {
20021995
throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of type " + Network.GuestType.Shared + " and network of type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled");
1996+
}
1997+
1998+
//No cidr can be specified in Basic zone
1999+
if (zone.getNetworkType() == NetworkType.Basic && cidr != null) {
2000+
throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask can't be specified for zone of type " + NetworkType.Basic);
20032001
}
20042002

20052003
// Check if cidr is RFC1918 compliant if the network is Guest Isolated
@@ -3285,6 +3283,7 @@ public Network updateNetwork(long networkId, String name, String displayText, Ac
32853283

32863284
long oldNetworkOfferingId = network.getNetworkOfferingId();
32873285
if (networkOfferingId != null) {
3286+
32883287
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
32893288
if (networkOffering == null || networkOffering.isSystemOnly()) {
32903289
throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);

‎server/src/com/cloud/network/dao/NetworkDao.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
9090

9191
boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap);
9292

93+
List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
9394
}

‎server/src/com/cloud/network/dao/NetworkDaoImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,13 @@ public List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestTy
387387

388388
return listBy(sc, null);
389389
}
390+
391+
@Override
392+
public List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
393+
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
394+
sc.setParameters("datacenter", zoneId);
395+
sc.setParameters("trafficType", trafficType);
396+
397+
return listBy(sc, null);
398+
}
390399
}

‎server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -589,22 +589,13 @@ protected List<LoadBalancerVO> findExistingLoadBalancers(String lbName, Long ipI
589589

590590
@DB
591591
public PublicIp allocIp(CreateLoadBalancerRuleCmd lb, Account account) throws InsufficientAddressCapacityException {
592-
//TODO: this only works in the guest network. Handle the public network case also.
593-
NetworkOfferingVO frontEndOffering = null;
594-
if (_frontendTrafficType == TrafficType.Guest) {
595-
frontEndOffering = _networkMgr.getExclusiveGuestNetworkOffering();
596-
}
597-
598-
if (frontEndOffering == null) {
599-
s_logger.warn("ELB: Could not find offering for direct networks of type " + _frontendTrafficType);
600-
return null;
601-
}
602-
603-
List<NetworkVO> networks = _networksDao.listBy(Account.ACCOUNT_ID_SYSTEM, frontEndOffering.getId(), lb.getZoneId());
604-
if (networks == null || networks.size() == 0) {
605-
s_logger.warn("ELB: Could not find network of offering type " + frontEndOffering + " in zone " + lb.getZoneId());
606-
return null;
607-
}
592+
//TODO: this only works in the guest network in Basic zone. Handle the public network case also.
593+
List<NetworkVO> networks = _networkDao.listByZoneAndTrafficType(lb.getZoneId(), TrafficType.Guest);
594+
if (networks.isEmpty()) {
595+
s_logger.warn("Unable to find network with traffic type " + TrafficType.Guest + " in zone id=" + lb.getZoneId());
596+
return null;
597+
}
598+
608599
Network frontEndNetwork = networks.get(0);
609600
Transaction txn = Transaction.currentTxn();
610601
txn.start();

0 commit comments

Comments
 (0)