1
0
mirror of https://github.com/gryf/mistral-evacuate.git synced 2026-02-07 08:45:48 +01:00

Inital import

This commit is contained in:
2015-11-16 16:45:21 +01:00
commit 6035092c13
3 changed files with 127 additions and 0 deletions

52
README.rst Normal file
View File

@@ -0,0 +1,52 @@
Mistral evacuate plugin
=======================
This is a PoC for providing automatic evacuation for VMs in OpenStack cloud
using Mistral.
Installation
------------
#. Copy ``filter_vm.py`` to the place reachable by python interpreter - see
``PYTHONPATH`` or ``sys.path`` for reference.
#. Append line
.. code:: ini
[entry_points]
mistral.actions =
custom.filter_vms = evac_poc:FilterAndEvacuate
to ``setup.cfg`` file under Mistral repository
#. Reinstall Mistral if it was installed in system (not in virtualenv).
#. Run db-sync tool via either
.. code:: shell-session
$ tools/sync_db.sh --config-file <path-to-config>
or
.. code:: shell-session
$ mistral-db-manage --config-file <path-to-config> populate
#. Register Mistral workflow:
.. code:: shell-session
$ mistral workflow-create evacuate-workflow.yaml
#. Create JSON file with content similar to:
.. code:: json
{
"search_opts": {
"host": "compute-hostanme"
}
}
#. Trigger the action via:
TBD

45
filter_vm_action.py Normal file
View File

@@ -0,0 +1,45 @@
"""
FilterVmAction - custom action.
Simple action for filtering VM on the presence of metadata/extra spec
"evacuate" flag
"""
from mistral.actions.openstack.actions import NovaAction
from mistral.workflow.utils import Result
class FilterVmAction(NovaAction):
"""
Filter and return VMs whith the flag 'evacuate' either on vm metadtata
or flavor extra spec.
"""
def __init__(self, metadata, flavor, uuid):
"""init."""
self._metadata = metadata
self._flavor = flavor
self._uuid = uuid
def run(self):
"""Entry point for the action execution."""
client = self._get_client()
metadata = self._metadata
if str(metadata.get('evacuate')).upper() == 'TRUE':
return Result(data={'status': 0, 'uuid': self._uuid})
elif str(metadata.get('evacuate')).upper() == 'FALSE':
return Result(error='sie nie udalo!!!!1111jeden')
# ether is no metadata for vm - check flavor
flavors = client.flavors.list()
try:
flavor = filter(lambda x: x.id == self._flavor, flavors)[0]
except:
raise Exception('Flavor not found')
evacuate = flavor.get_keys().get('evacuation:evacuate')
if str(evacuate).upper() == 'TRUE':
return Result(data={'status': 0, 'uuid': self._uuid})
return Result(data='1', error=True)

30
host-evacuate.yaml Normal file
View File

@@ -0,0 +1,30 @@
---
version: '2.0'
host-evacuate:
description: Evacuate VMs from given host
type: direct
input:
- search_opts
output:
vm_list: <% $.list_vms %>
tasks:
list_vms:
action: nova.servers_list search_opts=<% $.search_opts %>
publish:
vms: <% $.list_vms %>
on-success: filter_vms
filter_vms:
with-items: vm in <% $.vms %>
action: custom.filter_vms flavor=<% $.vm.flavor.id %> metadata=<% $.vm.metadata %> uuid=<% $.vm.id %>
publish:
filtered_vms: <% $.filter_vms.uuid %>
on-success: evacuate_vms
evacuate_vms:
with-items: vm_uuid in <% $.filtered_vms %>
action: nova.servers_evacuate server=<% $.vm_uuid %> on_shared_storage=false