]>
git.proxmox.com Git - pve-manager.git/blob - PVE/CLI/pveceph.pm
1 package PVE
::CLI
::pveceph
;
16 use PVE
::RPCEnvironment
;
18 use PVE
::Tools
qw(run_command);
19 use PVE
::JSONSchema
qw(get_standard_option);
21 use PVE
::Ceph
::Services
;
23 use PVE
::API2
::Ceph
::FS
;
24 use PVE
::API2
::Ceph
::MDS
;
25 use PVE
::API2
::Ceph
::MGR
;
26 use PVE
::API2
::Ceph
::MON
;
27 use PVE
::API2
::Ceph
::OSD
;
31 use base
qw(PVE::CLIHandler);
33 my $nodename = PVE
::INotify
::nodename
();
37 my $status = PVE
::Tools
::upid_read_status
($upid);
38 exit($status eq 'OK' ?
0 : -1);
41 sub setup_environment
{
42 PVE
::RPCEnvironment-
>setup_default_cli_env();
45 __PACKAGE__-
>register_method ({
49 description
=> "Destroy ceph related data and configuration files.",
51 additionalProperties
=> 0,
54 description
=> 'Additionally purge Ceph logs, /var/log/ceph.',
59 description
=> 'Additionally purge Ceph crash logs, /var/lib/ceph/crash.',
65 returns
=> { type
=> 'null' },
76 my $rados = PVE
::RADOS-
>new();
77 $pools = PVE
::Ceph
::Tools
::ls_pools
(undef, $rados);
78 $monstat = PVE
::Ceph
::Services
::get_services_info
('mon', undef, $rados);
79 $mdsstat = PVE
::Ceph
::Services
::get_services_info
('mds', undef, $rados);
80 $osdstat = $rados->mon_command({ prefix
=> 'osd metadata' });
82 warn "Error gathering ceph info, already purged? Message: $@" if $@;
84 my $osd = grep { $_->{hostname
} eq $nodename } @$osdstat;
85 my $mds = grep { $mdsstat->{$_}->{host
} eq $nodename } keys %$mdsstat;
86 my $mon = grep { $monstat->{$_}->{host
} eq $nodename } keys %$monstat;
89 $message .= "- remove pools, this will !!DESTROY DATA!!\n" if @$pools;
90 $message .= "- remove active OSD on $nodename\n" if $osd;
91 $message .= "- remove active MDS on $nodename\n" if $mds;
92 $message .= "- remove other MONs, $nodename is not the last MON\n"
93 if scalar(keys %$monstat) > 1 && $mon;
95 # display all steps at once
96 die "Unable to purge Ceph!\n\nTo continue:\n$message" if $message;
98 my $services = PVE
::Ceph
::Services
::get_local_services
();
99 $services->{mon
} = $monstat if $mon;
100 $services->{crash
}->{$nodename} = { direxists
=> 1 } if $param->{crash
};
101 $services->{logs
}->{$nodename} = { direxists
=> 1 } if $param->{logs
};
103 PVE
::Ceph
::Tools
::purge_all_ceph_services
($services);
104 PVE
::Ceph
::Tools
::purge_all_ceph_files
($services);
109 __PACKAGE__-
>register_method ({
113 description
=> "Install ceph related packages.",
115 additionalProperties
=> 0,
119 # for buster, luminous kept for testing/upgrade purposes only! - FIXME: remove with 6.2?
120 enum
=> ['luminous', 'nautilus', 'octopus'],
121 default => 'nautilus',
122 description
=> "Ceph version to install.",
125 'allow-experimental' => {
129 description
=> "Allow experimental versions. Use with care!",
133 returns
=> { type
=> 'null' },
137 my $default_vers = 'nautilus';
138 my $cephver = $param->{version
} || $default_vers;
141 if ($cephver eq 'nautilus') {
142 $repolist = "deb http://download.proxmox.com/debian/ceph-nautilus buster main\n";
143 } elsif ($cephver eq 'luminous') {
144 die "Not allowed to select version '$cephver'\n" if !$param->{'allow-experimental'};
145 $repolist = "deb http://download.proxmox.com/debian/ceph-luminous buster main\n";
146 } elsif ($cephver eq 'octopus') {
147 $repolist = "deb http://download.proxmox.com/debian/ceph-octopus buster main\n";
149 die "not implemented ceph version: $cephver";
151 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list", $repolist);
153 warn "WARNING: installing non-default ceph release '$cephver'!\n\n" if $cephver ne $default_vers;
155 local $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
156 print "update available package list\n";
157 eval { run_command
(['apt-get', '-q', 'update'], outfunc
=> sub {}, errfunc
=> sub { print STDERR
"$_[0]\n" }) };
159 my @apt_install = qw(apt-get --no-install-recommends -o Dpkg::Options::=--force-confnew install --);
160 my @ceph_packages = qw(
168 print "start installation\n";
169 if (system(@apt_install, @ceph_packages) != 0) {
170 die "apt failed during ceph installation ($?)\n";
173 print "\ninstalled ceph $cephver successfully\n";
178 __PACKAGE__-
>register_method ({
182 description
=> "Get Ceph Status.",
184 additionalProperties
=> 0,
186 returns
=> { type
=> 'null' },
188 PVE
::Ceph
::Tools
::check_ceph_inited
();
192 outfunc
=> sub { print "$_[0]\n" },
193 errfunc
=> sub { print STDERR
"$_[0]\n" }
199 init
=> [ 'PVE::API2::Ceph', 'init', [], { node
=> $nodename } ],
201 ls
=> [ 'PVE::API2::Ceph', 'lspools', [], { node
=> $nodename }, sub {
202 my ($data, $schema, $options) = @_;
203 PVE
::CLIFormatter
::print_api_result
($data, $schema,
215 }, $PVE::RESTHandler
::standard_output_options
],
216 create
=> [ 'PVE::API2::Ceph', 'createpool', ['name'], { node
=> $nodename }],
217 destroy
=> [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node
=> $nodename } ],
218 set
=> [ 'PVE::API2::Ceph', 'setpool', ['name'], { node
=> $nodename } ],
220 lspools
=> { alias
=> 'pool ls' },
221 createpool
=> { alias
=> 'pool create' },
222 destroypool
=> { alias
=> 'pool destroy' },
224 create
=> [ 'PVE::API2::Ceph::FS', 'createfs', [], { node
=> $nodename }],
227 create
=> [ 'PVE::API2::Ceph::OSD', 'createosd', ['dev'], { node
=> $nodename }, $upid_exit],
228 destroy
=> [ 'PVE::API2::Ceph::OSD', 'destroyosd', ['osdid'], { node
=> $nodename }, $upid_exit],
230 createosd
=> { alias
=> 'osd create' },
231 destroyosd
=> { alias
=> 'osd destroy' },
233 create
=> [ 'PVE::API2::Ceph::MON', 'createmon', [], { node
=> $nodename }, $upid_exit],
234 destroy
=> [ 'PVE::API2::Ceph::MON', 'destroymon', ['monid'], { node
=> $nodename }, $upid_exit],
236 createmon
=> { alias
=> 'mon create' },
237 destroymon
=> { alias
=> 'mon destroy' },
239 create
=> [ 'PVE::API2::Ceph::MGR', 'createmgr', [], { node
=> $nodename }, $upid_exit],
240 destroy
=> [ 'PVE::API2::Ceph::MGR', 'destroymgr', ['id'], { node
=> $nodename }, $upid_exit],
242 createmgr
=> { alias
=> 'mgr create' },
243 destroymgr
=> { alias
=> 'mgr destroy' },
245 create
=> [ 'PVE::API2::Ceph::MDS', 'createmds', [], { node
=> $nodename }, $upid_exit],
246 destroy
=> [ 'PVE::API2::Ceph::MDS', 'destroymds', ['name'], { node
=> $nodename }, $upid_exit],
248 start
=> [ 'PVE::API2::Ceph', 'start', [], { node
=> $nodename }, $upid_exit],
249 stop
=> [ 'PVE::API2::Ceph', 'stop', [], { node
=> $nodename }, $upid_exit],
250 install
=> [ __PACKAGE__
, 'install', [] ],
251 purge
=> [ __PACKAGE__
, 'purge', [] ],
252 status
=> [ __PACKAGE__
, 'status', []],