mirror of
https://git.proxmox.com/git/librados2-perl
synced 2025-10-04 19:51:41 +00:00
initial import
This commit is contained in:
commit
27bfc7c68e
77
Makefile
Normal file
77
Makefile
Normal file
@ -0,0 +1,77 @@
|
||||
RELEASE=3.1
|
||||
|
||||
VERSION=0.72.1
|
||||
PACKAGE=librados2-perl
|
||||
PKGREL=1
|
||||
|
||||
DESTDIR=
|
||||
PREFIX=/usr
|
||||
BINDIR=${PREFIX}/bin
|
||||
LIBDIR=${PREFIX}/lib
|
||||
SBINDIR=${PREFIX}/sbin
|
||||
MANDIR=${PREFIX}/share/man
|
||||
DOCDIR=${PREFIX}/share/doc/${PACKAGE}
|
||||
MAN1DIR=${MANDIR}/man1/
|
||||
PERLDIR=${PREFIX}/share/perl5
|
||||
PERLSODIR=${LIBDIR}/perl5/auto
|
||||
|
||||
ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
|
||||
GITVERSION:=$(shell cat .git/refs/heads/master)
|
||||
|
||||
DEB=${PACKAGE}_${VERSION}-${PKGREL}_${ARCH}.deb
|
||||
|
||||
all: ${DEB}
|
||||
|
||||
RADOS.c: RADOS.xs typemap
|
||||
xsubpp RADOS.xs -typemap typemap > RADOS.xsc
|
||||
mv RADOS.xsc RADOS.c
|
||||
|
||||
CFLAGS= -shared -fPIC -O2 -Wall -Wl,-z,relro -I/usr/lib/perl/5.14.2/CORE -DXS_VERSION=\"1.0\"
|
||||
RADOS.so: RADOS.c
|
||||
gcc ${CFLAGS} -lrados -o RADOS.so RADOS.c
|
||||
|
||||
|
||||
.PHONY: dinstall
|
||||
dinstall: deb
|
||||
dpkg -i ${DEB}
|
||||
|
||||
.PHONY: install
|
||||
install: PVE/RADOS.pm RADOS.so
|
||||
install -D -m 0644 PVE/RADOS.pm ${DESTDIR}${PERLDIR}/PVE/RADOS.pm
|
||||
install -D -m 0644 -s RADOS.so ${DESTDIR}${PERLSODIR}/PVE/RADOS.so
|
||||
|
||||
.PHONY: deb ${DEB}
|
||||
deb ${DEB}:
|
||||
rm -rf debian
|
||||
mkdir debian
|
||||
make DESTDIR=${CURDIR}/debian install
|
||||
install -d -m 0755 debian/DEBIAN
|
||||
sed -e s/@@VERSION@@/${VERSION}/ -e s/@@PKGRELEASE@@/${PKGREL}/ -e s/@@ARCH@@/${ARCH}/ <control.in >debian/DEBIAN/control
|
||||
install -D -m 0644 copyright debian/${DOCDIR}/copyright
|
||||
install -m 0644 changelog.Debian debian/${DOCDIR}/
|
||||
gzip -9 debian/${DOCDIR}/changelog.Debian
|
||||
echo "git clone git://git.proxmox.com/git/librados2-perl.git\\ngit checkout ${GITVERSION}" > debian/${DOCDIR}/SOURCE
|
||||
dpkg-deb --build debian
|
||||
mv debian.deb ${DEB}
|
||||
rm -rf debian
|
||||
lintian ${DEB}
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf debian *.deb ${PACKAGE}-*.tar.gz dist *.1.pod *.1.gz RADOS.so RADOS.c
|
||||
find . -name '*~' -exec rm {} ';'
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
|
||||
|
||||
.PHONY: upload
|
||||
upload: ${DEB}
|
||||
umount /pve/${RELEASE}; mount /pve/${RELEASE} -o rw
|
||||
mkdir -p /pve/${RELEASE}/extra
|
||||
rm -f /pve/${RELEASE}/extra/${PACKAGE}_*.deb
|
||||
rm -f /pve/${RELEASE}/extra/Packages*
|
||||
cp ${DEB} /pve/${RELEASE}/extra
|
||||
cd /pve/${RELEASE}/extra; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz
|
||||
umount /pve/${RELEASE}; mount /pve/${RELEASE} -o ro
|
||||
|
98
PVE/RADOS.pm
Normal file
98
PVE/RADOS.pm
Normal file
@ -0,0 +1,98 @@
|
||||
package PVE::RADOS;
|
||||
|
||||
use 5.014002;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use JSON;
|
||||
|
||||
require Exporter;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
|
||||
# Items to export into callers namespace by default. Note: do not export
|
||||
# names by default without a very good reason. Use EXPORT_OK instead.
|
||||
# Do not simply export all your public functions/methods/constants.
|
||||
|
||||
# This allows declaration use PVE::RADOS ':all';
|
||||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw(
|
||||
|
||||
) ] );
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
our @EXPORT = qw(
|
||||
|
||||
);
|
||||
|
||||
our $VERSION = '1.0';
|
||||
|
||||
require XSLoader;
|
||||
XSLoader::load('PVE::RADOS', $VERSION);
|
||||
|
||||
sub new {
|
||||
my $conn = pve_rados_create() ||
|
||||
die "unable to create RADOS object\n";
|
||||
|
||||
pve_rados_connect($conn);
|
||||
|
||||
my $self = bless { conn => $conn };
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
|
||||
pve_rados_shutdown($self->{conn});
|
||||
}
|
||||
|
||||
sub cluster_stat {
|
||||
my ($self) = @_;
|
||||
|
||||
return pve_rados_cluster_stat($self->{conn});
|
||||
}
|
||||
|
||||
# example: { prefix => 'mon dump', format => 'json' }
|
||||
sub mon_command {
|
||||
my ($self, $cmd) = @_;
|
||||
|
||||
my $json = encode_json($cmd);
|
||||
my $raw = pve_rados_mon_command($self->{conn}, [ $json ]);
|
||||
if ($cmd->{format} && $cmd->{format} eq 'json') {
|
||||
return decode_json($raw);
|
||||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
PVE::RADOS - Perl bindings for librados
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use PVE::RADOS;
|
||||
|
||||
my $rados = PVE::RADOS::new();
|
||||
my $stat = $rados->cluster_stat();
|
||||
my $res = $rados->mon_command({ prefix => 'mon dump', format => 'json' });
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Perl bindings for librados.
|
||||
|
||||
=head2 EXPORT
|
||||
|
||||
None by default.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Dietmar Maurer, E<lt>dietmar@proxmox.com<gt>
|
||||
|
||||
=cut
|
115
RADOS.xs
Normal file
115
RADOS.xs
Normal file
@ -0,0 +1,115 @@
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
|
||||
#include "ppport.h"
|
||||
|
||||
#include <rados/librados.h>
|
||||
|
||||
MODULE = PVE::RADOS PACKAGE = PVE::RADOS
|
||||
|
||||
rados_t pve_rados_create()
|
||||
PROTOTYPE:
|
||||
CODE:
|
||||
{
|
||||
rados_t clu = NULL;
|
||||
int ret = rados_create(&clu, NULL);
|
||||
|
||||
if (ret == 0)
|
||||
RETVAL = clu;
|
||||
else {
|
||||
warn("rados_create failed (ret=%d)\n", ret);
|
||||
RETVAL = NULL;
|
||||
}
|
||||
}
|
||||
OUTPUT: RETVAL
|
||||
|
||||
int pve_rados_connect(cluster)
|
||||
rados_t cluster
|
||||
PROTOTYPE: $
|
||||
CODE:
|
||||
{
|
||||
rados_conf_read_file(cluster, NULL);
|
||||
|
||||
RETVAL = rados_connect(cluster);
|
||||
if (RETVAL < 0) {
|
||||
die("rados_connect failed - %s\n", strerror(-RETVAL));
|
||||
}
|
||||
}
|
||||
OUTPUT: RETVAL
|
||||
|
||||
void
|
||||
pve_rados_shutdown(cluster)
|
||||
rados_t cluster
|
||||
PROTOTYPE: $
|
||||
CODE:
|
||||
{
|
||||
rados_shutdown(cluster);
|
||||
}
|
||||
|
||||
SV *
|
||||
pve_rados_mon_command(cluster, cmds)
|
||||
rados_t cluster
|
||||
AV *cmds
|
||||
PROTOTYPE: $$
|
||||
CODE:
|
||||
{
|
||||
const char *cmd[64];
|
||||
size_t cmdlen = 0;
|
||||
|
||||
char *outbuf =NULL;
|
||||
size_t outbuflen = 0;
|
||||
char *outs = NULL;
|
||||
size_t outslen = 0;
|
||||
|
||||
SV *arg;
|
||||
|
||||
while ((arg = av_pop(cmds)) && (arg != &PL_sv_undef)) {
|
||||
if (cmdlen >= 63) {
|
||||
die("too many arguments");
|
||||
}
|
||||
cmd[cmdlen] = SvPV_nolen(arg);
|
||||
cmdlen++;
|
||||
}
|
||||
|
||||
int ret = rados_mon_command(cluster, cmd, cmdlen,
|
||||
NULL, 0,
|
||||
&outbuf, &outbuflen,
|
||||
&outs, &outslen);
|
||||
|
||||
if (ret < 0) {
|
||||
die("mon_command failed - %s\n", outs);
|
||||
rados_buffer_free(outs);
|
||||
}
|
||||
|
||||
printf("TEST %d %d %d\n", ret, outbuflen, outslen);
|
||||
|
||||
RETVAL = newSVpv(outbuf, outbuflen);
|
||||
|
||||
rados_buffer_free(outbuf);
|
||||
}
|
||||
OUTPUT: RETVAL
|
||||
|
||||
HV *
|
||||
pve_rados_cluster_stat(cluster)
|
||||
rados_t cluster
|
||||
PROTOTYPE: $
|
||||
CODE:
|
||||
{
|
||||
struct rados_cluster_stat_t result;
|
||||
int ret = rados_cluster_stat(cluster, &result);
|
||||
|
||||
if(ret != 0) {
|
||||
warn("rados_cluster_stat failed (ret=%d)\n", ret);
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
HV * rh = (HV *)sv_2mortal((SV *)newHV());
|
||||
|
||||
hv_store(rh, "kb", 2, newSViv(result.kb), 0);
|
||||
hv_store(rh, "kb_used", 7, newSViv(result.kb_used), 0);
|
||||
hv_store(rh, "kb_avail", 8, newSViv(result.kb_avail), 0);
|
||||
hv_store(rh, "num_objects", 11, newSViv(result.num_objects), 0);
|
||||
|
||||
RETVAL = rh;
|
||||
}
|
||||
OUTPUT: RETVAL
|
12
changelog.Debian
Normal file
12
changelog.Debian
Normal file
@ -0,0 +1,12 @@
|
||||
libpve-storage-perl (3.0-19) unstable; urgency=low
|
||||
|
||||
* glusterfs : create volume through gluster block driver
|
||||
|
||||
-- Proxmox Support Team <support@proxmox.com> Thu, 16 Jan 2014 09:38:35 +0100
|
||||
|
||||
librados2-perl (0.72.1-1) unstable; urgency=low
|
||||
|
||||
* initial package
|
||||
|
||||
-- Proxmox Support Team <support@proxmox.com> Fri, 20 Mar 2009 11:13:19 +0100
|
||||
|
9
control.in
Normal file
9
control.in
Normal file
@ -0,0 +1,9 @@
|
||||
Package: librados2-perl
|
||||
Version: @@VERSION@@-@@PKGRELEASE@@
|
||||
Section: perl
|
||||
Priority: optional
|
||||
Architecture: @@ARCH@@
|
||||
Depends: libc6 (>= 2.2.5), perl (>= 5.14.2-21+deb7u1), perlapi-5.14.2, librados2 (>= 0.72.1)
|
||||
Maintainer: Proxmox Support Team <support@proxmox.com>
|
||||
Description: Perl bindings for librados
|
||||
This package contains librados perl binding used by Proxmox VE.
|
16
copyright
Normal file
16
copyright
Normal file
@ -0,0 +1,16 @@
|
||||
Copyright (C) 2014 Proxmox Server Solutions GmbH
|
||||
|
||||
This software is written by Proxmox Server Solutions GmbH <support@proxmox.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
Loading…
Reference in New Issue
Block a user