[pve-devel] [PATCH pve-ha-manager 2/2] check services better to avoid unknown behaviour
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Oct 12 09:55:41 CEST 2015
This fixes:
-) addition of an inexistent VM/CT
-) migration, relocation, deletion of a resource which was not ha
managed
-) deletion of a non existent group
-) a typo (s/storage/resource/)
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/API2/HA/Groups.pm | 3 +++
src/PVE/API2/HA/Resources.pm | 14 +++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/HA/Groups.pm b/src/PVE/API2/HA/Groups.pm
index 243eca8..700b8e9 100644
--- a/src/PVE/API2/HA/Groups.pm
+++ b/src/PVE/API2/HA/Groups.pm
@@ -224,6 +224,9 @@ __PACKAGE__->register_method ({
my $cfg = PVE::HA::Config::read_group_config();
+ die "no such ha group '$group'\n"
+ if !defined($cfg->{ids}->{$group});
+
delete $cfg->{ids}->{$group};
PVE::HA::Config::write_group_config($cfg)
diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm
index d4b4b71..6b5b009 100644
--- a/src/PVE/API2/HA/Resources.pm
+++ b/src/PVE/API2/HA/Resources.pm
@@ -127,6 +127,9 @@ __PACKAGE__->register_method ({
my $plugin = PVE::HA::Resources->lookup($type);
$plugin->verify_name($name);
+ die "no such resource '$sid' found in cluster\n"
+ if !$plugin->exists($name);
+
my $opts = $plugin->check_config($sid, $param, 1, 1);
PVE::HA::Config::lock_ha_domain(
@@ -229,11 +232,14 @@ __PACKAGE__->register_method ({
my $cfg = PVE::HA::Config::read_resources_config();
+ die "resource '$sid' is not HA managed\n"
+ if !defined($cfg->{ids}->{$sid});
+
delete $cfg->{ids}->{$sid};
PVE::HA::Config::write_resources_config($cfg)
- }, "delete storage failed");
+ }, "delete resource failed");
return undef;
}});
@@ -259,6 +265,9 @@ __PACKAGE__->register_method ({
my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+ die "resource '$sid' is not HA managed\n"
+ if !PVE::HA::Config::service_is_ha_managed($sid);
+
PVE::HA::Config::queue_crm_commands("migrate $sid $param->{node}");
return undef;
@@ -285,6 +294,9 @@ __PACKAGE__->register_method ({
my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+ die "resource '$sid' is not HA managed\n"
+ if !PVE::HA::Config::service_is_ha_managed($sid);
+
PVE::HA::Config::queue_crm_commands("relocate $sid $param->{node}");
return undef;
--
2.1.4
More information about the pve-devel
mailing list