]> git.proxmox.com Git - pve-storage.git/blame - PVE/Storage/CephTools.pm
Merge RBD and CephFS code into a helper module
[pve-storage.git] / PVE / Storage / CephTools.pm
CommitLineData
9b7ba1db
AA
1package PVE::Storage::CephTools;
2
3use strict;
4use warnings;
5use Net::IP;
6use PVE::Tools qw(run_command);
7
8sub hostlist {
9 my ($list_text, $separator) = @_;
10
11 my @monhostlist = PVE::Tools::split_list($list_text);
12 return join($separator, map {
13 my ($host, $port) = PVE::Tools::parse_host_and_port($_);
14 $port = defined($port) ? ":$port" : '';
15 $host = "[$host]" if Net::IP::ip_is_ipv6($host);
16 "${host}${port}"
17 } @monhostlist);
18}
19
20sub ceph_connect_option {
21 my ($scfg, $storeid, %options) = @_;
22
23 my $cmd_option = {};
24 my $ceph_storeid_conf = "/etc/pve/priv/ceph/${storeid}.conf";
25 my $pveceph_config = '/etc/pve/ceph.conf';
26 my $keyfile = "/etc/pve/priv/ceph/${storeid}.keyring";
27 $keyfile = "/etc/pve/priv/ceph/${storeid}.secret" if ($scfg->{type} eq 'cephfs');
28 my $pveceph_managed = !defined($scfg->{monhost});
29
30 $cmd_option->{ceph_conf} = $pveceph_config if $pveceph_managed;
31
32 if (-e $ceph_storeid_conf) {
33 if ($pveceph_managed) {
34 warn "ignoring custom ceph config for storage '$storeid', 'monhost' is not set (assuming pveceph managed cluster)!\n";
35 } else {
36 $cmd_option->{ceph_conf} = $ceph_storeid_conf;
37 }
38 }
39
40 $cmd_option->{keyring} = $keyfile if (-e $keyfile);
41 $cmd_option->{auth_supported} = (defined $cmd_option->{keyring}) ? 'cephx' : 'none';
42 $cmd_option->{userid} = $scfg->{username} ? $scfg->{username} : 'admin';
43 $cmd_option->{mon_host} = hostlist($scfg->{monhost}, ',') if (defined($scfg->{monhost}));
44
45 if (%options) {
46 foreach my $k (keys %options) {
47 $cmd_option->{$k} = $options{$k};
48 }
49 }
50
51 return $cmd_option;
52
53}
54
551;