[pve-devel] [PATCH ha-manager 1/4] resource agents: generate parameters inside resource classes
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Jan 13 15:15:30 CET 2016
The params of resource methods are normally specific for each
resource type.
CTs and VMs have the same interfaces in the needed cases so we could
generate the params in the exec_resource_agent method. This is not
clean because:
* resource specific stuff shouldn't be in this method
* this can make problems if we want to add another resource type
in the future which has a completely different interface
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/Env/PVE2.pm | 28 +++----------------
src/PVE/HA/Resources.pm | 72 ++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 65 insertions(+), 35 deletions(-)
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 3709a17..2dbe4ad 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -418,12 +418,7 @@ sub exec_resource_agent {
$self->log("info", "starting service $sid");
- my $params = {
- node => $nodename,
- vmid => $vmid
- };
-
- $plugin->start($self, $params);
+ $plugin->start($self, $vmid);
$running = $plugin->check_running($vmid);
@@ -441,16 +436,7 @@ sub exec_resource_agent {
$self->log("info", "stopping service $sid");
- my $timeout = 60; # fixme: make this configurable
-
- my $params = {
- node => $nodename,
- vmid => $vmid,
- timeout => $timeout,
- forceStop => 1,
- };
-
- $plugin->shutdown($self, $params);
+ $plugin->shutdown($self, $vmid);
$running = $plugin->check_running($vmid);
@@ -475,17 +461,9 @@ sub exec_resource_agent {
return SUCCESS;
}
- # we always do (live) migration
- my $params = {
- node => $nodename,
- vmid => $vmid,
- target => $target,
- online => 1,
- };
-
my $oldconfig = $plugin->config_file($vmid, $nodename);
- $plugin->migrate($self, $params);
+ $plugin->migrate($self, $vmid, $target, 1);
# something went wrong if old config file is still there
if (-f $oldconfig) {
diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index 26de643..bce396a 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -89,19 +89,19 @@ sub parse_section_header {
}
sub start {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id) = @_;
die "implement in subclass";
}
sub shutdown {
- my ($class, $haenv, $param) = @_;
+ my ($class, $haenv, $id) = @_;
die "implement in subclass";
}
sub migrate {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id, $target, $online) = @_;
die "implement in subclass";
}
@@ -176,22 +176,48 @@ sub exists {
}
sub start {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id) = @_;
+
+ my $nodename = $haenv->nodename();
+
+ my $params = {
+ node => $nodename,
+ vmid => $id
+ };
my $upid = PVE::API2::Qemu->vm_start($params);
$haenv->upid_wait($upid);
}
sub shutdown {
- my ($class, $haenv, $param) = @_;
+ my ($class, $haenv, $id) = @_;
- my $upid = PVE::API2::Qemu->vm_shutdown($param);
+ my $nodename = $haenv->nodename();
+ my $shutdown_timeout = 60; # fixme: make this configurable
+
+ my $params = {
+ node => $nodename,
+ vmid => $id,
+ timeout => $shutdown_timeout,
+ forceStop => 1,
+ };
+
+ my $upid = PVE::API2::Qemu->vm_shutdown($params);
$haenv->upid_wait($upid);
}
sub migrate {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id, $target, $online) = @_;
+
+ my $nodename = $haenv->nodename();
+
+ my $params = {
+ node => $nodename,
+ vmid => $id,
+ target => $target,
+ online => $online,
+ };
my $upid = PVE::API2::Qemu->migrate_vm($params);
$haenv->upid_wait($upid);
@@ -256,21 +282,47 @@ sub exists {
}
sub start {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id) = @_;
+
+ my $nodename = $haenv->nodename();
+
+ my $params = {
+ node => $nodename,
+ vmid => $id
+ };
my $upid = PVE::API2::LXC::Status->vm_start($params);
$haenv->upid_wait($upid);
}
sub shutdown {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id) = @_;
+
+ my $nodename = $haenv->nodename();
+ my $shutdown_timeout = 60; # fixme: make this configurable
+
+ my $params = {
+ node => $nodename,
+ vmid => $id,
+ timeout => $shutdown_timeout,
+ forceStop => 1,
+ };
my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
$haenv->upid_wait($upid);
}
sub migrate {
- my ($class, $haenv, $params) = @_;
+ my ($class, $haenv, $id, $target, $online) = @_;
+
+ my $nodename = $haenv->nodename();
+
+ my $params = {
+ node => $nodename,
+ vmid => $id,
+ target => $target,
+ online => $online,
+ };
my $upid = PVE::API2::LXC->migrate_vm($params);
$haenv->upid_wait($upid);
--
2.1.4
More information about the pve-devel
mailing list