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({
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) = @_;
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;
}
$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({
}
};
- cluster_join($setup);
+ cluster_join($cfg, $setup);
};
PMG::ClusterConfig::lock_config($code, "cluster join failed");
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}});
$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");
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 {