]> git.proxmox.com Git - librados2-perl.git/blame - PVE/RADOS.pm
fix .so install path
[librados2-perl.git] / PVE / RADOS.pm
CommitLineData
27bfc7c6
DM
1package PVE::RADOS;
2
3use 5.014002;
4use strict;
5use warnings;
6use Carp;
7use JSON;
8
9require Exporter;
10
11our @ISA = qw(Exporter);
12
13# Items to export into callers namespace by default. Note: do not export
14# names by default without a very good reason. Use EXPORT_OK instead.
15# Do not simply export all your public functions/methods/constants.
16
17# This allows declaration use PVE::RADOS ':all';
18# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19# will save memory.
20our %EXPORT_TAGS = ( 'all' => [ qw(
21
22) ] );
23
24our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25
26our @EXPORT = qw(
27
28);
29
30our $VERSION = '1.0';
31
32require XSLoader;
33XSLoader::load('PVE::RADOS', $VERSION);
34
35sub new {
612779b1
DM
36 my ($class, %params) = @_;
37
27bfc7c6
DM
38 my $conn = pve_rados_create() ||
39 die "unable to create RADOS object\n";
40
612779b1
DM
41 my $timeout = delete $params{timeout} || 5;
42
43 pve_rados_conf_set($conn, 'client_mount_timeout', $timeout);
44
45 foreach my $k (keys %params) {
46 pve_rados_conf_set($conn, $k, $params{$k});
47 }
48
27bfc7c6
DM
49 pve_rados_connect($conn);
50
51 my $self = bless { conn => $conn };
52
53 return $self;
54}
55
56sub DESTROY {
57 my ($self) = @_;
58
59 pve_rados_shutdown($self->{conn});
60}
61
62sub cluster_stat {
63 my ($self) = @_;
64
65 return pve_rados_cluster_stat($self->{conn});
66}
67
68# example: { prefix => 'mon dump', format => 'json' }
69sub mon_command {
70 my ($self, $cmd) = @_;
71
b2a25d5d
DM
72 $cmd->{format} = 'json' if !$cmd->{format};
73
27bfc7c6
DM
74 my $json = encode_json($cmd);
75 my $raw = pve_rados_mon_command($self->{conn}, [ $json ]);
76 if ($cmd->{format} && $cmd->{format} eq 'json') {
77 return decode_json($raw);
78 }
79 return $raw;
80}
81
82
831;
84__END__
85
86=head1 NAME
87
88PVE::RADOS - Perl bindings for librados
89
90=head1 SYNOPSIS
91
92 use PVE::RADOS;
93
94 my $rados = PVE::RADOS::new();
95 my $stat = $rados->cluster_stat();
96 my $res = $rados->mon_command({ prefix => 'mon dump', format => 'json' });
97
98=head1 DESCRIPTION
99
100Perl bindings for librados.
101
102=head2 EXPORT
103
104None by default.
105
106=head1 AUTHOR
107
108Dietmar Maurer, E<lt>dietmar@proxmox.com<gt>
109
110=cut