132
133
return template % int(instance_id)
135
def id_to_ec2_snap_id(instance_id):
136
"""Convert an snapshot ID (int) to an ec2 snapshot ID
137
(snap-[base 16 number])"""
138
return id_to_ec2_id(instance_id, 'snap-%08x')
141
def id_to_ec2_vol_id(instance_id):
142
"""Convert an volume ID (int) to an ec2 volume ID (vol-[base 16 number])"""
143
return id_to_ec2_id(instance_id, 'vol-%08x')
136
def id_to_ec2_snap_id(snapshot_id):
137
"""Get or create an ec2 volume ID (vol-[base 16 number]) from uuid."""
138
if utils.is_uuid_like(snapshot_id):
139
ctxt = context.get_admin_context()
140
int_id = get_int_id_from_snapshot_uuid(ctxt, snapshot_id)
141
return id_to_ec2_id(int_id)
143
return id_to_ec2_id(snapshot_id, 'snap-%08x')
146
def id_to_ec2_vol_id(volume_id):
147
"""Get or create an ec2 volume ID (vol-[base 16 number]) from uuid."""
148
if utils.is_uuid_like(volume_id):
149
ctxt = context.get_admin_context()
150
int_id = get_int_id_from_volume_uuid(ctxt, volume_id)
151
return id_to_ec2_id(int_id)
153
return id_to_ec2_id(volume_id, 'vol-%08x')
156
def ec2_vol_id_to_uuid(ec2_id):
157
"""Get the cooresponding UUID for the given ec2-id."""
158
ctxt = context.get_admin_context()
160
# NOTE(jgriffith) first strip prefix to get just the numeric
161
int_id = ec2_id_to_id(ec2_id)
162
return get_volume_uuid_from_int_id(ctxt, int_id)
165
def get_int_id_from_volume_uuid(context, volume_uuid):
166
if volume_uuid is None:
169
return db.get_ec2_volume_id_by_uuid(context, volume_uuid)
170
except exception.NotFound:
171
raise exception.VolumeNotFound()
174
def get_volume_uuid_from_int_id(context, int_id):
175
return db.get_volume_uuid_by_ec2_id(context, int_id)
178
def ec2_snap_id_to_uuid(ec2_id):
179
"""Get the cooresponding UUID for the given ec2-id."""
180
ctxt = context.get_admin_context()
182
# NOTE(jgriffith) first strip prefix to get just the numeric
183
int_id = ec2_id_to_id(ec2_id)
184
return get_snapshot_uuid_from_int_id(ctxt, int_id)
187
def get_int_id_from_snapshot_uuid(context, snapshot_uuid):
188
if snapshot_uuid is None:
191
return db.get_ec2_snapshot_id_by_uuid(context, snapshot_uuid)
192
except exception.NotFound:
193
raise exception.SnapshotNotFound()
196
def get_snapshot_uuid_from_int_id(context, int_id):
197
return db.get_snapshot_uuid_by_ec2_id(context, int_id)
200
def ec2_instance_id_to_uuid(context, ec2_id):
201
int_id = ec2_id_to_id(ec2_id)
202
return db.instance_get(context, int_id)['uuid']
146
204
_c2u = re.compile('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))')
176
238
if lowered_value == 'false':
178
valueneg = value[1:] if value[0] == '-' else value
183
if valueneg[0] == '0':
184
if valueneg[1] in 'xX':
185
return int(value, 16)
186
elif valueneg[1] in 'bB':
202
return complex(value)
240
for prefix, base in [('0x', 16), ('0b', 2), ('0', 8), ('', 10)]:
242
if lowered_value.startswith((prefix, "-" + prefix)):
243
return int(lowered_value, base)
247
return _negative_zero(float(value))
203
248
except ValueError: