[PATCH v3] changes: - fixed VM/CT exist check - added internal error exception --- src/PVE/HA/Tools.pm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm index 94613de..f3f6110 100644 --- a/src/PVE/HA/Tools.pm +++ b/src/PVE/HA/Tools.pm @@ -5,6 +5,7 @@ use warnings; use JSON; use PVE::JSONSchema; use PVE::Tools; +use PVE::Cluster; PVE::JSONSchema::register_format('pve-ha-resource-id', \&pve_verify_ha_resource_id); sub pve_verify_ha_resource_id { @@ -18,7 +19,7 @@ sub pve_verify_ha_resource_id { } PVE::JSONSchema::register_standard_option('pve-ha-resource-id', { - description => "HA resource ID. This consists of a resource type followed by a resource specific name, separated with collon (example: vm:100).", + description => "HA resource ID. This consists of a resource type followed by a resource specific name, separated with collon (example: vm:100 / ct:100).", typetext => "<type>:<name>", type => 'string', format => 'pve-ha-resource-id', }); @@ -35,7 +36,7 @@ sub pve_verify_ha_resource_or_vm_id { } PVE::JSONSchema::register_standard_option('pve-ha-resource-or-vm-id', { - description => "HA resource ID. This consists of a resource type followed by a resource specific name, separated with collon (example: vm:100). For virtual machines, you can simply use the VM id as shortcut (example: 100).", + description => "HA resource ID. This consists of a resource type followed by a resource specific name, separated with collon (example: vm:100 / ct:100). For virtual machines and containers, you can simply use the VM or CT id as shortcut (example: 100).", typetext => "<type>:<name>", type => 'string', format => 'pve-ha-resource-or-vm-id', }); @@ -69,8 +70,21 @@ sub parse_sid { if ($sid =~ m/^(\d+)$/) { $name = $1; - $type ='vm'; - $sid = "vm:$name"; + 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"; + } + $sid = "$type:$name"; + } + else { + die "unable do add resource - VM/CT $1 does not exist\n"; + } } elsif ($sid =~m/^(\S+):(\S+)$/) { $name = $2; $type = $1; -- 2.1.4 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel