add on_add and on_delete hooks

on_add_hook allows to encapsulate storage specific add steps, like
copying a keyring (RDB) or creating a volume group (LVM) in a clean
manner.
The same for deletion with on_delete_hook, here all should be cleaned
up, as much as possible.

Until now, this was done directly in the api config CREATE and DELETE
code, respectively, with a series of

if ($storage_type eq 'foo) {
    ...
} elsif ($storage_type eq 'bar') {
    ...
}

which isn't really that nice...

Another nice result of this approach is that also external plugins
can use those hooks and to their setup/cleanup steps sanely.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2018-07-02 15:54:44 +02:00
committed by Wolfgang Bumiller
parent d7b707626a
commit 3932ca0d1b
2 changed files with 28 additions and 0 deletions

View File

@ -352,6 +352,26 @@ sub parse_config {
# Storage implementation
# called during addition of storage (before the new storage config got written)
# die to abort additon if there are (grave) problems
# NOTE: runs in a storage config *locked* context
sub on_add_hook {
my ($class, $storeid, $scfg, %param) = @_;
# do nothing by default
}
# called during deletion of storage (before the new storage config got written)
# and if the activate check on addition fails, to cleanup all storage traces
# which on_add_hook may have created.
# die to abort deletion if there are (very grave) problems
# NOTE: runs in a storage config *locked* context
sub on_delete_hook {
my ($class, $storeid, $scfg) = @_;
# do nothing by default
}
sub cluster_lock_storage {
my ($class, $storeid, $shared, $timeout, $func, @param) = @_;