Skip to content

Commit 4e82435

Browse files
Delete local storage properties in agent.properties during delete pool
1 parent 91f1ada commit 4e82435

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
431431

432432
protected static final String LOCAL_STORAGE_PATH = "local.storage.path";
433433
protected static final String LOCAL_STORAGE_UUID = "local.storage.uuid";
434-
protected static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images/";
434+
public static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images";
435435

436436
protected List<String> localStoragePaths = new ArrayList<>();
437437
protected List<String> localStorageUUIDs = new ArrayList<>();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@
2222
import com.cloud.agent.api.Answer;
2323
import com.cloud.agent.api.DeleteStoragePoolCommand;
2424
import 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;
2528
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
2629
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
2730
import com.cloud.resource.CommandWrapper;
2831
import com.cloud.resource.ResourceWrapper;
32+
import com.cloud.storage.Storage;
2933
import 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)
3240
public 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

Comments
 (0)