From 349a4dd3235f76548afdf92ce69b6ff6aacc74bd Mon Sep 17 00:00:00 2001 From: Ruby Loo Date: Tue, 6 Dec 2016 17:20:26 +0000 Subject: [PATCH] Use IronicObject._from_db_object_list method This cleans up the code so that wherever an object needs to convert a list of database entities to a list of the objects, IronicObject._from_db_object_list() is used. Individual object's _from_db_object_list() methods are removed. Change-Id: Ic9d16b30da0067606804ad6b5997af4bc864ad93 --- ironic/objects/chassis.py | 3 +-- ironic/objects/node.py | 2 +- ironic/objects/port.py | 11 +++-------- ironic/objects/portgroup.py | 10 ++-------- ironic/objects/volume_connector.py | 12 ++---------- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/ironic/objects/chassis.py b/ironic/objects/chassis.py index 4ade052fe9..102dc5a96c 100644 --- a/ironic/objects/chassis.py +++ b/ironic/objects/chassis.py @@ -111,8 +111,7 @@ class Chassis(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return [Chassis._from_db_object(cls(context), obj) - for obj in db_chassis] + return cls._from_db_object_list(context, db_chassis) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. diff --git a/ironic/objects/node.py b/ironic/objects/node.py index 1fcef73e8f..bd63a17707 100644 --- a/ironic/objects/node.py +++ b/ironic/objects/node.py @@ -251,7 +251,7 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat): db_nodes = cls.dbapi.get_node_list(filters=filters, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return [Node._from_db_object(cls(context), obj) for obj in db_nodes] + return cls._from_db_object_list(context, db_nodes) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. diff --git a/ironic/objects/port.py b/ironic/objects/port.py index e8b3186592..98a83cd27e 100644 --- a/ironic/objects/port.py +++ b/ironic/objects/port.py @@ -52,11 +52,6 @@ class Port(base.IronicObject, object_base.VersionedObjectDictCompat): 'internal_info': object_fields.FlexibleDictField(nullable=True), } - @staticmethod - def _from_db_object_list(db_objects, cls, context): - """Converts a list of database entities to a list of formal objects.""" - return [Port._from_db_object(cls(context), obj) for obj in db_objects] - # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. # Implications of calling new remote procedures should be thought through. @@ -157,7 +152,7 @@ class Port(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return Port._from_db_object_list(db_ports, cls, context) + return cls._from_db_object_list(context, db_ports) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. @@ -181,7 +176,7 @@ class Port(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return Port._from_db_object_list(db_ports, cls, context) + return cls._from_db_object_list(context, db_ports) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. @@ -206,7 +201,7 @@ class Port(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return Port._from_db_object_list(db_ports, cls, context) + return cls._from_db_object_list(context, db_ports) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. diff --git a/ironic/objects/portgroup.py b/ironic/objects/portgroup.py index 021a7620ad..75917f1bef 100644 --- a/ironic/objects/portgroup.py +++ b/ironic/objects/portgroup.py @@ -45,12 +45,6 @@ class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat): 'standalone_ports_supported': object_fields.BooleanField(), } - @staticmethod - def _from_db_object_list(db_objects, cls, context): - """Converts a list of database entities to a list of formal objects.""" - return [Portgroup._from_db_object(cls(context), obj) for obj in - db_objects] - # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. # Implications of calling new remote procedures should be thought through. @@ -170,7 +164,7 @@ class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return Portgroup._from_db_object_list(db_portgroups, cls, context) + return cls._from_db_object_list(context, db_portgroups) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. @@ -196,7 +190,7 @@ class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat): marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return Portgroup._from_db_object_list(db_portgroups, cls, context) + return cls._from_db_object_list(context, db_portgroups) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. diff --git a/ironic/objects/volume_connector.py b/ironic/objects/volume_connector.py index e91c5e8cc5..86459e4b2e 100644 --- a/ironic/objects/volume_connector.py +++ b/ironic/objects/volume_connector.py @@ -39,12 +39,6 @@ class VolumeConnector(base.IronicObject, 'extra': object_fields.FlexibleDictField(nullable=True), } - @staticmethod - def _from_db_object_list(db_objects, cls, context): - """Convert a list of database entities to a list of formal objects.""" - return [VolumeConnector._from_db_object(cls(context), obj) - for obj in db_objects] - # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. # Implications of calling new remote procedures should be thought through. @@ -126,8 +120,7 @@ class VolumeConnector(base.IronicObject, marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return VolumeConnector._from_db_object_list(db_connectors, - cls, context) + return cls._from_db_object_list(context, db_connectors) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls. @@ -153,8 +146,7 @@ class VolumeConnector(base.IronicObject, marker=marker, sort_key=sort_key, sort_dir=sort_dir) - return VolumeConnector._from_db_object_list(db_connectors, - cls, context) + return cls._from_db_object_list(context, db_connectors) # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable # methods can be used in the future to replace current explicit RPC calls.