1
0
mirror of https://github.com/gryf/mistral-evacuate.git synced 2026-03-24 11:23:39 +01:00

Add new action so it can use filtered data

This commit adds evacuate_vm_action which is a wrapper for nova.evacuate
API call, but it checks the result of filtering from previous step, before
executing evacuation.

Also change a little bit workflow and filter action, so they suit new
approach

Signed-off-by: Dawid Deja <dawid.deja@intel.com>
This commit is contained in:
Dawid Deja
2016-02-02 15:13:46 +01:00
parent 992af39ce0
commit 503c35c435
4 changed files with 35 additions and 13 deletions

View File

@@ -30,19 +30,26 @@ class FilterVmAction(NovaAction):
metadata = self._metadata
if str(metadata.get('evacuate')).upper() == 'TRUE':
return Result(data={'status': 0, 'uuid': self._uuid})
return Result(data={'evacuate': True, 'uuid': self._uuid})
elif str(metadata.get('evacuate')).upper() == 'FALSE':
return Result(error='evacuate for vm %s is disabled' % self._uuid)
return Result(data={'evacuate': False, 'uuid': self._uuid})
# ether is no metadata for vm - check flavor
# Ether is no metadata for vm - check flavor.
try:
flavor = [x for x in client.flavors.list() if x.id == '1'][0]
# Maybe this should be done in different action
# only once per whole workflow.
# In case there is ~100 VMs to evacuate, there will be
# the same amount of calls to nova API.
flavor = filter(
lambda f: f.id == self._flavor,
client.flavors.list()
)[0]
except IndexError:
raise FilterVmException('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={'evacuate': True, 'uuid': self._uuid})
return Result(error='evacuate for vm %s is disabled' % self._uuid)
return Result(data={'evacuate': False, 'uuid': self._uuid})