Use physical resource names with a short_id

The short_id is a random, but stable, 12-character alphanumeric ID.

This will allow two resources of the same name to exist concurrently. That
is necessary for resources to be replaced during an update without
interruption.

Change-Id: If32904a47c6f8fb651e317ce91f2a04f6eadcc0b
This commit is contained in:
Zane Bitter 2013-06-17 12:24:49 +02:00
parent d0cdccace0
commit 9e2ecf7568
2 changed files with 21 additions and 3 deletions

View File

@ -21,6 +21,7 @@ from heat.common import exception
from heat.openstack.common import excutils
from heat.db import api as db_api
from heat.common import identifier
from heat.common import short_id
from heat.engine import timestamp
from heat.engine.properties import Properties
@ -397,7 +398,11 @@ class Resource(object):
self.state_set(self.UPDATE_COMPLETE)
def physical_resource_name(self):
return '%s-%s' % (self.stack.name, self.name)
assert self.id is not None
return '%s-%s-%s' % (self.stack.name,
self.name,
short_id.get_id(self.id))
def validate(self):
logger.info('Validating %s' % str(self))

View File

@ -75,10 +75,23 @@ class PhysName(object):
self.resource_name = resource_name
def __eq__(self, physical_name):
return physical_name == repr(self)
try:
stack, res, short_id = str(physical_name).rsplit('-', 2)
except ValueError:
return False
if self.stack_name != stack or self.resource_name != res:
return False
if len(short_id) != 12:
return False
return True
def __ne__(self, physical_name):
return not self.__eq__(physical_name)
def __repr__(self):
return '%s-%s' % (self.stack_name, self.resource_name)
return '%s-%s-%s' % (self.stack_name,
self.resource_name,
'x' * 12)