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