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