]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
factor out resource config update from api to HA::Config
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 2 Oct 2019 09:46:02 +0000 (11:46 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 4 Oct 2019 15:20:25 +0000 (17:20 +0200)
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@proxmox.com>
src/PVE/API2/HA/Resources.pm
src/PVE/HA/Config.pm

index 22d7f28c5062c3643b0d504093d66df9122ffc28..5c11d8bfff5abbf4c5b415281e1f422fc6286850 100644 (file)
@@ -237,39 +237,7 @@ __PACKAGE__->register_method ({
 
        check_service_state($sid, $param->{state});
 
-       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)
-
-           }, "update resource failed");
+       PVE::HA::Config::update_resources_config($sid, $param, $delete, $digest);
 
        return undef;
     }});
index ead1ee280f0083ec5bab4b971fa3f7e4b611985d..676eaafdd978aa43ec7c66da4d052b8b0e3d602b 100644 (file)
@@ -125,6 +125,43 @@ sub read_and_check_resources_config {
     return $conf;
 }
 
+sub update_resources_config {
+    my ($sid, $param, $delete, $digest) = @_;
+
+    lock_ha_domain(
+       sub {
+           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);
+       }, "update resources config failed");
+}
+
 sub parse_sid {
     my ($sid) = @_;