]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Ceph.pm
1 package PVE
::API2
::CephOSD
;
10 use PVE
::Ceph
::Services
;
12 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
14 use PVE
::Exception
qw(raise_param_exc);
15 use PVE
::JSONSchema
qw(get_standard_option);
18 use PVE
::RPCEnvironment
;
19 use PVE
::Tools
qw(run_command file_set_contents);
21 use base
qw(PVE::RESTHandler);
23 my $get_osd_status = sub {
24 my ($rados, $osdid) = @_;
26 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
28 my $osdlist = $stat->{osds
} || [];
30 my $flags = $stat->{flags
} || undef;
33 foreach my $d (@$osdlist) {
34 $osdstat->{$d->{osd
}} = $d if defined($d->{osd
});
36 if (defined($osdid)) {
37 die "no such OSD '$osdid'\n" if !$osdstat->{$osdid};
38 return $osdstat->{$osdid};
41 return wantarray?
($osdstat, $flags):$osdstat;
44 my $get_osd_usage = sub {
47 my $osdlist = $rados->mon_command({ prefix
=> 'pg dump',
48 dumpcontents
=> [ 'osds' ]}) || [];
51 foreach my $d (@$osdlist) {
52 $osdstat->{$d->{osd
}} = $d if defined($d->{osd
});
58 __PACKAGE__-
>register_method ({
62 description
=> "Get Ceph osd list/tree.",
66 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
69 additionalProperties
=> 0,
71 node
=> get_standard_option
('pve-node'),
74 # fixme: return a list instead of extjs tree format ?
81 PVE
::Ceph
::Tools
::check_ceph_inited
();
83 my $rados = PVE
::RADOS-
>new();
84 my $res = $rados->mon_command({ prefix
=> 'osd tree' });
86 die "no tree nodes found\n" if !($res && $res->{nodes
});
88 my ($osdhash, $flags) = &$get_osd_status($rados);
90 my $usagehash = &$get_osd_usage($rados);
92 my $osdmetadata_tmp = $rados->mon_command({ prefix
=> 'osd metadata' });
95 foreach my $osd (@$osdmetadata_tmp) {
96 $osdmetadata->{$osd->{id
}} = $osd;
101 foreach my $e (@{$res->{nodes
}}) {
102 $nodes->{$e->{id
}} = $e;
110 foreach my $opt (qw(status crush_weight reweight device_class)) {
111 $new->{$opt} = $e->{$opt} if defined($e->{$opt});
114 if (my $stat = $osdhash->{$e->{id
}}) {
115 $new->{in} = $stat->{in} if defined($stat->{in});
118 if (my $stat = $usagehash->{$e->{id
}}) {
119 $new->{total_space
} = ($stat->{kb
} || 1) * 1024;
120 $new->{bytes_used
} = ($stat->{kb_used
} || 0) * 1024;
121 $new->{percent_used
} = ($new->{bytes_used
}*100)/$new->{total_space
};
122 if (my $d = $stat->{perf_stat
}) {
123 $new->{commit_latency_ms
} = $d->{commit_latency_ms
};
124 $new->{apply_latency_ms
} = $d->{apply_latency_ms
};
128 my $osdmd = $osdmetadata->{$e->{id
}};
129 if ($e->{type
} eq 'osd' && $osdmd) {
130 if ($osdmd->{bluefs
}) {
131 $new->{osdtype
} = 'bluestore';
132 $new->{blfsdev
} = $osdmd->{bluestore_bdev_dev_node
};
133 $new->{dbdev
} = $osdmd->{bluefs_db_dev_node
};
134 $new->{waldev
} = $osdmd->{bluefs_wal_dev_node
};
136 $new->{osdtype
} = 'filestore';
140 $newnodes->{$e->{id
}} = $new;
143 foreach my $e (@{$res->{nodes
}}) {
144 my $new = $newnodes->{$e->{id
}};
145 if ($e->{children
} && scalar(@{$e->{children
}})) {
146 $new->{children
} = [];
148 foreach my $cid (@{$e->{children
}}) {
149 $nodes->{$cid}->{parent
} = $e->{id
};
150 if ($nodes->{$cid}->{type
} eq 'osd' &&
151 $e->{type
} eq 'host') {
152 $newnodes->{$cid}->{host
} = $e->{name
};
154 push @{$new->{children
}}, $newnodes->{$cid};
157 $new->{leaf
} = ($e->{id
} >= 0) ?
1 : 0;
162 foreach my $e (@{$res->{nodes
}}) {
163 if (!$nodes->{$e->{id
}}->{parent
}) {
164 push @$roots, $newnodes->{$e->{id
}};
168 die "no root node\n" if !@$roots;
170 my $data = { root
=> { leaf
=> 0, children
=> $roots } };
172 # we want this for the noout flag
173 $data->{flags
} = $flags if $flags;
178 __PACKAGE__-
>register_method ({
182 description
=> "Create OSD",
186 additionalProperties
=> 0,
188 node
=> get_standard_option
('pve-node'),
190 description
=> "Block device name.",
194 description
=> "Block device name for journal (filestore) or block.db (bluestore).",
199 description
=> "Block device name for block.wal (bluestore only).",
204 description
=> "File system type (filestore only).",
206 enum
=> ['xfs', 'ext4'],
211 description
=> "Use bluestore instead of filestore. This is the default.",
218 returns
=> { type
=> 'string' },
222 my $rpcenv = PVE
::RPCEnvironment
::get
();
224 my $authuser = $rpcenv->get_user();
226 raise_param_exc
({ 'bluestore' => "conflicts with parameter 'fstype'" })
227 if (defined($param->{fstype
}) && defined($param->{bluestore
}) && $param->{bluestore
});
229 PVE
::Ceph
::Tools
::check_ceph_inited
();
231 PVE
::Ceph
::Tools
::setup_pve_symlinks
();
233 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_osd');
235 my $bluestore = $param->{bluestore
} // 1;
240 if ($param->{journal_dev
} && ($param->{journal_dev
} ne $param->{dev
})) {
241 $journal_dev = PVE
::Diskmanage
::verify_blockdev_path
($param->{journal_dev
});
244 if ($param->{wal_dev
} &&
245 ($param->{wal_dev
} ne $param->{dev
}) &&
246 (!$param->{journal_dev
} || $param->{wal_dev
} ne $param->{journal_dev
})) {
247 raise_param_exc
({ 'wal_dev' => "can only be set with paramater 'bluestore'"})
249 $wal_dev = PVE
::Diskmanage
::verify_blockdev_path
($param->{wal_dev
});
252 $param->{dev
} = PVE
::Diskmanage
::verify_blockdev_path
($param->{dev
});
254 my $devname = $param->{dev
};
255 $devname =~ s
|/dev/||;
257 my $disklist = PVE
::Diskmanage
::get_disks
($devname, 1);
259 my $diskinfo = $disklist->{$devname};
260 die "unable to get device info for '$devname'\n"
263 die "device '$param->{dev}' is in use\n"
264 if $diskinfo->{used
};
266 my $devpath = $diskinfo->{devpath
};
267 my $rados = PVE
::RADOS-
>new();
268 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
269 die "unable to get fsid\n" if !$monstat->{monmap
} || !$monstat->{monmap
}->{fsid
};
271 my $fsid = $monstat->{monmap
}->{fsid
};
272 $fsid = $1 if $fsid =~ m/^([0-9a-f\-]+)$/;
274 my $ceph_bootstrap_osd_keyring = PVE
::Ceph
::Tools
::get_config
('ceph_bootstrap_osd_keyring');
276 if (! -f
$ceph_bootstrap_osd_keyring) {
277 my $bindata = $rados->mon_command({ prefix
=> 'auth get', entity
=> 'client.bootstrap-osd', format
=> 'plain' });
278 file_set_contents
($ceph_bootstrap_osd_keyring, $bindata);
284 my $fstype = $param->{fstype
} || 'xfs';
287 my $ccname = PVE
::Ceph
::Tools
::get_config
('ccname');
289 my $cmd = ['ceph-disk', 'prepare', '--zap-disk',
290 '--cluster', $ccname, '--cluster-uuid', $fsid ];
293 print "create OSD on $devpath (bluestore)\n";
294 push @$cmd, '--bluestore';
297 print "using device '$journal_dev' for block.db\n";
298 push @$cmd, '--block.db', $journal_dev;
302 print "using device '$wal_dev' for block.wal\n";
303 push @$cmd, '--block.wal', $wal_dev;
306 push @$cmd, $devpath;
308 print "create OSD on $devpath ($fstype)\n";
309 push @$cmd, '--filestore', '--fs-type', $fstype;
311 print "using device '$journal_dev' for journal\n";
312 push @$cmd, '--journal-dev', $devpath, $journal_dev;
314 push @$cmd, $devpath;
318 PVE
::Ceph
::Tools
::wipe_disks
($devpath);
323 return $rpcenv->fork_worker('cephcreateosd', $devname, $authuser, $worker);
326 __PACKAGE__-
>register_method ({
327 name
=> 'destroyosd',
330 description
=> "Destroy OSD",
334 additionalProperties
=> 0,
336 node
=> get_standard_option
('pve-node'),
338 description
=> 'OSD ID',
342 description
=> "If set, we remove partition table entries.",
349 returns
=> { type
=> 'string' },
353 my $rpcenv = PVE
::RPCEnvironment
::get
();
355 my $authuser = $rpcenv->get_user();
357 PVE
::Ceph
::Tools
::check_ceph_inited
();
359 my $osdid = $param->{osdid
};
361 my $rados = PVE
::RADOS-
>new();
362 my $osdstat = &$get_osd_status($rados, $osdid);
364 die "osd is in use (in == 1)\n" if $osdstat->{in};
365 #&$run_ceph_cmd(['osd', 'out', $osdid]);
367 die "osd is still runnung (up == 1)\n" if $osdstat->{up
};
369 my $osdsection = "osd.$osdid";
374 # reopen with longer timeout
375 $rados = PVE
::RADOS-
>new(timeout
=> PVE
::Ceph
::Tools
::get_config
('long_rados_timeout'));
377 print "destroy OSD $osdsection\n";
380 PVE
::Ceph
::Services
::ceph_service_cmd
('stop', $osdsection);
381 PVE
::Ceph
::Services
::ceph_service_cmd
('disable', $osdsection);
385 print "Remove $osdsection from the CRUSH map\n";
386 $rados->mon_command({ prefix
=> "osd crush remove", name
=> $osdsection, format
=> 'plain' });
388 print "Remove the $osdsection authentication key.\n";
389 $rados->mon_command({ prefix
=> "auth del", entity
=> $osdsection, format
=> 'plain' });
391 print "Remove OSD $osdsection\n";
392 $rados->mon_command({ prefix
=> "osd rm", ids
=> [ $osdsection ], format
=> 'plain' });
394 # try to unmount from standard mount point
395 my $mountpoint = "/var/lib/ceph/osd/ceph-$osdid";
397 my $disks_to_wipe = {};
398 my $remove_partition = sub {
401 return if !$part || (! -b
$part );
402 my $partnum = PVE
::Diskmanage
::get_partnum
($part);
403 my $devpath = PVE
::Diskmanage
::get_blockdev
($part);
405 print "remove partition $part (disk '${devpath}', partnum $partnum)\n";
406 eval { run_command
(['/sbin/sgdisk', '-d', $partnum, "${devpath}"]); };
409 $disks_to_wipe->{$devpath} = 1;
412 my $partitions_to_remove = [];
414 if ($param->{cleanup
}) {
415 if (my $fd = IO
::File-
>new("/proc/mounts", "r")) {
416 while (defined(my $line = <$fd>)) {
417 my ($dev, $path, $fstype) = split(/\s+/, $line);
418 next if !($dev && $path && $fstype);
419 next if $dev !~ m
|^/dev/|;
420 if ($path eq $mountpoint) {
421 my $data_part = abs_path
($dev);
422 push @$partitions_to_remove, $data_part;
429 foreach my $path (qw(journal block block.db block.wal)) {
430 my $part = abs_path
("$mountpoint/$path");
432 push @$partitions_to_remove, $part;
437 print "Unmount OSD $osdsection from $mountpoint\n";
438 eval { run_command
(['/bin/umount', $mountpoint]); };
441 } elsif ($param->{cleanup
}) {
442 #be aware of the ceph udev rules which can remount.
443 foreach my $part (@$partitions_to_remove) {
444 $remove_partition->($part);
447 PVE
::Ceph
::Tools
::wipe_disks
(keys %$disks_to_wipe);
451 return $rpcenv->fork_worker('cephdestroyosd', $osdsection, $authuser, $worker);
454 __PACKAGE__-
>register_method ({
456 path
=> '{osdid}/in',
458 description
=> "ceph osd in",
462 check
=> ['perm', '/', [ 'Sys.Modify' ]],
465 additionalProperties
=> 0,
467 node
=> get_standard_option
('pve-node'),
469 description
=> 'OSD ID',
474 returns
=> { type
=> "null" },
478 PVE
::Ceph
::Tools
::check_ceph_inited
();
480 my $osdid = $param->{osdid
};
482 my $rados = PVE
::RADOS-
>new();
484 my $osdstat = &$get_osd_status($rados, $osdid); # osd exists?
486 my $osdsection = "osd.$osdid";
488 $rados->mon_command({ prefix
=> "osd in", ids
=> [ $osdsection ], format
=> 'plain' });
493 __PACKAGE__-
>register_method ({
495 path
=> '{osdid}/out',
497 description
=> "ceph osd out",
501 check
=> ['perm', '/', [ 'Sys.Modify' ]],
504 additionalProperties
=> 0,
506 node
=> get_standard_option
('pve-node'),
508 description
=> 'OSD ID',
513 returns
=> { type
=> "null" },
517 PVE
::Ceph
::Tools
::check_ceph_inited
();
519 my $osdid = $param->{osdid
};
521 my $rados = PVE
::RADOS-
>new();
523 my $osdstat = &$get_osd_status($rados, $osdid); # osd exists?
525 my $osdsection = "osd.$osdid";
527 $rados->mon_command({ prefix
=> "osd out", ids
=> [ $osdsection ], format
=> 'plain' });
532 package PVE
::API2
::Ceph
;
541 use PVE
::Ceph
::Tools
;
542 use PVE
::Ceph
::Services
;
543 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
544 use PVE
::JSONSchema
qw(get_standard_option);
547 use PVE
::RESTHandler
;
548 use PVE
::RPCEnvironment
;
550 use PVE
::Tools
qw(run_command file_get_contents file_set_contents);
552 use PVE
::API2
::Ceph
::FS
;
553 use PVE
::API2
::Ceph
::MDS
;
554 use PVE
::API2
::Storage
::Config
;
556 use base
qw(PVE::RESTHandler);
558 my $pve_osd_default_journal_size = 1024*5;
560 __PACKAGE__-
>register_method ({
561 subclass
=> "PVE::API2::CephOSD",
565 __PACKAGE__-
>register_method ({
566 subclass
=> "PVE::API2::Ceph::MDS",
570 __PACKAGE__-
>register_method ({
571 subclass
=> "PVE::API2::Ceph::FS",
575 __PACKAGE__-
>register_method ({
579 description
=> "Directory index.",
580 permissions
=> { user
=> 'all' },
582 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
585 additionalProperties
=> 0,
587 node
=> get_standard_option
('pve-node'),
596 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
610 { name
=> 'status' },
612 { name
=> 'config' },
622 __PACKAGE__-
>register_method ({
626 description
=> "List local disks.",
630 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
633 additionalProperties
=> 0,
635 node
=> get_standard_option
('pve-node'),
637 description
=> "Only list specific types of disks.",
639 enum
=> ['unused', 'journal_disks'],
649 dev
=> { type
=> 'string' },
650 used
=> { type
=> 'string', optional
=> 1 },
651 gpt
=> { type
=> 'boolean' },
652 size
=> { type
=> 'integer' },
653 osdid
=> { type
=> 'integer' },
654 vendor
=> { type
=> 'string', optional
=> 1 },
655 model
=> { type
=> 'string', optional
=> 1 },
656 serial
=> { type
=> 'string', optional
=> 1 },
659 # links => [ { rel => 'child', href => "{}" } ],
664 PVE
::Ceph
::Tools
::check_ceph_inited
();
666 my $disks = PVE
::Diskmanage
::get_disks
(undef, 1);
669 foreach my $dev (keys %$disks) {
670 my $d = $disks->{$dev};
671 if ($param->{type
}) {
672 if ($param->{type
} eq 'journal_disks') {
673 next if $d->{osdid
} >= 0;
675 } elsif ($param->{type
} eq 'unused') {
678 die "internal error"; # should not happen
682 $d->{dev
} = "/dev/$dev";
689 __PACKAGE__-
>register_method ({
694 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
696 description
=> "Get Ceph configuration.",
698 additionalProperties
=> 0,
700 node
=> get_standard_option
('pve-node'),
703 returns
=> { type
=> 'string' },
707 PVE
::Ceph
::Tools
::check_ceph_inited
();
709 my $path = PVE
::Ceph
::Tools
::get_config
('pve_ceph_cfgpath');
710 return file_get_contents
($path);
714 my $add_storage = sub {
715 my ($pool, $storeid) = @_;
717 my $storage_params = {
722 content
=> 'rootdir,images',
725 PVE
::API2
::Storage
::Config-
>create($storage_params);
728 my $get_storages = sub {
731 my $cfg = PVE
::Storage
::config
();
733 my $storages = $cfg->{ids
};
735 foreach my $storeid (keys %$storages) {
736 my $curr = $storages->{$storeid};
737 $res->{$storeid} = $storages->{$storeid}
738 if $curr->{type
} eq 'rbd' && $pool eq $curr->{pool
};
744 __PACKAGE__-
>register_method ({
748 description
=> "Get Ceph monitor list.",
752 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
755 additionalProperties
=> 0,
757 node
=> get_standard_option
('pve-node'),
765 name
=> { type
=> 'string' },
766 addr
=> { type
=> 'string' },
769 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
774 PVE
::Ceph
::Tools
::check_ceph_inited
();
778 my $cfg = cfs_read_file
('ceph.conf');
781 foreach my $section (keys %$cfg) {
782 my $d = $cfg->{$section};
783 if ($section =~ m/^mon\.(\S+)$/) {
785 if ($d->{'mon addr'} && $d->{'host'}) {
786 $monhash->{$monid} = {
787 addr
=> $d->{'mon addr'},
788 host
=> $d->{'host'},
796 my $rados = PVE
::RADOS-
>new();
797 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
798 my $mons = $monstat->{monmap
}->{mons
};
799 foreach my $d (@$mons) {
800 next if !defined($d->{name
});
801 $monhash->{$d->{name
}}->{rank
} = $d->{rank
};
802 $monhash->{$d->{name
}}->{addr
} = $d->{addr
};
803 if (grep { $_ eq $d->{rank
} } @{$monstat->{quorum
}}) {
804 $monhash->{$d->{name
}}->{quorum
} = 1;
810 return PVE
::RESTHandler
::hash_to_array
($monhash, 'name');
813 __PACKAGE__-
>register_method ({
817 description
=> "Create initial ceph default configuration and setup symlinks.",
821 check
=> ['perm', '/', [ 'Sys.Modify' ]],
824 additionalProperties
=> 0,
826 node
=> get_standard_option
('pve-node'),
828 description
=> "Use specific network for all ceph related traffic",
829 type
=> 'string', format
=> 'CIDR',
833 'cluster-network' => {
834 description
=> "Declare a separate cluster network, OSDs will route" .
835 "heartbeat, object replication and recovery traffic over it",
836 type
=> 'string', format
=> 'CIDR',
837 requires
=> 'network',
842 description
=> 'Targeted number of replicas per object',
850 description
=> 'Minimum number of available replicas per object to allow I/O',
858 description
=> "Placement group bits, used to specify the " .
859 "default number of placement groups.\n\nNOTE: 'osd pool " .
860 "default pg num' does not work for default pools.",
868 description
=> "Disable cephx authentification.\n\n" .
869 "WARNING: cephx is a security feature protecting against " .
870 "man-in-the-middle attacks. Only consider disabling cephx ".
871 "if your network is private!",
878 returns
=> { type
=> 'null' },
882 my $version = PVE
::Ceph
::Tools
::get_local_version
(1);
884 if (!$version || $version < 12) {
885 die "Ceph Luminous required - please run 'pveceph install'\n";
887 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_bin');
890 # simply load old config if it already exists
891 my $cfg = cfs_read_file
('ceph.conf');
893 if (!$cfg->{global
}) {
898 UUID
::generate
($uuid);
899 UUID
::unparse
($uuid, $fsid);
901 my $auth = $param->{disable_cephx
} ?
'none' : 'cephx';
905 'auth cluster required' => $auth,
906 'auth service required' => $auth,
907 'auth client required' => $auth,
908 'osd journal size' => $pve_osd_default_journal_size,
909 'osd pool default size' => $param->{size
} // 3,
910 'osd pool default min size' => $param->{min_size
} // 2,
911 'mon allow pool delete' => 'true',
914 # this does not work for default pools
915 #'osd pool default pg num' => $pg_num,
916 #'osd pool default pgp num' => $pg_num,
919 $cfg->{global
}->{keyring
} = '/etc/pve/priv/$cluster.$name.keyring';
920 $cfg->{osd
}->{keyring
} = '/var/lib/ceph/osd/ceph-$id/keyring';
922 if ($param->{pg_bits
}) {
923 $cfg->{global
}->{'osd pg bits'} = $param->{pg_bits
};
924 $cfg->{global
}->{'osd pgp bits'} = $param->{pg_bits
};
927 if ($param->{network
}) {
928 $cfg->{global
}->{'public network'} = $param->{network
};
929 $cfg->{global
}->{'cluster network'} = $param->{network
};
932 if ($param->{'cluster-network'}) {
933 $cfg->{global
}->{'cluster network'} = $param->{'cluster-network'};
936 cfs_write_file
('ceph.conf', $cfg);
938 PVE
::Ceph
::Tools
::setup_pve_symlinks
();
943 my $find_mon_ip = sub {
944 my ($pubnet, $node, $overwrite_ip) = @_;
947 return $overwrite_ip // PVE
::Cluster
::remote_node_ip
($node);
950 my $allowed_ips = PVE
::Network
::get_local_ip_from_cidr
($pubnet);
951 die "No IP configured and up from ceph public network '$pubnet'\n"
952 if scalar(@$allowed_ips) < 1;
954 if (!$overwrite_ip) {
955 if (scalar(@$allowed_ips) == 1) {
956 return $allowed_ips->[0];
958 die "Multiple IPs for ceph public network '$pubnet' detected on $node:\n".
959 join("\n", @$allowed_ips) ."\nuse 'mon-address' to specify one of them.\n";
961 if (grep { $_ eq $overwrite_ip } @$allowed_ips) {
962 return $overwrite_ip;
964 die "Monitor IP '$overwrite_ip' not in ceph public network '$pubnet'\n"
965 if !PVE
::Network
::is_ip_in_cidr
($overwrite_ip, $pubnet);
967 die "Specified monitor IP '$overwrite_ip' not configured or up on $node!\n";
971 my $create_mgr = sub {
972 my ($rados, $id) = @_;
974 my $clustername = PVE
::Ceph
::Tools
::get_config
('ccname');
975 my $mgrdir = "/var/lib/ceph/mgr/$clustername-$id";
976 my $mgrkeyring = "$mgrdir/keyring";
977 my $mgrname = "mgr.$id";
979 die "ceph manager directory '$mgrdir' already exists\n"
982 print "creating manager directory '$mgrdir'\n";
984 print "creating keys for '$mgrname'\n";
985 my $output = $rados->mon_command({ prefix
=> 'auth get-or-create',
988 mon
=> 'allow profile mgr',
993 file_set_contents
($mgrkeyring, $output);
995 print "setting owner for directory\n";
996 run_command
(["chown", 'ceph:ceph', '-R', $mgrdir]);
998 print "enabling service 'ceph-mgr\@$id.service'\n";
999 PVE
::Ceph
::Services
::ceph_service_cmd
('enable', $mgrname);
1000 print "starting service 'ceph-mgr\@$id.service'\n";
1001 PVE
::Ceph
::Services
::ceph_service_cmd
('start', $mgrname);
1004 my $destroy_mgr = sub {
1007 my $clustername = PVE
::Ceph
::Tools
::get_config
('ccname');
1008 my $mgrname = "mgr.$mgrid";
1009 my $mgrdir = "/var/lib/ceph/mgr/$clustername-$mgrid";
1011 die "ceph manager directory '$mgrdir' not found\n"
1014 print "disabling service 'ceph-mgr\@$mgrid.service'\n";
1015 PVE
::Ceph
::Services
::ceph_service_cmd
('disable', $mgrname);
1016 print "stopping service 'ceph-mgr\@$mgrid.service'\n";
1017 PVE
::Ceph
::Services
::ceph_service_cmd
('stop', $mgrname);
1019 print "removing manager directory '$mgrdir'\n";
1020 File
::Path
::remove_tree
($mgrdir);
1023 __PACKAGE__-
>register_method ({
1024 name
=> 'createmon',
1027 description
=> "Create Ceph Monitor and Manager",
1031 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1034 additionalProperties
=> 0,
1036 node
=> get_standard_option
('pve-node'),
1040 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1041 description
=> "The ID for the monitor, when omitted the same as the nodename",
1043 'exclude-manager' => {
1047 description
=> "When set, only a monitor will be created.",
1050 description
=> 'Overwrites autodetected monitor IP address. ' .
1051 'Must be in the public network of ceph.',
1052 type
=> 'string', format
=> 'ip',
1057 returns
=> { type
=> 'string' },
1061 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_mon');
1063 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_mgr')
1064 if (!$param->{'exclude-manager'});
1066 PVE
::Ceph
::Tools
::check_ceph_inited
();
1068 PVE
::Ceph
::Tools
::setup_pve_symlinks
();
1070 my $rpcenv = PVE
::RPCEnvironment
::get
();
1072 my $authuser = $rpcenv->get_user();
1074 my $cfg = cfs_read_file
('ceph.conf');
1078 my $monaddrhash = {};
1080 my $systemd_managed = PVE
::Ceph
::Tools
::systemd_managed
();
1082 foreach my $section (keys %$cfg) {
1083 next if $section eq 'global';
1084 my $d = $cfg->{$section};
1085 if ($section =~ m/^mon\./) {
1087 if ($d->{'mon addr'}) {
1088 $monaddrhash->{$d->{'mon addr'}} = $section;
1093 my $monid = $param->{id
} // $param->{node
};
1095 my $monsection = "mon.$monid";
1096 my $pubnet = $cfg->{global
}->{'public network'};
1097 my $ip = $find_mon_ip->($pubnet, $param->{node
}, $param->{'mon-address'});
1099 my $monaddr = Net
::IP
::ip_is_ipv6
($ip) ?
"[$ip]:6789" : "$ip:6789";
1100 my $monname = $param->{node
};
1102 die "monitor '$monsection' already exists\n" if $cfg->{$monsection};
1103 die "monitor address '$monaddr' already in use by '$monaddrhash->{$monaddr}'\n"
1104 if $monaddrhash->{$monaddr};
1109 my $pve_ckeyring_path = PVE
::Ceph
::Tools
::get_config
('pve_ckeyring_path');
1111 if (! -f
$pve_ckeyring_path) {
1112 run_command
("ceph-authtool $pve_ckeyring_path --create-keyring " .
1113 "--gen-key -n client.admin");
1116 my $pve_mon_key_path = PVE
::Ceph
::Tools
::get_config
('pve_mon_key_path');
1117 if (! -f
$pve_mon_key_path) {
1118 run_command
("cp $pve_ckeyring_path $pve_mon_key_path.tmp");
1119 run_command
("ceph-authtool $pve_mon_key_path.tmp -n client.admin --set-uid=0 " .
1120 "--cap mds 'allow' " .
1121 "--cap osd 'allow *' " .
1122 "--cap mgr 'allow *' " .
1123 "--cap mon 'allow *'");
1124 run_command
("cp $pve_mon_key_path.tmp /etc/ceph/ceph.client.admin.keyring") if $systemd_managed;
1125 run_command
("chown ceph:ceph /etc/ceph/ceph.client.admin.keyring") if $systemd_managed;
1126 run_command
("ceph-authtool $pve_mon_key_path.tmp --gen-key -n mon. --cap mon 'allow *'");
1127 run_command
("mv $pve_mon_key_path.tmp $pve_mon_key_path");
1130 my $ccname = PVE
::Ceph
::Tools
::get_config
('ccname');
1132 my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
1133 -d
$mondir && die "monitor filesystem '$mondir' already exist\n";
1135 my $monmap = "/tmp/monmap";
1140 run_command
("chown ceph:ceph $mondir") if $systemd_managed;
1142 if ($moncount > 0) {
1143 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::Ceph
::Tools
::get_config
('long_rados_timeout'));
1144 my $mapdata = $rados->mon_command({ prefix
=> 'mon getmap', format
=> 'plain' });
1145 file_set_contents
($monmap, $mapdata);
1147 run_command
("monmaptool --create --clobber --add $monid $monaddr --print $monmap");
1150 run_command
("ceph-mon --mkfs -i $monid --monmap $monmap --keyring $pve_mon_key_path");
1151 run_command
("chown ceph:ceph -R $mondir") if $systemd_managed;
1156 File
::Path
::remove_tree
($mondir);
1160 $cfg->{$monsection} = {
1162 'mon addr' => $monaddr,
1165 cfs_write_file
('ceph.conf', $cfg);
1167 my $create_keys_pid = fork();
1168 if (!defined($create_keys_pid)) {
1169 die "Could not spawn ceph-create-keys to create bootstrap keys\n";
1170 } elsif ($create_keys_pid == 0) {
1171 exit PVE
::Tools
::run_command
(['ceph-create-keys', '-i', $monid]);
1173 PVE
::Ceph
::Services
::ceph_service_cmd
('start', $monsection);
1175 if ($systemd_managed) {
1176 #to ensure we have the correct startup order.
1177 eval { PVE
::Tools
::run_command
(['/bin/systemctl', 'enable', "ceph-mon\@${monid}.service"]); };
1178 warn "Enable ceph-mon\@${monid}.service manually"if $@;
1180 waitpid($create_keys_pid, 0);
1184 if (!$param->{'exclude-manager'}) {
1185 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::Ceph
::Tools
::get_config
('long_rados_timeout'));
1186 $create_mgr->($rados, $monid);
1190 return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker);
1193 __PACKAGE__-
>register_method ({
1194 name
=> 'destroymon',
1195 path
=> 'mon/{monid}',
1197 description
=> "Destroy Ceph Monitor and Manager.",
1201 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1204 additionalProperties
=> 0,
1206 node
=> get_standard_option
('pve-node'),
1208 description
=> 'Monitor ID',
1210 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1212 'exclude-manager' => {
1216 description
=> "When set, removes only the monitor, not the manager"
1220 returns
=> { type
=> 'string' },
1224 my $rpcenv = PVE
::RPCEnvironment
::get
();
1226 my $authuser = $rpcenv->get_user();
1228 PVE
::Ceph
::Tools
::check_ceph_inited
();
1230 my $cfg = cfs_read_file
('ceph.conf');
1232 my $monid = $param->{monid
};
1233 my $monsection = "mon.$monid";
1235 my $rados = PVE
::RADOS-
>new();
1236 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
1237 my $monlist = $monstat->{monmap
}->{mons
};
1239 die "no such monitor id '$monid'\n"
1240 if !defined($cfg->{$monsection});
1242 my $ccname = PVE
::Ceph
::Tools
::get_config
('ccname');
1244 my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
1245 -d
$mondir || die "monitor filesystem '$mondir' does not exist on this node\n";
1247 die "can't remove last monitor\n" if scalar(@$monlist) <= 1;
1252 # reopen with longer timeout
1253 $rados = PVE
::RADOS-
>new(timeout
=> PVE
::Ceph
::Tools
::get_config
('long_rados_timeout'));
1255 $rados->mon_command({ prefix
=> "mon remove", name
=> $monid, format
=> 'plain' });
1257 eval { PVE
::Ceph
::Services
::ceph_service_cmd
('stop', $monsection); };
1260 delete $cfg->{$monsection};
1261 cfs_write_file
('ceph.conf', $cfg);
1262 File
::Path
::remove_tree
($mondir);
1265 if (!$param->{'exclude-manager'}) {
1266 eval { $destroy_mgr->($monid); };
1271 return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);
1274 __PACKAGE__-
>register_method ({
1275 name
=> 'createmgr',
1278 description
=> "Create Ceph Manager",
1282 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1285 additionalProperties
=> 0,
1287 node
=> get_standard_option
('pve-node'),
1291 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1292 description
=> "The ID for the manager, when omitted the same as the nodename",
1296 returns
=> { type
=> 'string' },
1300 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_mgr');
1302 PVE
::Ceph
::Tools
::check_ceph_inited
();
1304 my $rpcenv = PVE
::RPCEnvironment
::get
();
1306 my $authuser = $rpcenv->get_user();
1308 my $mgrid = $param->{id
} // $param->{node
};
1313 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::Ceph
::Tools
::get_config
('long_rados_timeout'));
1315 $create_mgr->($rados, $mgrid);
1318 return $rpcenv->fork_worker('cephcreatemgr', "mgr.$mgrid", $authuser, $worker);
1321 __PACKAGE__-
>register_method ({
1322 name
=> 'destroymgr',
1325 description
=> "Destroy Ceph Manager.",
1329 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1332 additionalProperties
=> 0,
1334 node
=> get_standard_option
('pve-node'),
1336 description
=> 'The ID of the manager',
1338 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1342 returns
=> { type
=> 'string' },
1346 my $rpcenv = PVE
::RPCEnvironment
::get
();
1348 my $authuser = $rpcenv->get_user();
1350 PVE
::Ceph
::Tools
::check_ceph_inited
();
1352 my $mgrid = $param->{id
};
1357 $destroy_mgr->($mgrid);
1360 return $rpcenv->fork_worker('cephdestroymgr', "mgr.$mgrid", $authuser, $worker);
1363 __PACKAGE__-
>register_method ({
1367 description
=> "Stop ceph services.",
1371 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1374 additionalProperties
=> 0,
1376 node
=> get_standard_option
('pve-node'),
1378 description
=> 'Ceph service name.',
1381 default => 'ceph.target',
1382 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1386 returns
=> { type
=> 'string' },
1390 my $rpcenv = PVE
::RPCEnvironment
::get
();
1392 my $authuser = $rpcenv->get_user();
1394 PVE
::Ceph
::Tools
::check_ceph_inited
();
1396 my $cfg = cfs_read_file
('ceph.conf');
1397 scalar(keys %$cfg) || die "no configuration\n";
1403 if ($param->{service
}) {
1404 push @$cmd, $param->{service
};
1407 PVE
::Ceph
::Services
::ceph_service_cmd
(@$cmd);
1410 return $rpcenv->fork_worker('srvstop', $param->{service
} || 'ceph',
1411 $authuser, $worker);
1414 __PACKAGE__-
>register_method ({
1418 description
=> "Start ceph services.",
1422 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1425 additionalProperties
=> 0,
1427 node
=> get_standard_option
('pve-node'),
1429 description
=> 'Ceph service name.',
1432 default => 'ceph.target',
1433 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1437 returns
=> { type
=> 'string' },
1441 my $rpcenv = PVE
::RPCEnvironment
::get
();
1443 my $authuser = $rpcenv->get_user();
1445 PVE
::Ceph
::Tools
::check_ceph_inited
();
1447 my $cfg = cfs_read_file
('ceph.conf');
1448 scalar(keys %$cfg) || die "no configuration\n";
1453 my $cmd = ['start'];
1454 if ($param->{service
}) {
1455 push @$cmd, $param->{service
};
1458 PVE
::Ceph
::Services
::ceph_service_cmd
(@$cmd);
1461 return $rpcenv->fork_worker('srvstart', $param->{service
} || 'ceph',
1462 $authuser, $worker);
1465 __PACKAGE__-
>register_method ({
1469 description
=> "Restart ceph services.",
1473 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1476 additionalProperties
=> 0,
1478 node
=> get_standard_option
('pve-node'),
1480 description
=> 'Ceph service name.',
1483 default => 'ceph.target',
1484 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1488 returns
=> { type
=> 'string' },
1492 my $rpcenv = PVE
::RPCEnvironment
::get
();
1494 my $authuser = $rpcenv->get_user();
1496 PVE
::Ceph
::Tools
::check_ceph_inited
();
1498 my $cfg = cfs_read_file
('ceph.conf');
1499 scalar(keys %$cfg) || die "no configuration\n";
1504 my $cmd = ['restart'];
1505 if ($param->{service
}) {
1506 push @$cmd, $param->{service
};
1509 PVE
::Ceph
::Services
::ceph_service_cmd
(@$cmd);
1512 return $rpcenv->fork_worker('srvrestart', $param->{service
} || 'ceph',
1513 $authuser, $worker);
1516 __PACKAGE__-
>register_method ({
1520 description
=> "Get ceph status.",
1524 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1527 additionalProperties
=> 0,
1529 node
=> get_standard_option
('pve-node'),
1532 returns
=> { type
=> 'object' },
1536 PVE
::Ceph
::Tools
::check_ceph_enabled
();
1538 my $rados = PVE
::RADOS-
>new();
1539 my $status = $rados->mon_command({ prefix
=> 'status' });
1540 $status->{health
} = $rados->mon_command({ prefix
=> 'health', detail
=> 'detail' });
1544 __PACKAGE__-
>register_method ({
1548 description
=> "List all pools.",
1552 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1555 additionalProperties
=> 0,
1557 node
=> get_standard_option
('pve-node'),
1565 pool
=> { type
=> 'integer' },
1566 pool_name
=> { type
=> 'string' },
1567 size
=> { type
=> 'integer' },
1570 links
=> [ { rel
=> 'child', href
=> "{pool_name}" } ],
1575 PVE
::Ceph
::Tools
::check_ceph_inited
();
1577 my $rados = PVE
::RADOS-
>new();
1580 my $res = $rados->mon_command({ prefix
=> 'df' });
1582 foreach my $d (@{$res->{pools
}}) {
1583 next if !$d->{stats
};
1584 next if !defined($d->{id
});
1585 $stats->{$d->{id
}} = $d->{stats
};
1588 $res = $rados->mon_command({ prefix
=> 'osd dump' });
1589 my $rulestmp = $rados->mon_command({ prefix
=> 'osd crush rule dump'});
1592 for my $rule (@$rulestmp) {
1593 $rules->{$rule->{rule_id
}} = $rule->{rule_name
};
1597 foreach my $e (@{$res->{pools
}}) {
1599 foreach my $attr (qw(pool pool_name size min_size pg_num crush_rule)) {
1600 $d->{$attr} = $e->{$attr} if defined($e->{$attr});
1603 if (defined($d->{crush_rule
}) && defined($rules->{$d->{crush_rule
}})) {
1604 $d->{crush_rule_name
} = $rules->{$d->{crush_rule
}};
1607 if (my $s = $stats->{$d->{pool
}}) {
1608 $d->{bytes_used
} = $s->{bytes_used
};
1609 $d->{percent_used
} = $s->{percent_used
};
1618 __PACKAGE__-
>register_method ({
1619 name
=> 'createpool',
1622 description
=> "Create POOL",
1626 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1629 additionalProperties
=> 0,
1631 node
=> get_standard_option
('pve-node'),
1633 description
=> "The name of the pool. It must be unique.",
1637 description
=> 'Number of replicas per object',
1645 description
=> 'Minimum number of replicas per object',
1653 description
=> "Number of placement groups.",
1661 description
=> "The rule to use for mapping object placement in the cluster.",
1666 description
=> "The application of the pool, 'rbd' by default.",
1668 enum
=> ['rbd', 'cephfs', 'rgw'],
1672 description
=> "Configure VM and CT storage using the new pool.",
1678 returns
=> { type
=> 'string' },
1682 PVE
::Cluster
::check_cfs_quorum
();
1683 PVE
::Ceph
::Tools
::check_ceph_inited
();
1685 my $pve_ckeyring_path = PVE
::Ceph
::Tools
::get_config
('pve_ckeyring_path');
1687 die "not fully configured - missing '$pve_ckeyring_path'\n"
1688 if ! -f
$pve_ckeyring_path;
1690 my $pool = $param->{name
};
1691 my $rpcenv = PVE
::RPCEnvironment
::get
();
1692 my $user = $rpcenv->get_user();
1694 if ($param->{add_storages
}) {
1695 $rpcenv->check($user, '/storage', ['Datastore.Allocate']);
1696 die "pool name contains characters which are illegal for storage naming\n"
1697 if !PVE
::JSONSchema
::parse_storage_id
($pool);
1700 my $pg_num = $param->{pg_num
} || 128;
1701 my $size = $param->{size
} || 3;
1702 my $min_size = $param->{min_size
} || 2;
1703 my $application = $param->{application
} // 'rbd';
1707 PVE
::Ceph
::Tools
::create_pool
($pool, $param);
1709 if ($param->{add_storages
}) {
1711 eval { $add_storage->($pool, "${pool}"); };
1713 warn "failed to add storage: $@";
1716 die "adding storage for pool '$pool' failed, check log and add manually!\n"
1721 return $rpcenv->fork_worker('cephcreatepool', $pool, $user, $worker);
1724 __PACKAGE__-
>register_method ({
1725 name
=> 'get_flags',
1728 description
=> "get all set ceph flags",
1732 check
=> ['perm', '/', [ 'Sys.Audit' ]],
1735 additionalProperties
=> 0,
1737 node
=> get_standard_option
('pve-node'),
1740 returns
=> { type
=> 'string' },
1744 PVE
::Ceph
::Tools
::check_ceph_inited
();
1746 my $pve_ckeyring_path = PVE
::Ceph
::Tools
::get_config
('pve_ckeyring_path');
1748 die "not fully configured - missing '$pve_ckeyring_path'\n"
1749 if ! -f
$pve_ckeyring_path;
1751 my $rados = PVE
::RADOS-
>new();
1753 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
1755 return $stat->{flags
} // '';
1758 __PACKAGE__-
>register_method ({
1760 path
=> 'flags/{flag}',
1762 description
=> "Set a ceph flag",
1766 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1769 additionalProperties
=> 0,
1771 node
=> get_standard_option
('pve-node'),
1773 description
=> 'The ceph flag to set/unset',
1775 enum
=> [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
1779 returns
=> { type
=> 'null' },
1783 PVE
::Ceph
::Tools
::check_ceph_inited
();
1785 my $pve_ckeyring_path = PVE
::Ceph
::Tools
::get_config
('pve_ckeyring_path');
1787 die "not fully configured - missing '$pve_ckeyring_path'\n"
1788 if ! -f
$pve_ckeyring_path;
1790 my $set = $param->{set
} // !$param->{unset
};
1791 my $rados = PVE
::RADOS-
>new();
1793 $rados->mon_command({
1794 prefix
=> "osd set",
1795 key
=> $param->{flag
},
1801 __PACKAGE__-
>register_method ({
1802 name
=> 'unset_flag',
1803 path
=> 'flags/{flag}',
1805 description
=> "Unset a ceph flag",
1809 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1812 additionalProperties
=> 0,
1814 node
=> get_standard_option
('pve-node'),
1816 description
=> 'The ceph flag to set/unset',
1818 enum
=> [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
1822 returns
=> { type
=> 'null' },
1826 PVE
::Ceph
::Tools
::check_ceph_inited
();
1828 my $pve_ckeyring_path = PVE
::Ceph
::Tools
::get_config
('pve_ckeyring_path');
1830 die "not fully configured - missing '$pve_ckeyring_path'\n"
1831 if ! -f
$pve_ckeyring_path;
1833 my $set = $param->{set
} // !$param->{unset
};
1834 my $rados = PVE
::RADOS-
>new();
1836 $rados->mon_command({
1837 prefix
=> "osd unset",
1838 key
=> $param->{flag
},
1844 __PACKAGE__-
>register_method ({
1845 name
=> 'destroypool',
1846 path
=> 'pools/{name}',
1848 description
=> "Destroy pool",
1852 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1855 additionalProperties
=> 0,
1857 node
=> get_standard_option
('pve-node'),
1859 description
=> "The name of the pool. It must be unique.",
1863 description
=> "If true, destroys pool even if in use",
1868 remove_storages
=> {
1869 description
=> "Remove all pveceph-managed storages configured for this pool",
1876 returns
=> { type
=> 'string' },
1880 PVE
::Ceph
::Tools
::check_ceph_inited
();
1882 my $rpcenv = PVE
::RPCEnvironment
::get
();
1883 my $user = $rpcenv->get_user();
1884 $rpcenv->check($user, '/storage', ['Datastore.Allocate'])
1885 if $param->{remove_storages
};
1887 my $pool = $param->{name
};
1890 my $storages = $get_storages->($pool);
1892 # if not forced, destroy ceph pool only when no
1893 # vm disks are on it anymore
1894 if (!$param->{force
}) {
1895 my $storagecfg = PVE
::Storage
::config
();
1896 foreach my $storeid (keys %$storages) {
1897 my $storage = $storages->{$storeid};
1899 # check if any vm disks are on the pool
1900 print "checking storage '$storeid' for RBD images..\n";
1901 my $res = PVE
::Storage
::vdisk_list
($storagecfg, $storeid);
1902 die "ceph pool '$pool' still in use by storage '$storeid'\n"
1903 if @{$res->{$storeid}} != 0;
1907 PVE
::Ceph
::Tools
::destroy_pool
($pool);
1909 if ($param->{remove_storages
}) {
1911 foreach my $storeid (keys %$storages) {
1912 # skip external clusters, not managed by pveceph
1913 next if $storages->{$storeid}->{monhost
};
1914 eval { PVE
::API2
::Storage
::Config-
>delete({storage
=> $storeid}) };
1916 warn "failed to remove storage '$storeid': $@\n";
1920 die "failed to remove (some) storages - check log and remove manually!\n"
1924 return $rpcenv->fork_worker('cephdestroypool', $pool, $user, $worker);
1928 __PACKAGE__-
>register_method ({
1932 description
=> "Get OSD crush map",
1936 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1939 additionalProperties
=> 0,
1941 node
=> get_standard_option
('pve-node'),
1944 returns
=> { type
=> 'string' },
1948 PVE
::Ceph
::Tools
::check_ceph_inited
();
1950 # this produces JSON (difficult to read for the user)
1951 # my $txt = &$run_ceph_cmd_text(['osd', 'crush', 'dump'], quiet => 1);
1955 my $mapfile = "/var/tmp/ceph-crush.map.$$";
1956 my $mapdata = "/var/tmp/ceph-crush.txt.$$";
1958 my $rados = PVE
::RADOS-
>new();
1961 my $bindata = $rados->mon_command({ prefix
=> 'osd getcrushmap', format
=> 'plain' });
1962 file_set_contents
($mapfile, $bindata);
1963 run_command
(['crushtool', '-d', $mapfile, '-o', $mapdata]);
1964 $txt = file_get_contents
($mapdata);
1976 __PACKAGE__-
>register_method({
1980 description
=> "Read ceph log",
1983 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
1987 additionalProperties
=> 0,
1989 node
=> get_standard_option
('pve-node'),
2008 description
=> "Line number",
2012 description
=> "Line text",
2021 PVE
::Ceph
::Tools
::check_ceph_inited
();
2023 my $rpcenv = PVE
::RPCEnvironment
::get
();
2024 my $user = $rpcenv->get_user();
2025 my $node = $param->{node
};
2027 my $logfile = "/var/log/ceph/ceph.log";
2028 my ($count, $lines) = PVE
::Tools
::dump_logfile
($logfile, $param->{start
}, $param->{limit
});
2030 $rpcenv->set_result_attrib('total', $count);
2035 __PACKAGE__-
>register_method ({
2039 description
=> "List ceph rules.",
2043 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
2046 additionalProperties
=> 0,
2048 node
=> get_standard_option
('pve-node'),
2057 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
2062 PVE
::Ceph
::Tools
::check_ceph_inited
();
2064 my $rados = PVE
::RADOS-
>new();
2066 my $rules = $rados->mon_command({ prefix
=> 'osd crush rule ls' });
2070 foreach my $rule (@$rules) {
2071 push @$res, { name
=> $rule };