[pve-devel] [PATCH v2 librados2-perl 3/3] allow to specify the userid with rados_create

Alwin Antreich a.antreich at proxmox.com
Wed Apr 4 17:37:51 CEST 2018


This allows to connect to a cluster with a different user, besides admin

Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/RADOS.pm |  4 +++-
 RADOS.xs     | 13 ++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/PVE/RADOS.pm b/PVE/RADOS.pm
index 2ed92b7..d53f655 100644
--- a/PVE/RADOS.pm
+++ b/PVE/RADOS.pm
@@ -14,6 +14,7 @@ require Exporter;

 my $rados_default_timeout = 5;
 my $ceph_default_conf = '/etc/ceph/ceph.conf';
+my $ceph_default_user = 'admin';


 our @ISA = qw(Exporter);
@@ -162,7 +163,8 @@ sub new {

 	my $conn;
 	eval {
-	    $conn = pve_rados_create() ||
+	    my $ceph_user = delete $params{userid} || $ceph_default_user;
+	    $conn = pve_rados_create($ceph_user) ||
 		die "unable to create RADOS object\n";

 	    if (defined($params{ceph_conf}) && (!-e $params{ceph_conf})) {
diff --git a/RADOS.xs b/RADOS.xs
index ad3cf96..f3f5516 100644
--- a/RADOS.xs
+++ b/RADOS.xs
@@ -14,12 +14,19 @@
 MODULE = PVE::RADOS		PACKAGE = PVE::RADOS

 rados_t
-pve_rados_create()
-PROTOTYPE:
+pve_rados_create(user)
+SV *user
+PROTOTYPE: $
 CODE:
 {
+    char *u = NULL;
     rados_t clu = NULL;
-    int ret = rados_create(&clu, NULL);
+
+    if (SvOK(user)) {
+	u = SvPV_nolen(user);
+    }
+
+    int ret = rados_create(&clu, u);

     if (ret == 0)
         RETVAL = clu;
--
2.11.0





More information about the pve-devel mailing list