[pve-devel] [PATCH v3] HA parse_sid changed to accept CT

Alen Grizonic a.grizonic at proxmox.com
Tue Sep 1 11:53:59 CEST 2015


[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





More information about the pve-devel mailing list