]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Ceph/MDS.pm
1 package PVE
::API2
::Ceph
::MDS
;
8 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::RPCEnvironment
;
13 use base
qw(PVE::RESTHandler);
15 __PACKAGE__-
>register_method ({
19 description
=> "MDS directory index.",
21 check
=> ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any
=> 1],
26 additionalProperties
=> 0,
28 node
=> get_standard_option
('pve-node'),
37 description
=> "The name (ID) for the MDS",
49 description
=> 'State of the MDS',
54 description
=> 'If true, the standby MDS is polling the active MDS for faster recovery (hot standby).',
62 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
69 my $cfg = PVE
::CephTools
::parse_ceph_config
();
73 foreach my $section (keys %$cfg) {
74 my $d = $cfg->{$section};
76 if ($section =~ m/^mds\.(\S+)$/) {
78 if (defined($d->{host
})) {
79 $mds_hash->{$mds_id} = {
89 my $mds_state = PVE
::CephTools
::get_cluster_mds_state
();
90 foreach my $name (keys %$mds_state) {
91 my $d = $mds_state->{$name};
92 # just overwrite, this always provides more info
93 $mds_hash->{$name}->{$_} = $d->{$_} for keys %$d;
96 return PVE
::RESTHandler
::hash_to_array
($mds_hash, 'name');
100 __PACKAGE__-
>register_method ({
104 description
=> "Create Ceph Metadata Server (MDS)",
108 check
=> ['perm', '/', [ 'Sys.Modify' ]],
111 additionalProperties
=> 0,
113 node
=> get_standard_option
('pve-node'),
117 default => 'nodename',
118 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
119 description
=> "The ID for the mds, when omitted the same as the nodename",
125 description
=> "Determines whether a ceph-mds daemon should poll and replay the log of an active MDS. ".
126 "Faster switch on MDS failure, but needs more idle resources.",
130 returns
=> { type
=> 'string' },
134 PVE
::CephTools
::check_ceph_installed
('ceph_mds');
136 PVE
::CephTools
::check_ceph_inited
();
138 my $rpcenv = PVE
::RPCEnvironment
::get
();
139 my $authuser = $rpcenv->get_user();
141 my $nodename = $param->{node
};
142 $nodename = INotify
::nodename
() if $nodename eq 'localhost';
144 my $mds_id = $param->{name
} // $nodename;
147 my $timeout = PVE
::CephTools
::get_config
('long_rados_timeout');
148 my $rados = PVE
::RADOS-
>new(timeout
=> $timeout);
150 my $cfg = PVE
::CephTools
::parse_ceph_config
();
152 my $section = "mds.$mds_id";
154 if (defined($cfg->{$section})) {
155 die "MDS '$mds_id' already referenced in ceph config, abort!\n"
158 if (!defined($cfg->{mds
}->{keyring
})) {
159 # $id isn't a perl variable but a ceph metavariable
160 my $keyring = '/var/lib/ceph/mds/ceph-$id/keyring';
162 $cfg->{mds
}->{keyring
} = $keyring;
165 $cfg->{$section}->{host
} = $nodename;
166 $cfg->{$section}->{"mds standby for name"} = 'pve';
168 if ($param->{hotstandby
}) {
169 $cfg->{$section}->{"mds standby replay"} = 'true';
172 PVE
::CephTools
::write_ceph_config
($cfg);
174 eval { PVE
::CephTools
::create_mds
($mds_id, $rados) };
176 # we abort early if the section is defined, so we know that we
177 # wrote it at this point. Do not auto remove the service, could
178 # do real harm for previously manual setup MDS
179 warn "Encountered error, remove '$section' from ceph.conf\n";
180 $cfg = PVE
::CephTools
::parse_ceph_config
();
181 delete $cfg->{$section};
182 PVE
::CephTools
::write_ceph_config
($cfg);
188 return $rpcenv->fork_worker('cephcreatemds', "mds.$mds_id", $authuser, $worker);
192 __PACKAGE__-
>register_method ({
193 name
=> 'destroymds',
196 description
=> "Destroy Ceph Metadata Server",
200 check
=> ['perm', '/', [ 'Sys.Modify' ]],
203 additionalProperties
=> 0,
205 node
=> get_standard_option
('pve-node'),
207 description
=> 'The name (ID) of the mds',
209 pattern
=> '[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?',
213 returns
=> { type
=> 'string' },
217 my $rpcenv = PVE
::RPCEnvironment
::get
();
219 my $authuser = $rpcenv->get_user();
221 PVE
::CephTools
::check_ceph_inited
();
223 my $mds_id = $param->{name
};
226 my $timeout = PVE
::CephTools
::get_config
('long_rados_timeout');
227 my $rados = PVE
::RADOS-
>new(timeout
=> $timeout);
229 my $cfg = PVE
::CephTools
::parse_ceph_config
();
231 if (defined($cfg->{"mds.$mds_id"})) {
232 delete $cfg->{"mds.$mds_id"};
233 PVE
::CephTools
::write_ceph_config
($cfg);
236 PVE
::CephTools
::destroy_mds
($mds_id, $rados);
239 return $rpcenv->fork_worker('cephdestroymds', "mds.$mds_id", $authuser, $worker);