Add a method for querying a resource's type

Change-Id: Ie07a01668c5958494631806ffc0748f659eb8a1b
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-11-22 11:06:57 +01:00
parent ab71a7e0aa
commit 248d878011
2 changed files with 11 additions and 5 deletions

View File

@ -132,6 +132,9 @@ class Resource(object):
return result
return not result
def type(self):
return self.t['Type']
def identifier(self):
'''Return an identifier for this resource'''
return identifier.ResourceIdentifier(resource_name=self.name,
@ -335,7 +338,7 @@ class Resource(object):
'resource_status': new_state,
'name': new_state,
'resource_status_reason': reason,
'resource_type': self.t['Type'],
'resource_type': self.type(),
'resource_properties': dict(self.properties)}
try:
db_api.event_create(self.context, ev)
@ -399,9 +402,7 @@ class GenericResource(Resource):
properties_schema = {}
def handle_create(self):
logger.warning('Creating generic resource (Type "%s")' %
self.t['Type'])
logger.warning('Creating generic resource (Type "%s")' % self.type())
def handle_update(self):
logger.warning('Updating generic resource (Type "%s")' %
self.t['Type'])
logger.warning('Updating generic resource (Type "%s")' % self.type())

View File

@ -49,6 +49,11 @@ class ResourceTest(unittest.TestCase):
res.state_set('blarg', 'wibble')
self.assertEqual(res.state_description, 'wibble')
def test_type(self):
tmpl = {'Type': 'Foo'}
res = resource.GenericResource('test_resource', tmpl, self.stack)
self.assertEqual(res.type(), 'Foo')
def test_created_time(self):
tmpl = {'Type': 'Foo'}
res = resource.GenericResource('test_res_new', tmpl, self.stack)