1
0
mirror of https://github.com/gryf/mistral-evacuate.git synced 2026-02-14 12:55:56 +01:00
Files
mistral-evacuate/filter_vm_action.py
Dawid Deja 44c00b9ca4 Separate geting flavors and filtering into separe tasks
Also minimalize numbers of calls to nova API

Signed-off-by: Dawid Deja <dawid.deja@intel.com>
2016-02-03 18:24:07 +01:00

31 lines
820 B
Python

"""
FilterVmAction - custom action.
Simple action for filtering VM on the presence of metadata/extra spec
"evacuate" flag
"""
from mistral.actions import base
class FilterVmAction(base.Action):
"""
Filter and return VMs whith the flag 'evacuate' either on vm metadtata
or flavor extra spec.
"""
def __init__(self, flavors, vms):
"""init."""
self._flavors = flavors
self._vms = vms
def run(self):
"""Entry point for the action execution."""
result = []
for vm in self._vms:
if str(vm['metadata'].get('evacuate')).upper() == 'TRUE'\
or (str(vm['metadata'].get('evacuate')).upper() != 'FALSE'
and vm['flavor']['id'] in self._flavors):
result.append(vm['id'])
return result