2222import com .cloud .agent .api .Answer ;
2323import com .cloud .agent .api .DeleteStoragePoolCommand ;
2424import com .cloud .agent .api .to .StorageFilerTO ;
25+ import com .cloud .agent .dao .impl .PropertiesStorage ;
26+ import com .cloud .agent .properties .AgentProperties ;
27+ import com .cloud .agent .properties .AgentPropertiesFileHandler ;
2528import com .cloud .hypervisor .kvm .resource .LibvirtComputingResource ;
2629import com .cloud .hypervisor .kvm .storage .KVMStoragePoolManager ;
2730import com .cloud .resource .CommandWrapper ;
2831import com .cloud .resource .ResourceWrapper ;
32+ import com .cloud .storage .Storage ;
2933import com .cloud .utils .exception .CloudRuntimeException ;
3034
35+ import java .util .Arrays ;
36+ import java .util .HashMap ;
37+ import java .util .stream .Collectors ;
38+
3139@ ResourceWrapper (handles = DeleteStoragePoolCommand .class )
3240public final class LibvirtDeleteStoragePoolCommandWrapper extends CommandWrapper <DeleteStoragePoolCommand , Answer , LibvirtComputingResource > {
3341 @ Override
@@ -39,6 +47,34 @@ public Answer execute(final DeleteStoragePoolCommand command, final LibvirtCompu
3947 final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource .getStoragePoolMgr ();
4048
4149 storagePoolMgr .deleteStoragePool (pool .getType (), pool .getUuid ());
50+ if (Storage .StoragePoolType .Filesystem .equals (pool .getType ()) && !libvirtComputingResource .DEFAULT_LOCAL_STORAGE_PATH .equals (pool .getPath ())) {
51+ String localStoragePath = AgentPropertiesFileHandler .getPropertyValue (AgentProperties .LOCAL_STORAGE_PATH );
52+ String localStorageUuid = AgentPropertiesFileHandler .getPropertyValue (AgentProperties .LOCAL_STORAGE_UUID );
53+
54+ String uuidToRemove = pool .getUuid ();
55+ String pathToRemove = pool .getPath ();
56+
57+ if (localStorageUuid != null && uuidToRemove != null ) {
58+ localStorageUuid = Arrays .stream (localStorageUuid .split ("," ))
59+ .filter (uuid -> !uuid .equals (uuidToRemove ))
60+ .collect (Collectors .joining ("," ));
61+ }
62+
63+ if (localStoragePath != null && pathToRemove != null ) {
64+ localStoragePath = Arrays .stream (localStoragePath .split ("," ))
65+ .filter (path -> !path .equals (pathToRemove ))
66+ .collect (Collectors .joining ("," ));
67+ }
68+
69+ PropertiesStorage agentProperties = new PropertiesStorage ();
70+ agentProperties .configure ("AgentProperties" , new HashMap <String , Object >());
71+ if (localStorageUuid != null ) {
72+ agentProperties .persist (AgentProperties .LOCAL_STORAGE_UUID .getName (), localStorageUuid );
73+ }
74+ if (localStoragePath != null ) {
75+ agentProperties .persist (AgentProperties .LOCAL_STORAGE_PATH .getName (), localStoragePath );
76+ }
77+ }
4278 }
4379
4480 return new Answer (command );
0 commit comments