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