-
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.
Change-Id: Id0bba4dfd411b10cad3dcb3806f228757b369531
- Loading branch information
Showing
15 changed files
with
313 additions
and
12 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
backend/common/decapod_common/playbooks/tasks/clean_restapi_host.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,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 |
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,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
28
docs/source/playbook-plugins/remove-restapi/example-config.rst
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,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" | ||
] | ||
} | ||
} |
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,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 | ||
==================== ==================== |
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_restapi/config.yaml | ||
include decapod_plugin_playbook_remove_restapi/playbook.yaml |
Empty file.
15 changes: 15 additions & 0 deletions
15
plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi/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. |
21 changes: 21 additions & 0 deletions
21
plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi/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,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" |
90 changes: 90 additions & 0 deletions
90
plugins/playbook/remove_restapi/decapod_plugin_playbook_remove_restapi/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,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 | ||
} |
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 | ||
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,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 | ||
) |
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,3 @@ | ||
[DEFAULT] | ||
X-Python3-Version: >= 3.4 | ||
Depends3: python3-decapod-common (>= 1.1), python3-decapod-common (<< 1.2) |