]>
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 if ($cephver eq 'luminous') {
98 PVE
::Tools
::file_set_contents
("/etc/apt/sources.list.d/ceph.list",
99 "deb http://download.proxmox.com/debian/ceph-luminous stretch main\n");
101 die "not implemented ceph version: $cephver";
104 local $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
105 print "update available package list\n";
106 eval { run_command
(['apt-get', '-q', 'update'], outfunc
=> sub {}, errfunc
=> sub { print STDERR
"$_[0]\n" }) };
108 my @apt_install = qw(apt-get --no-install-recommends -o Dpkg::Options::=--force-confnew install --);
109 my @ceph_packages = qw(
117 print "start installation\n";
118 if (system(@apt_install, @ceph_packages) != 0) {
119 die "apt failed during ceph installation ($?)\n";
122 print "\ninstalled ceph $cephver successfully\n";
124 if (! -e
'/etc/systemd/system/ceph.service') {
125 print "\nreplacing ceph init script with own ceph.service\n";
127 run_command
('cp -v /usr/share/doc/pve-manager/examples/ceph.service /etc/systemd/system/ceph.service');
128 run_command
('systemctl daemon-reload');
129 run_command
('systemctl enable ceph.service');
132 warn "WARNING: could not install ceph.service: $@\n";
134 print "installed ceph.service successfully\n";
142 init
=> [ 'PVE::API2::Ceph', 'init', [], { node
=> $nodename } ],
144 ls
=> [ 'PVE::API2::Ceph', 'lspools', [], { node
=> $nodename }, sub {
147 printf("%-20s %10s %10s %10s %10s %20s\n", "Name", "size", "min_size",
148 "pg_num", "%-used", "used");
149 foreach my $p (sort {$a->{pool_name
} cmp $b->{pool_name
}} @$res) {
150 printf("%-20s %10d %10d %10d %10.2f %20d\n", $p->{pool_name
},
151 $p->{size
}, $p->{min_size
}, $p->{pg_num
},
152 $p->{percent_used
}, $p->{bytes_used
});
155 create
=> [ 'PVE::API2::Ceph', 'createpool', ['name'], { node
=> $nodename }],
156 destroy
=> [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node
=> $nodename } ],
158 lspools
=> { alias
=> 'pool ls' },
159 createpool
=> { alias
=> 'pool create' },
160 destroypool
=> { alias
=> 'pool destroy' },
162 create
=> [ 'PVE::API2::Ceph::FS', 'createfs', [], { node
=> $nodename }],
165 create
=> [ 'PVE::API2::Ceph::OSD', 'createosd', ['dev'], { node
=> $nodename }, $upid_exit],
166 destroy
=> [ 'PVE::API2::Ceph::OSD', 'destroyosd', ['osdid'], { node
=> $nodename }, $upid_exit],
168 createosd
=> { alias
=> 'osd create' },
169 destroyosd
=> { alias
=> 'osd destroy' },
171 create
=> [ 'PVE::API2::Ceph::MON', 'createmon', [], { node
=> $nodename }, $upid_exit],
172 destroy
=> [ 'PVE::API2::Ceph::MON', 'destroymon', ['monid'], { node
=> $nodename }, $upid_exit],
174 createmon
=> { alias
=> 'mon create' },
175 destroymon
=> { alias
=> 'mon destroy' },
177 create
=> [ 'PVE::API2::Ceph::MGR', 'createmgr', [], { node
=> $nodename }, $upid_exit],
178 destroy
=> [ 'PVE::API2::Ceph::MGR', 'destroymgr', ['id'], { node
=> $nodename }, $upid_exit],
180 createmgr
=> { alias
=> 'mgr create' },
181 destroymgr
=> { alias
=> 'mgr destroy' },
183 create
=> [ 'PVE::API2::Ceph::MDS', 'createmds', [], { node
=> $nodename }, $upid_exit],
184 destroy
=> [ 'PVE::API2::Ceph::MDS', 'destroymds', ['name'], { node
=> $nodename }, $upid_exit],
186 start
=> [ 'PVE::API2::Ceph', 'start', ['service'], { node
=> $nodename }, $upid_exit],
187 stop
=> [ 'PVE::API2::Ceph', 'stop', ['service'], { node
=> $nodename }, $upid_exit],
188 install
=> [ __PACKAGE__
, 'install', [] ],
189 purge
=> [ __PACKAGE__
, 'purge', [] ],
190 status
=> [ 'PVE::API2::Ceph', 'status', [], { node
=> $nodename }, sub {
192 my $json = JSON-
>new->allow_nonref;
193 print $json->pretty->encode($res) . "\n";