[pve-devel] [PATCH cluster] add qdevice status api call

Oguz Bektas o.bektas at proxmox.com
Fri Jun 28 17:43:59 CEST 2019


Co-developed-by: Wolfgang Bumiller <w.bumiller at proxmox.com>

On Fri, Jun 28, 2019 at 05:42:35PM +0200, Oguz Bektas wrote:
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
>  data/PVE/API2/ClusterConfig.pm | 55 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
> index e7142b5..81041dc 100644
> --- a/data/PVE/API2/ClusterConfig.pm
> +++ b/data/PVE/API2/ClusterConfig.pm
> @@ -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";
> @@ -69,6 +71,7 @@ __PACKAGE__->register_method({
>  	    { name => 'nodes' },
>  	    { name => 'totem' },
>  	    { name => 'join' },
> +	    { name => 'qdevice' },
>  	];
>  
>  	return $result;
> @@ -552,4 +555,56 @@ __PACKAGE__->register_method({
>  	return $totem_cfg;
>      }});
>  
> +__PACKAGE__->register_method ({
> +    name => 'status',
> +    path => 'qdevice',
> +    method => 'GET',
> +    description => 'Get QDevice and configuration.',
> +    permissions => {
> +	check => ['perm', '/', [ 'Sys.Audit' ]],
> +    },
> +    parameters => {
> +	additionalProperties => 0,
> +	properties => {},
> +    },
> +    returns => {
> +	type => "object",
> +    },
> +    code => sub {
> +	my ($param) = @_;
> +
> +	my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
> +	my $qdevice_cfg = $conf->{main}->{quorum}->{device} // {};
> +	my $socket_path="/var/run/corosync-qdevice/corosync-qdevice.sock";
> +
> +	my $qdevice_socket = IO::Socket::UNIX->new(
> +	    Type => SOCK_STREAM,
> +	    Peer => $socket_path,
> +	);
> +
> +	print $qdevice_socket "status verbose\n";
> +	my @qdevice_matches = (
> +	    "Algorithm",
> +	    "Echo reply",
> +	    "Last poll call",
> +	    "Model",
> +	    "QNetd host",
> +	    "State",
> +	    "Tie-breaker",
> +	);
> +	my $keys = { map { $_ => 1 } @qdevice_matches };
> +	my $result = {};
> +	while (my $line = <$qdevice_socket>) {
> +	    chomp $line;
> +	    next if $line =~ /^\s/;
> +	    if ($line =~ /^(.*?)\s*:\s*(.*)$/) {
> +		$result->{$1} = $2 if $keys->{$1};
> +	    }
> +	}
> +
> +	return $result;
> +    }});
> +#TODO: possibly add setup and remove methods
> +
> +
>  1;
> -- 
> 2.11.0
> 
> 




More information about the pve-devel mailing list