]>
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 { | |
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 | ||
56 | sub DESTROY { | |
57 | my ($self) = @_; | |
58 | ||
59 | pve_rados_shutdown($self->{conn}); | |
60 | } | |
61 | ||
62 | sub cluster_stat { | |
63 | my ($self) = @_; | |
64 | ||
65 | return pve_rados_cluster_stat($self->{conn}); | |
66 | } | |
67 | ||
f5996c62 DM |
68 | # example1: { prefix => 'get_command_descriptions'}) |
69 | # example2: { prefix => 'mon dump', format => 'json' } | |
27bfc7c6 DM |
70 | sub mon_command { |
71 | my ($self, $cmd) = @_; | |
72 | ||
b2a25d5d DM |
73 | $cmd->{format} = 'json' if !$cmd->{format}; |
74 | ||
27bfc7c6 DM |
75 | my $json = encode_json($cmd); |
76 | my $raw = pve_rados_mon_command($self->{conn}, [ $json ]); | |
77 | if ($cmd->{format} && $cmd->{format} eq 'json') { | |
23c2cb25 | 78 | return length($raw) ? decode_json($raw) : undef; |
27bfc7c6 DM |
79 | } |
80 | return $raw; | |
81 | } | |
82 | ||
83 | ||
84 | 1; | |
85 | __END__ | |
86 | ||
87 | =head1 NAME | |
88 | ||
89 | PVE::RADOS - Perl bindings for librados | |
90 | ||
91 | =head1 SYNOPSIS | |
92 | ||
93 | use PVE::RADOS; | |
94 | ||
95 | my $rados = PVE::RADOS::new(); | |
96 | my $stat = $rados->cluster_stat(); | |
97 | my $res = $rados->mon_command({ prefix => 'mon dump', format => 'json' }); | |
98 | ||
99 | =head1 DESCRIPTION | |
100 | ||
101 | Perl bindings for librados. | |
102 | ||
103 | =head2 EXPORT | |
104 | ||
105 | None by default. | |
106 | ||
107 | =head1 AUTHOR | |
108 | ||
109 | Dietmar Maurer, E<lt>dietmar@proxmox.com<gt> | |
110 | ||
111 | =cut |