]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Ceph/MDS.pm
1948969026482a6b92cf741281fd4e83abfd84eb
1 package PVE
::API2
::Ceph
::MDS
;
7 use PVE
::Ceph
::Services
;
8 use PVE
::Cluster
qw(cfs_read_file cfs_write_file);
10 use PVE
::JSONSchema
qw(get_standard_option);
13 use PVE
::RPCEnvironment
;
15 use base
qw(PVE::RESTHandler);
17 __PACKAGE__-
>register_method ({
21 description
=> "MDS directory index.",
23 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
28 additionalProperties
=> 0,
30 node
=> get_standard_option
('pve-node'),
39 description
=> "The name (ID) for the MDS",
51 description
=> 'State of the MDS',
56 description
=> 'If true, the standby MDS is polling the active MDS for faster recovery (hot standby).',
64 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
69 PVE
::Ceph
::Tools
::check_ceph_inited
();
73 my $cfg = cfs_read_file
('ceph.conf');
77 foreach my $section (keys %$cfg) {
78 my $d = $cfg->{$section};
80 if ($section =~ m/^mds\.(\S+)$/) {
82 if (defined($d->{host
})) {
83 $mds_hash->{$mds_id} = {
93 my $mds_state = PVE
::Ceph
::Services
::get_cluster_mds_state
();
94 foreach my $name (keys %$mds_state) {
95 my $d = $mds_state->{$name};
96 # just overwrite, this always provides more info
97 $mds_hash->{$name}->{$_} = $d->{$_} for keys %$d;
100 return PVE
::RESTHandler
::hash_to_array
($mds_hash, 'name');
104 __PACKAGE__-
>register_method ({
108 description
=> "Create Ceph Metadata Server (MDS)",
112 check
=> ['perm', '/', [ 'Sys.Modify' ]],
115 additionalProperties
=> 0,
117 node
=> get_standard_option
('pve-node'),
121 default => 'nodename',
122 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
123 description
=> "The ID for the mds, when omitted the same as the nodename",
129 description
=> "Determines whether a ceph-mds daemon should poll and replay the log of an active MDS. ".
130 "Faster switch on MDS failure, but needs more idle resources.",
134 returns
=> { type
=> 'string' },
138 PVE
::Ceph
::Tools
::check_ceph_installed
('ceph_mds');
140 PVE
::Ceph
::Tools
::check_ceph_inited
();
142 my $rpcenv = PVE
::RPCEnvironment
::get
();
143 my $authuser = $rpcenv->get_user();
145 my $nodename = $param->{node
};
146 $nodename = INotify
::nodename
() if $nodename eq 'localhost';
148 my $mds_id = $param->{name
} // $nodename;
151 my $timeout = PVE
::Ceph
::Tools
::get_config
('long_rados_timeout');
152 my $rados = PVE
::RADOS-
>new(timeout
=> $timeout);
154 my $cfg = cfs_read_file
('ceph.conf');
156 my $section = "mds.$mds_id";
158 if (defined($cfg->{$section})) {
159 die "MDS '$mds_id' already referenced in ceph config, abort!\n"
162 if (!defined($cfg->{mds
}->{keyring
})) {
163 # $id isn't a perl variable but a ceph metavariable
164 my $keyring = '/var/lib/ceph/mds/ceph-$id/keyring';
166 $cfg->{mds
}->{keyring
} = $keyring;
169 $cfg->{$section}->{host
} = $nodename;
170 $cfg->{$section}->{"mds standby for name"} = 'pve';
172 if ($param->{hotstandby
}) {
173 $cfg->{$section}->{"mds standby replay"} = 'true';
176 cfs_write_file
('ceph.conf', $cfg);
178 eval { PVE
::Ceph
::Services
::create_mds
($mds_id, $rados) };
180 # we abort early if the section is defined, so we know that we
181 # wrote it at this point. Do not auto remove the service, could
182 # do real harm for previously manual setup MDS
183 warn "Encountered error, remove '$section' from ceph.conf\n";
184 my $cfg = cfs_read_file
('ceph.conf');
185 delete $cfg->{$section};
186 cfs_write_file
('ceph.conf', $cfg);
192 return $rpcenv->fork_worker('cephcreatemds', "mds.$mds_id", $authuser, $worker);
196 __PACKAGE__-
>register_method ({
197 name
=> 'destroymds',
200 description
=> "Destroy Ceph Metadata Server",
204 check
=> ['perm', '/', [ 'Sys.Modify' ]],
207 additionalProperties
=> 0,
209 node
=> get_standard_option
('pve-node'),
211 description
=> 'The name (ID) of the mds',
213 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
217 returns
=> { type
=> 'string' },
221 my $rpcenv = PVE
::RPCEnvironment
::get
();
223 my $authuser = $rpcenv->get_user();
225 PVE
::Ceph
::Tools
::check_ceph_inited
();
227 my $mds_id = $param->{name
};
230 my $timeout = PVE
::Ceph
::Tools
::get_config
('long_rados_timeout');
231 my $rados = PVE
::RADOS-
>new(timeout
=> $timeout);
233 my $cfg = cfs_read_file
('ceph.conf');
235 if (defined($cfg->{"mds.$mds_id"})) {
236 delete $cfg->{"mds.$mds_id"};
237 cfs_write_file
('ceph.conf', $cfg);
240 PVE
::Ceph
::Services
::destroy_mds
($mds_id, $rados);
243 return $rpcenv->fork_worker('cephdestroymds', "mds.$mds_id", $authuser, $worker);