5555import com .cloud .configuration .dao .ConfigurationDao ;
5656import com .cloud .dc .AccountVlanMapVO ;
5757import com .cloud .dc .DataCenter ;
58- import com .cloud .dc .DataCenter .DataCenterNetworkType ;
58+ import com .cloud .dc .DataCenter .NetworkType ;
5959import com .cloud .dc .DataCenterIpAddressVO ;
6060import com .cloud .dc .DataCenterVO ;
6161import com .cloud .dc .HostPodVO ;
7171import com .cloud .dc .dao .HostPodDao ;
7272import com .cloud .dc .dao .PodVlanMapDao ;
7373import com .cloud .dc .dao .VlanDao ;
74+ import com .cloud .deploy .DataCenterDeployment ;
7475import com .cloud .domain .DomainVO ;
7576import com .cloud .domain .dao .DomainDao ;
7677import com .cloud .event .EventTypes ;
8485import com .cloud .exception .PermissionDeniedException ;
8586import com .cloud .hypervisor .Hypervisor .HypervisorType ;
8687import com .cloud .network .NetworkManager ;
88+ import com .cloud .network .NetworkVO ;
89+ import com .cloud .network .Networks .BroadcastDomainType ;
8790import com .cloud .network .Networks .TrafficType ;
8891import com .cloud .network .dao .IPAddressDao ;
8992import com .cloud .offering .DiskOffering ;
@@ -897,7 +900,7 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
897900 }
898901
899902 //if zone is of Basic type, don't allow to add vnet range
900- if (vnetRange != null && zone .getNetworkType () == DataCenterNetworkType .Basic ) {
903+ if (vnetRange != null && zone .getNetworkType () == NetworkType .Basic ) {
901904 throw new InvalidParameterValueException ("Can't add vnet range for the zone that supports Basic network" );
902905 }
903906
@@ -1021,7 +1024,7 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
10211024 }
10221025
10231026 @ Override @ DB
1024- public DataCenterVO createZone (long userId , String zoneName , String dns1 , String dns2 , String internalDns1 , String internalDns2 , String vnetRange , String guestCidr , String domain , Long domainId , DataCenterNetworkType zoneType ) {
1027+ public DataCenterVO createZone (long userId , String zoneName , String dns1 , String dns2 , String internalDns1 , String internalDns2 , String vnetRange , String guestCidr , String domain , Long domainId , NetworkType zoneType ) {
10251028 int vnetStart = 0 ;
10261029 int vnetEnd = 0 ;
10271030 if (vnetRange != null ) {
@@ -1046,21 +1049,55 @@ public DataCenterVO createZone(long userId, String zoneName, String dns1, String
10461049
10471050 checkZoneParameters (zoneName , dns1 , dns2 , internalDns1 , internalDns2 , true , domainId );
10481051
1049- // Create the new zone in the database
1050- DataCenterVO zone = new DataCenterVO (zoneName , null , dns1 , dns2 , internalDns1 , internalDns2 , vnetRange , guestCidr , domain , domainId , zoneType );
1051- zone = _zoneDao .persist (zone );
1052+ Transaction txn = Transaction .currentTxn ();
1053+ try {
1054+ // Create the new zone in the database
1055+ DataCenterVO zone = new DataCenterVO (zoneName , null , dns1 , dns2 , internalDns1 , internalDns2 , vnetRange , guestCidr , domain , domainId , zoneType );
1056+ zone = _zoneDao .persist (zone );
10521057
1053- // Add vnet entries for the new zone if zone type is Advanced
1054- if (vnetRange != null ) {
1055- _zoneDao .addVnet (zone .getId (), vnetStart , vnetEnd );
1056- }
1057-
1058- if (vnetRange != null ) {
1059- saveConfigurationEvent (userId , null , EventTypes .EVENT_ZONE_CREATE , "Successfully created new zone with name: " + zoneName + "." , "dcId=" + zone .getId (), "dns1=" + dns1 , "dns2=" + dns2 , "internalDns1=" + internalDns1 , "internalDns2=" + internalDns2 , "vnetRange=" + vnetRange , "guestCidr=" + guestCidr );
1060- } else {
1061- saveConfigurationEvent (userId , null , EventTypes .EVENT_ZONE_CREATE , "Successfully created new zone with name: " + zoneName + "." , "dcId=" + zone .getId (), "dns1=" + dns1 , "dns2=" + dns2 , "internalDns1=" + internalDns1 , "internalDns2=" + internalDns2 , "guestCidr=" + guestCidr );
1062- }
1063- return zone ;
1058+ // Add vnet entries for the new zone if zone type is Advanced
1059+ if (vnetRange != null ) {
1060+ _zoneDao .addVnet (zone .getId (), vnetStart , vnetEnd );
1061+ }
1062+
1063+ //if zone is basic, create a untagged network
1064+ if (zone != null && zone .getNetworkType () == NetworkType .Basic ) {
1065+ //Create network
1066+ DataCenterDeployment plan = new DataCenterDeployment (zone .getId (), null , null , null );
1067+ NetworkVO userNetwork = new NetworkVO ();
1068+ userNetwork .setBroadcastDomainType (BroadcastDomainType .Native );
1069+
1070+ Account systemAccount = _accountDao .findById (Account .ACCOUNT_ID_SYSTEM );
1071+
1072+ List <NetworkOfferingVO > networkOffering = _networkOfferingDao .findByType (GuestIpType .DirectPodBased );
1073+ if (networkOffering == null || networkOffering .isEmpty ()) {
1074+ throw new CloudRuntimeException ("No default DirectPodBased network offering is found" );
1075+ }
1076+
1077+ List <NetworkVO > networks = _networkMgr .setupNetworkConfiguration (systemAccount , networkOffering .get (0 ), userNetwork , plan , null , null , true );
1078+
1079+ if (networks == null || networks .isEmpty ()) {
1080+ txn .rollback ();
1081+ throw new CloudRuntimeException ("Fail to create a network" );
1082+ }
1083+ }
1084+
1085+ if (vnetRange != null ) {
1086+ saveConfigurationEvent (userId , null , EventTypes .EVENT_ZONE_CREATE , "Successfully created new zone with name: " + zoneName + "." , "dcId=" + zone .getId (), "dns1=" + dns1 , "dns2=" + dns2 , "internalDns1=" + internalDns1 , "internalDns2=" + internalDns2 , "vnetRange=" + vnetRange , "guestCidr=" + guestCidr );
1087+ } else {
1088+ saveConfigurationEvent (userId , null , EventTypes .EVENT_ZONE_CREATE , "Successfully created new zone with name: " + zoneName + "." , "dcId=" + zone .getId (), "dns1=" + dns1 , "dns2=" + dns2 , "internalDns1=" + internalDns1 , "internalDns2=" + internalDns2 , "guestCidr=" + guestCidr );
1089+ }
1090+
1091+ txn .commit ();
1092+ return zone ;
1093+ } catch (Exception ex ) {
1094+ txn .rollback ();
1095+ s_logger .warn ("Exception: " , ex );
1096+ throw new CloudRuntimeException ("Fail to create a network" );
1097+ }finally {
1098+ txn .close ();
1099+ }
1100+
10641101 }
10651102
10661103 @ Override
@@ -1079,13 +1116,13 @@ public DataCenter createZone(CreateZoneCmd cmd) {
10791116 Boolean isBasic = false ;
10801117
10811118
1082- if (!(type .equalsIgnoreCase (DataCenterNetworkType .Basic .toString ())) && !(type .equalsIgnoreCase (DataCenterNetworkType .Advanced .toString ()))) {
1119+ if (!(type .equalsIgnoreCase (NetworkType .Basic .toString ())) && !(type .equalsIgnoreCase (NetworkType .Advanced .toString ()))) {
10831120 throw new InvalidParameterValueException ("Invalid zone type; only Advanced and Basic values are supported" );
1084- } else if (type .endsWith (DataCenterNetworkType .Basic .toString ())) {
1121+ } else if (type .endsWith (NetworkType .Basic .toString ())) {
10851122 isBasic = true ;
10861123 }
10871124
1088- DataCenterNetworkType zoneType = isBasic ? DataCenterNetworkType .Basic : DataCenterNetworkType .Advanced ;
1125+ NetworkType zoneType = isBasic ? NetworkType .Basic : NetworkType .Advanced ;
10891126 DomainVO domainVO = null ;
10901127
10911128 if (userId == null ) {
@@ -1097,10 +1134,11 @@ public DataCenter createZone(CreateZoneCmd cmd) {
10971134 }
10981135
10991136 //Verify zone type
1100- if (zoneType == DataCenterNetworkType .Basic && vnetRange != null ) {
1137+ if (zoneType == NetworkType .Basic && vnetRange != null ) {
11011138 vnetRange = null ;
11021139 }
1103- return createZone (userId , zoneName , dns1 , dns2 , internalDns1 , internalDns2 , vnetRange , guestCidr , domainVO != null ? domainVO .getName () : null , domainId , zoneType );
1140+
1141+ return createZone (userId , zoneName , dns1 , dns2 , internalDns1 , internalDns2 , vnetRange , guestCidr , domainVO != null ? domainVO .getName () : null , domainId , zoneType );
11041142 }
11051143
11061144 @ Override
@@ -1483,9 +1521,9 @@ public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, Str
14831521 }
14841522
14851523 //Allow adding untagged direct vlan only for Basic zone
1486- if (zone .getNetworkType () == DataCenterNetworkType .Advanced && vlanId .equals (Vlan .UNTAGGED ) && !forVirtualNetwork ) {
1524+ if (zone .getNetworkType () == NetworkType .Advanced && vlanId .equals (Vlan .UNTAGGED ) && !forVirtualNetwork ) {
14871525 throw new InvalidParameterValueException ("Direct untagged network is not supported for the zone " + zone .getId () + " of type " + zone .getNetworkType ());
1488- } else if (zone .getNetworkType () == DataCenterNetworkType .Basic && !(vlanId .equals (Vlan .UNTAGGED ) && !forVirtualNetwork )) {
1526+ } else if (zone .getNetworkType () == NetworkType .Basic && !(vlanId .equals (Vlan .UNTAGGED ) && !forVirtualNetwork )) {
14891527 throw new InvalidParameterValueException ("Only direct untagged network is supported in the zone " + zone .getId () + " of type " + zone .getNetworkType ());
14901528 }
14911529
0 commit comments