]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG/API2/Cluster.pm: write local cluster config after join
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Apr 2017 14:56:10 +0000 (16:56 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Apr 2017 15:17:51 +0000 (17:17 +0200)
PMG/API2/Cluster.pm
PMG/CLI/pmgcm.pm
PMG/ClusterConfig.pm

index 0032a58fd3287df299338255f30bb58f3959cd89..56c002cd85b0f0fd9381653182ed17459ae26e4f 100644 (file)
@@ -19,13 +19,19 @@ use PMG::Cluster;
 use base qw(PVE::RESTHandler);
 
 sub cluster_join {
-    my ($conn_setup) = @_;
+    my ($cfg, $conn_setup) = @_;
 
     my $conn = PVE::APIClient::LWP->new(%$conn_setup);
 
     my $info = PMG::Cluster::read_local_cluster_info();
 
     my $res = $conn->post("/config/cluster/nodes", $info);
+
+    foreach my $node (@$res) {
+       $cfg->{ids}->{$node->{cid}} = $node;
+    }
+
+    $cfg->write();
 }
 
 __PACKAGE__->register_method({
@@ -105,7 +111,16 @@ __PACKAGE__->register_method({
     proxyto => 'master',
     protected => 1,
     parameters => $add_node_schema,
-    returns => { type => 'null' },
+    returns => {
+       description => "Returns the resulting node list.",
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {
+               cid => { type => 'integer' },
+           },
+       },
+    },
     code => sub {
        my ($param) = @_;
 
@@ -121,7 +136,7 @@ __PACKAGE__->register_method({
                my $d = $cfg->{ids}->{$cid};
 
                if ($d->{type} eq 'node' && $d->{ip} eq $param->{ip} && $d->{name} eq $param->{name}) {
-                   $nextcid = $cid; # allow overwrite existing node data
+                   $next_cid = $cid; # allow overwrite existing node data
                    last;
                }
 
@@ -150,11 +165,11 @@ __PACKAGE__->register_method({
            $cfg->{ids}->{$node->{cid}} = $node;
 
            $cfg->write();
-       };
 
-       PMG::ClusterConfig::lock_config($code, "create cluster failed");
+           return PVE::RESTHandler::hash_to_array($cfg->{ids}, 'cid');
+       };
 
-       return undef;
+       return PMG::ClusterConfig::lock_config($code, "add node failed");
     }});
 
 __PACKAGE__->register_method({
@@ -235,7 +250,7 @@ __PACKAGE__->register_method({
                }
            };
 
-           cluster_join($setup);
+           cluster_join($cfg, $setup);
        };
 
        PMG::ClusterConfig::lock_config($code, "cluster join failed");
index b99eaeb67bb83b4d8dd5bc2bdde11b1411dbd925..8a62b1092416fb4ff6317795cb7ac548eb955181 100644 (file)
@@ -90,7 +90,7 @@ __PACKAGE__->register_method({
        my ($param) = @_;
 
        my $code = sub {
-           my $cfg = PVE::INotify::read_file('cluster.conf');
+           my $cfg = PMG::ClusterConfig->new();
 
            die "cluster alreayd defined\n" if scalar(keys %{$cfg->{ids}});
 
@@ -114,7 +114,7 @@ __PACKAGE__->register_method({
                $setup->{manual_verification} = 1;
            }
 
-           PMG::API2::Cluster::cluster_join($setup);
+           PMG::API2::Cluster::cluster_join($cfg, $setup);
        };
 
        PMG::ClusterConfig::lock_config($code, "cluster join failed");
index 3440118c512e77f065c3ed66ce9f4de588f53865..7bf4243eb84d7687959479e399972e51b4a34dc0 100644 (file)
@@ -155,10 +155,11 @@ my $lockfile = "/var/lock/pmgcluster.lck";
 sub lock_config {
     my ($code, $errmsg) = @_;
 
-    my $p = PVE::Tools::lock_file($lockfile, undef, $code);
+    my $res = PVE::Tools::lock_file($lockfile, undef, $code);
     if (my $err = $@) {
        $errmsg ? die "$errmsg: $err" : die $err;
     }
+    return $res;
 }
 
 sub read_cluster_conf {