Add identity helper property to CellMapping

This adds CellMapping.identity, a property to help with quick logging of
a CellMapping. It's tempting to just log a a whole CellMapping object,
but that can be bad due to the credentials stored within. This adds a
convenient way to log the uuid or name-and-uuid of a CellMapping without
having to replicate the is-name-set-or-none logic everywhere.

Related to blueprint cells-aware-api
Change-Id: Ie8eaf08e9f5bda56431358c40ccf187251be4542
This commit is contained in:
Dan Smith
2017-03-09 08:14:04 -08:00
parent 9b8ab58360
commit 35f803f6f4
6 changed files with 36 additions and 12 deletions

View File

@@ -32,6 +32,13 @@ class CellMapping(base.NovaTimestampObject, base.NovaObject):
'database_connection': fields.StringField(),
}
@property
def identity(self):
if 'name' in self and self.name:
return '%s(%s)' % (self.uuid, self.name)
else:
return self.uuid
@staticmethod
def _from_db_object(context, cell_mapping, db_cell_mapping):
for key in cell_mapping.fields: