Skip to content

Commit

Permalink
Plugin for removing metadata server from the host
Browse files Browse the repository at this point in the history
Change-Id: I04592ceb77cf8758c2edefb8f402b962078359a7
  • Loading branch information
9seconds committed Apr 28, 2017
1 parent 529b236 commit 258cd2b
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 79 deletions.
76 changes: 0 additions & 76 deletions backend/common/decapod_common/playbooks/plays/deploy_mds.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
- ./plugins/playbook/purge_cluster/decapod_plugin_playbook_purge_cluster:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_cluster:ro
- ./plugins/playbook/purge_telegraf/decapod_plugin_playbook_purge_telegraf:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_telegraf:ro
- ./plugins/playbook/remove_client/decapod_plugin_playbook_remove_client:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_client:ro
- ./plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mds:ro
- ./plugins/playbook/remove_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon:ro
- ./plugins/playbook/remove_nfs/decapod_plugin_playbook_remove_nfs:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_nfs:ro
- ./plugins/playbook/remove_osd/decapod_plugin_playbook_remove_osd:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_osd:ro
Expand Down Expand Up @@ -77,6 +78,7 @@ services:
- ./plugins/playbook/purge_cluster/decapod_plugin_playbook_purge_cluster:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_cluster:ro
- ./plugins/playbook/purge_telegraf/decapod_plugin_playbook_purge_telegraf:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_telegraf:ro
- ./plugins/playbook/remove_client/decapod_plugin_playbook_remove_client:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_client:ro
- ./plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mds:ro
- ./plugins/playbook/remove_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon:ro
- ./plugins/playbook/remove_nfs/decapod_plugin_playbook_remove_nfs:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_nfs:ro
- ./plugins/playbook/remove_osd/decapod_plugin_playbook_remove_osd:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_osd:ro
Expand Down Expand Up @@ -109,6 +111,7 @@ services:
- ./plugins/playbook/purge_cluster/decapod_plugin_playbook_purge_cluster:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_cluster:ro
- ./plugins/playbook/purge_telegraf/decapod_plugin_playbook_purge_telegraf:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_purge_telegraf:ro
- ./plugins/playbook/remove_client/decapod_plugin_playbook_remove_client:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_client:ro
- ./plugins/playbook/remove_mds/decapod_plugin_playbook_remove_mds:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mds:ro
- ./plugins/playbook/remove_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon:ro
- ./plugins/playbook/remove_nfs/decapod_plugin_playbook_remove_nfs:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_nfs:ro
- ./plugins/playbook/remove_osd/decapod_plugin_playbook_remove_osd:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_osd:ro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,61 @@
# limitations under the License.


- include: "{{ decapod_common_playbooks }}/plays/deploy_mds.yaml"
- include: "{{ decapod_common_playbooks }}/plays/add_ceph_ansible_role.yaml"

- hosts: mons
become: true
tasks:
- block:
- name: get default pg_num
command: >
ceph --cluster {{ cluster | quote }} daemon
mon.{{ ansible_hostname }} config get osd_pool_default_pg_num
register: default_pg_num

- name: create filesystem pools
command: >
ceph --cluster {{ cluster | quote }} osd pool create
{{ item | quote }}
{{ (default_pg_num.stdout | from_json).osd_pool_default_pg_num }}
with_items:
- cephfs_data
- cephfs_metadata
changed_when: false

- name: check if ceph filesystem already exists
command: ceph --cluster {{ cluster | quote }} fs get cephfs
register: check_existing_cephfs
changed_when: false
failed_when: false

- name: create ceph filesystem
command: >
ceph --cluster {{ cluster | quote }} fs new
cephfs cephfs_metadata cephfs_data
changed_when: false
when: check_existing_cephfs.rc != 0

- name: allow multimds
command: >
ceph --cluster {{ cluster | quote }} fs set cephfs
allow_multimds true --yes-i-really-mean-it
changed_when: false
when: mds_allow_multimds

- name: set max mds
command: >
ceph --cluster {{ cluster | quote }} fs set cephfs max_mds
{{ mds_max_mds }}
changed_when: false
when:
- mds_allow_multimds
- mds_max_mds
when:
- "{{ (groups.mdss | length) > 0 }}"
- "{{ inventory_hostname == (groups.mons | last) }}"

- hosts: mdss
become: true
roles:
- ceph-mds
12 changes: 10 additions & 2 deletions plugins/playbook/add_mds/decapod_plugin_playbook_add_mds/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,16 @@ def get_inventory_groups(self, cluster, servers, hints):

mons = [
cluster_servers[item["server_id"]]
for item in cluster.configuration.state if item["role"] == "mons"
]
for item in cluster.configuration.state if item["role"] == "mons"]
mdss = [
cluster_servers[item["server_id"]]
for item in cluster.configuration.state if item["role"] == "mdss"]

mdss_ips = {srv.ip for srv in mdss}
for srv in servers:
if srv.ip not in mdss_ips:
mdss_ips.add(srv.ip)
mdss.append(srv)

return {
"mons": mons,
Expand Down
2 changes: 2 additions & 0 deletions plugins/playbook/remove_mds/MANIFEST.in
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.
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.
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
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
}
9 changes: 9 additions & 0 deletions plugins/playbook/remove_mds/setup.cfg
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

0 comments on commit 258cd2b

Please sign in to comment.