-
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 of CLI/RBD clients
Change-Id: Ia196c082e737610f2cea04282674ce5a1408e40a
- Loading branch information
Showing
12 changed files
with
323 additions
and
53 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
backend/common/decapod_common/playbooks/tasks/purge_ceph_client.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,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 |
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_client/config.yaml | ||
include decapod_plugin_playbook_remove_client/playbook.yaml |
Empty file.
15 changes: 15 additions & 0 deletions
15
plugins/playbook/remove_client/decapod_plugin_playbook_remove_client/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. |
23 changes: 23 additions & 0 deletions
23
plugins/playbook/remove_client/decapod_plugin_playbook_remove_client/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,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" |
132 changes: 132 additions & 0 deletions
132
plugins/playbook/remove_client/decapod_plugin_playbook_remove_client/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,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 |
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.