diff options
author | Dan Smith <danms@us.ibm.com> | 2013-05-28 15:55:58 -0700 |
---|---|---|
committer | Dan Smith <danms@us.ibm.com> | 2013-06-07 11:43:37 -0700 |
commit | e86d5b063bbb741d411bf4b50b5cc8a9829960db (patch) | |
tree | ded16b65dc5c4aabfd690c1ea6b9fa500e9f47fd /nova/objects | |
parent | 65f6c536fecd3c788b2e0dfa9d66ecd24ca550e1 (diff) | |
download | nova-e86d5b063bbb741d411bf4b50b5cc8a9829960db.tar.gz nova-e86d5b063bbb741d411bf4b50b5cc8a9829960db.tar.xz nova-e86d5b063bbb741d411bf4b50b5cc8a9829960db.zip |
Add lists of instance objects
This adds a list-of-instances object, which can house the "get all"
methods for instances. It's very simple, emulates a list, but
provides us an object-oriented way to get multiple instances that
mirrors the model.
Related to blueprint unified-object-model
Change-Id: Id6579030b88b92d4cb7db13ee6718ad01db7bf63
Diffstat (limited to 'nova/objects')
-rw-r--r-- | nova/objects/instance.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py index 0489f1374..58c581542 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -239,3 +239,57 @@ class Instance(base.NovaObject): uuid=self.uuid, expected_attrs=extra) self[attrname] = instance[attrname] + + +def _make_instance_list(context, inst_list, db_inst_list, expected_attrs): + inst_list.objects = [] + for db_inst in db_inst_list: + inst_obj = Instance._from_db_object(Instance(), db_inst, + expected_attrs=expected_attrs) + inst_obj._context = context + inst_list.objects.append(inst_obj) + inst_list.obj_reset_changes() + return inst_list + + +class InstanceList(base.ObjectListBase, base.NovaObject): + @base.remotable_classmethod + def get_by_filters(cls, context, filters, + sort_key=None, sort_dir=None, limit=None, marker=None, + expected_attrs=None): + db_inst_list = db.instance_get_all_by_filters( + context, filters, sort_key, sort_dir, limit, marker, + columns_to_join=expected_attrs) + + return _make_instance_list(context, cls(), db_inst_list, + expected_attrs) + + @base.remotable_classmethod + def get_by_host(cls, context, host, expected_attrs=None): + db_inst_list = db.instance_get_all_by_host( + context, host, columns_to_join=expected_attrs) + return _make_instance_list(context, cls(), db_inst_list, + expected_attrs) + + @base.remotable_classmethod + def get_by_host_and_node(cls, context, host, node, expected_attrs=None): + db_inst_list = db.instance_get_all_by_host_and_node( + context, host, node) + return _make_instance_list(context, cls(), db_inst_list, + expected_attrs) + + @base.remotable_classmethod + def get_by_host_and_not_type(cls, context, host, type_id=None, + expected_attrs=None): + db_inst_list = db.instance_get_all_by_host_and_not_type( + context, host, type_id=type_id) + return _make_instance_list(context, cls(), db_inst_list, + expected_attrs) + + @base.remotable_classmethod + def get_hung_in_rebooting(cls, context, reboot_window, + expected_attrs=None): + db_inst_list = db.instance_get_all_hung_in_rebooting(context, + reboot_window) + return _make_instance_list(context, cls(), db_inst_list, + expected_attrs) |