]> git.proxmox.com Git - pve-manager.git/blame - bin/pveceph
pveceph: use git.ceph.com for key download url.
[pve-manager.git] / bin / pveceph
CommitLineData
7cce0f3e 1#!/usr/bin/perl -T
39ab3ea6
DM
2
3use strict;
4use warnings;
5use Getopt::Long;
6use Fcntl ':flock';
7use File::Path;
8use IO::File;
9use JSON;
10use Data::Dumper;
872c529b 11use LWP::UserAgent;
39ab3ea6
DM
12
13use PVE::SafeSyslog;
14use PVE::Cluster;
15use PVE::INotify;
16use PVE::RPCEnvironment;
17use PVE::Storage;
18use PVE::Tools qw(run_command);
19use PVE::JSONSchema qw(get_standard_option);
5f41ee67 20use PVE::CephTools;
38db610a 21use PVE::API2::Ceph;
39ab3ea6
DM
22
23use PVE::CLIHandler;
24
25use base qw(PVE::CLIHandler);
26
27$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
28
29initlog ('pveceph');
30
31die "please run as root\n" if $> != 0;
32
33PVE::INotify::inotify_init();
34
35my $rpcenv = PVE::RPCEnvironment->init('cli');
36
37$rpcenv->init_request();
38$rpcenv->set_language($ENV{LANG});
39$rpcenv->set_user('root@pam');
40
68e0c4bd
DM
41my $upid_exit = sub {
42 my $upid = shift;
43 my $status = PVE::Tools::upid_read_status($upid);
44 exit($status eq 'OK' ? 0 : -1);
45};
46
39ab3ea6
DM
47my $nodename = PVE::INotify::nodename();
48
39ab3ea6
DM
49__PACKAGE__->register_method ({
50 name => 'purge',
51 path => 'purge',
52 method => 'POST',
53 description => "Destroy ceph related data and configuration files.",
54 parameters => {
55 additionalProperties => 0,
56 properties => {
57 },
58 },
59 returns => { type => 'null' },
60 code => sub {
61 my ($param) = @_;
62
63 my $monstat;
64
5f41ee67
DM
65 eval {
66 my $rados = PVE::RADOS->new();
67 my $monstat = $rados->mon_command({ prefix => 'mon_status' });
68 };
39ab3ea6
DM
69 my $err = $@;
70
71 die "detected running ceph services- unable to purge data\n"
72 if !$err;
73
74 # fixme: this is dangerous - should we really support this function?
5f41ee67 75 PVE::CephTools::purge_all_ceph_files();
39ab3ea6
DM
76
77 return undef;
78 }});
79
80__PACKAGE__->register_method ({
81 name => 'install',
82 path => 'install',
83 method => 'POST',
84 description => "Install ceph related packages.",
85 parameters => {
86 additionalProperties => 0,
87 properties => {
56c87a6f
DM
88 version => {
89 type => 'string',
845f6216 90 enum => ['dumpling', 'emperor', 'firefly', 'giant', 'hammer'],
56c87a6f
DM
91 optional => 1,
92 }
39ab3ea6
DM
93 },
94 },
95 returns => { type => 'null' },
96 code => sub {
97 my ($param) = @_;
98
43da1fd0 99 my $cephver = $param->{version} || 'firefly';
39ab3ea6
DM
100
101 local $ENV{DEBIAN_FRONTEND} = 'noninteractive';
102
d2ed45a8 103 my $keyurl = "https://git.ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc";
39ab3ea6 104
549e50f5 105 print "download and import ceph repository keys\n";
872c529b
DM
106
107 # Note: wget on Debian wheezy cannot handle new ceph.com certificates, so
108 # we use LWP::UserAgent
109 #system("wget -q -O- '$keyurl'| apt-key add - 2>&1 >/dev/null") == 0 ||
110 #die "unable to download ceph release key\n";
111
112 my $tmp_key_file = "/tmp/ceph-release-keys.asc";
bf394af5 113 my $ua = LWP::UserAgent->new(protocols_allowed => ['http', 'https'], timeout => 30);
872c529b
DM
114 $ua->env_proxy;
115 my $response = $ua->get($keyurl);
116 if ($response->is_success) {
117 my $data = $response->decoded_content;
118 PVE::Tools::file_set_contents($tmp_key_file, $data);
119 } else {
120 die "unable to download ceph release key: " . $response->status_line . "\n";
121 }
122
123 system("apt-key add $tmp_key_file 2>&1 >/dev/null") == 0 ||
39ab3ea6
DM
124 die "unable to download ceph release key\n";
125
872c529b 126 unlink $tmp_key_file;
39ab3ea6
DM
127
128 my $source = "deb http://ceph.com/debian-$cephver wheezy main\n";
129
130 PVE::Tools::file_set_contents("/etc/apt/sources.list.d/ceph.list", $source);
131
132 print "update available package list\n";
133 eval { run_command(['apt-get', '-q', 'update'], outfunc => sub {}, errfunc => sub {}); };
134
135 run_command(['apt-get', '-q', '--assume-yes', '--no-install-recommends',
136 '-o', 'Dpkg::Options::=--force-confnew',
137 'install', '--',
138 'ceph', 'ceph-common', 'gdisk']);
139
140 return undef;
141 }});
142
39ab3ea6 143my $cmddef = {
f016ec96 144 init => [ 'PVE::API2::Ceph', 'init', [], { node => $nodename } ],
b0537f7b
DM
145 lspools => [ 'PVE::API2::Ceph', 'lspools', [], { node => $nodename }, sub {
146 my $res = shift;
147
d54f1126 148 printf("%-20s %10s %10s %20s\n", "Name", "size", "pg_num", "used");
b0537f7b 149 foreach my $p (sort {$a->{pool_name} cmp $b->{pool_name}} @$res) {
d54f1126 150 printf("%-20s %10d %10d %20d\n", $p->{pool_name}, $p->{size}, $p->{pg_num}, $p->{bytes_used});
b0537f7b
DM
151 }
152 }],
153 createpool => [ 'PVE::API2::Ceph', 'createpool', ['name'], { node => $nodename }],
154 destroypool => [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node => $nodename } ],
7d4fc5ef
DM
155 createosd => [ 'PVE::API2::CephOSD', 'createosd', ['dev'], { node => $nodename }, $upid_exit],
156 destroyosd => [ 'PVE::API2::CephOSD', 'destroyosd', ['osdid'], { node => $nodename }, $upid_exit],
52d7be41
DM
157 createmon => [ 'PVE::API2::Ceph', 'createmon', [], { node => $nodename }, $upid_exit],
158 destroymon => [ 'PVE::API2::Ceph', 'destroymon', ['monid'], { node => $nodename }, $upid_exit],
159 start => [ 'PVE::API2::Ceph', 'start', ['service'], { node => $nodename }, $upid_exit],
160 stop => [ 'PVE::API2::Ceph', 'stop', ['service'], { node => $nodename }, $upid_exit],
38db610a 161 install => [ __PACKAGE__, 'install', [] ],
39ab3ea6 162 purge => [ __PACKAGE__, 'purge', [] ],
f016ec96 163 status => [ 'PVE::API2::Ceph', 'status', [], { node => $nodename }, sub {
39ab3ea6
DM
164 my $res = shift;
165 my $json = JSON->new->allow_nonref;
166 print $json->pretty->encode($res) . "\n";
167 }],
168};
169
170my $cmd = shift;
171
172PVE::CLIHandler::handle_cmd($cmddef, "pveceph", $cmd, \@ARGV, undef, $0);
173
174exit 0;
175
176__END__
177
178=head1 NAME
179
180pveceph - tool to manage ceph services on pve nodes
181
182=head1 SYNOPSIS
183
184=include synopsis
185
186=head1 DESCRIPTION
187
188Tool to manage ceph services on pve nodes.
189
190=include pve_copyright