[pve-devel] [PATCH ha-manager 02/13] Move code updating resource config from API2::HA::Resources to HA::Config

Fabian Ebner f.ebner at proxmox.com
Thu Sep 26 13:38:48 CEST 2019


This makes it easier to update the resource configuration from within the CRM/LRM stack,
which is needed for the new 'stop' command.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/HA/Resources.pm | 31 +------------------------------
 src/PVE/HA/Config.pm         | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm
index 1ffdf2e..0682b57 100644
--- a/src/PVE/API2/HA/Resources.pm
+++ b/src/PVE/API2/HA/Resources.pm
@@ -239,36 +239,7 @@ __PACKAGE__->register_method ({
 
 	PVE::HA::Config::lock_ha_domain(
 	    sub {
-
-		my $cfg = PVE::HA::Config::read_resources_config();
-
-		PVE::SectionConfig::assert_if_modified($cfg, $digest);
-
-		my $scfg = $cfg->{ids}->{$sid} ||
-		    die "no such resource '$sid'\n";
-
-		my $plugin = PVE::HA::Resources->lookup($scfg->{type});
-		my $opts = $plugin->check_config($sid, $param, 0, 1);
-
-		foreach my $k (%$opts) {
-		    $scfg->{$k} = $opts->{$k};
-		}
-
-		if ($delete) {
-		    my $options = $plugin->private()->{options}->{$type};
-		    foreach my $k (PVE::Tools::split_list($delete)) {
-			my $d = $options->{$k} ||
-			    die "no such option '$k'\n";
-			die "unable to delete required option '$k'\n"
-			    if !$d->{optional};
-			die "unable to delete fixed option '$k'\n"
-			    if $d->{fixed};
-			delete $scfg->{$k};
-		    }
-		}
-
-		PVE::HA::Config::write_resources_config($cfg)
-
+		PVE::HA::Config::update_resources_config($digest, $delete, $sid, $param);
 	    }, "update resource failed");
 
 	return undef;
diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index ead1ee2..23cb7ae 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -125,6 +125,40 @@ sub read_and_check_resources_config {
     return $conf;
 }
 
+sub update_resources_config {
+    my ($digest, $delete, $sid, $param) = @_;
+
+    my $cfg = read_resources_config();
+    ($sid, my $type, my $name) = parse_sid($sid);
+
+    PVE::SectionConfig::assert_if_modified($cfg, $digest);
+
+    my $scfg = $cfg->{ids}->{$sid} ||
+	die "no such resource '$sid'\n";
+
+    my $plugin = PVE::HA::Resources->lookup($scfg->{type});
+    my $opts = $plugin->check_config($sid, $param, 0, 1);
+
+    foreach my $k (%$opts) {
+	$scfg->{$k} = $opts->{$k};
+    }
+
+    if ($delete) {
+	my $options = $plugin->private()->{options}->{$type};
+	foreach my $k (PVE::Tools::split_list($delete)) {
+	    my $d = $options->{$k} ||
+		die "no such option '$k'\n";
+	    die "unable to delete required option '$k'\n"
+		if !$d->{optional};
+	    die "unable to delete fixed option '$k'\n"
+		if $d->{fixed};
+	    delete $scfg->{$k};
+	}
+    }
+
+    write_resources_config($cfg)
+}
+
 sub parse_sid {
     my ($sid) = @_;
 
-- 
2.20.1





More information about the pve-devel mailing list