api: disks: delete: add flag for cleaning up storage config

Update node restrictions to reflect that the storage is not available
anymore on the particular node. If the storage was only configured for
that node, remove it altogether.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>

slight style fixup

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Ebner
2021-10-25 15:47:49 +02:00
committed by Fabian Grünbichler
parent f81908eb58
commit cde43c4880
5 changed files with 109 additions and 0 deletions

View File

@ -38,6 +38,33 @@ my $api_storage_config = sub {
return $scfg;
};
# For storages that $match->($scfg), update node restrictions to not include $node anymore and
# in case no node remains, remove the storage altogether.
sub cleanup_storages_for_node {
my ($self, $match, $node) = @_;
my $config = PVE::Storage::config();
my $cluster_nodes = PVE::Cluster::get_nodelist();
for my $storeid (keys $config->{ids}->%*) {
my $scfg = PVE::Storage::storage_config($config, $storeid);
next if !$match->($scfg);
my $nodes = $scfg->{nodes} || { map { $_ => 1 } $cluster_nodes->@* };
next if !$nodes->{$node}; # not configured on $node, so nothing to do
delete $nodes->{$node};
if (scalar(keys $nodes->%*) > 0) {
$self->update({
nodes => join(',', sort keys $nodes->%*),
storage => $storeid,
});
} else {
$self->delete({storage => $storeid});
}
}
}
__PACKAGE__->register_method ({
name => 'index',
path => '',