summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authormdietz <mdietz@openstack>2010-10-04 21:08:08 +0000
committermdietz <mdietz@openstack>2010-10-04 21:08:08 +0000
commitec6af5b56545a7ec62033a6574683e3b93dc862c (patch)
tree5a5c2041818d1387aee07bf23797d1a5a1a28bed /nova/api
parent7e66ee636910763630fcf5e6ff23848389713c81 (diff)
parentdd0f365c98ae68afff9a0fbc75e7d5b88499b282 (diff)
merge from gundlach ec2 conversion
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index f43da42bd..3f440c85c 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -72,6 +72,20 @@ def _gen_key(context, user_id, key_name):
return {'private_key': private_key, 'fingerprint': fingerprint}
+def ec2_id_to_internal_id(ec2_id):
+ """Convert an ec2 ID (i-[base 36 number]) to an internal id (int)"""
+ return int(ec2_id[2:], 36)
+
+
+def internal_id_to_ec2_id(internal_id):
+ """Convert an internal ID (int) to an ec2 ID (i-[base 36 number])"""
+ digits = []
+ while internal_id != 0:
+ internal_id, remainder = divmod(internal_id, 36)
+ digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[remainder])
+ return "i-%s" % ''.join(reversed(digits))
+
+
class CloudController(object):
""" CloudController provides the critical dispatch between
inbound API calls through the endpoint and messages
@@ -113,16 +127,6 @@ class CloudController(object):
result[key] = [line]
return result
- def ec2_id_to_internal_id(ec2_id):
- """Convert an ec2 ID (i-[base 36 number]) to an internal id (int)"""
- # TODO(gundlach): Maybe this should actually work?
- return ec2_id[2:]
-
- def internal_id_to_ec2_id(internal_id):
- """Convert an internal ID (int) to an ec2 ID (i-[base 36 number])"""
- # TODO(gundlach): Yo maybe this should actually convert to base 36
- return "i-%d" % internal_id
-
def get_metadata(self, address):
instance_ref = db.fixed_ip_get_instance(None, address)
if instance_ref is None: