]> git.proxmox.com Git - pmg-api.git/commitdiff
implement pmgcm delete
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 11 Jan 2018 08:25:59 +0000 (09:25 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 11 Jan 2018 08:25:59 +0000 (09:25 +0100)
PMG/CLI/pmgcm.pm

index 53791e555db13519062a496fc5f6278cb06e2598..65c461340f4fc3e43b233e62f76d2eeedae82a32 100644 (file)
@@ -108,6 +108,52 @@ __PACKAGE__->register_method({
        return undef;
     }});
 
+__PACKAGE__->register_method({
+    name => 'delete',
+    path => 'delete',
+    method => 'GET',
+    description => "Remove a node from the cluster.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           cid => {
+               description => "Cluster Node ID.",
+               type => 'integer',
+               minimum => 1,
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+
+       my $code = sub {
+           my $cinfo = PMG::ClusterConfig->new();
+
+           die "no cluster defined\n" if !scalar(keys %{$cinfo->{ids}});
+
+           my $master = $cinfo->{master} || die "unable to lookup master node\n";
+
+           die "operation not permitted (not master)\n"
+               if $cinfo->{local}->{cid} != $master->{cid};
+
+           my $cid = $param->{cid};
+
+           die "unable to delete master node\n"
+               if $cinfo->{local}->{cid} == $cid;
+
+           die "no such node (cid == $cid does not exists)\n" if !$cinfo->{ids}->{$cid};
+
+           delete $cinfo->{ids}->{$cid};
+
+           $cinfo->write();
+       };
+
+       PMG::ClusterConfig::lock_config($code, "delete cluster node failed");
+
+       return undef;
+    }});
+
 __PACKAGE__->register_method({
     name => 'join',
     path => 'join',
@@ -215,6 +261,7 @@ __PACKAGE__->register_method({
 our $cmddef = {
     status => [ 'PMG::API2::Cluster', 'status', [], {}, $format_nodelist],
     create => [ 'PMG::API2::Cluster', 'create', [], {}, $upid_exit],
+    delete => [ __PACKAGE__, 'delete', ['cid']],
     join => [ __PACKAGE__, 'join', ['master_ip']],
     join_cmd => [ __PACKAGE__, 'join_cmd', []],
     sync => [ __PACKAGE__, 'sync', []],