1
0
mirror of https://github.com/gryf/mistral-evacuate.git synced 2026-04-28 15:34:06 +02:00

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>
This commit is contained in:
Dawid Deja
2016-02-03 18:24:07 +01:00
parent bcafa3f466
commit 44c00b9ca4
6 changed files with 79 additions and 76 deletions
+32
View File
@@ -0,0 +1,32 @@
"""
FindFlavorsByExtraSpecs - custom action.
It works pretty similar to nova.flavors_findall, but it looks for items in
flavors extra spec
"""
from mistral.actions.openstack.actions import NovaAction
class FindFlavorsByExtraSpecs(NovaAction):
def __init__(self, extra_specs):
if type(extra_specs) is dict:
self._extra_specs = extra_specs
else:
raise TypeError("Extra spec must be a dictionary")
def run(self):
client = self._get_client()
flavors = client.flavors.list()
result = []
for flavor in flavors:
flavor_extra_specs = flavor.get_keys().items()
if all(
item in flavor_extra_specs
for item in self._extra_specs.items()
):
result.append(flavor.id)
return result