]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Ceph.pm
1 package PVE
::API2
::CephOSD
;
11 use PVE
::Exception
qw(raise_param_exc);
12 use PVE
::JSONSchema
qw(get_standard_option);
15 use PVE
::RPCEnvironment
;
16 use PVE
::Tools
qw(run_command file_set_contents);
18 use base
qw(PVE::RESTHandler);
20 my $get_osd_status = sub {
21 my ($rados, $osdid) = @_;
23 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
25 my $osdlist = $stat->{osds
} || [];
27 my $flags = $stat->{flags
} || undef;
30 foreach my $d (@$osdlist) {
31 $osdstat->{$d->{osd
}} = $d if defined($d->{osd
});
33 if (defined($osdid)) {
34 die "no such OSD '$osdid'\n" if !$osdstat->{$osdid};
35 return $osdstat->{$osdid};
38 return wantarray?
($osdstat, $flags):$osdstat;
41 my $get_osd_usage = sub {
44 my $osdlist = $rados->mon_command({ prefix
=> 'pg dump',
45 dumpcontents
=> [ 'osds' ]}) || [];
48 foreach my $d (@$osdlist) {
49 $osdstat->{$d->{osd
}} = $d if defined($d->{osd
});
55 __PACKAGE__-
>register_method ({
59 description
=> "Get Ceph osd list/tree.",
63 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
66 additionalProperties
=> 0,
68 node
=> get_standard_option
('pve-node'),
71 # fixme: return a list instead of extjs tree format ?
78 PVE
::CephTools
::check_ceph_inited
();
80 my $rados = PVE
::RADOS-
>new();
81 my $res = $rados->mon_command({ prefix
=> 'osd tree' });
83 die "no tree nodes found\n" if !($res && $res->{nodes
});
85 my ($osdhash, $flags) = &$get_osd_status($rados);
87 my $usagehash = &$get_osd_usage($rados);
89 my $osdmetadata_tmp = $rados->mon_command({ prefix
=> 'osd metadata' });
92 foreach my $osd (@$osdmetadata_tmp) {
93 $osdmetadata->{$osd->{id
}} = $osd;
98 foreach my $e (@{$res->{nodes
}}) {
99 $nodes->{$e->{id
}} = $e;
107 foreach my $opt (qw(status crush_weight reweight device_class)) {
108 $new->{$opt} = $e->{$opt} if defined($e->{$opt});
111 if (my $stat = $osdhash->{$e->{id
}}) {
112 $new->{in} = $stat->{in} if defined($stat->{in});
115 if (my $stat = $usagehash->{$e->{id
}}) {
116 $new->{total_space
} = ($stat->{kb
} || 1) * 1024;
117 $new->{bytes_used
} = ($stat->{kb_used
} || 0) * 1024;
118 $new->{percent_used
} = ($new->{bytes_used
}*100)/$new->{total_space
};
119 if (my $d = $stat->{perf_stat
}) {
120 $new->{commit_latency_ms
} = $d->{commit_latency_ms
};
121 $new->{apply_latency_ms
} = $d->{apply_latency_ms
};
125 my $osdmd = $osdmetadata->{$e->{id
}};
126 if ($e->{type
} eq 'osd' && $osdmd) {
127 if ($osdmd->{bluefs
}) {
128 $new->{osdtype
} = 'bluestore';
129 $new->{blfsdev
} = $osdmd->{bluestore_bdev_dev_node
};
130 $new->{dbdev
} = $osdmd->{bluefs_db_dev_node
};
131 $new->{waldev
} = $osdmd->{bluefs_wal_dev_node
};
133 $new->{osdtype
} = 'filestore';
137 $newnodes->{$e->{id
}} = $new;
140 foreach my $e (@{$res->{nodes
}}) {
141 my $new = $newnodes->{$e->{id
}};
142 if ($e->{children
} && scalar(@{$e->{children
}})) {
143 $new->{children
} = [];
145 foreach my $cid (@{$e->{children
}}) {
146 $nodes->{$cid}->{parent
} = $e->{id
};
147 if ($nodes->{$cid}->{type
} eq 'osd' &&
148 $e->{type
} eq 'host') {
149 $newnodes->{$cid}->{host
} = $e->{name
};
151 push @{$new->{children
}}, $newnodes->{$cid};
154 $new->{leaf
} = ($e->{id
} >= 0) ?
1 : 0;
159 foreach my $e (@{$res->{nodes
}}) {
160 if (!$nodes->{$e->{id
}}->{parent
}) {
161 push @$roots, $newnodes->{$e->{id
}};
165 die "no root node\n" if !@$roots;
167 my $data = { root
=> { leaf
=> 0, children
=> $roots } };
169 # we want this for the noout flag
170 $data->{flags
} = $flags if $flags;
175 __PACKAGE__-
>register_method ({
179 description
=> "Create OSD",
183 additionalProperties
=> 0,
185 node
=> get_standard_option
('pve-node'),
187 description
=> "Block device name.",
191 description
=> "Block device name for journal (filestore) or block.db (bluestore).",
196 description
=> "Block device name for block.wal (bluestore only).",
201 description
=> "File system type (filestore only).",
203 enum
=> ['xfs', 'ext4'],
208 description
=> "Use bluestore instead of filestore. This is the default.",
215 returns
=> { type
=> 'string' },
219 my $rpcenv = PVE
::RPCEnvironment
::get
();
221 my $authuser = $rpcenv->get_user();
223 raise_param_exc
({ 'bluestore' => "conflicts with parameter 'fstype'" })
224 if (defined($param->{fstype
}) && defined($param->{bluestore
}) && $param->{bluestore
});
226 PVE
::CephTools
::check_ceph_inited
();
228 PVE
::CephTools
::setup_pve_symlinks
();
230 PVE
::CephTools
::check_ceph_installed
('ceph_osd');
232 my $bluestore = $param->{bluestore
} // 1;
237 if ($param->{journal_dev
} && ($param->{journal_dev
} ne $param->{dev
})) {
238 $journal_dev = PVE
::Diskmanage
::verify_blockdev_path
($param->{journal_dev
});
241 if ($param->{wal_dev
} &&
242 ($param->{wal_dev
} ne $param->{dev
}) &&
243 (!$param->{journal_dev
} || $param->{wal_dev
} ne $param->{journal_dev
})) {
244 raise_param_exc
({ 'wal_dev' => "can only be set with paramater 'bluestore'"})
246 $wal_dev = PVE
::Diskmanage
::verify_blockdev_path
($param->{wal_dev
});
249 $param->{dev
} = PVE
::Diskmanage
::verify_blockdev_path
($param->{dev
});
251 my $devname = $param->{dev
};
252 $devname =~ s
|/dev/||;
254 my $disklist = PVE
::Diskmanage
::get_disks
($devname, 1);
256 my $diskinfo = $disklist->{$devname};
257 die "unable to get device info for '$devname'\n"
260 die "device '$param->{dev}' is in use\n"
261 if $diskinfo->{used
};
263 my $devpath = $diskinfo->{devpath
};
264 my $rados = PVE
::RADOS-
>new();
265 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
266 die "unable to get fsid\n" if !$monstat->{monmap
} || !$monstat->{monmap
}->{fsid
};
268 my $fsid = $monstat->{monmap
}->{fsid
};
269 $fsid = $1 if $fsid =~ m/^([0-9a-f\-]+)$/;
271 my $ceph_bootstrap_osd_keyring = PVE
::CephTools
::get_config
('ceph_bootstrap_osd_keyring');
273 if (! -f
$ceph_bootstrap_osd_keyring) {
274 my $bindata = $rados->mon_command({ prefix
=> 'auth get', entity
=> 'client.bootstrap-osd', format
=> 'plain' });
275 file_set_contents
($ceph_bootstrap_osd_keyring, $bindata);
281 my $fstype = $param->{fstype
} || 'xfs';
284 my $ccname = PVE
::CephTools
::get_config
('ccname');
286 my $cmd = ['ceph-disk', 'prepare', '--zap-disk',
287 '--cluster', $ccname, '--cluster-uuid', $fsid ];
290 print "create OSD on $devpath (bluestore)\n";
291 push @$cmd, '--bluestore';
294 print "using device '$journal_dev' for block.db\n";
295 push @$cmd, '--block.db', $journal_dev;
299 print "using device '$wal_dev' for block.wal\n";
300 push @$cmd, '--block.wal', $wal_dev;
303 push @$cmd, $devpath;
305 print "create OSD on $devpath ($fstype)\n";
306 push @$cmd, '--filestore', '--fs-type', $fstype;
308 print "using device '$journal_dev' for journal\n";
309 push @$cmd, '--journal-dev', $devpath, $journal_dev;
311 push @$cmd, $devpath;
319 return $rpcenv->fork_worker('cephcreateosd', $devname, $authuser, $worker);
322 __PACKAGE__-
>register_method ({
323 name
=> 'destroyosd',
326 description
=> "Destroy OSD",
330 additionalProperties
=> 0,
332 node
=> get_standard_option
('pve-node'),
334 description
=> 'OSD ID',
338 description
=> "If set, we remove partition table entries.",
345 returns
=> { type
=> 'string' },
349 my $rpcenv = PVE
::RPCEnvironment
::get
();
351 my $authuser = $rpcenv->get_user();
353 PVE
::CephTools
::check_ceph_inited
();
355 my $osdid = $param->{osdid
};
357 my $rados = PVE
::RADOS-
>new();
358 my $osdstat = &$get_osd_status($rados, $osdid);
360 die "osd is in use (in == 1)\n" if $osdstat->{in};
361 #&$run_ceph_cmd(['osd', 'out', $osdid]);
363 die "osd is still runnung (up == 1)\n" if $osdstat->{up
};
365 my $osdsection = "osd.$osdid";
370 # reopen with longer timeout
371 $rados = PVE
::RADOS-
>new(timeout
=> PVE
::CephTools
::get_config
('long_rados_timeout'));
373 print "destroy OSD $osdsection\n";
376 PVE
::CephTools
::ceph_service_cmd
('stop', $osdsection);
377 PVE
::CephTools
::ceph_service_cmd
('disable', $osdsection);
381 print "Remove $osdsection from the CRUSH map\n";
382 $rados->mon_command({ prefix
=> "osd crush remove", name
=> $osdsection, format
=> 'plain' });
384 print "Remove the $osdsection authentication key.\n";
385 $rados->mon_command({ prefix
=> "auth del", entity
=> $osdsection, format
=> 'plain' });
387 print "Remove OSD $osdsection\n";
388 $rados->mon_command({ prefix
=> "osd rm", ids
=> [ $osdsection ], format
=> 'plain' });
390 # try to unmount from standard mount point
391 my $mountpoint = "/var/lib/ceph/osd/ceph-$osdid";
393 my $disks_to_wipe = {};
394 my $remove_partition = sub {
397 return if !$part || (! -b
$part );
398 my $partnum = PVE
::Diskmanage
::get_partnum
($part);
399 my $devpath = PVE
::Diskmanage
::get_blockdev
($part);
401 print "remove partition $part (disk '${devpath}', partnum $partnum)\n";
402 eval { run_command
(['/sbin/sgdisk', '-d', $partnum, "${devpath}"]); };
405 $disks_to_wipe->{$devpath} = 1;
408 my $partitions_to_remove = [];
410 if ($param->{cleanup
}) {
411 if (my $fd = IO
::File-
>new("/proc/mounts", "r")) {
412 while (defined(my $line = <$fd>)) {
413 my ($dev, $path, $fstype) = split(/\s+/, $line);
414 next if !($dev && $path && $fstype);
415 next if $dev !~ m
|^/dev/|;
416 if ($path eq $mountpoint) {
417 my $data_part = abs_path
($dev);
418 push @$partitions_to_remove, $data_part;
425 foreach my $path (qw(journal block block.db block.wal)) {
426 my $part = abs_path
("$mountpoint/$path");
428 push @$partitions_to_remove, $part;
433 print "Unmount OSD $osdsection from $mountpoint\n";
434 eval { run_command
(['/bin/umount', $mountpoint]); };
437 } elsif ($param->{cleanup
}) {
438 #be aware of the ceph udev rules which can remount.
439 foreach my $part (@$partitions_to_remove) {
440 $remove_partition->($part);
442 my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M count=200 conv=fdatasync);
443 foreach my $devpath (keys %$disks_to_wipe) {
444 print "wipe disk: $devpath\n";
445 eval { run_command
([@wipe_cmd, "of=${devpath}"]) };
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
::CephTools
::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
::CephTools
::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
;
543 use PVE
::JSONSchema
qw(get_standard_option);
546 use PVE
::RESTHandler
;
547 use PVE
::RPCEnvironment
;
549 use PVE
::Tools
qw(run_command file_get_contents file_set_contents);
551 use PVE
::API2
::Ceph
::FS
;
552 use PVE
::API2
::Ceph
::MDS
;
553 use PVE
::API2
::Storage
::Config
;
555 use base
qw(PVE::RESTHandler);
557 my $pve_osd_default_journal_size = 1024*5;
559 __PACKAGE__-
>register_method ({
560 subclass
=> "PVE::API2::CephOSD",
564 __PACKAGE__-
>register_method ({
565 subclass
=> "PVE::API2::Ceph::MDS",
569 __PACKAGE__-
>register_method ({
570 subclass
=> "PVE::API2::Ceph::FS",
574 __PACKAGE__-
>register_method ({
578 description
=> "Directory index.",
579 permissions
=> { user
=> 'all' },
581 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
584 additionalProperties
=> 0,
586 node
=> get_standard_option
('pve-node'),
595 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
609 { name
=> 'status' },
611 { name
=> 'config' },
621 __PACKAGE__-
>register_method ({
625 description
=> "List local disks.",
629 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
632 additionalProperties
=> 0,
634 node
=> get_standard_option
('pve-node'),
636 description
=> "Only list specific types of disks.",
638 enum
=> ['unused', 'journal_disks'],
648 dev
=> { type
=> 'string' },
649 used
=> { type
=> 'string', optional
=> 1 },
650 gpt
=> { type
=> 'boolean' },
651 size
=> { type
=> 'integer' },
652 osdid
=> { type
=> 'integer' },
653 vendor
=> { type
=> 'string', optional
=> 1 },
654 model
=> { type
=> 'string', optional
=> 1 },
655 serial
=> { type
=> 'string', optional
=> 1 },
658 # links => [ { rel => 'child', href => "{}" } ],
663 PVE
::CephTools
::check_ceph_inited
();
665 my $disks = PVE
::Diskmanage
::get_disks
(undef, 1);
668 foreach my $dev (keys %$disks) {
669 my $d = $disks->{$dev};
670 if ($param->{type
}) {
671 if ($param->{type
} eq 'journal_disks') {
672 next if $d->{osdid
} >= 0;
674 } elsif ($param->{type
} eq 'unused') {
677 die "internal error"; # should not happen
681 $d->{dev
} = "/dev/$dev";
688 __PACKAGE__-
>register_method ({
693 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
695 description
=> "Get Ceph configuration.",
697 additionalProperties
=> 0,
699 node
=> get_standard_option
('pve-node'),
702 returns
=> { type
=> 'string' },
706 PVE
::CephTools
::check_ceph_inited
();
708 my $path = PVE
::CephTools
::get_config
('pve_ceph_cfgpath');
709 return file_get_contents
($path);
713 my $add_storage = sub {
714 my ($pool, $storeid) = @_;
716 my $storage_params = {
721 content
=> 'rootdir,images',
724 PVE
::API2
::Storage
::Config-
>create($storage_params);
727 my $get_storages = sub {
730 my $cfg = PVE
::Storage
::config
();
732 my $storages = $cfg->{ids
};
734 foreach my $storeid (keys %$storages) {
735 my $curr = $storages->{$storeid};
736 $res->{$storeid} = $storages->{$storeid}
737 if $curr->{type
} eq 'rbd' && $pool eq $curr->{pool
};
743 __PACKAGE__-
>register_method ({
747 description
=> "Get Ceph monitor list.",
751 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
754 additionalProperties
=> 0,
756 node
=> get_standard_option
('pve-node'),
764 name
=> { type
=> 'string' },
765 addr
=> { type
=> 'string' },
768 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
773 PVE
::CephTools
::check_ceph_inited
();
777 my $cfg = PVE
::CephTools
::parse_ceph_config
();
780 foreach my $section (keys %$cfg) {
781 my $d = $cfg->{$section};
782 if ($section =~ m/^mon\.(\S+)$/) {
784 if ($d->{'mon addr'} && $d->{'host'}) {
785 $monhash->{$monid} = {
786 addr
=> $d->{'mon addr'},
787 host
=> $d->{'host'},
795 my $rados = PVE
::RADOS-
>new();
796 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
797 my $mons = $monstat->{monmap
}->{mons
};
798 foreach my $d (@$mons) {
799 next if !defined($d->{name
});
800 $monhash->{$d->{name
}}->{rank
} = $d->{rank
};
801 $monhash->{$d->{name
}}->{addr
} = $d->{addr
};
802 if (grep { $_ eq $d->{rank
} } @{$monstat->{quorum
}}) {
803 $monhash->{$d->{name
}}->{quorum
} = 1;
809 return PVE
::RESTHandler
::hash_to_array
($monhash, 'name');
812 __PACKAGE__-
>register_method ({
816 description
=> "Create initial ceph default configuration and setup symlinks.",
820 check
=> ['perm', '/', [ 'Sys.Modify' ]],
823 additionalProperties
=> 0,
825 node
=> get_standard_option
('pve-node'),
827 description
=> "Use specific network for all ceph related traffic",
828 type
=> 'string', format
=> 'CIDR',
832 'cluster-network' => {
833 description
=> "Declare a separate cluster network, OSDs will route" .
834 "heartbeat, object replication and recovery traffic over it",
835 type
=> 'string', format
=> 'CIDR',
836 requires
=> 'network',
841 description
=> 'Targeted number of replicas per object',
849 description
=> 'Minimum number of available replicas per object to allow I/O',
857 description
=> "Placement group bits, used to specify the " .
858 "default number of placement groups.\n\nNOTE: 'osd pool " .
859 "default pg num' does not work for default pools.",
867 description
=> "Disable cephx authentification.\n\n" .
868 "WARNING: cephx is a security feature protecting against " .
869 "man-in-the-middle attacks. Only consider disabling cephx ".
870 "if your network is private!",
877 returns
=> { type
=> 'null' },
881 my $version = PVE
::CephTools
::get_local_version
(1);
883 if (!$version || $version < 12) {
884 die "Ceph Luminous required - please run 'pveceph install'\n";
886 PVE
::CephTools
::check_ceph_installed
('ceph_bin');
889 # simply load old config if it already exists
890 my $cfg = PVE
::CephTools
::parse_ceph_config
();
892 if (!$cfg->{global
}) {
897 UUID
::generate
($uuid);
898 UUID
::unparse
($uuid, $fsid);
900 my $auth = $param->{disable_cephx
} ?
'none' : 'cephx';
904 'auth cluster required' => $auth,
905 'auth service required' => $auth,
906 'auth client required' => $auth,
907 'osd journal size' => $pve_osd_default_journal_size,
908 'osd pool default size' => $param->{size
} // 3,
909 'osd pool default min size' => $param->{min_size
} // 2,
910 'mon allow pool delete' => 'true',
913 # this does not work for default pools
914 #'osd pool default pg num' => $pg_num,
915 #'osd pool default pgp num' => $pg_num,
918 $cfg->{global
}->{keyring
} = '/etc/pve/priv/$cluster.$name.keyring';
919 $cfg->{osd
}->{keyring
} = '/var/lib/ceph/osd/ceph-$id/keyring';
921 if ($param->{pg_bits
}) {
922 $cfg->{global
}->{'osd pg bits'} = $param->{pg_bits
};
923 $cfg->{global
}->{'osd pgp bits'} = $param->{pg_bits
};
926 if ($param->{network
}) {
927 $cfg->{global
}->{'public network'} = $param->{network
};
928 $cfg->{global
}->{'cluster network'} = $param->{network
};
931 if ($param->{'cluster-network'}) {
932 $cfg->{global
}->{'cluster network'} = $param->{'cluster-network'};
935 PVE
::CephTools
::write_ceph_config
($cfg);
937 PVE
::CephTools
::setup_pve_symlinks
();
942 my $find_mon_ip = sub {
943 my ($pubnet, $node, $overwrite_ip) = @_;
946 return $overwrite_ip // PVE
::Cluster
::remote_node_ip
($node);
949 my $allowed_ips = PVE
::Network
::get_local_ip_from_cidr
($pubnet);
950 die "No IP configured and up from ceph public network '$pubnet'\n"
951 if scalar(@$allowed_ips) < 1;
953 if (!$overwrite_ip) {
954 if (scalar(@$allowed_ips) == 1) {
955 return $allowed_ips->[0];
957 die "Multiple IPs for ceph public network '$pubnet' detected on $node:\n".
958 join("\n", @$allowed_ips) ."\nuse 'mon-address' to specify one of them.\n";
960 if (grep { $_ eq $overwrite_ip } @$allowed_ips) {
961 return $overwrite_ip;
963 die "Monitor IP '$overwrite_ip' not in ceph public network '$pubnet'\n"
964 if !PVE
::Network
::is_ip_in_cidr
($overwrite_ip, $pubnet);
966 die "Specified monitor IP '$overwrite_ip' not configured or up on $node!\n";
970 my $create_mgr = sub {
971 my ($rados, $id) = @_;
973 my $clustername = PVE
::CephTools
::get_config
('ccname');
974 my $mgrdir = "/var/lib/ceph/mgr/$clustername-$id";
975 my $mgrkeyring = "$mgrdir/keyring";
976 my $mgrname = "mgr.$id";
978 die "ceph manager directory '$mgrdir' already exists\n"
981 print "creating manager directory '$mgrdir'\n";
983 print "creating keys for '$mgrname'\n";
984 my $output = $rados->mon_command({ prefix
=> 'auth get-or-create',
987 mon
=> 'allow profile mgr',
992 file_set_contents
($mgrkeyring, $output);
994 print "setting owner for directory\n";
995 run_command
(["chown", 'ceph:ceph', '-R', $mgrdir]);
997 print "enabling service 'ceph-mgr\@$id.service'\n";
998 PVE
::CephTools
::ceph_service_cmd
('enable', $mgrname);
999 print "starting service 'ceph-mgr\@$id.service'\n";
1000 PVE
::CephTools
::ceph_service_cmd
('start', $mgrname);
1003 my $destroy_mgr = sub {
1006 my $clustername = PVE
::CephTools
::get_config
('ccname');
1007 my $mgrname = "mgr.$mgrid";
1008 my $mgrdir = "/var/lib/ceph/mgr/$clustername-$mgrid";
1010 die "ceph manager directory '$mgrdir' not found\n"
1013 print "disabling service 'ceph-mgr\@$mgrid.service'\n";
1014 PVE
::CephTools
::ceph_service_cmd
('disable', $mgrname);
1015 print "stopping service 'ceph-mgr\@$mgrid.service'\n";
1016 PVE
::CephTools
::ceph_service_cmd
('stop', $mgrname);
1018 print "removing manager directory '$mgrdir'\n";
1019 File
::Path
::remove_tree
($mgrdir);
1022 __PACKAGE__-
>register_method ({
1023 name
=> 'createmon',
1026 description
=> "Create Ceph Monitor and Manager",
1030 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1033 additionalProperties
=> 0,
1035 node
=> get_standard_option
('pve-node'),
1039 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1040 description
=> "The ID for the monitor, when omitted the same as the nodename",
1042 'exclude-manager' => {
1046 description
=> "When set, only a monitor will be created.",
1049 description
=> 'Overwrites autodetected monitor IP address. ' .
1050 'Must be in the public network of ceph.',
1051 type
=> 'string', format
=> 'ip',
1056 returns
=> { type
=> 'string' },
1060 PVE
::CephTools
::check_ceph_installed
('ceph_mon');
1062 PVE
::CephTools
::check_ceph_installed
('ceph_mgr')
1063 if (!$param->{'exclude-manager'});
1065 PVE
::CephTools
::check_ceph_inited
();
1067 PVE
::CephTools
::setup_pve_symlinks
();
1069 my $rpcenv = PVE
::RPCEnvironment
::get
();
1071 my $authuser = $rpcenv->get_user();
1073 my $cfg = PVE
::CephTools
::parse_ceph_config
();
1077 my $monaddrhash = {};
1079 my $systemd_managed = PVE
::CephTools
::systemd_managed
();
1081 foreach my $section (keys %$cfg) {
1082 next if $section eq 'global';
1083 my $d = $cfg->{$section};
1084 if ($section =~ m/^mon\./) {
1086 if ($d->{'mon addr'}) {
1087 $monaddrhash->{$d->{'mon addr'}} = $section;
1092 my $monid = $param->{id
} // $param->{node
};
1094 my $monsection = "mon.$monid";
1095 my $pubnet = $cfg->{global
}->{'public network'};
1096 my $ip = $find_mon_ip->($pubnet, $param->{node
}, $param->{'mon-address'});
1098 my $monaddr = Net
::IP
::ip_is_ipv6
($ip) ?
"[$ip]:6789" : "$ip:6789";
1099 my $monname = $param->{node
};
1101 die "monitor '$monsection' already exists\n" if $cfg->{$monsection};
1102 die "monitor address '$monaddr' already in use by '$monaddrhash->{$monaddr}'\n"
1103 if $monaddrhash->{$monaddr};
1108 my $pve_ckeyring_path = PVE
::CephTools
::get_config
('pve_ckeyring_path');
1110 if (! -f
$pve_ckeyring_path) {
1111 run_command
("ceph-authtool $pve_ckeyring_path --create-keyring " .
1112 "--gen-key -n client.admin");
1115 my $pve_mon_key_path = PVE
::CephTools
::get_config
('pve_mon_key_path');
1116 if (! -f
$pve_mon_key_path) {
1117 run_command
("cp $pve_ckeyring_path $pve_mon_key_path.tmp");
1118 run_command
("ceph-authtool $pve_mon_key_path.tmp -n client.admin --set-uid=0 " .
1119 "--cap mds 'allow' " .
1120 "--cap osd 'allow *' " .
1121 "--cap mgr 'allow *' " .
1122 "--cap mon 'allow *'");
1123 run_command
("cp $pve_mon_key_path.tmp /etc/ceph/ceph.client.admin.keyring") if $systemd_managed;
1124 run_command
("chown ceph:ceph /etc/ceph/ceph.client.admin.keyring") if $systemd_managed;
1125 run_command
("ceph-authtool $pve_mon_key_path.tmp --gen-key -n mon. --cap mon 'allow *'");
1126 run_command
("mv $pve_mon_key_path.tmp $pve_mon_key_path");
1129 my $ccname = PVE
::CephTools
::get_config
('ccname');
1131 my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
1132 -d
$mondir && die "monitor filesystem '$mondir' already exist\n";
1134 my $monmap = "/tmp/monmap";
1139 run_command
("chown ceph:ceph $mondir") if $systemd_managed;
1141 if ($moncount > 0) {
1142 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::CephTools
::get_config
('long_rados_timeout'));
1143 my $mapdata = $rados->mon_command({ prefix
=> 'mon getmap', format
=> 'plain' });
1144 file_set_contents
($monmap, $mapdata);
1146 run_command
("monmaptool --create --clobber --add $monid $monaddr --print $monmap");
1149 run_command
("ceph-mon --mkfs -i $monid --monmap $monmap --keyring $pve_mon_key_path");
1150 run_command
("chown ceph:ceph -R $mondir") if $systemd_managed;
1155 File
::Path
::remove_tree
($mondir);
1159 $cfg->{$monsection} = {
1161 'mon addr' => $monaddr,
1164 PVE
::CephTools
::write_ceph_config
($cfg);
1166 my $create_keys_pid = fork();
1167 if (!defined($create_keys_pid)) {
1168 die "Could not spawn ceph-create-keys to create bootstrap keys\n";
1169 } elsif ($create_keys_pid == 0) {
1170 exit PVE
::Tools
::run_command
(['ceph-create-keys', '-i', $monid]);
1172 PVE
::CephTools
::ceph_service_cmd
('start', $monsection);
1174 if ($systemd_managed) {
1175 #to ensure we have the correct startup order.
1176 eval { PVE
::Tools
::run_command
(['/bin/systemctl', 'enable', "ceph-mon\@${monid}.service"]); };
1177 warn "Enable ceph-mon\@${monid}.service manually"if $@;
1179 waitpid($create_keys_pid, 0);
1183 if (!$param->{'exclude-manager'}) {
1184 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::CephTools
::get_config
('long_rados_timeout'));
1185 $create_mgr->($rados, $monid);
1189 return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker);
1192 __PACKAGE__-
>register_method ({
1193 name
=> 'destroymon',
1194 path
=> 'mon/{monid}',
1196 description
=> "Destroy Ceph Monitor and Manager.",
1200 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1203 additionalProperties
=> 0,
1205 node
=> get_standard_option
('pve-node'),
1207 description
=> 'Monitor ID',
1209 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1211 'exclude-manager' => {
1215 description
=> "When set, removes only the monitor, not the manager"
1219 returns
=> { type
=> 'string' },
1223 my $rpcenv = PVE
::RPCEnvironment
::get
();
1225 my $authuser = $rpcenv->get_user();
1227 PVE
::CephTools
::check_ceph_inited
();
1229 my $cfg = PVE
::CephTools
::parse_ceph_config
();
1231 my $monid = $param->{monid
};
1232 my $monsection = "mon.$monid";
1234 my $rados = PVE
::RADOS-
>new();
1235 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
1236 my $monlist = $monstat->{monmap
}->{mons
};
1238 die "no such monitor id '$monid'\n"
1239 if !defined($cfg->{$monsection});
1241 my $ccname = PVE
::CephTools
::get_config
('ccname');
1243 my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
1244 -d
$mondir || die "monitor filesystem '$mondir' does not exist on this node\n";
1246 die "can't remove last monitor\n" if scalar(@$monlist) <= 1;
1251 # reopen with longer timeout
1252 $rados = PVE
::RADOS-
>new(timeout
=> PVE
::CephTools
::get_config
('long_rados_timeout'));
1254 $rados->mon_command({ prefix
=> "mon remove", name
=> $monid, format
=> 'plain' });
1256 eval { PVE
::CephTools
::ceph_service_cmd
('stop', $monsection); };
1259 delete $cfg->{$monsection};
1260 PVE
::CephTools
::write_ceph_config
($cfg);
1261 File
::Path
::remove_tree
($mondir);
1264 if (!$param->{'exclude-manager'}) {
1265 eval { $destroy_mgr->($monid); };
1270 return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);
1273 __PACKAGE__-
>register_method ({
1274 name
=> 'createmgr',
1277 description
=> "Create Ceph Manager",
1281 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1284 additionalProperties
=> 0,
1286 node
=> get_standard_option
('pve-node'),
1290 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1291 description
=> "The ID for the manager, when omitted the same as the nodename",
1295 returns
=> { type
=> 'string' },
1299 PVE
::CephTools
::check_ceph_installed
('ceph_mgr');
1301 PVE
::CephTools
::check_ceph_inited
();
1303 my $rpcenv = PVE
::RPCEnvironment
::get
();
1305 my $authuser = $rpcenv->get_user();
1307 my $mgrid = $param->{id
} // $param->{node
};
1312 my $rados = PVE
::RADOS-
>new(timeout
=> PVE
::CephTools
::get_config
('long_rados_timeout'));
1314 $create_mgr->($rados, $mgrid);
1317 return $rpcenv->fork_worker('cephcreatemgr', "mgr.$mgrid", $authuser, $worker);
1320 __PACKAGE__-
>register_method ({
1321 name
=> 'destroymgr',
1324 description
=> "Destroy Ceph Manager.",
1328 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1331 additionalProperties
=> 0,
1333 node
=> get_standard_option
('pve-node'),
1335 description
=> 'The ID of the manager',
1337 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
1341 returns
=> { type
=> 'string' },
1345 my $rpcenv = PVE
::RPCEnvironment
::get
();
1347 my $authuser = $rpcenv->get_user();
1349 PVE
::CephTools
::check_ceph_inited
();
1351 my $mgrid = $param->{id
};
1356 $destroy_mgr->($mgrid);
1359 return $rpcenv->fork_worker('cephdestroymgr', "mgr.$mgrid", $authuser, $worker);
1362 __PACKAGE__-
>register_method ({
1366 description
=> "Stop ceph services.",
1370 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1373 additionalProperties
=> 0,
1375 node
=> get_standard_option
('pve-node'),
1377 description
=> 'Ceph service name.',
1380 default => 'ceph.target',
1381 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1385 returns
=> { type
=> 'string' },
1389 my $rpcenv = PVE
::RPCEnvironment
::get
();
1391 my $authuser = $rpcenv->get_user();
1393 PVE
::CephTools
::check_ceph_inited
();
1395 my $cfg = PVE
::CephTools
::parse_ceph_config
();
1396 scalar(keys %$cfg) || die "no configuration\n";
1402 if ($param->{service
}) {
1403 push @$cmd, $param->{service
};
1406 PVE
::CephTools
::ceph_service_cmd
(@$cmd);
1409 return $rpcenv->fork_worker('srvstop', $param->{service
} || 'ceph',
1410 $authuser, $worker);
1413 __PACKAGE__-
>register_method ({
1417 description
=> "Start ceph services.",
1421 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1424 additionalProperties
=> 0,
1426 node
=> get_standard_option
('pve-node'),
1428 description
=> 'Ceph service name.',
1431 default => 'ceph.target',
1432 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1436 returns
=> { type
=> 'string' },
1440 my $rpcenv = PVE
::RPCEnvironment
::get
();
1442 my $authuser = $rpcenv->get_user();
1444 PVE
::CephTools
::check_ceph_inited
();
1446 my $cfg = PVE
::CephTools
::parse_ceph_config
();
1447 scalar(keys %$cfg) || die "no configuration\n";
1452 my $cmd = ['start'];
1453 if ($param->{service
}) {
1454 push @$cmd, $param->{service
};
1457 PVE
::CephTools
::ceph_service_cmd
(@$cmd);
1460 return $rpcenv->fork_worker('srvstart', $param->{service
} || 'ceph',
1461 $authuser, $worker);
1464 __PACKAGE__-
>register_method ({
1468 description
=> "Restart ceph services.",
1472 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1475 additionalProperties
=> 0,
1477 node
=> get_standard_option
('pve-node'),
1479 description
=> 'Ceph service name.',
1482 default => 'ceph.target',
1483 pattern
=> '(mon|mds|osd|mgr)\.[A-Za-z0-9\-]{1,32}',
1487 returns
=> { type
=> 'string' },
1491 my $rpcenv = PVE
::RPCEnvironment
::get
();
1493 my $authuser = $rpcenv->get_user();
1495 PVE
::CephTools
::check_ceph_inited
();
1497 my $cfg = PVE
::CephTools
::parse_ceph_config
();
1498 scalar(keys %$cfg) || die "no configuration\n";
1503 my $cmd = ['restart'];
1504 if ($param->{service
}) {
1505 push @$cmd, $param->{service
};
1508 PVE
::CephTools
::ceph_service_cmd
(@$cmd);
1511 return $rpcenv->fork_worker('srvrestart', $param->{service
} || 'ceph',
1512 $authuser, $worker);
1515 __PACKAGE__-
>register_method ({
1519 description
=> "Get ceph status.",
1523 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1526 additionalProperties
=> 0,
1528 node
=> get_standard_option
('pve-node'),
1531 returns
=> { type
=> 'object' },
1535 PVE
::CephTools
::check_ceph_enabled
();
1537 my $rados = PVE
::RADOS-
>new();
1538 my $status = $rados->mon_command({ prefix
=> 'status' });
1539 $status->{health
} = $rados->mon_command({ prefix
=> 'health', detail
=> 'detail' });
1543 __PACKAGE__-
>register_method ({
1547 description
=> "List all pools.",
1551 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1554 additionalProperties
=> 0,
1556 node
=> get_standard_option
('pve-node'),
1564 pool
=> { type
=> 'integer' },
1565 pool_name
=> { type
=> 'string' },
1566 size
=> { type
=> 'integer' },
1569 links
=> [ { rel
=> 'child', href
=> "{pool_name}" } ],
1574 PVE
::CephTools
::check_ceph_inited
();
1576 my $rados = PVE
::RADOS-
>new();
1579 my $res = $rados->mon_command({ prefix
=> 'df' });
1581 foreach my $d (@{$res->{pools
}}) {
1582 next if !$d->{stats
};
1583 next if !defined($d->{id
});
1584 $stats->{$d->{id
}} = $d->{stats
};
1587 $res = $rados->mon_command({ prefix
=> 'osd dump' });
1588 my $rulestmp = $rados->mon_command({ prefix
=> 'osd crush rule dump'});
1591 for my $rule (@$rulestmp) {
1592 $rules->{$rule->{rule_id
}} = $rule->{rule_name
};
1596 foreach my $e (@{$res->{pools
}}) {
1598 foreach my $attr (qw(pool pool_name size min_size pg_num crush_rule)) {
1599 $d->{$attr} = $e->{$attr} if defined($e->{$attr});
1602 if (defined($d->{crush_rule
}) && defined($rules->{$d->{crush_rule
}})) {
1603 $d->{crush_rule_name
} = $rules->{$d->{crush_rule
}};
1606 if (my $s = $stats->{$d->{pool
}}) {
1607 $d->{bytes_used
} = $s->{bytes_used
};
1608 $d->{percent_used
} = $s->{percent_used
};
1617 __PACKAGE__-
>register_method ({
1618 name
=> 'createpool',
1621 description
=> "Create POOL",
1625 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1628 additionalProperties
=> 0,
1630 node
=> get_standard_option
('pve-node'),
1632 description
=> "The name of the pool. It must be unique.",
1636 description
=> 'Number of replicas per object',
1644 description
=> 'Minimum number of replicas per object',
1652 description
=> "Number of placement groups.",
1660 description
=> "The rule to use for mapping object placement in the cluster.",
1665 description
=> "The application of the pool, 'rbd' by default.",
1667 enum
=> ['rbd', 'cephfs', 'rgw'],
1671 description
=> "Configure VM and CT storage using the new pool.",
1677 returns
=> { type
=> 'string' },
1681 PVE
::Cluster
::check_cfs_quorum
();
1682 PVE
::CephTools
::check_ceph_inited
();
1684 my $pve_ckeyring_path = PVE
::CephTools
::get_config
('pve_ckeyring_path');
1686 die "not fully configured - missing '$pve_ckeyring_path'\n"
1687 if ! -f
$pve_ckeyring_path;
1689 my $pool = $param->{name
};
1690 my $rpcenv = PVE
::RPCEnvironment
::get
();
1691 my $user = $rpcenv->get_user();
1693 if ($param->{add_storages
}) {
1694 $rpcenv->check($user, '/storage', ['Datastore.Allocate']);
1695 die "pool name contains characters which are illegal for storage naming\n"
1696 if !PVE
::JSONSchema
::parse_storage_id
($pool);
1699 my $pg_num = $param->{pg_num
} || 64;
1700 my $size = $param->{size
} || 3;
1701 my $min_size = $param->{min_size
} || 2;
1702 my $application = $param->{application
} // 'rbd';
1706 PVE
::CephTools
::create_pool
($pool, $param);
1708 if ($param->{add_storages
}) {
1710 eval { $add_storage->($pool, "${pool}"); };
1712 warn "failed to add storage: $@";
1715 die "adding storage for pool '$pool' failed, check log and add manually!\n"
1720 return $rpcenv->fork_worker('cephcreatepool', $pool, $user, $worker);
1723 __PACKAGE__-
>register_method ({
1724 name
=> 'get_flags',
1727 description
=> "get all set ceph flags",
1731 check
=> ['perm', '/', [ 'Sys.Audit' ]],
1734 additionalProperties
=> 0,
1736 node
=> get_standard_option
('pve-node'),
1739 returns
=> { type
=> 'string' },
1743 PVE
::CephTools
::check_ceph_inited
();
1745 my $pve_ckeyring_path = PVE
::CephTools
::get_config
('pve_ckeyring_path');
1747 die "not fully configured - missing '$pve_ckeyring_path'\n"
1748 if ! -f
$pve_ckeyring_path;
1750 my $rados = PVE
::RADOS-
>new();
1752 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
1754 return $stat->{flags
} // '';
1757 __PACKAGE__-
>register_method ({
1759 path
=> 'flags/{flag}',
1761 description
=> "Set a ceph flag",
1765 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1768 additionalProperties
=> 0,
1770 node
=> get_standard_option
('pve-node'),
1772 description
=> 'The ceph flag to set/unset',
1774 enum
=> [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
1778 returns
=> { type
=> 'null' },
1782 PVE
::CephTools
::check_ceph_inited
();
1784 my $pve_ckeyring_path = PVE
::CephTools
::get_config
('pve_ckeyring_path');
1786 die "not fully configured - missing '$pve_ckeyring_path'\n"
1787 if ! -f
$pve_ckeyring_path;
1789 my $set = $param->{set
} // !$param->{unset
};
1790 my $rados = PVE
::RADOS-
>new();
1792 $rados->mon_command({
1793 prefix
=> "osd set",
1794 key
=> $param->{flag
},
1800 __PACKAGE__-
>register_method ({
1801 name
=> 'unset_flag',
1802 path
=> 'flags/{flag}',
1804 description
=> "Unset a ceph flag",
1808 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1811 additionalProperties
=> 0,
1813 node
=> get_standard_option
('pve-node'),
1815 description
=> 'The ceph flag to set/unset',
1817 enum
=> [ 'full', 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill', 'norebalance', 'norecover', 'noscrub', 'nodeep-scrub', 'notieragent'],
1821 returns
=> { type
=> 'null' },
1825 PVE
::CephTools
::check_ceph_inited
();
1827 my $pve_ckeyring_path = PVE
::CephTools
::get_config
('pve_ckeyring_path');
1829 die "not fully configured - missing '$pve_ckeyring_path'\n"
1830 if ! -f
$pve_ckeyring_path;
1832 my $set = $param->{set
} // !$param->{unset
};
1833 my $rados = PVE
::RADOS-
>new();
1835 $rados->mon_command({
1836 prefix
=> "osd unset",
1837 key
=> $param->{flag
},
1843 __PACKAGE__-
>register_method ({
1844 name
=> 'destroypool',
1845 path
=> 'pools/{name}',
1847 description
=> "Destroy pool",
1851 check
=> ['perm', '/', [ 'Sys.Modify' ]],
1854 additionalProperties
=> 0,
1856 node
=> get_standard_option
('pve-node'),
1858 description
=> "The name of the pool. It must be unique.",
1862 description
=> "If true, destroys pool even if in use",
1867 remove_storages
=> {
1868 description
=> "Remove all pveceph-managed storages configured for this pool",
1875 returns
=> { type
=> 'string' },
1879 PVE
::CephTools
::check_ceph_inited
();
1881 my $rpcenv = PVE
::RPCEnvironment
::get
();
1882 my $user = $rpcenv->get_user();
1883 $rpcenv->check($user, '/storage', ['Datastore.Allocate'])
1884 if $param->{remove_storages
};
1886 my $pool = $param->{name
};
1889 my $storages = $get_storages->($pool);
1891 # if not forced, destroy ceph pool only when no
1892 # vm disks are on it anymore
1893 if (!$param->{force
}) {
1894 my $storagecfg = PVE
::Storage
::config
();
1895 foreach my $storeid (keys %$storages) {
1896 my $storage = $storages->{$storeid};
1898 # check if any vm disks are on the pool
1899 print "checking storage '$storeid' for RBD images..\n";
1900 my $res = PVE
::Storage
::vdisk_list
($storagecfg, $storeid);
1901 die "ceph pool '$pool' still in use by storage '$storeid'\n"
1902 if @{$res->{$storeid}} != 0;
1906 PVE
::CephTools
::destroy_pool
($pool);
1908 if ($param->{remove_storages
}) {
1910 foreach my $storeid (keys %$storages) {
1911 # skip external clusters, not managed by pveceph
1912 next if $storages->{$storeid}->{monhost
};
1913 eval { PVE
::API2
::Storage
::Config-
>delete({storage
=> $storeid}) };
1915 warn "failed to remove storage '$storeid': $@\n";
1919 die "failed to remove (some) storages - check log and remove manually!\n"
1923 return $rpcenv->fork_worker('cephdestroypool', $pool, $user, $worker);
1927 __PACKAGE__-
>register_method ({
1931 description
=> "Get OSD crush map",
1935 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
1938 additionalProperties
=> 0,
1940 node
=> get_standard_option
('pve-node'),
1943 returns
=> { type
=> 'string' },
1947 PVE
::CephTools
::check_ceph_inited
();
1949 # this produces JSON (difficult to read for the user)
1950 # my $txt = &$run_ceph_cmd_text(['osd', 'crush', 'dump'], quiet => 1);
1954 my $mapfile = "/var/tmp/ceph-crush.map.$$";
1955 my $mapdata = "/var/tmp/ceph-crush.txt.$$";
1957 my $rados = PVE
::RADOS-
>new();
1960 my $bindata = $rados->mon_command({ prefix
=> 'osd getcrushmap', format
=> 'plain' });
1961 file_set_contents
($mapfile, $bindata);
1962 run_command
(['crushtool', '-d', $mapfile, '-o', $mapdata]);
1963 $txt = file_get_contents
($mapdata);
1975 __PACKAGE__-
>register_method({
1979 description
=> "Read ceph log",
1982 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
1986 additionalProperties
=> 0,
1988 node
=> get_standard_option
('pve-node'),
2007 description
=> "Line number",
2011 description
=> "Line text",
2020 my $rpcenv = PVE
::RPCEnvironment
::get
();
2021 my $user = $rpcenv->get_user();
2022 my $node = $param->{node
};
2024 my $logfile = "/var/log/ceph/ceph.log";
2025 my ($count, $lines) = PVE
::Tools
::dump_logfile
($logfile, $param->{start
}, $param->{limit
});
2027 $rpcenv->set_result_attrib('total', $count);
2032 __PACKAGE__-
>register_method ({
2036 description
=> "List ceph rules.",
2040 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
2043 additionalProperties
=> 0,
2045 node
=> get_standard_option
('pve-node'),
2054 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
2059 PVE
::CephTools
::check_ceph_inited
();
2061 my $rados = PVE
::RADOS-
>new();
2063 my $rules = $rados->mon_command({ prefix
=> 'osd crush rule ls' });
2067 foreach my $rule (@$rules) {
2068 push @$res, { name
=> $rule };