Signed-off-by: Daniel Kral <[email protected]>
---
src/PVE/HA/Config.pm | 8 +-------
src/PVE/HA/Tools.pm | 23 +++++++++++++++--------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 844ab1b1..bca5bb1c 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -197,13 +197,7 @@ sub parse_sid {
my $vmlist = PVE::Cluster::get_vmlist();
if (defined($vmlist->{ids}->{$name})) {
my $vm_type = $vmlist->{ids}->{$name}->{type};
- if ($vm_type eq 'lxc') {
- $type = 'ct';
- } elsif ($vm_type eq 'qemu') {
- $type = 'vm';
- } else {
- die "internal error";
- }
+ $type = PVE::HA::Tools::get_ha_resource_type($vm_type);
$sid = "$type:$name";
} else {
die "unable do detect SID from VMID - VM/CT $1 does not exist\n";
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
index 1fa53df8..26629fb5 100644
--- a/src/PVE/HA/Tools.pm
+++ b/src/PVE/HA/Tools.pm
@@ -289,6 +289,18 @@ sub has_min_version {
return 1;
}
+sub get_ha_resource_type {
+ my ($pve_resource_type) = @_;
+
+ if ($pve_resource_type eq 'lxc') {
+ return 'ct';
+ } elsif ($pve_resource_type eq 'qemu') {
+ return 'vm';
+ } else {
+ die "unknown PVE resource type '$pve_resource_type'";
+ }
+}
+
# bash auto completion helper
# NOTE: we use PVE::HA::Config here without declaring an 'use' clause above as
@@ -309,15 +321,10 @@ sub complete_sid {
while (my ($vmid, $info) = each %{ $vmlist->{ids} }) {
- my $sid;
+ my $type = eval { get_ha_resource_type($info->{type}) };
+ next if $@; # silently ignore unknown pve types
- if ($info->{type} eq 'lxc') {
- $sid = "ct:$vmid";
- } elsif ($info->{type} eq 'qemu') {
- $sid = "vm:$vmid";
- } else {
- next; # should not happen
- }
+ my $sid = "$type:$vmid";
next if $cfg->{ids}->{$sid};
--
2.47.3