]>
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,
67 enum
=> ['all', 'versions', ],
71 returns
=> { type
=> 'object' },
75 my $scope = $param->{scope
} // 'all';
78 # FIXME: remove with 7.0 depreacated by structured 'versions'
79 version
=> PVE
::Cluster
::get_node_kv
("ceph-version"),
82 if (defined(my $versions = PVE
::Ceph
::Services
::get_ceph_versions
())) {
83 $res->{node
} = $versions;
86 return $res if ($scope eq 'versions');
88 # only check now, we want to allow calls with scope 'versions' on non-ceph nodes too!
89 PVE
::Ceph
::Tools
::check_ceph_inited
();
90 my $rados = PVE
::RADOS-
>new();
92 for my $type ( qw(mon mgr mds) ) {
93 my $typedata = PVE
::Ceph
::Services
::get_cluster_service
($type);
95 for my $host (sort keys %$typedata) {
96 for my $service (sort keys %{$typedata->{$host}}) {
97 $data->{"$service\@$host"} = $typedata->{$host}->{$service};
101 # get data from metadata call and merge 'our' data
102 my $services = $rados->mon_command({ prefix
=> "$type metadata" });
103 for my $service ( @$services ) {
104 my $hostname = $service->{hostname
};
105 next if !defined($hostname); # can happen if node is dead
107 my $servicename = $service->{name
} // $service->{id
};
108 my $id = "$servicename\@$hostname";
110 if ($data->{$id}) { # copy values over to the metadata hash
111 for my $k (keys %{$data->{$id}}) {
112 $service->{$k} = $data->{$id}->{$k};
115 $data->{$id} = $service;
118 $res->{$type} = $data;
121 $res->{osd
} = $rados->mon_command({ prefix
=> "osd metadata" });
127 __PACKAGE__-
>register_method ({
131 description
=> "Get ceph status.",
134 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
137 additionalProperties
=> 0,
140 returns
=> { type
=> 'object' },
144 PVE
::Ceph
::Tools
::check_ceph_inited
();
146 return PVE
::Ceph
::Tools
::ceph_cluster_status
();
150 my $possible_flags = PVE
::Ceph
::Tools
::get_possible_osd_flags
();
151 my $possible_flags_list = [ sort keys %$possible_flags ];
153 my $get_current_set_flags = sub {
156 $rados //= PVE
::RADOS-
>new();
158 my $stat = $rados->mon_command({ prefix
=> 'osd dump' });
159 my $setflags = $stat->{flags
} // '';
160 return { map { $_ => 1 } PVE
::Tools
::split_list
($setflags) };
163 __PACKAGE__-
>register_method ({
164 name
=> 'get_all_flags',
167 description
=> "get the status of all ceph flags",
170 check
=> ['perm', '/', [ 'Sys.Audit' ]],
173 additionalProperties
=> 0,
181 additionalProperties
=> 1,
184 description
=> "Flag name.",
185 type
=> 'string', enum
=> $possible_flags_list,
189 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
194 PVE
::Ceph
::Tools
::check_ceph_configured
();
196 my $setflags = $get_current_set_flags->();
199 foreach my $flag (@$possible_flags_list) {
202 description
=> $possible_flags->{$flag}->{description
},
206 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($flag);
207 if ($setflags->{$realflag}) {
218 __PACKAGE__-
>register_method ({
222 description
=> "Set/Unset multiple ceph flags at once.",
225 check
=> ['perm', '/', [ 'Sys.Modify' ]],
228 additionalProperties
=> 0,
229 properties
=> $possible_flags,
231 returns
=> { type
=> 'string' },
235 my $rpcenv = PVE
::RPCEnvironment
::get
();
236 my $user = $rpcenv->get_user();
237 PVE
::Ceph
::Tools
::check_ceph_configured
();
240 my $rados = PVE
::RADOS-
>new(); # (re-)open for forked worker
242 my $setflags = $get_current_set_flags->($rados);
245 foreach my $flag (@$possible_flags_list) {
246 next if !defined($param->{$flag});
247 my $val = $param->{$flag};
248 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($flag);
250 next if !$val == !$setflags->{$realflag}; # we do not set/unset flags to the same state
252 my $prefix = $val ?
'set' : 'unset';
254 print "$prefix $flag\n";
255 $rados->mon_command({ prefix
=> "osd $prefix", key
=> $flag, });
258 warn "error with $flag: '$err'\n";
264 die "could not set/unset $errors flags\n";
268 return $rpcenv->fork_worker('cephsetflags', undef, $user, $worker);
272 __PACKAGE__-
>register_method ({
274 path
=> 'flags/{flag}',
276 description
=> "Get the status of a specific ceph flag.",
279 check
=> ['perm', '/', [ 'Sys.Audit' ]],
282 additionalProperties
=> 0,
285 description
=> "The name of the flag name to get.",
286 type
=> 'string', enum
=> $possible_flags_list,
296 PVE
::Ceph
::Tools
::check_ceph_configured
();
298 my $realflag = PVE
::Ceph
::Tools
::get_real_flag_name
($param->{flag
});
300 my $setflags = $get_current_set_flags->();
301 if ($setflags->{$realflag}) {
308 __PACKAGE__-
>register_method ({
309 name
=> 'update_flag',
310 path
=> 'flags/{flag}',
312 description
=> "Set or clear (unset) a specific ceph flag",
315 check
=> ['perm', '/', [ 'Sys.Modify' ]],
318 additionalProperties
=> 0,
321 description
=> 'The ceph flag to update',
323 enum
=> $possible_flags_list,
326 description
=> 'The new value of the flag',
331 returns
=> { type
=> 'null' },
335 PVE
::Ceph
::Tools
::check_ceph_configured
();
337 my $cmd = $param->{value
} ?
'set' : 'unset';
339 my $rados = PVE
::RADOS-
>new();
340 $rados->mon_command({
341 prefix
=> "osd $cmd",
342 key
=> $param->{flag
},