Pass only instance reservation specific columns to the reservation table
Some duplicated columns, such as 'id', are overwritten by columns with the same name defined in the instance reservation table. This patch prevents the instance reservation columns from overwriting the reservation columns values in the to_dict method. Partially implements: blueprint new-instance-reservation Change-Id: I188c1db4512073bf36371b9022bd17716547bdbe
This commit is contained in:
parent
c17a052434
commit
a323230594
|
@ -21,7 +21,7 @@ from sqlalchemy.orm import attributes
|
|||
class _BlazarBase(models.ModelBase, models.TimestampMixin):
|
||||
"""Base class for all Blazar SQLAlchemy DB Models."""
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self, include=None):
|
||||
"""sqlalchemy based automatic to_dict method."""
|
||||
d = {}
|
||||
|
||||
|
@ -30,7 +30,11 @@ class _BlazarBase(models.ModelBase, models.TimestampMixin):
|
|||
# here and thereby cause it to load...
|
||||
unloaded = attributes.instance_state(self).unloaded
|
||||
|
||||
for col in self.__table__.columns:
|
||||
columns = self.__table__.columns
|
||||
if include:
|
||||
columns = [col for col in columns if col.name in include]
|
||||
|
||||
for col in columns:
|
||||
if col.name not in unloaded:
|
||||
d[col.name] = getattr(self, col.name)
|
||||
|
||||
|
|
|
@ -124,7 +124,9 @@ class Reservation(mb.BlazarBase):
|
|||
raise RuntimeError(e)
|
||||
|
||||
if self.instance_reservations:
|
||||
d.update(self.instance_reservations.to_dict())
|
||||
ir_keys = ['vcpus', 'memory_mb', 'disk_gb', 'amount', 'affinity',
|
||||
'flavor_id', 'aggregate_id', 'server_group_id']
|
||||
d.update(self.instance_reservations.to_dict(include=ir_keys))
|
||||
|
||||
return d
|
||||
|
||||
|
|
Loading…
Reference in New Issue