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

Alen Grizonic a.grizonic at proxmox.com
Tue Sep 1 11:26:43 CEST 2015


[PATCH v2] changes -> VM/CT exist check added
---
 src/PVE/HA/Config.pm |  1 +
 src/PVE/HA/Tools.pm  | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 58f5b58..b860abc 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -14,6 +14,7 @@ PVE::HA::Groups->register();
 PVE::HA::Groups->init();
 
 PVE::HA::Resources::PVEVM->register();
+PVE::HA::Resources::PVECT->register();
 #PVE::HA::Resources::IPAddr->register();
 
 PVE::HA::Resources->init();
diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm
index 94613de..c840e97 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,19 @@ sub parse_sid {
 
     if ($sid =~ m/^(\d+)$/) {
 	$name = $1;
-	$type ='vm';
-	$sid = "vm:$name";
+	my $vmlist = PVE::Cluster::get_vmlist();
+	my $vm_type = $vmlist->{ids}->{$name}->{type};
+	if (defined($vm_type)) {
+	    if ($vm_type eq 'lxc') {
+		$type = 'ct';
+	    } elsif ($vm_type eq 'qemu') {
+		$type = 'vm';
+	    }
+	    $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