7777import com .cloud .org .Grouping ;
7878import com .cloud .user .*;
7979import com .cloud .user .dao .AccountDao ;
80+ import com .cloud .user .dao .UserDao ;
81+ import com .cloud .utils .Journal ;
8082import com .cloud .utils .NumbersUtil ;
8183import com .cloud .utils .Pair ;
8284import com .cloud .utils .component .Adapters ;
@@ -127,6 +129,8 @@ public class NetworkManagerImpl implements NetworkManager, Manager, Listener {
127129 @ Inject
128130 DomainDao _domainDao = null ;
129131 @ Inject
132+ UserDao _userDao = null ;
133+ @ Inject
130134 ConfigurationDao _configDao ;
131135 @ Inject
132136 UserVmDao _userVmDao = null ;
@@ -856,14 +860,14 @@ public boolean configure(final String name, final Map<String, Object> params) th
856860 NetworkOfferingVO offering = null ;
857861 if (_networkOfferingDao .findByUniqueName (NetworkOffering .DefaultSharedNetworkOfferingWithSGService ) == null ) {
858862 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultSharedNetworkOfferingWithSGService , "Offering for Shared Security group enabled networks" , TrafficType .Guest , null ,
859- true , Availability .Optional , null , defaultSharedNetworkOfferingProviders , true , Network .GuestType .Shared , false , null , true , null , true );
863+ true , Availability .Optional , null , defaultSharedNetworkOfferingProviders , true , Network .GuestType .Shared , false , null , true , null , true , false );
860864 offering .setState (NetworkOffering .State .Enabled );
861865 _networkOfferingDao .update (offering .getId (), offering );
862866 }
863867
864868 if (_networkOfferingDao .findByUniqueName (NetworkOffering .DefaultSharedNetworkOffering ) == null ) {
865869 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultSharedNetworkOffering , "Offering for Shared networks" , TrafficType .Guest , null , true , Availability .Optional , null ,
866- defaultSharedNetworkOfferingProviders , true , Network .GuestType .Shared , false , null , true , null , true );
870+ defaultSharedNetworkOfferingProviders , true , Network .GuestType .Shared , false , null , true , null , true , false );
867871 offering .setState (NetworkOffering .State .Enabled );
868872 _networkOfferingDao .update (offering .getId (), offering );
869873 }
@@ -886,7 +890,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
886890 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultIsolatedNetworkOfferingWithSourceNatService ,
887891 "Offering for Isolated networks with Source Nat service enabled" , TrafficType .Guest ,
888892 null , false , Availability .Required , null , defaultINetworkOfferingProvidersForVpcNetwork ,
889- true , Network .GuestType .Isolated , false , null , true , null , false );
893+ true , Network .GuestType .Isolated , false , null , true , null , false , false );
890894 offering .setState (NetworkOffering .State .Enabled );
891895 _networkOfferingDao .update (offering .getId (), offering );
892896 }
@@ -895,7 +899,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
895899 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultIsolatedNetworkOfferingForVpcNetworks ,
896900 "Offering for Isolated VPC networks with Source Nat service enabled" , TrafficType .Guest ,
897901 null , false , Availability .Optional , null , defaultVPCOffProviders ,
898- true , Network .GuestType .Isolated , false , null , false , null , false );
902+ true , Network .GuestType .Isolated , false , null , false , null , false , false );
899903 offering .setState (NetworkOffering .State .Enabled );
900904 _networkOfferingDao .update (offering .getId (), offering );
901905 }
@@ -906,7 +910,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
906910 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultIsolatedNetworkOfferingForVpcNetworksNoLB ,
907911 "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled" , TrafficType .Guest ,
908912 null , false , Availability .Optional , null , defaultVPCOffProviders ,
909- true , Network .GuestType .Isolated , false , null , false , null , false );
913+ true , Network .GuestType .Isolated , false , null , false , null , false , false );
910914 offering .setState (NetworkOffering .State .Enabled );
911915 _networkOfferingDao .update (offering .getId (), offering );
912916 }
@@ -915,7 +919,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
915919 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultIsolatedNetworkOffering ,
916920 "Offering for Isolated networks with no Source Nat service" , TrafficType .Guest , null , true ,
917921 Availability .Optional , null , defaultIsolatedNetworkOfferingProviders , true , Network .GuestType .Isolated ,
918- false , null , true , null , true );
922+ false , null , true , null , true , false );
919923 offering .setState (NetworkOffering .State .Enabled );
920924 _networkOfferingDao .update (offering .getId (), offering );
921925 }
@@ -944,7 +948,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
944948
945949 if (_networkOfferingDao .findByUniqueName (NetworkOffering .DefaultSharedEIPandELBNetworkOffering ) == null ) {
946950 offering = _configMgr .createNetworkOffering (NetworkOffering .DefaultSharedEIPandELBNetworkOffering , "Offering for Shared networks with Elastic IP and Elastic LB capabilities" , TrafficType .Guest , null , true ,
947- Availability .Optional , null , netscalerServiceProviders , true , Network .GuestType .Shared , false , null , true , serviceCapabilityMap , true );
951+ Availability .Optional , null , netscalerServiceProviders , true , Network .GuestType .Shared , false , null , true , serviceCapabilityMap , true , false );
948952 offering .setState (NetworkOffering .State .Enabled );
949953 offering .setDedicatedLB (false );
950954 _networkOfferingDao .update (offering .getId (), offering );
@@ -1999,8 +2003,6 @@ public Network createGuestNetwork(long networkOfferingId, String name, String di
19992003 return network ;
20002004 }
20012005
2002-
2003-
20042006 @ Override
20052007 @ DB
20062008 public boolean shutdownNetwork (long networkId , ReservationContext context , boolean cleanupElements ) {
@@ -2533,14 +2535,13 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
25332535 }
25342536
25352537 // create new Virtual network (Isolated with SourceNAT) for the user if it doesn't exist
2538+ List <NetworkOfferingVO > requiredOfferings = _networkOfferingDao .listByAvailability (Availability .Required , false );
2539+ if (requiredOfferings .size () < 1 ) {
2540+ throw new CloudRuntimeException ("Unable to find network offering with availability=" +
2541+ Availability .Required + " to automatically create the network as part of createVlanIpRange" );
2542+ }
25362543 if (createNetwork ) {
2537- List <NetworkOfferingVO > requiredOfferings = _networkOfferingDao .listByAvailability (Availability .Required , false );
2538- if (requiredOfferings .size () < 1 ) {
2539- throw new CloudRuntimeException ("Unable to find network offering with availability=" +
2540- Availability .Required + " to automatically create the network as part of createVlanIpRange" );
2541- }
25422544 if (requiredOfferings .get (0 ).getState () == NetworkOffering .State .Enabled ) {
2543-
25442545 long physicalNetworkId = _networkModel .findPhysicalNetworkId (zoneId , requiredOfferings .get (0 ).getTags (), requiredOfferings .get (0 ).getTrafficType ());
25452546 // Validate physical network
25462547 PhysicalNetwork physicalNetwork = _physicalNetworkDao .findById (physicalNetworkId );
@@ -2595,6 +2596,31 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
25952596 }
25962597
25972598 txn .commit ();
2599+
2600+ // if the network offering has persistent set to true, implement the network
2601+ if ( createNetwork && requiredOfferings .get (0 ).getIsPersistent () ) {
2602+ DataCenter zone = _dcDao .findById (zoneId );
2603+ DeployDestination dest = new DeployDestination (zone , null , null , null );
2604+ Account callerAccount = UserContext .current ().getCaller ();
2605+ UserVO callerUser = _userDao .findById (UserContext .current ().getCallerUserId ());
2606+ Journal journal = new Journal .LogJournal ("Implementing " + guestNetwork , s_logger );
2607+ ReservationContext context = new ReservationContextImpl (UUID .randomUUID ().toString (), journal , callerUser , callerAccount );
2608+ s_logger .debug ("Implementing network " + guestNetwork + " as a part of network provision for persistent network" );
2609+ try {
2610+ Pair <NetworkGuru , NetworkVO > implementedNetwork = implementNetwork (guestNetwork .getId (), dest , context );
2611+ if (implementedNetwork .first () == null ) {
2612+ s_logger .warn ("Failed to implement the network " + guestNetwork );
2613+ }
2614+ guestNetwork = implementedNetwork .second ();
2615+ } catch (Exception ex ) {
2616+ s_logger .warn ("Failed to implement network " + guestNetwork + " elements and resources as a part of" +
2617+ " network provision due to " , ex );
2618+ CloudRuntimeException e = new CloudRuntimeException ("Failed to implement network (with specified id)" +
2619+ " elements and resources as a part of network provision for persistent network" );
2620+ e .addProxyObject (guestNetwork , guestNetwork .getId (), "networkId" );
2621+ throw e ;
2622+ }
2623+ }
25982624 return true ;
25992625 }
26002626
0 commit comments