]>
Commit | Line | Data |
---|---|---|
27bfc7c6 DM |
1 | package PVE::RADOS; |
2 | ||
3 | use 5.014002; | |
4 | use strict; | |
5 | use warnings; | |
6 | use Carp; | |
7 | use JSON; | |
8 | ||
9 | require Exporter; | |
10 | ||
11 | our @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. | |
20 | our %EXPORT_TAGS = ( 'all' => [ qw( | |
21 | ||
22 | ) ] ); | |
23 | ||
24 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |
25 | ||
26 | our @EXPORT = qw( | |
27 | ||
28 | ); | |
29 | ||
30 | our $VERSION = '1.0'; | |
31 | ||
32 | require XSLoader; | |
33 | XSLoader::load('PVE::RADOS', $VERSION); | |
34 | ||
35 | sub new { | |
36 | my $conn = pve_rados_create() || | |
37 | die "unable to create RADOS object\n"; | |
38 | ||
39 | pve_rados_connect($conn); | |
40 | ||
41 | my $self = bless { conn => $conn }; | |
42 | ||
43 | return $self; | |
44 | } | |
45 | ||
46 | sub DESTROY { | |
47 | my ($self) = @_; | |
48 | ||
49 | pve_rados_shutdown($self->{conn}); | |
50 | } | |
51 | ||
52 | sub cluster_stat { | |
53 | my ($self) = @_; | |
54 | ||
55 | return pve_rados_cluster_stat($self->{conn}); | |
56 | } | |
57 | ||
58 | # example: { prefix => 'mon dump', format => 'json' } | |
59 | sub mon_command { | |
60 | my ($self, $cmd) = @_; | |
61 | ||
62 | my $json = encode_json($cmd); | |
63 | my $raw = pve_rados_mon_command($self->{conn}, [ $json ]); | |
64 | if ($cmd->{format} && $cmd->{format} eq 'json') { | |
65 | return decode_json($raw); | |
66 | } | |
67 | return $raw; | |
68 | } | |
69 | ||
70 | ||
71 | 1; | |
72 | __END__ | |
73 | ||
74 | =head1 NAME | |
75 | ||
76 | PVE::RADOS - Perl bindings for librados | |
77 | ||
78 | =head1 SYNOPSIS | |
79 | ||
80 | use PVE::RADOS; | |
81 | ||
82 | my $rados = PVE::RADOS::new(); | |
83 | my $stat = $rados->cluster_stat(); | |
84 | my $res = $rados->mon_command({ prefix => 'mon dump', format => 'json' }); | |
85 | ||
86 | =head1 DESCRIPTION | |
87 | ||
88 | Perl bindings for librados. | |
89 | ||
90 | =head2 EXPORT | |
91 | ||
92 | None by default. | |
93 | ||
94 | =head1 AUTHOR | |
95 | ||
96 | Dietmar Maurer, E<lt>dietmar@proxmox.com<gt> | |
97 | ||
98 | =cut |