5959import com .cloud .configuration .Config ;
6060import com .cloud .host .Host ;
6161import com .cloud .host .dao .HostDao ;
62+ import com .cloud .resource .ResourceState ;
6263import com .cloud .storage .DataStoreRole ;
6364import com .cloud .storage .ResizeVolumePayload ;
6465import com .cloud .storage .SnapshotVO ;
@@ -214,6 +215,7 @@ private void deleteResourceDefinition(StoragePoolVO storagePoolVO, String rscDef
214215 }
215216 throw new CloudRuntimeException ("Linstor: Unable to delete resource definition: " + rscDefName );
216217 }
218+ s_logger .info (String .format ("Linstor: Deleted resource %s" , rscDefName ));
217219 } catch (ApiException apiEx )
218220 {
219221 s_logger .error ("Linstor: ApiEx - " + apiEx .getMessage ());
@@ -865,7 +867,7 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
865867 Host host = null ;
866868 for (String nodeName : linstorNodeNames ) {
867869 host = _hostDao .findByName (nodeName );
868- if (host != null ) {
870+ if (host != null && host . getResourceState () == ResourceState . Enabled ) {
869871 s_logger .info (String .format ("Linstor: Make resource %s available on node %s ..." , rscName , nodeName ));
870872 ApiCallRcList answers = api .resourceMakeAvailableOnNode (rscName , nodeName , new ResourceMakeAvailable ());
871873 if (!answers .hasError ()) {
@@ -892,21 +894,16 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
892894 }
893895
894896 private Optional <RemoteHostEndPoint > getDiskfullEP (DevelopersApi api , String rscName ) throws ApiException {
895- com .linbit .linstor .api .model .StoragePool linSP =
896- LinstorUtil .getDiskfulStoragePool (api , rscName );
897- if (linSP != null )
898- {
899- Host host = _hostDao .findByName (linSP .getNodeName ());
900- if (host == null )
901- {
902- s_logger .error ("Linstor: Host '" + linSP .getNodeName () + "' not found." );
903- return Optional .empty ();
904- }
905- else
906- {
907- return Optional .of (RemoteHostEndPoint .getHypervisorHostEndPoint (host ));
897+ List <com .linbit .linstor .api .model .StoragePool > linSPs = LinstorUtil .getDiskfulStoragePools (api , rscName );
898+ if (linSPs != null ) {
899+ for (com .linbit .linstor .api .model .StoragePool sp : linSPs ) {
900+ Host host = _hostDao .findByName (sp .getNodeName ());
901+ if (host != null && host .getResourceState () == ResourceState .Enabled ) {
902+ return Optional .of (RemoteHostEndPoint .getHypervisorHostEndPoint (host ));
903+ }
908904 }
909905 }
906+ s_logger .error ("Linstor: No diskfull host found." );
910907 return Optional .empty ();
911908 }
912909
@@ -958,9 +955,11 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) {
958955 }
959956 else {
960957 answer = new Answer (cmd , false , "Unable to get matching Linstor endpoint." );
958+ deleteResourceDefinition (pool , rscName );
961959 }
962960 } catch (ApiException exc ) {
963961 s_logger .error ("copy template failed: " , exc );
962+ deleteResourceDefinition (pool , rscName );
964963 throw new CloudRuntimeException (exc .getBestMessage ());
965964 }
966965 return answer ;
0 commit comments