-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin for removing metadata server from the host
Change-Id: I04592ceb77cf8758c2edefb8f402b962078359a7
- Loading branch information
Showing
12 changed files
with
332 additions
and
79 deletions.
There are no files selected for viewing
76 changes: 0 additions & 76 deletions
76
backend/common/decapod_common/playbooks/plays/deploy_mds.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include decapod_plugin_playbook_remove_mds/config.yaml | ||
include decapod_plugin_playbook_remove_mds/playbook.yaml |
Empty file.
15 changes: 15 additions & 0 deletions
15
plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
# Copyright (c) 2016 Mirantis Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
74 changes: 74 additions & 0 deletions
74
plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds/playbook.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
# Copyright (c) 2016 Mirantis Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
- include: "{{ decapod_common_playbooks }}/plays/init.yaml" | ||
|
||
|
||
- hosts: mdss_to_remove | ||
become: true | ||
tasks: | ||
- name: get ceph status | ||
command: ceph --cluster {{ cluster | quote }} -s --format json | ||
register: ceph_status | ||
|
||
- name: get ranks of mdss on this host | ||
set_fact: | ||
mds_ranks: "{{ ceph_status.stdout | from_json | json_query(query) }}" | ||
vars: | ||
query: "fsmap.by_rank[?name=='{{ ansible_hostname }}'].rank" | ||
|
||
- name: stop mds on this host | ||
service: | ||
name: "ceph-mds@{{ ansible_hostname }}" | ||
state: stopped | ||
enabled: no | ||
when: mds_ranks | ||
|
||
- name: remove mds rank | ||
command: ceph --cluster {{ cluster | quote }} mds rm {{ item }} | ||
with_items: "{{ mds_ranks }}" | ||
|
||
- name: rmfailed mds | ||
command: > | ||
ceph --cluster {{ cluster | quote }} mds rmfailed {{ item }} | ||
--yes-i-really-mean-it | ||
with_items: "{{ mds_ranks }}" | ||
|
||
- name: remove mds package | ||
apt: | ||
name: ceph-mds | ||
state: absent | ||
|
||
- name: remove mds data | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
with_items: | ||
- /var/lib/ceph/mds | ||
- /var/lib/ceph/bootstrap-mds | ||
|
||
|
||
- hosts: mons | ||
become: true | ||
roles: | ||
- ceph-fetch-keys | ||
|
||
|
||
- hosts: mdss | ||
become: true | ||
roles: | ||
- ceph-mds |
110 changes: 110 additions & 0 deletions
110
plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds/plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2016 Mirantis Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Playbook plugin for Remove metadata server from host.""" | ||
|
||
|
||
from decapod_common import log | ||
from decapod_common import playbook_plugin | ||
from decapod_common.models import cluster_data | ||
from decapod_common.models import server | ||
|
||
|
||
DESCRIPTION = "Remove metadata server from host" | ||
"""Plugin description.""" | ||
|
||
LOG = log.getLogger(__name__) | ||
"""Logger.""" | ||
|
||
|
||
class RemoveMds(playbook_plugin.CephAnsiblePlaybook): | ||
|
||
NAME = "Remove metadata server from host" | ||
DESCRIPTION = DESCRIPTION | ||
PUBLIC = True | ||
REQUIRED_SERVER_LIST = True | ||
SERVER_LIST_POLICY = playbook_plugin.ServerListPolicy.in_this_cluster | ||
|
||
def on_post_execute(self, task, exc_value, exc_type, exc_tb): | ||
super().on_post_execute(task, exc_value, exc_type, exc_tb) | ||
|
||
if exc_value: | ||
LOG.warning("Cannot remove REST API host: %s (%s)", | ||
exc_value, exc_type) | ||
raise exc_value | ||
|
||
playbook_config = self.get_playbook_configuration(task) | ||
config = playbook_config.configuration["inventory"] | ||
cluster = playbook_config.cluster | ||
servers = playbook_config.servers | ||
servers = {srv.ip: srv for srv in servers} | ||
|
||
group_vars = config.pop("mdss_to_remove") | ||
group_servers = [servers[ip] for ip in group_vars] | ||
cluster.remove_servers(group_servers, "mdss") | ||
|
||
if cluster.configuration.changed: | ||
cluster.save() | ||
|
||
def make_playbook_configuration(self, cluster, servers, hints): | ||
data = cluster_data.ClusterData.find_one(cluster.model_id) | ||
global_vars = self.make_global_vars(cluster, data, servers, hints) | ||
inventory = self.make_inventory(cluster, data, servers, hints) | ||
|
||
return global_vars, inventory | ||
|
||
def make_global_vars(self, cluster, data, servers, hints): | ||
result = super().make_global_vars(cluster, servers, hints) | ||
result.update(data.global_vars) | ||
|
||
return result | ||
|
||
def make_inventory(self, cluster, data, servers, hints): | ||
groups = self.get_inventory_groups(cluster, servers, hints) | ||
inventory = {"_meta": {"hostvars": {}}} | ||
|
||
for name, group_servers in groups.items(): | ||
for srv in group_servers: | ||
inventory.setdefault(name, []).append(srv.ip) | ||
|
||
hostvars = inventory["_meta"]["hostvars"].setdefault( | ||
srv.ip, {}) | ||
hostvars.update(data.get_host_vars(srv.ip)) | ||
hostvars["ansible_user"] = srv.username | ||
|
||
return inventory | ||
|
||
def get_inventory_groups(self, cluster, servers, hints): | ||
cluster_servers = server.ServerModel.cluster_servers(cluster.model_id) | ||
cluster_servers = {item._id: item for item in cluster_servers} | ||
|
||
all_mdss = [ | ||
cluster_servers[item["server_id"]] | ||
for item in cluster.configuration.state if item["role"] == "mdss" | ||
] | ||
all_mdss_ips = {srv.ip for srv in all_mdss} | ||
for srv in servers: | ||
all_mdss_ips.discard(srv.ip) | ||
|
||
mons = [ | ||
cluster_servers[item["server_id"]] | ||
for item in cluster.configuration.state if item["role"] == "mons" | ||
] | ||
|
||
return { | ||
"mdss": [srv for srv in all_mdss if srv.ip in all_mdss_ips], | ||
"mons": mons, | ||
"mdss_to_remove": servers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[bdist_wheel] | ||
python-tag = py3 | ||
|
||
[flake8] | ||
exclude = build,dist,docs/conf.py,*.egg-info,.eggs,.cache,.tox | ||
inline-quotes = " | ||
application-import-names = decapod_api,decapod_common,decapod_controller,decapodlib | ||
import-order-style = smarkets | ||
Oops, something went wrong.