3636import com .cloud .agent .api .DeleteLogicalRouterPortCommand ;
3737import com .cloud .agent .api .DeleteLogicalSwitchAnswer ;
3838import com .cloud .agent .api .DeleteLogicalSwitchCommand ;
39+ import com .cloud .agent .api .FindL2GatewayServiceAnswer ;
40+ import com .cloud .agent .api .FindL2GatewayServiceCommand ;
3941import com .cloud .agent .api .FindLogicalRouterPortAnswer ;
4042import com .cloud .agent .api .FindLogicalRouterPortCommand ;
4143import com .cloud .dc .DataCenter ;
5456import com .cloud .network .Network .State ;
5557import com .cloud .network .NetworkModel ;
5658import com .cloud .network .NetworkProfile ;
57- import com .cloud .network .NiciraNvpNicMappingVO ;
58- import com .cloud .network .NiciraNvpRouterMappingVO ;
5959import com .cloud .network .Networks .BroadcastDomainType ;
6060import com .cloud .network .NiciraNvpDeviceVO ;
61+ import com .cloud .network .NiciraNvpNicMappingVO ;
62+ import com .cloud .network .NiciraNvpRouterMappingVO ;
6163import com .cloud .network .PhysicalNetwork ;
6264import com .cloud .network .PhysicalNetwork .IsolationMethod ;
6365import com .cloud .network .dao .NetworkDao ;
6769import com .cloud .network .dao .NiciraNvpRouterMappingDao ;
6870import com .cloud .network .dao .PhysicalNetworkDao ;
6971import com .cloud .network .dao .PhysicalNetworkVO ;
72+ import com .cloud .network .nicira .L2GatewayServiceConfig ;
7073import com .cloud .offering .NetworkOffering ;
7174import com .cloud .offerings .dao .NetworkOfferingServiceMapDao ;
7275import com .cloud .resource .ResourceManager ;
@@ -209,6 +212,16 @@ public Network implement(final Network network, final NetworkOffering offering,
209212 final String transportzoneuuid = niciraNvpHost .getDetail ("transportzoneuuid" );
210213 final String transportzoneisotype = niciraNvpHost .getDetail ("transportzoneisotype" );
211214
215+ if (offering .getGuestType ().equals (GuestType .Shared )) {
216+ try {
217+ checkL2GatewayServiceSharedNetwork (niciraNvpHost );
218+ }
219+ catch (Exception e ){
220+ s_logger .error ("L2 Gateway Service Issue: " + e .getMessage ());
221+ return null ;
222+ }
223+ }
224+
212225 final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand (transportzoneuuid , transportzoneisotype , name , context .getDomain ().getName () + "-"
213226 + context .getAccount ().getAccountName ());
214227 final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer ) agentMgr .easySend (niciraNvpHost .getId (), cmd );
@@ -230,6 +243,26 @@ public Network implement(final Network network, final NetworkOffering offering,
230243 return implemented ;
231244 }
232245
246+ private void checkL2GatewayServiceSharedNetwork (HostVO niciraNvpHost ) throws Exception {
247+ String l2GatewayServiceUuid = niciraNvpHost .getDetail ("l2gatewayserviceuuid" );
248+ if (l2GatewayServiceUuid == null ){
249+ throw new Exception ("No L2 Gateway Service found" );
250+ }
251+ else {
252+ final FindL2GatewayServiceCommand cmdL2GWService = new FindL2GatewayServiceCommand (new L2GatewayServiceConfig (l2GatewayServiceUuid ));
253+ final FindL2GatewayServiceAnswer answerL2GWService = (FindL2GatewayServiceAnswer ) agentMgr .easySend (niciraNvpHost .getId (), cmdL2GWService );
254+ if (answerL2GWService == null || !answerL2GWService .getResult ()){
255+ throw new Exception ("No L2 Gateway Service found with uuid " + l2GatewayServiceUuid );
256+ }
257+ else {
258+ String uuidFound = answerL2GWService .getGatewayServiceUuid ();
259+ if (! uuidFound .equals (l2GatewayServiceUuid )){
260+ throw new Exception ("Found L2 Gateway Service " + uuidFound + " instead of " + l2GatewayServiceUuid );
261+ }
262+ }
263+ }
264+ }
265+
233266 @ Override
234267 public void reserve (final NicProfile nic , final Network network , final VirtualMachineProfile vm , final DeployDestination dest , final ReservationContext context )
235268 throws InsufficientVirtualNetworkCapacityException , InsufficientAddressCapacityException {
0 commit comments