Skip to content

Commit

Permalink
Plugin for removing REST API
Browse files Browse the repository at this point in the history
Change-Id: Id0bba4dfd411b10cad3dcb3806f228757b369531
  • Loading branch information
9seconds committed Apr 7, 2017
1 parent fa111b4 commit 51cfb61
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
# 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: Is running by systemd
command: systemctl is-active ceph-rest-api
failed_when: false
register: is_active_in_systemd

- name: SIGTERM nohupped process
command: pkill -TERM ceph-rest-api
failed_when: false
register: sigterm_result
when: is_active_in_systemd.rc != 0

- name: Wait untill nohupped process is stopped
command: pgrep ceph-rest-api
register: ceph_restapi_pid.rc
until: ceph_restapi_pid.rc != 0
failed_when: false
retries: 10
delay: 2
when: is_active_in_systemd.rc != 0

- name: SIGKILL nohupped process
command: pkill -KILL ceph-rest-api
when: is_active_in_systemd.rc != 0 and ceph_restapi_pid.rc == 0

- name: Stop SystemD unit
service:
name: ceph-rest-api.service
state: stopped
enabled: no

- name: Remove SystemD unit
file:
path: "{{ item }}"
state: absent
with_items:
- /lib/systemd/system/ceph-rest-api.service
- /etc/systemd/system/ceph.target.wants/ceph-rest-api.service

- name: Remove Rest API directory
file:
path: /var/lib/ceph/restapi
state: absent
3 changes: 3 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
- ./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_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon: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_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
- ./plugins/playbook/server_discovery/decapod_plugin_playbook_server_discovery:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_server_discovery:ro
Expand All @@ -66,6 +67,7 @@ services:
- ./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_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon: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_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
- ./plugins/playbook/server_discovery/decapod_plugin_playbook_server_discovery:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_server_discovery:ro
Expand All @@ -90,6 +92,7 @@ services:
- ./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_mon/decapod_plugin_playbook_remove_mon:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_remove_mon: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_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
- ./plugins/playbook/server_discovery/decapod_plugin_playbook_server_discovery:/usr/local/lib/python3.5/dist-packages/decapod_plugin_playbook_server_discovery:ro
Expand Down
1 change: 1 addition & 0 deletions docs/source/playbook-plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The section contains the following topics:
playbook-plugins/plugin-add-rgw.rst
playbook-plugins/plugin-remove-rgw.rst
playbook-plugins/plugin-add-restapi.rst
playbook-plugins/plugin-remove-restapi.rst
playbook-plugins/plugin-purge-cluster.rst
playbook-plugins/plugin-telegraf-integration.rst
playbook-plugins/plugin-purge-telegraf.rst
Expand Down
16 changes: 16 additions & 0 deletions docs/source/playbook-plugins/plugin-remove-restapi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _plugins_remove_restapi:

====================
Remove REST API host
====================

The *Remove REST API host* playbook plugin allows you to remove a host
with REST APIs from the cluster.

The section contains the following topics:

.. toctree::
:maxdepth: 1

remove-restapi/overview.rst
remove-restapi/example-config.rst
28 changes: 28 additions & 0 deletions docs/source/playbook-plugins/remove-restapi/example-config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _plugin_remove_restapi_example_config:

=====================
Configuration example
=====================

The following is an example of the *Remove REST API host* plugin
configuration:

.. code-block:: json
{
"global_vars": {
"cluster": "ceph"
},
"inventory": {
"_meta": {
"hostvars": {
"10.0.0.22": {
"ansible_user": "ansible"
}
}
},
"restapis": [
"10.0.0.22"
]
}
}
16 changes: 16 additions & 0 deletions docs/source/playbook-plugins/remove-restapi/overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _plugin_remove_restapi_overview:

========
Overview
========

The following table shows the general information about the *Remove REST
API host* plugin:

==================== ====================
Property Value
==================== ====================
ID remove_restapi
Name Remove REST API Host
Required Server List Yes
==================== ====================
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,12 @@
enabled: no


- name: Stop REST APIs
- name: Clear REST APIs
hosts: restapis
become: true
gather_facts: false
tasks:
- name: Stop Ceph REST API service
service:
name: ceph-rest-api.service
state: stopped
enabled: no

# After installation, ceph-ansible runs Rest API using nohup
# therefore we need to stop it with pkill
- name: Stop Ceph REST API process
command: pkill ceph-rest-api
failed_when: false
- include: "{{ decapod_common_playbooks }}/tasks/clean_restapi_host.yaml"


- name: Clear OSDs
Expand Down
2 changes: 2 additions & 0 deletions plugins/playbook/remove_restapi/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include decapod_plugin_playbook_remove_restapi/config.yaml
include decapod_plugin_playbook_remove_restapi/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,21 @@
---
# 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.


- hosts: restapis
become: true
tasks:
- include: "{{ decapod_common_playbooks }}/tasks/clean_restapi_host.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- 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 Ceph REST API host."""


from decapod_common import log
from decapod_common import playbook_plugin


DESCRIPTION = "Remove Ceph REST API host"
"""Plugin description."""

HINTS_SCHEMA = {

}
"""Schema for playbook hints."""

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


class RemoveRestapi(playbook_plugin.Playbook):

NAME = "Remove Ceph REST API 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("restapis")
group_servers = [servers[ip] for ip in group_vars]
cluster.remove_servers(group_servers, "restapis")

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

def make_playbook_configuration(self, cluster, servers, hints):
global_vars = self.make_global_vars(cluster, servers, hints)
inventory = self.make_inventory(cluster, servers, hints)

return global_vars, inventory

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

def make_inventory(self, cluster, 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["ansible_user"] = srv.username

return inventory

def get_inventory_groups(self, cluster, servers, hints):
return {
"restapis": servers
}
9 changes: 9 additions & 0 deletions plugins/playbook/remove_restapi/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_restapi/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 Ceph REST API removal plugin."""


import setuptools


setuptools.setup(
name="decapod-plugin-playbook-remove-restapi",
description="Remove Ceph REST API host",
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_restapi = decapod_plugin_playbook_remove_restapi.plugin:RemoveRestapi" # NOQA
]
},
python_requires=">= 3.4",
include_package_data=True,
package_data={
"decapod_plugin_playbook_remove_restapi": [
"config.yaml",
"playbook.yaml"
]
},
install_requires=[
"decapod-common~=1.1.dev1"
],
zip_safe=False
)
3 changes: 3 additions & 0 deletions plugins/playbook/remove_restapi/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 51cfb61

Please sign in to comment.