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:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
17
evacuate_vm_action.py
Normal file
17
evacuate_vm_action.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from mistral.actions.openstack.actions import NovaAction
|
||||||
|
from mistral.workflow.utils import Result
|
||||||
|
|
||||||
|
|
||||||
|
class EvacuateVmAction(NovaAction):
|
||||||
|
|
||||||
|
def __init__(self, uuid, on_shared_storage, evacuate):
|
||||||
|
self._uuid = uuid
|
||||||
|
self._on_shared_storage = on_shared_storage
|
||||||
|
self._evacuate = evacuate
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
client = self._get_client()
|
||||||
|
|
||||||
|
if self._evacuate:
|
||||||
|
client.servers.evacuate(self._uuid,
|
||||||
|
on_shared_storage=self._on_shared_storage)
|
||||||
@@ -30,19 +30,26 @@ class FilterVmAction(NovaAction):
|
|||||||
metadata = self._metadata
|
metadata = self._metadata
|
||||||
|
|
||||||
if str(metadata.get('evacuate')).upper() == 'TRUE':
|
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':
|
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:
|
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:
|
except IndexError:
|
||||||
raise FilterVmException('Flavor not found')
|
raise FilterVmException('Flavor not found')
|
||||||
|
|
||||||
evacuate = flavor.get_keys().get('evacuation:evacuate')
|
evacuate = flavor.get_keys().get('evacuation:evacuate')
|
||||||
|
|
||||||
if str(evacuate).upper() == 'TRUE':
|
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})
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ host-evacuate:
|
|||||||
input:
|
input:
|
||||||
- search_opts
|
- search_opts
|
||||||
|
|
||||||
output:
|
|
||||||
vm_list: <% $.list_vms %>
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
list_vms:
|
list_vms:
|
||||||
action: nova.servers_list search_opts=<% $.search_opts %>
|
action: nova.servers_list search_opts=<% $.search_opts %>
|
||||||
@@ -20,11 +17,11 @@ host-evacuate:
|
|||||||
|
|
||||||
filter_vms:
|
filter_vms:
|
||||||
with-items: vm in <% $.vms %>
|
with-items: vm in <% $.vms %>
|
||||||
action: custom.filter_vm flavor=<% $.vm.flavor.id %> metadata=<% $.vm.metadata %> uuid=<% $.vm.id %>
|
action: custom.filter flavor=<% $.vm.flavor.id %> metadata=<% $.vm.metadata %> uuid=<% $.vm.id %>
|
||||||
publish:
|
publish:
|
||||||
filtered_vms: <% $.filter_vms.uuid %>
|
filtered_vms: <% $.filter_vms %>
|
||||||
on-success: evacuate_vms
|
on-success: evacuate_vms
|
||||||
|
|
||||||
evacuate_vms:
|
evacuate_vms:
|
||||||
with-items: vm_uuid in <% $.filtered_vms %>
|
with-items: vm in <% $.filtered_vms %>
|
||||||
action: nova.servers_evacuate server=<% $.vm_uuid %> on_shared_storage=false
|
action: custom.evacuate uuid=<% $.vm.uuid %> evacuate=<% $.vm.evacuate %> on_shared_storage=false
|
||||||
|
|||||||
Reference in New Issue
Block a user