]>
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
::OSD
;
29 use base
qw(PVE::CLIHandler);
31 my $nodename = PVE
::INotify
::nodename
();
35 my $status = PVE
::Tools
::upid_read_status
($upid);
36 exit($status eq 'OK' ?
0 : -1);
39 sub setup_environment
{
40 PVE
::RPCEnvironment-
>setup_default_cli_env();
43 __PACKAGE__-
>register_method ({
47 description
=> "Destroy ceph related data and configuration files.",
49 additionalProperties
=> 0,
53 returns
=> { type
=> 'null' },
60 my $rados = PVE
::RADOS-
>new();
61 my $monstat = $rados->mon_command({ prefix
=> 'mon_status' });
65 die "detected running ceph services- unable to purge data\n"
68 # fixme: this is dangerous - should we really support this function?
69 PVE
::Ceph
::Tools
::purge_all_ceph_files
();
74 __PACKAGE__-
>register_method ({
78 description
=> "Install ceph related packages.",
80 additionalProperties
=> 0,
84 #enum => ['hammer', 'jewel'], # for jessie
85 enum
=> ['luminous',], # for stretch
90 returns
=> { type
=> 'null' },
94 my $cephver = $param->{version
} || 'luminous';
96 local $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
98 if ($cephver eq 'luminous') {
99 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list",
100 "deb http://download.proxmox.com/debian/ceph-luminous stretch main\n");
102 # use fixed devel repo for now, because there is no officila repo for jessie
105 my $keyurl = $devrepo ?
106 "https://git.ceph.com/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc" :
107 "https://git.ceph.com/?p=ceph.git;a=blob_plain;f=keys/release.asc";
109 print "download and import ceph repository keys\n";
111 # Note: wget on Debian wheezy cannot handle new ceph.com certificates, so
112 # we use LWP::UserAgent
113 #system("wget -q -O- '$keyurl'| apt-key add - 2>&1 >/dev/null") == 0 ||
114 #die "unable to download ceph release key\n";
116 my $tmp_key_file = "/tmp/ceph-release-keys.asc";
117 my $ua = LWP
::UserAgent-
>new(protocols_allowed
=> ['http', 'https'], timeout
=> 120);
119 my $response = $ua->get($keyurl);
120 if ($response->is_success) {
121 my $data = $response->decoded_content;
122 PVE
::Tools
::file_set_contents
($tmp_key_file, $data);
124 die "unable to download ceph release key: " . $response->status_line . "\n";
127 system("apt-key add $tmp_key_file 2>&1 >/dev/null") == 0 ||
128 die "unable to download ceph release key\n";
130 unlink $tmp_key_file;
132 my $source = $devrepo ?
133 "deb http://gitbuilder.ceph.com/ceph-deb-jessie-x86_64-basic/ref/$devrepo jessie main\n" :
134 "deb http://download.ceph.com/debian-$cephver jessie main\n";
136 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list", $source);
139 print "update available package list\n";
140 eval { run_command
(['apt-get', '-q', 'update'], outfunc
=> sub {}, errfunc
=> sub {}); };
142 system('apt-get', '--no-install-recommends',
143 '-o', 'Dpkg::Options::=--force-confnew',
145 'ceph', 'ceph-common', 'ceph-mds', 'ceph-fuse', 'gdisk');
147 if (PVE
::Ceph
::Tools
::systemd_managed
() && ! -e
'/etc/systemd/system/ceph.service') {
148 #to disable old SysV init scripts.
149 print "replacing ceph init script with own ceph.service\n";
151 PVE
::Tools
::run_command
('cp -v /usr/share/doc/pve-manager/examples/ceph.service /etc/systemd/system/ceph.service');
152 PVE
::Tools
::run_command
('systemctl daemon-reload');
153 PVE
::Tools
::run_command
('systemctl enable ceph.service');
155 warn "could not install ceph.service\n" if $@;
162 init
=> [ 'PVE::API2::Ceph', 'init', [], { node
=> $nodename } ],
164 ls
=> [ 'PVE::API2::Ceph', 'lspools', [], { node
=> $nodename }, sub {
167 printf("%-20s %10s %10s %10s %10s %20s\n", "Name", "size", "min_size",
168 "pg_num", "%-used", "used");
169 foreach my $p (sort {$a->{pool_name
} cmp $b->{pool_name
}} @$res) {
170 printf("%-20s %10d %10d %10d %10.2f %20d\n", $p->{pool_name
},
171 $p->{size
}, $p->{min_size
}, $p->{pg_num
},
172 $p->{percent_used
}, $p->{bytes_used
});
175 create
=> [ 'PVE::API2::Ceph', 'createpool', ['name'], { node
=> $nodename }],
176 destroy
=> [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node
=> $nodename } ],
178 lspools
=> { alias
=> 'pool ls' },
179 createpool
=> { alias
=> 'pool create' },
180 destroypool
=> { alias
=> 'pool destroy' },
182 create
=> [ 'PVE::API2::Ceph::FS', 'createfs', [], { node
=> $nodename }],
185 create
=> [ 'PVE::API2::Ceph::OSD', 'createosd', ['dev'], { node
=> $nodename }, $upid_exit],
186 destroy
=> [ 'PVE::API2::Ceph::OSD', 'destroyosd', ['osdid'], { node
=> $nodename }, $upid_exit],
188 createosd
=> { alias
=> 'osd create' },
189 destroyosd
=> { alias
=> 'osd destroy' },
191 create
=> [ 'PVE::API2::Ceph', 'createmon', [], { node
=> $nodename }, $upid_exit],
192 destroy
=> [ 'PVE::API2::Ceph', 'destroymon', ['monid'], { node
=> $nodename }, $upid_exit],
194 createmon
=> { alias
=> 'mon create' },
195 destroymon
=> { alias
=> 'mon destroy' },
197 create
=> [ 'PVE::API2::Ceph::MGR', 'createmgr', [], { node
=> $nodename }, $upid_exit],
198 destroy
=> [ 'PVE::API2::Ceph::MGR', 'destroymgr', ['id'], { node
=> $nodename }, $upid_exit],
200 createmgr
=> { alias
=> 'mgr create' },
201 destroymgr
=> { alias
=> 'mgr destroy' },
203 create
=> [ 'PVE::API2::Ceph::MDS', 'createmds', [], { node
=> $nodename }, $upid_exit],
204 destroy
=> [ 'PVE::API2::Ceph::MDS', 'destroymds', ['name'], { node
=> $nodename }, $upid_exit],
206 start
=> [ 'PVE::API2::Ceph', 'start', ['service'], { node
=> $nodename }, $upid_exit],
207 stop
=> [ 'PVE::API2::Ceph', 'stop', ['service'], { node
=> $nodename }, $upid_exit],
208 install
=> [ __PACKAGE__
, 'install', [] ],
209 purge
=> [ __PACKAGE__
, 'purge', [] ],
210 status
=> [ 'PVE::API2::Ceph', 'status', [], { node
=> $nodename }, sub {
212 my $json = JSON-
>new->allow_nonref;
213 print $json->pretty->encode($res) . "\n";