]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Cluster/Ceph.pm
1 package PVE
::API2
::Cluster
::Ceph
;
8 use PVE
::Ceph
::Services
;
11 use PVE
::Exception
qw(raise_param_exc);
12 use PVE
::JSONSchema
qw(get_standard_option);
16 use PVE
::Tools
qw(extract_param);
18 use base
qw(PVE::RESTHandler);
20 __PACKAGE__-
>register_method ({
24 description
=> "Cluster ceph index.",
25 permissions
=> { user
=> 'all' },
27 additionalProperties
=> 0,
36 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
42 { name
=> 'metadata' },
51 __PACKAGE__-
>register_method ({
55 description
=> "Get ceph metadata.",
58 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
61 additionalProperties
=> 0,
64 returns
=> { type
=> 'object' },
68 PVE
::Ceph
::Tools
::check_ceph_inited
();
70 my $rados = PVE
::RADOS-
>new();
73 # FIXME: remove with 7.0 depreacated by structured 'versions'
74 version
=> PVE
::Cluster
::get_node_kv
("ceph-version"),
77 if (defined(my $vers = PVE
::Ceph
::Services
::get_ceph_versions
())) {
81 for my $type ( qw(mon mgr mds) ) {
82 my $typedata = PVE
::Ceph
::Services
::get_cluster_service
($type);
84 for my $host (sort keys %$typedata) {
85 for my $service (sort keys %{$typedata->{$host}}) {
86 $data->{"$service\@$host"} = $typedata->{$host}->{$service};
90 # get data from metadata call and merge 'our' data
91 my $services = $rados->mon_command({ prefix
=> "$type metadata" });
92 for my $service ( @$services ) {
93 my $hostname = $service->{hostname
};
94 next if !defined($hostname); # can happen if node is dead
96 my $servicename = $service->{name
} // $service->{id
};
97 my $id = "$servicename\@$hostname";
99 if ($data->{$id}) { # copy values over to the metadata hash
100 for my $k (keys %{$data->{$id}}) {
101 $service->{$k} = $data->{$id}->{$k};
104 $data->{$id} = $service;
107 $res->{$type} = $data;
110 $res->{osd
} = $rados->mon_command({ prefix
=> "osd metadata" });
116 __PACKAGE__-
>register_method ({
120 description
=> "Get ceph status.",
123 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
126 additionalProperties
=> 0,
129 returns
=> { type
=> 'object' },
133 PVE
::Ceph
::Tools
::check_ceph_inited
();
135 my $rados = PVE
::RADOS-
>new();
136 my $status = $rados->mon_command({ prefix
=> 'status' });
137 $status->{health
} = $rados->mon_command({ prefix
=> 'health', detail
=> 'detail' });
142 my $possible_flags = PVE
::Ceph
::Tools
::get_possible_osd_flags
();
143 my $possible_flags_list = [ sort keys %$possible_flags ];
145 my $get_current_set_flags = sub {
148 $rados //= PVE
::RADOS-
>new();
150 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
151 my $setflags = $stat->{flags
} // '';
152 return { map { $_ => 1 } PVE
::Tools
::split_list
($setflags) };
155 __PACKAGE__-
>register_method ({
156 name
=> 'get_all_flags',
159 description
=> "get the status of all ceph flags",
162 check
=> ['perm', '/', [ 'Sys.Audit' ]],
165 additionalProperties
=> 0,
173 additionalProperties
=> 1,
176 description
=> "Flag name.",
177 type
=> 'string', enum
=> $possible_flags_list,
181 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
186 PVE
::Ceph
::Tools
::check_ceph_configured
();
188 my $setflags = $get_current_set_flags->();
191 foreach my $flag (@$possible_flags_list) {
194 description
=> $possible_flags->{$flag}->{description
},
198 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($flag);
199 if ($setflags->{$realflag}) {
210 __PACKAGE__-
>register_method ({
214 description
=> "Set/Unset multiple ceph flags at once.",
217 check
=> ['perm', '/', [ 'Sys.Modify' ]],
220 additionalProperties
=> 0,
221 properties
=> $possible_flags,
223 returns
=> { type
=> 'string' },
227 my $rpcenv = PVE
::RPCEnvironment
::get
();
228 my $user = $rpcenv->get_user();
229 PVE
::Ceph
::Tools
::check_ceph_configured
();
232 my $rados = PVE
::RADOS-
>new(); # (re-)open for forked worker
234 my $setflags = $get_current_set_flags->($rados);
237 foreach my $flag (@$possible_flags_list) {
238 next if !defined($param->{$flag});
239 my $val = $param->{$flag};
240 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($flag);
242 next if !$val == !$setflags->{$realflag}; # we do not set/unset flags to the same state
244 my $prefix = $val ?
'set' : 'unset';
246 print "$prefix $flag\n";
247 $rados->mon_command({ prefix
=> "osd $prefix", key
=> $flag, });
250 warn "error with $flag: '$err'\n";
256 die "could not set/unset $errors flags\n";
260 return $rpcenv->fork_worker('cephsetflags', undef, $user, $worker);
264 __PACKAGE__-
>register_method ({
266 path
=> 'flags/{flag}',
268 description
=> "Get the status of a specific ceph flag.",
271 check
=> ['perm', '/', [ 'Sys.Audit' ]],
274 additionalProperties
=> 0,
277 description
=> "The name of the flag name to get.",
278 type
=> 'string', enum
=> $possible_flags_list,
288 PVE
::Ceph
::Tools
::check_ceph_configured
();
290 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($param->{flag
});
292 my $setflags = $get_current_set_flags->();
293 if ($setflags->{$realflag}) {
300 __PACKAGE__-
>register_method ({
301 name
=> 'update_flag',
302 path
=> 'flags/{flag}',
304 description
=> "Set or clear (unset) a specific ceph flag",
307 check
=> ['perm', '/', [ 'Sys.Modify' ]],
310 additionalProperties
=> 0,
313 description
=> 'The ceph flag to update',
315 enum
=> $possible_flags_list,
318 description
=> 'The new value of the flag',
323 returns
=> { type
=> 'null' },
327 PVE
::Ceph
::Tools
::check_ceph_configured
();
329 my $cmd = $param->{value
} ?
'set' : 'unset';
331 my $rados = PVE
::RADOS-
>new();
332 $rados->mon_command({
333 prefix
=> "osd $cmd",
334 key
=> $param->{flag
},