[pve-devel] [PATCH storage v3 3/5] Merge RBD and CephFS code into a helper module
Alwin Antreich
a.antreich at proxmox.com
Mon Jun 11 11:31:31 CEST 2018
Some methods for connecting to a ceph cluster are the same for RBD and
CephFS, these are merged into the helper modules.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/CephStorageTools.pm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
PVE/Makefile | 1 +
2 files changed, 56 insertions(+)
create mode 100644 PVE/CephStorageTools.pm
diff --git a/PVE/CephStorageTools.pm b/PVE/CephStorageTools.pm
new file mode 100644
index 0000000..4bbfc55
--- /dev/null
+++ b/PVE/CephStorageTools.pm
@@ -0,0 +1,55 @@
+package PVE::CephStorageTools;
+
+use strict;
+use warnings;
+use Net::IP;
+use PVE::Tools qw(run_command);
+
+sub hostlist {
+ my ($list_text, $separator) = @_;
+
+ my @monhostlist = PVE::Tools::split_list($list_text);
+ return join($separator, map {
+ my ($host, $port) = PVE::Tools::parse_host_and_port($_);
+ $port = defined($port) ? ":$port" : '';
+ $host = "[$host]" if Net::IP::ip_is_ipv6($host);
+ "${host}${port}"
+ } @monhostlist);
+}
+
+sub ceph_connect_option {
+ my ($scfg, $storeid, %options) = @_;
+
+ my $cmd_option = {};
+ my $ceph_storeid_conf = "/etc/pve/priv/ceph/${storeid}.conf";
+ my $pveceph_config = '/etc/pve/ceph.conf';
+ my $keyfile = "/etc/pve/priv/ceph/${storeid}.keyring";
+ $keyfile = "/etc/pve/priv/ceph/${storeid}.secret" if ($scfg->{type} eq 'cephfs');
+ my $pveceph_managed = !defined($scfg->{monhost});
+
+ $cmd_option->{ceph_conf} = $pveceph_config if $pveceph_managed;
+
+ if (-e $ceph_storeid_conf) {
+ if ($pveceph_managed) {
+ warn "ignoring custom ceph config for storage '$storeid', 'monhost' is not set (assuming pveceph managed cluster)!\n";
+ } else {
+ $cmd_option->{ceph_conf} = $ceph_storeid_conf;
+ }
+ }
+
+ $cmd_option->{keyring} = $keyfile if (-e $keyfile);
+ $cmd_option->{auth_supported} = (defined $cmd_option->{keyring}) ? 'cephx' : 'none';
+ $cmd_option->{userid} = $scfg->{username} ? $scfg->{username} : 'admin';
+ $cmd_option->{mon_host} = PVE::CephStorageTools::hostlist($scfg->{monhost}, ',') if (defined($scfg->{monhost}));
+
+ if (%options) {
+ foreach my $k (keys %options) {
+ $cmd_option->{$k} = $options{$k};
+ }
+ }
+
+ return $cmd_option;
+
+}
+
+1;
diff --git a/PVE/Makefile b/PVE/Makefile
index ae2bd35..0a3ecb4 100644
--- a/PVE/Makefile
+++ b/PVE/Makefile
@@ -4,6 +4,7 @@
install:
install -D -m 0644 Storage.pm ${DESTDIR}${PERLDIR}/PVE/Storage.pm
install -D -m 0644 Diskmanage.pm ${DESTDIR}${PERLDIR}/PVE/Diskmanage.pm
+ install -D -m 0644 CephStorageTools.pm ${DESTDIR}${PERLDIR}/PVE/CephStorageTools.pm
make -C Storage install
make -C API2 install
make -C CLI install
--
2.11.0
More information about the pve-devel
mailing list