[pve-devel] [RFC v2 1/3] Adding PVECT resource class so that CT can be HA managed
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Sep 1 14:01:51 CEST 2015
Extend the PVEVM resource class and add a PVECT resource class so
that service type specific operations (e.g.: start, migrate, ...)
can be handled through an plugin and so independent of the service
type.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/Resources.pm | 124 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index 099280d..afa1009 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -69,11 +69,36 @@ sub parse_section_header {
return undef;
}
+sub start {
+ die "implement in subclass";
+}
+
+sub shutdown {
+ die "implement in subclass";
+}
+
+sub migrate {
+ die "implement in subclass";
+}
+
+sub config_file {
+ die "implement in subclass"
+}
+
+sub check_running {
+ die "implement in subclass";
+}
+
+
+# virtual machine resource class
package PVE::HA::Resources::PVEVM;
use strict;
use warnings;
+use PVE::QemuServer;
+use PVE::API2::Qemu;
+
use base qw(PVE::HA::Resources);
sub type {
@@ -94,6 +119,105 @@ sub options {
};
}
+sub config_file {
+ my ($class, $vmid, $nodename);
+
+ return PVE::QemuServer::config_file($vmid, $nodename);
+}
+
+sub start {
+ my ($class, $haenv, $param) = @_;
+
+ my $upid = PVE::API2::Qemu->vm_start($param);
+ $haenv->upid_wait($upid);
+}
+
+sub shutdown {
+ my ($class, $haenv, $param) = @_;
+
+ my $upid = PVE::API2::Qemu->vm_shutdown($param);
+ $haenv->upid_wait($upid);
+}
+
+
+sub migrate {
+ my ($class, $haenv, $params) = @_;
+
+ my $upid = PVE::API2::Qemu->migrate_vm($params);
+ $haenv->upid_wait($upid);
+}
+
+sub check_running {
+ my ($class, $vmid) = @_;
+
+ return PVE::QemuServer::check_running($vmid, 1);
+}
+
+
+# container resource class
+package PVE::HA::Resources::PVECT;
+
+use strict;
+use warnings;
+
+use PVE::LXC;
+use PVE::API2::LXC::Status;
+
+use base qw(PVE::HA::Resources);
+
+sub type {
+ return 'ct';
+}
+
+sub verify_name {
+ my ($class, $name) = @_;
+
+ die "invalid VMID\n" if $name !~ m/^[1-9][0-9]+$/;
+}
+
+sub options {
+ return {
+ state => { optional => 1 },
+ group => { optional => 1 },
+ comment => { optional => 1 },
+ };
+}
+
+sub config_file {
+ my ($class, $vmid, $nodename);
+
+ return PVE::LXC::config_file($vmid, $nodename);
+}
+
+sub start {
+ my ($class, $haenv, $param) = @_;
+
+ my $upid = PVE::API2::LXC::Status->vm_start($param);
+ $haenv->upid_wait($upid);
+}
+
+sub shutdown {
+ my ($class, $haenv, $params) = @_;
+
+ my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
+ $haenv->upid_wait($upid);
+}
+
+# no live migration for LXC
+# so we die for now
+sub migrate {
+ my ($class, $haenv, $params) = @_;
+
+ my $upid = PVE::API2::LXC->migrate_vm($params);
+ $haenv->upid_wait($upid);
+}
+
+sub check_running {
+ my ($class, $vmid) = @_;
+
+ return PVE::LXC::check_running($vmid);
+}
+
# package PVE::HA::Resources::IPAddr;
# use strict;
--
2.1.4
More information about the pve-devel
mailing list