2424
2525import javax .inject .Inject ;
2626
27+ import com .cloud .exception .UnsupportedServiceException ;
2728import com .cloud .network .element .UserDataServiceProvider ;
2829import com .cloud .storage .VMTemplateVO ;
2930import com .cloud .storage .dao .VMTemplateDao ;
@@ -605,7 +606,7 @@ private boolean enableStaticNat(long ipId, long vmId, long networkId, boolean is
605606 // enable static nat on the backend
606607 s_logger .trace ("Enabling static nat for ip address " + ipAddress + " and vm id=" + vmId + " on the backend" );
607608 if (applyStaticNatForIp (ipId , false , caller , false )) {
608- applyUserData (vmId , network , guestNic );
609+ applyUserDataIfNeeded (vmId , network , guestNic );
609610 performedIpAssoc = false ; // ignor unassignIPFromVpcNetwork in finally block
610611 return true ;
611612 } else {
@@ -629,8 +630,14 @@ private boolean enableStaticNat(long ipId, long vmId, long networkId, boolean is
629630 return false ;
630631 }
631632
632- protected void applyUserData (long vmId , Network network , Nic guestNic ) throws ResourceUnavailableException {
633- UserDataServiceProvider element = _networkModel .getUserDataUpdateProvider (network );
633+ protected void applyUserDataIfNeeded (long vmId , Network network , Nic guestNic ) throws ResourceUnavailableException {
634+ UserDataServiceProvider element = null ;
635+ try {
636+ element = _networkModel .getUserDataUpdateProvider (network );
637+ } catch (UnsupportedServiceException ex ) {
638+ s_logger .info (String .format ("%s is not supported by network %s, skipping." , Service .UserData .getName (), network ));
639+ return ;
640+ }
634641 if (element == null ) {
635642 s_logger .error ("Can't find network element for " + Service .UserData .getName () + " provider needed for UserData update" );
636643 } else {
@@ -1144,7 +1151,7 @@ public boolean revokeAllPFAndStaticNatRulesForIp(long ipId, long userId, Account
11441151 Nic guestNic = _networkModel .getNicInNetwork (vmId , guestNetwork .getId ());
11451152 if (applyStaticNatForIp (ipId , false , caller , true )) {
11461153 if (ipAddress .getState () == IpAddress .State .Releasing ) {
1147- applyUserData (vmId , guestNetwork , guestNic );
1154+ applyUserDataIfNeeded (vmId , guestNetwork , guestNic );
11481155 }
11491156 } else {
11501157 success = false ;
@@ -1289,7 +1296,7 @@ public boolean disableStaticNat(long ipId) throws ResourceUnavailableException,
12891296
12901297 if (disableStaticNat (ipId , caller , ctx .getCallingUserId (), false )) {
12911298 Nic guestNic = _networkModel .getNicInNetworkIncludingRemoved (vmId , guestNetwork .getId ());
1292- applyUserData (vmId , guestNetwork , guestNic );
1299+ applyUserDataIfNeeded (vmId , guestNetwork , guestNic );
12931300 return true ;
12941301 }
12951302 return false ;
0 commit comments