Skip to content

Commit

Permalink
Plugin for removing of CLI/RBD clients
Browse files Browse the repository at this point in the history
Change-Id: Ia196c082e737610f2cea04282674ce5a1408e40a
  • Loading branch information
9seconds committed Apr 20, 2017
1 parent de583b4 commit b08d295
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
# 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.

# Mandatory parameters to use:
# - purge_only_client - if we run it as a part ot removing 'clients' role.
# - uninstall_packages - if we need to remove packages.
# - apt_purge - if we need not only to remove packages but to purge them
# as well.


- name: fail if node has blocking role
fail:
msg: >
Cannot remove client for {{ inventory_hostname }}
because it is still has role {{ blocked_by }}
when:
- purge_only_client
- blocked_by is defined and blocked_by

- name: uninstall ceph packages
apt:
name: "{{ item }}"
state: absent
purge: "{{ apt_purge | ternary('yes', 'no') }}"
autoremove: "{{ apt_purge | ternary('yes', 'no') }}"
when: uninstall_packages
with_items:
- ceph
- ceph-common
- ceph-fs-common
- ceph-fuse
- ceph-mds
- ceph-release
- ceph-radosgw
- radosgw
- rbd-mirror
- calamari-server

- name: uninstall ceph remaining packages
apt:
name: "{{ item }}"
state: absent
purge: "{{ apt_purge | ternary('yes', 'no') }}"
autoremove: "{{ apt_purge | ternary('yes', 'no') }}"
when: uninstall_packages
with_items:
- libcephfs1
- libcephfs2
- librados2
- libradosstriper1
- librbd1
- python-cephfs
- python-rados
- python-rbd

- name: remove configuration and own files
file:
path: "{{ item }}"
state: absent
with_items:
- /var/lib/ceph
- /etc/ceph
3 changes: 3 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
- ./plugins/playbook/playbook_helloworld/decapod_plugin_playbook_helloworld:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_helloworld:ro
- ./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_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 @@ -73,6 +74,7 @@ services:
- ./plugins/playbook/playbook_helloworld/decapod_plugin_playbook_helloworld:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_helloworld:ro
- ./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_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 @@ -103,6 +105,7 @@ services:
- ./plugins/playbook/playbook_helloworld/decapod_plugin_playbook_helloworld:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_helloworld:ro
- ./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_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 @@ -82,56 +82,21 @@


- name: Remove ceph data
become: true
hosts: all
become: true
vars:
ceph_packages:
- ceph
- ceph-common
- ceph-fs-common
- ceph-fuse
- ceph-mds
- ceph-release
- ceph-radosgw
- radosgw
- rbd-mirror
- calamari-server
ceph_remaining_packages:
- libcephfs1
- libcephfs2
- librados2
- libradosstriper1
- librbd1
- python-cephfs
- python-rados
- python-rbd
purge_only_client: false
uninstall_packages: true
apt_purge: true
tasks:
- name: purge ceph packages
apt:
name: "{{ item }}"
state: absent
purge: yes
autoremove: yes
with_items: "{{ ceph_packages }}"

- name: purge remaining ceph packages with apt
apt:
name: "{{ item }}"
state: absent
purge: yes
autoremove: yes
with_items: "{{ ceph_remaining_packages }}"
- include: "{{ decapod_common_playbooks }}/tasks/purge_ceph_client.yaml"

- name: remove ceph files
file:
path: "{{ item }}"
state: absent
with_items:
- /var/lib/ceph
- /etc/ceph
- /var/log/ceph
- name: Remove Ceph logs
file:
path: /var/log/ceph
state: absent

- name: Remove ceph fact
file:
path: "/etc/ansible/facts.d/ceph_{{ cluster }}.fact"
state: absent
- name: Remove Ceph facts
file:
path: "/etc/ansible/facts.d/ceph_{{ cluster }}.fact"
state: absent
2 changes: 2 additions & 0 deletions plugins/playbook/remove_client/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include decapod_plugin_playbook_remove_client/config.yaml
include decapod_plugin_playbook_remove_client/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) 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.


- hosts: clients
become: true
vars:
purge_only_client: true
tasks:
- include: "{{ decapod_common_playbooks }}/tasks/purge_ceph_client.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# -*- 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_client plugin for Decapod."""


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


DESCRIPTION = "Remove CLI/RBD client from the host"
"""Plugin description."""

HINTS_SCHEMA = {
"uninstall_packages": {
"description": "Remove Ceph packages, not only keys",
"type": "boolean",
"typename": "boolean",
"default_value": True
},
"apt_purge": {
"description": "Purge packages, not only remove them",
"type": "boolean",
"typename": "boolean",
"default_value": True
}
}
"""Schema for playbook hints."""

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

BLOCKED_ROLES = {
"iscsigws",
"mdss",
"mgrs",
"mons",
"nfss",
"osds",
"rbdmirrors",
"restapis",
"rgws"
}
"""Do not execute if server has such role."""


class RemoveClient(playbook_plugin.Playbook):

NAME = DESCRIPTION
DESCRIPTION = DESCRIPTION
PUBLIC = True
REQUIRED_SERVER_LIST = True
SERVER_LIST_POLICY = playbook_plugin.ServerListPolicy.in_this_cluster
HINTS = playbook_plugin_hints.Hints(HINTS_SCHEMA)

def get_dynamic_inventory(self):
servers = {srv._id: srv for srv in self.playbook_config.servers}
inventory = super().get_dynamic_inventory()
hostvars = inventory["_meta"]["hostvars"]

for data in self.playbook_config.cluster.configuration.state:
if data["server_id"] in servers and data["role"] in BLOCKED_ROLES:
srv = servers[data["server_id"]]
hostvars[srv.ip]["blocked_by"] = data["role"]

for values in hostvars.values():
values.setdefault("blocked_by", "")

return inventory

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 client from 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("clients")
group_servers = [servers[ip] for ip in group_vars]
cluster.remove_servers(group_servers, "clients")

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):
return {
"cluster": data.global_vars.get("cluster", cluster.name),
"uninstall_packages": bool(hints["uninstall_packages"]),
"apt_purge": bool(hints["apt_purge"])
}

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

return inventory
9 changes: 9 additions & 0 deletions plugins/playbook/remove_client/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 b08d295

Please sign in to comment.