]>
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);
22 use PVE
::API2
::Ceph
::FS
;
23 use PVE
::API2
::Ceph
::MDS
;
24 use PVE
::API2
::Ceph
::MGR
;
25 use PVE
::API2
::Ceph
::MON
;
26 use PVE
::API2
::Ceph
::OSD
;
30 use base
qw(PVE::CLIHandler);
32 my $nodename = PVE
::INotify
::nodename
();
36 my $status = PVE
::Tools
::upid_read_status
($upid);
37 exit($status eq 'OK' ?
0 : -1);
40 sub setup_environment
{
41 PVE
::RPCEnvironment-
>setup_default_cli_env();
44 __PACKAGE__-
>register_method ({
48 description
=> "Destroy ceph related data and configuration files.",
50 additionalProperties
=> 0,
54 returns
=> { type
=> 'null' },
61 my $rados = PVE
::RADOS-
>new();
62 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
66 die "detected running ceph services- unable to purge data\n"
69 # fixme: this is dangerous - should we really support this function?
70 PVE
::Ceph
::Tools
::purge_all_ceph_files
();
75 __PACKAGE__-
>register_method ({
79 description
=> "Install ceph related packages.",
81 additionalProperties
=> 0,
85 #enum => ['hammer', 'jewel'], # for jessie
86 enum
=> ['luminous',], # for stretch
91 returns
=> { type
=> 'null' },
95 my $cephver = $param->{version
} || 'luminous';
97 local $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
99 if ($cephver eq 'luminous') {
100 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list",
101 "deb http://download.proxmox.com/debian/ceph-luminous stretch main\n");
103 # use fixed devel repo for now, because there is no officila repo for jessie
106 my $keyurl = $devrepo ?
107 "https://git.ceph.com/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc" :
108 "https://git.ceph.com/?p=ceph.git;a=blob_plain;f=keys/release.asc";
110 print "download and import ceph repository keys\n";
112 # Note: wget on Debian wheezy cannot handle new ceph.com certificates, so
113 # we use LWP::UserAgent
114 #system("wget -q -O- '$keyurl'| apt-key add - 2>&1 >/dev/null") == 0 ||
115 #die "unable to download ceph release key\n";
117 my $tmp_key_file = "/tmp/ceph-release-keys.asc";
118 my $ua = LWP
::UserAgent-
>new(protocols_allowed
=> ['http', 'https'], timeout
=> 120);
120 my $response = $ua->get($keyurl);
121 if ($response->is_success) {
122 my $data = $response->decoded_content;
123 PVE
::Tools
::file_set_contents
($tmp_key_file, $data);
125 die "unable to download ceph release key: " . $response->status_line . "\n";
128 system("apt-key add $tmp_key_file 2>&1 >/dev/null") == 0 ||
129 die "unable to download ceph release key\n";
131 unlink $tmp_key_file;
133 my $source = $devrepo ?
134 "deb http://gitbuilder.ceph.com/ceph-deb-jessie-x86_64-basic/ref/$devrepo jessie main\n" :
135 "deb http://download.ceph.com/debian-$cephver jessie main\n";
137 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list", $source);
140 print "update available package list\n";
141 eval { run_command
(['apt-get', '-q', 'update'], outfunc
=> sub {}, errfunc
=> sub {}); };
143 print "start installation\n";
144 system('apt-get', '--no-install-recommends',
145 '-o', 'Dpkg::Options::=--force-confnew',
147 'ceph', 'ceph-common', 'ceph-mds', 'ceph-fuse', 'gdisk') == 0
148 || die "apt failed during ceph installation ($?)\n";
150 print "\ninstalled ceph $cephver successfully\n";
152 if (PVE
::Ceph
::Tools
::systemd_managed
() && ! -e
'/etc/systemd/system/ceph.service') {
153 #to disable old SysV init scripts.
154 print "\nreplacing ceph init script with own ceph.service\n";
156 PVE
::Tools
::run_command
('cp -v /usr/share/doc/pve-manager/examples/ceph.service /etc/systemd/system/ceph.service');
157 PVE
::Tools
::run_command
('systemctl daemon-reload');
158 PVE
::Tools
::run_command
('systemctl enable ceph.service');
161 warn "WARNING: could not install ceph.service: $@\n";
163 print "installed ceph.service successfully\n";
171 init
=> [ 'PVE::API2::Ceph', 'init', [], { node
=> $nodename } ],
173 ls
=> [ 'PVE::API2::Ceph', 'lspools', [], { node
=> $nodename }, sub {
176 printf("%-20s %10s %10s %10s %10s %20s\n", "Name", "size", "min_size",
177 "pg_num", "%-used", "used");
178 foreach my $p (sort {$a->{pool_name
} cmp $b->{pool_name
}} @$res) {
179 printf("%-20s %10d %10d %10d %10.2f %20d\n", $p->{pool_name
},
180 $p->{size
}, $p->{min_size
}, $p->{pg_num
},
181 $p->{percent_used
}, $p->{bytes_used
});
184 create
=> [ 'PVE::API2::Ceph', 'createpool', ['name'], { node
=> $nodename }],
185 destroy
=> [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node
=> $nodename } ],
187 lspools
=> { alias
=> 'pool ls' },
188 createpool
=> { alias
=> 'pool create' },
189 destroypool
=> { alias
=> 'pool destroy' },
191 create
=> [ 'PVE::API2::Ceph::FS', 'createfs', [], { node
=> $nodename }],
194 create
=> [ 'PVE::API2::Ceph::OSD', 'createosd', ['dev'], { node
=> $nodename }, $upid_exit],
195 destroy
=> [ 'PVE::API2::Ceph::OSD', 'destroyosd', ['osdid'], { node
=> $nodename }, $upid_exit],
197 createosd
=> { alias
=> 'osd create' },
198 destroyosd
=> { alias
=> 'osd destroy' },
200 create
=> [ 'PVE::API2::Ceph::MON', 'createmon', [], { node
=> $nodename }, $upid_exit],
201 destroy
=> [ 'PVE::API2::Ceph::MON', 'destroymon', ['monid'], { node
=> $nodename }, $upid_exit],
203 createmon
=> { alias
=> 'mon create' },
204 destroymon
=> { alias
=> 'mon destroy' },
206 create
=> [ 'PVE::API2::Ceph::MGR', 'createmgr', [], { node
=> $nodename }, $upid_exit],
207 destroy
=> [ 'PVE::API2::Ceph::MGR', 'destroymgr', ['id'], { node
=> $nodename }, $upid_exit],
209 createmgr
=> { alias
=> 'mgr create' },
210 destroymgr
=> { alias
=> 'mgr destroy' },
212 create
=> [ 'PVE::API2::Ceph::MDS', 'createmds', [], { node
=> $nodename }, $upid_exit],
213 destroy
=> [ 'PVE::API2::Ceph::MDS', 'destroymds', ['name'], { node
=> $nodename }, $upid_exit],
215 start
=> [ 'PVE::API2::Ceph', 'start', ['service'], { node
=> $nodename }, $upid_exit],
216 stop
=> [ 'PVE::API2::Ceph', 'stop', ['service'], { node
=> $nodename }, $upid_exit],
217 install
=> [ __PACKAGE__
, 'install', [] ],
218 purge
=> [ __PACKAGE__
, 'purge', [] ],
219 status
=> [ 'PVE::API2::Ceph', 'status', [], { node
=> $nodename }, sub {
221 my $json = JSON-
>new->allow_nonref;
222 print $json->pretty->encode($res) . "\n";