add InstanceGroup.get_by_instance_uuid

Add a new method to the InstanceGroup object that lets you get a group
by an instance UUID.  Right now Nova only lets you have an instance in
a single group, so that's why this is a method of InstanceGroup and
not InstanceGroupList.

Change-Id: Ic0181e241471ad817284209e6a1093a438962bf1
Related-bug: #1379451
This commit is contained in:
Russell Bryant 2014-10-09 19:45:11 +00:00
parent b4e5a59fac
commit f0624f4446
3 changed files with 23 additions and 4 deletions

View File

@ -31,7 +31,8 @@ class InstanceGroup(base.NovaPersistentObject, base.NovaObject):
# Version 1.6: Add get_by_name()
# Version 1.7: Deprecate metadetails
# Version 1.8: Add count_members_by_user()
VERSION = '1.8'
# Version 1.9: Add get_by_instance_uuid()
VERSION = '1.9'
fields = {
'id': fields.IntegerField(),
@ -89,6 +90,11 @@ class InstanceGroup(base.NovaPersistentObject, base.NovaObject):
raise exception.InstanceGroupNotFound(group_uuid=name)
@base.remotable_classmethod
def get_by_instance_uuid(cls, context, instance_uuid):
db_inst = db.instance_group_get_by_instance(context, instance_uuid)
return cls._from_db_object(context, cls(), db_inst)
@classmethod
def get_by_hint(cls, context, hint):
if uuidutils.is_uuid_like(hint):
@ -179,7 +185,8 @@ class InstanceGroupList(base.ObjectListBase, base.NovaObject):
# Version 1.3: InstanceGroup <= version 1.6
# Version 1.4: InstanceGroup <= version 1.7
# Version 1.5: InstanceGroup <= version 1.8
VERSION = '1.5'
# Version 1.6: InstanceGroup <= version 1.9
VERSION = '1.6'
fields = {
'objects': fields.ListOfObjectsField('InstanceGroup'),
@ -192,6 +199,7 @@ class InstanceGroupList(base.ObjectListBase, base.NovaObject):
'1.3': '1.6',
'1.4': '1.7',
'1.5': '1.8',
'1.6': '1.9',
}
@base.remotable_classmethod

View File

@ -54,6 +54,17 @@ class _TestInstanceGroupObjects(test.TestCase):
self.assertEqual(obj_result.members, members)
self.assertEqual(obj_result.policies, policies)
def test_get_by_instance_uuid(self):
values = self._get_default_values()
policies = ['policy1', 'policy2']
members = ['instance_id1', 'instance_id2']
db_result = self._create_instance_group(self.context, values,
policies=policies,
members=members)
obj_result = instance_group.InstanceGroup.get_by_instance_uuid(
self.context, 'instance_id1')
self.assertEqual(obj_result.uuid, db_result.uuid)
def test_refresh(self):
values = self._get_default_values()
db_result = self._create_instance_group(self.context, values)

View File

@ -958,8 +958,8 @@ object_data = {
'InstanceExternalEvent': '1.0-f1134523654407a875fd59b80f759ee7',
'InstanceFault': '1.2-313438e37e9d358f3566c85f6ddb2d3e',
'InstanceFaultList': '1.1-aeb598ffd0cd6aa61fca7adf0f5e900d',
'InstanceGroup': '1.8-9f3ef6ee21e424f817f76a63d35eb803',
'InstanceGroupList': '1.5-b507229896d60fad117cb3223dbaa0cc',
'InstanceGroup': '1.9-95ece99f092e8f4f88327cdbb44162c9',
'InstanceGroupList': '1.6-c6b78f3c9d9080d33c08667e80589817',
'InstanceInfoCache': '1.5-ef64b604498bfa505a8c93747a9d8b2f',
'InstanceList': '1.9-6f290799b0ac19eb9e72ed580520b883',
'InstancePCIRequest': '1.1-e082d174f4643e5756ba098c47c1510f',