[pve-devel] [RFC ha-manager v2 3/7] add Hardware Base class
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri Mar 11 16:57:12 CET 2016
This is the super class of the Sim::Hardware class.
For now it provides only a method for executing a fence agent
command to fence another node.
The Sim::TestHardware class overwrites it, as it does not support
forking and/or exec'ing.
In the Sim::RTHardware class we support forking but not fencing,
this will be addressed in a future patch.
---
src/PVE/HA/Env/PVE2.pm | 6 ++++--
src/PVE/HA/Hardware.pm | 31 +++++++++++++++++++++++++++++++
src/PVE/HA/Makefile | 3 ++-
src/PVE/HA/Sim/Hardware.pm | 3 ++-
src/PVE/HA/Sim/TestHardware.pm | 18 ++++++++++++++----
src/PVE/Service/pve_ha_crm.pm | 4 +++-
6 files changed, 56 insertions(+), 9 deletions(-)
create mode 100644 src/PVE/HA/Hardware.pm
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 220f77c..6dd6aa0 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -27,7 +27,7 @@ PVE::HA::Resources->init();
my $lockdir = "/etc/pve/priv/lock";
sub new {
- my ($this, $nodename) = @_;
+ my ($this, $nodename, $hardware) = @_;
die "missing nodename" if !$nodename;
@@ -37,6 +37,8 @@ sub new {
$self->{nodename} = $nodename;
+ $self->{hardware} = $hardware;
+
return $self;
}
@@ -49,7 +51,7 @@ sub nodename {
sub hardware {
my ($self) = @_;
- die "hardware is for testing and simulation only";
+ return $self->{hardware}; # || die "hardware is for testing and simulation only";
}
sub read_manager_status {
diff --git a/src/PVE/HA/Hardware.pm b/src/PVE/HA/Hardware.pm
new file mode 100644
index 0000000..36dee73
--- /dev/null
+++ b/src/PVE/HA/Hardware.pm
@@ -0,0 +1,31 @@
+package PVE::HA::Hardware;
+
+# Hardware resources base class
+# Sim and PVE2 use this for some fence abstraction
+# Sim uses it also to abstract the rest of nodes Hardware
+use strict;
+use warnings;
+use PVE::HA::Config;
+
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ # setup execution environment
+ $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+ my $cmd = "$agent " . PVE::HA::FenceConfig::gen_arg_str(@param);
+
+ exec($cmd);
+}
+
+sub new {
+ my ($this) = @_;
+
+ my $class = ref($this) || $this;
+
+ my $self = bless {}, $class;
+
+ return $self;
+}
+
+1;
diff --git a/src/PVE/HA/Makefile b/src/PVE/HA/Makefile
index 43e37cb..d5f655f 100644
--- a/src/PVE/HA/Makefile
+++ b/src/PVE/HA/Makefile
@@ -1,4 +1,5 @@
-SOURCES=CRM.pm Env.pm Groups.pm Resources.pm Config.pm LRM.pm Manager.pm NodeStatus.pm Tools.pm FenceConfig.pm
+SOURCES=CRM.pm Env.pm Groups.pm Resources.pm Config.pm LRM.pm Manager.pm \
+ NodeStatus.pm Tools.pm FenceConfig.pm Hardware.pm
.PHONY: install
install:
diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 8bb3fe3..2027f13 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -15,10 +15,11 @@ use IO::File;
use Fcntl qw(:DEFAULT :flock);
use File::Copy;
use File::Path qw(make_path remove_tree);
-use PVE::HA::Config 'testenv';
+use PVE::HA::Config;
my $watchdog_timeout = 60;
+use base qw(PVE::HA::Hardware);
# Status directory layout
#
diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index cfd48e7..8f09b6e 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -81,6 +81,19 @@ sub log {
$self->{logfh}->flush();
}
+# simulates fence agent, also the watchdog
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ # let all agent succeed and behave the same for now
+ $self->sim_hardware_cmd("power $node off", $agent);
+ $self->log('info', "server '$node' stopped by poweroff ($agent)");
+ $self->{nodes}->{$node}->{crm} = undef;
+ $self->{nodes}->{$node}->{lrm} = undef;
+
+ return 0; # EXIT_SUCCESS
+}
+
# simulate hardware commands
# power <node> <on|off>
# network <node> <on|off>
@@ -292,10 +305,7 @@ sub run {
foreach my $n (@nodes) {
if (!$self->watchdog_check($n)) {
- $self->sim_hardware_cmd("power $n off", 'watchdog');
- $self->log('info', "server '$n' stopped by poweroff (watchdog)");
- $self->{nodes}->{$n}->{crm} = undef;
- $self->{nodes}->{$n}->{lrm} = undef;
+ $self->exec_fence_agent('watchdog', $n);
}
}
}
diff --git a/src/PVE/Service/pve_ha_crm.pm b/src/PVE/Service/pve_ha_crm.pm
index f0d2cd5..151820e 100644
--- a/src/PVE/Service/pve_ha_crm.pm
+++ b/src/PVE/Service/pve_ha_crm.pm
@@ -6,6 +6,7 @@ use warnings;
use PVE::Daemon;
use Data::Dumper;
+use PVE::HA::Hardware;
use PVE::HA::Env;
use PVE::HA::Env::PVE2;
use PVE::HA::CRM;
@@ -21,7 +22,8 @@ my $daemon = __PACKAGE__->new('pve-ha-crm', $cmdline, %daemon_options);
sub run {
my ($self) = @_;
- $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename});
+ my $hw = PVE::HA::Hardware->new();
+ $self->{haenv} = PVE::HA::Env->new('PVE::HA::Env::PVE2', $self->{nodename}, $hw);
$self->{crm} = PVE::HA::CRM->new($self->{haenv});
--
2.1.4
More information about the pve-devel
mailing list