diff options
| author | vladimir.p <vladimir@zadarastorage.com> | 2011-08-24 10:16:20 -0700 |
|---|---|---|
| committer | vladimir.p <vladimir@zadarastorage.com> | 2011-08-24 10:16:20 -0700 |
| commit | 207ce4f19655e70d14f3a67a45ba6acf8f12380d (patch) | |
| tree | daa5e1f5ea1d7b9fd9be64af66cc507495dfe489 /nova/volume | |
| parent | 163923f57d075fa5d46a5b54073fc6cd30e5c624 (diff) | |
added volume type search by extra_spec
Diffstat (limited to 'nova/volume')
| -rw-r--r-- | nova/volume/volume_types.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/nova/volume/volume_types.py b/nova/volume/volume_types.py index 9df1e39f8..9b02d4ccc 100644 --- a/nova/volume/volume_types.py +++ b/nova/volume/volume_types.py @@ -68,13 +68,43 @@ def purge(context, name): raise exception.ApiError(_("Unknown volume type: %s") % name) -def get_all_types(context, inactive=0): +def get_all_types(context, inactive=0, search_opts={}): """Get all non-deleted volume_types. Pass true as argument if you want deleted volume types returned also. """ - return db.volume_type_get_all(context, inactive) + vol_types = db.volume_type_get_all(context, inactive) + + if search_opts: + LOG.debug(_("Searching by: %s") % str(search_opts)) + + def _check_extra_specs_match(vol_type, searchdict): + for k, v in searchdict.iteritems(): + if k not in vol_type['extra_specs'].keys()\ + or vol_type['extra_specs'][k] != v: + return False + return True + + # search_option to filter_name mapping. + filter_mapping = {'extra_specs': _check_extra_specs_match} + + result = {} + for type_name, type_args in vol_types.iteritems(): + # go over all filters in the list + for opt, values in search_opts.iteritems(): + try: + filter_func = filter_mapping[opt] + except KeyError: + # no such filter - ignore it, go to next filter + continue + else: + if filter_func(type_args, values): + # if one of conditions didn't match - remove + result[type_name] = type_args + break + vol_types = result + return vol_types def get_volume_type(context, id): |
