Skip to content

Commit

Permalink
Plugin for removing RBD mirror hosts
Browse files Browse the repository at this point in the history
Change-Id: I88277117f42eef79121ec7c4559bc87556305f0b
  • Loading branch information
9seconds committed Apr 17, 2017
1 parent 4c99cdf commit 8cfb9c6
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# 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 }}/init.yaml"
when: decapod_initialized | default(false) | bool

- name: clean out pool
include: "{{ decapod_common_playbooks }}/tasks/clean_rbdmirror_pool.yaml"
with_items: "{{ rbd_mirrors | unique }}"
loop_control:
loop_var: poolname

- name: Is running by systemd
command: systemctl is-active ceph-rbd-mirror@admin
failed_when: false
register: is_active_in_systemd

- name: stop rbd mirror daemon
service:
name: ceph-rbd-mirror@admin
state: stopped
enabled: no
when: is_active_in_systemd.rc == 0

- name: remove rbd-mirror package
apt:
name: rbd-mirror
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# 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.


- name: find out mirroring data, part 1
command: >
rbd --cluster {{ cluster | quote }} mirror pool
info {{ poolname | quote }}
--format json
register: pool_data

- name: remove peers
command: >
rbd --cluster {{ cluster | quote }} mirror pool
peer remove {{ poolname | quote }} {{ item | quote }}
register: peers_removed
with_items: "{{ pool_data.stdout | from_json | json_query('peers[0].uuid') }}"
when: pool_data.stdout | from_json | json_query('peers[0].uuid') | bool

- name: find out mirroring data, part 2
command: >
rbd --cluster {{ cluster | quote }} mirror pool
info {{ poolname | quote }}
--format json
register: pool_data
when: not(peers_removed | skipped)

- name: disable mirroring if no peers are available
command: >
rbd --cluster {{ cluster | quote }} mirror pool
disable {{ poolname | quote }}
when: not(pool_data.stdout | from_json | json_query('peers[0].uuid') | bool)
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/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
- ./plugins/playbook/remove_rbdmirror/decapod_plugin_playbook_remove_rbdmirror:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rbdmirror:ro
- ./plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_restapi:ro
- ./plugins/playbook/remove_rgw/decapod_plugin_playbook_remove_rgw:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rgw:ro
- ./plugins/playbook/restart_services/decapod_plugin_playbook_restart_services:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_restart_services:ro
Expand Down Expand Up @@ -73,6 +74,7 @@ services:
- ./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
- ./plugins/playbook/remove_rbdmirror/decapod_plugin_playbook_remove_rbdmirror:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rbdmirror:ro
- ./plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_restapi:ro
- ./plugins/playbook/remove_rgw/decapod_plugin_playbook_remove_rgw:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rgw:ro
- ./plugins/playbook/restart_services/decapod_plugin_playbook_restart_services:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_restart_services:ro
Expand Down Expand Up @@ -101,6 +103,7 @@ services:
- ./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
- ./plugins/playbook/remove_rbdmirror/decapod_plugin_playbook_remove_rbdmirror:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rbdmirror:ro
- ./plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_restapi:ro
- ./plugins/playbook/remove_rgw/decapod_plugin_playbook_remove_rgw:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_rgw:ro
- ./plugins/playbook/restart_services/decapod_plugin_playbook_restart_services:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_restart_services:ro
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# Copyright (c) 2017 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.


- name: find out peers for remote cluster
command: >
rbd --cluster {{ cluster | quote }} mirror pool
info {{ poolname | quote }}
--format json
register: pool_info

- name: add cluster peers
command: >
rbd --cluster {{ cluster | quote }} mirror pool
peer add {{ poolname | quote }}
{{
('client.%s@%s' | format(ceph_rbd_mirror_remote_user, clustername))
| quote
}}
when: >
clustername not in
(pool_info.stdout | from_json | json_query("peers[*].cluster_name"))
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
enable {{ item | quote }} pool
with_items: "{{ poolnames }}"

- name: add cluster peers
command: >
rbd --cluster {{ cluster | quote }} mirror pool
peer add {{ item | quote }}
{{ ('%s@%s' | format(ceph_rbd_mirror_remote_user, clustername)) | quote }}
with_items: "{{ poolnames }}"
- include: "{{ playbook_dir }}/tasks/add_peers.yaml"
when: add_peers
with_items: "{{ poolnames }}"
loop_control:
loop_var: poolname
2 changes: 2 additions & 0 deletions plugins/playbook/remove_rbdmirror/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include decapod_plugin_playbook_remove_rbdmirror/config.yaml
include decapod_plugin_playbook_remove_rbdmirror/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,23 @@
---
# 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: rbdmirrors
become: true
tasks:
- include: "{{ decapod_common_playbooks }}/tasks/clean_rbdmirror_host.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- 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 RBD mirror host from cluster."""


import itertools

from decapod_common import log
from decapod_common import playbook_plugin
from decapod_common.models import cluster_data


DESCRIPTION = "Remove RBD mirror host from cluster"
"""Plugin description."""

LOG = log.getLogger(__name__)
"""Logger."""


class RemoveRbdmirror(playbook_plugin.Playbook):

NAME = "Remove RBD mirror host from cluster"
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:
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}
mirror_servers = config.pop("rbdmirrors")
mirror_servers = [servers[ip] for ip in mirror_servers]
cluster.remove_servers(mirror_servers, "rbdmirrors")

if cluster.configuration.changed:
cluster.save()

data = cluster_data.ClusterData.find_one(cluster.model_id)
for srv in mirror_servers:
hostvars = data.get_host_vars(srv.ip)
hostvars.pop("rbd_mirrors", None)
data.host_vars[srv.ip] = hostvars
data.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 get_dynamic_inventory(self):
inventory = super().get_dynamic_inventory()

hostvars = inventory["_meta"]["hostvars"]
for data in hostvars.values():
pools = data.get("rbd_mirrors", {}).values()
pools = itertools.chain.from_iterable(pools)
data["rbd_mirrors"] = sorted(pools)

return inventory

def make_global_vars(self, cluster, data, servers, hints):
return {
"cluster": data.global_vars.get("cluster", cluster.name)
}

def make_inventory(self, cluster, data, servers, hints):
groups = {"rbdmirrors": servers}
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.setdefault("ansible_user", srv.username)

return inventory
9 changes: 9 additions & 0 deletions plugins/playbook/remove_rbdmirror/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
48 changes: 48 additions & 0 deletions plugins/playbook/remove_rbdmirror/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
# -*- 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.
"""Setup script for decapod_plugin_playbook_remove_rbdmirror plugin."""


import setuptools


setuptools.setup(
name="decapod-plugin-playbook-remove-rbdmirror",
description="Remove RBD mirror host from cluster",
version="1.1.0.dev1",
author="Sergey Arkhipov",
author_email="sarkhipov@mirantis.com",
url="https://github.com/Mirantis/ceph-lcm",
packages=setuptools.find_packages(),
entry_points={
"decapod.playbooks": [
"remove_rbdmirror = decapod_plugin_playbook_remove_rbdmirror.plugin:RemoveRbdmirror" # NOQA
]
},
python_requires=">= 3.4",
include_package_data=True,
package_data={
"decapod_plugin_playbook_remove_rbdmirror": [
"config.yaml",
"playbook.yaml"
]
},
install_requires=[
"decapod-common~=1.1.dev1"
],
zip_safe=False
)
3 changes: 3 additions & 0 deletions plugins/playbook/remove_rbdmirror/stdeb.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[DEFAULT]
X-Python3-Version: >= 3.4
Depends3: python3-decapod-common (>= 1.1), python3-decapod-common (<< 1.2)

0 comments on commit 8cfb9c6

Please sign in to comment.