Improve dictionary representation of package from Glare

Several keys added to dictionary representation of package imported
from Glare to match packages from murano.
Thus, dashboard API works in a similar way, no matter what backend
is used.
It also allows dashboard to filter applications by category and by
some text in name, description or tags.

Change-Id: Ia08a0629e55b8fa318b787d87bb3a2f793cb2a2a
Closes-bug: #1561935
This commit is contained in:
Valerii Kovalchuk 2016-03-24 15:34:17 +02:00
parent a83b28643b
commit 34f5336863
1 changed files with 12 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import yaml
from muranoclient.common import exceptions as exc
from muranoclient.common import utils
from muranoclient.i18n import _
def rewrap_http_exceptions(func):
@ -325,7 +326,17 @@ class PackageWrapper(object):
return getattr(self._item, name)
def to_dict(self):
return {'id': self.id, 'name': self.name, 'owner_id': self.owner_id}
keys = ('author', 'categories', 'class_definitions', 'created',
'description', 'enabled', 'fully_qualified_name', 'id',
'is_public', 'name', 'owner_id', 'tags', 'type',
'updated')
missing_keys = [key for key in keys if not hasattr(self, key)]
if missing_keys:
raise KeyError(_("Some attributes are missing in "
"%(pkg_name)s: %(attrs)s.") %
{'pkg_name': self.name,
'attrs': ", ".join(missing_keys)})
return {key: getattr(self, key) for key in keys}
class NamespaceResolver(object):