]> git.proxmox.com Git - pve-cluster.git/commitdiff
add qdevice status api call
authorOguz Bektas <o.bektas@proxmox.com>
Mon, 1 Jul 2019 16:31:01 +0000 (18:31 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 2 Jul 2019 08:59:18 +0000 (10:59 +0200)
Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
data/PVE/API2/ClusterConfig.pm

index d338b8a2d2aae132044cf549eb9650e89d00b0fa..6d23056a6b2a7b2a3c6ba299d46334c0c1d870cf 100644 (file)
@@ -12,6 +12,8 @@ use PVE::Cluster;
 use PVE::APIClient::LWP;
 use PVE::Corosync;
 
+use IO::Socket::UNIX;
+
 use base qw(PVE::RESTHandler);
 
 my $clusterconf = "/etc/pve/corosync.conf";
@@ -53,6 +55,7 @@ __PACKAGE__->register_method({
            { name => 'nodes' },
            { name => 'totem' },
            { name => 'join' },
+           { name => 'qdevice' },
        ];
 
        return $result;
@@ -534,4 +537,54 @@ __PACKAGE__->register_method({
        return $totem_cfg;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'status',
+    path => 'qdevice',
+    method => 'GET',
+    description => 'Get QDevice status',
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Audit' ]],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {},
+    },
+    returns => {
+       type => "object",
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $result = {};
+       my $socket_path = "/var/run/corosync-qdevice/corosync-qdevice.sock";
+       return $result if !-S $socket_path;
+
+       my $qdevice_socket = IO::Socket::UNIX->new(
+           Type => SOCK_STREAM,
+           Peer => $socket_path,
+       );
+
+       print $qdevice_socket "status verbose\n";
+       my $qdevice_keys = {
+           "Algorithm" => 1,
+           "Echo reply" => 1,
+           "Last poll call" => 1,
+           "Model" => 1,
+           "QNetd host" => 1,
+           "State" => 1,
+           "Tie-breaker" => 1,
+       };
+       while (my $line = <$qdevice_socket>) {
+           chomp $line;
+           next if $line =~ /^\s/;
+           if ($line =~ /^(.*?)\s*:\s*(.*)$/) {
+               $result->{$1} = $2 if $qdevice_keys->{$1};
+           }
+       }
+
+       return $result;
+    }});
+#TODO: possibly add setup and remove methods
+
+
 1;