rbd plugin: factor out helper to check if volume already exists
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
committed by
Fabian Grünbichler
parent
9adc4c69ef
commit
3bf2193b44
@ -348,6 +348,16 @@ sub rbd_volume_du {
|
|||||||
die "got no matching image from rbd du\n";
|
die "got no matching image from rbd du\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my sub rbd_volume_exists {
|
||||||
|
my ($scfg, $storeid, $volname) = @_;
|
||||||
|
|
||||||
|
eval {
|
||||||
|
my $cmd = $rbd_cmd->($scfg, $storeid, 'info', $volname);
|
||||||
|
run_rbd_command($cmd, errmsg => "exist check", quiet => 1);
|
||||||
|
};
|
||||||
|
return $@ ? undef : 1;
|
||||||
|
}
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
sub type {
|
sub type {
|
||||||
@ -869,11 +879,8 @@ sub rename_volume {
|
|||||||
$target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format)
|
$target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format)
|
||||||
if !$target_volname;
|
if !$target_volname;
|
||||||
|
|
||||||
eval {
|
die "target volume '${target_volname}' already exists\n"
|
||||||
my $cmd = $rbd_cmd->($scfg, $storeid, 'info', $target_volname);
|
if rbd_volume_exists($scfg, $storeid, $target_volname);
|
||||||
run_rbd_command($cmd, errmsg => "exist check", quiet => 1);
|
|
||||||
};
|
|
||||||
die "target volume '${target_volname}' already exists\n" if !$@;
|
|
||||||
|
|
||||||
my $cmd = $rbd_cmd->($scfg, $storeid, 'rename', $source_image, $target_volname);
|
my $cmd = $rbd_cmd->($scfg, $storeid, 'rename', $source_image, $target_volname);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user