diff options
| author | Andy Smith <code@term.ie> | 2011-01-12 15:03:08 -0800 |
|---|---|---|
| committer | Andy Smith <code@term.ie> | 2011-01-12 15:03:08 -0800 |
| commit | 5fbc74784918abb509aba88400e6ed9a1d01deb9 (patch) | |
| tree | c94566c8bc59732b5b4bc5da0fd9de94553dada6 /nova | |
| parent | 1fa45c2ce52612455d88d1fdabec38d4bcc01ca7 (diff) | |
| download | nova-5fbc74784918abb509aba88400e6ed9a1d01deb9.tar.gz nova-5fbc74784918abb509aba88400e6ed9a1d01deb9.tar.xz nova-5fbc74784918abb509aba88400e6ed9a1d01deb9.zip | |
standardize on hex for ids, allow configurable instance names
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/ec2/cloud.py | 14 | ||||
| -rw-r--r-- | nova/db/api.py | 4 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 4 |
3 files changed, 11 insertions, 11 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 7df2feb98..c68a1f4bc 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -73,17 +73,13 @@ def _gen_key(context, user_id, key_name): def ec2_id_to_id(ec2_id): - """Convert an ec2 ID (i-[base 36 number]) to an instance id (int)""" - return int(ec2_id[2:], 36) + """Convert an ec2 ID (i-[base 16 number]) to an instance id (int)""" + return int(ec2_id.split('-')[-1], 16) -def id_to_ec2_id(instance_id, template='i-%s'): - """Convert an instance ID (int) to an ec2 ID (i-[base 36 number])""" - digits = [] - while instance_id != 0: - instance_id, remainder = divmod(instance_id, 36) - digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[remainder]) - return template % (''.join(reversed(digits)).zfill(8)) +def id_to_ec2_id(instance_id, template='i-%08x'): + """Convert an instance ID (int) to an ec2 ID (i-[base 16 number])""" + return template % instance_id class CloudController(object): diff --git a/nova/db/api.py b/nova/db/api.py index 1f81ef145..e57766b5c 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -42,6 +42,10 @@ flags.DEFINE_string('db_backend', 'sqlalchemy', 'The backend to use for db') flags.DEFINE_boolean('enable_new_services', True, 'Services to be added to the available pool on create') +flags.DEFINE_string('instance_name_template', 'instance-%08x', + 'Template string to be used to generate instance names') +flags.DEFINE_string('volume_name_template', 'volume-%08x', + 'Template string to be used to generate instance names') IMPL = utils.LazyPluggable(FLAGS['db_backend'], diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 1dc46fe78..bbc89e573 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -169,7 +169,7 @@ class Instance(BASE, NovaBase): @property def name(self): - return "instance-%08x" % self.id + return FLAGS.instance_name_template % self.id admin_pass = Column(String(255)) user_id = Column(String(255)) @@ -256,7 +256,7 @@ class Volume(BASE, NovaBase): @property def name(self): - return "volume-%08x" % self.id + return FLAGS.volume_name_template % self.id user_id = Column(String(255)) project_id = Column(String(255)) |
