Renamed image_ref variables to image_href. Since the convention is that x_ref
vars may imply that they are db objects.
This commit is contained in:
@@ -849,7 +849,7 @@ class CloudController(object):
|
||||
instances = self.compute_api.create(context,
|
||||
instance_type=instance_types.get_instance_type_by_name(
|
||||
kwargs.get('instance_type', None)),
|
||||
image_ref=self._get_image(context, kwargs['image_ref'])['id'],
|
||||
image_href=self._get_image(context, kwargs['image_href'])['id'],
|
||||
min_count=int(kwargs.get('min_count', max_count)),
|
||||
max_count=max_count,
|
||||
kernel_id=kwargs.get('kernel_id'),
|
||||
|
||||
@@ -140,15 +140,15 @@ class Controller(common.OpenstackController):
|
||||
key_name = key_pair['name']
|
||||
key_data = key_pair['public_key']
|
||||
|
||||
image_ref = self._image_ref_from_req_data(env)
|
||||
image_href = self._image_ref_from_req_data(env)
|
||||
try:
|
||||
image_service, image_id = nova.image.get_image_service(image_ref)
|
||||
image_service, image_id = nova.image.get_image_service(image_href)
|
||||
kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(
|
||||
req, image_service, image_id)
|
||||
images = set([str(x['id']) for x in image_service.index(context)])
|
||||
assert str(image_id) in images
|
||||
except:
|
||||
msg = _("Cannot find requested image %s") % image_ref
|
||||
msg = _("Cannot find requested image %s") % image_href
|
||||
return faults.Fault(exc.HTTPBadRequest(msg))
|
||||
|
||||
personality = env['server'].get('personality')
|
||||
@@ -172,7 +172,7 @@ class Controller(common.OpenstackController):
|
||||
(inst,) = self.compute_api.create(
|
||||
context,
|
||||
inst_type,
|
||||
image_ref,
|
||||
image_href,
|
||||
kernel_id=kernel_id,
|
||||
ramdisk_id=ramdisk_id,
|
||||
display_name=name,
|
||||
@@ -188,7 +188,7 @@ class Controller(common.OpenstackController):
|
||||
return faults.Fault(exc.HTTPBadRequest(msg))
|
||||
|
||||
inst['instance_type'] = inst_type
|
||||
inst['image_id'] = image_ref
|
||||
inst['image_id'] = image_href
|
||||
|
||||
builder = self._get_view_builder(req)
|
||||
server = builder.build(inst, is_detail=True)
|
||||
@@ -701,13 +701,13 @@ class ControllerV11(Controller):
|
||||
instance_id = int(instance_id)
|
||||
|
||||
try:
|
||||
image_ref = info["rebuild"]["imageRef"]
|
||||
image_href = info["rebuild"]["imageRef"]
|
||||
except (KeyError, TypeError):
|
||||
msg = _("Could not parse imageRef from request.")
|
||||
LOG.debug(msg)
|
||||
return faults.Fault(exc.HTTPBadRequest(explanation=msg))
|
||||
|
||||
image_id = common.get_id_from_href(image_ref)
|
||||
image_id = common.get_id_from_href(image_href)
|
||||
personalities = info["rebuild"].get("personality", [])
|
||||
metadata = info["rebuild"].get("metadata", {})
|
||||
|
||||
|
||||
@@ -131,10 +131,10 @@ class ViewBuilderV11(ViewBuilder):
|
||||
|
||||
def _build_image(self, response, inst):
|
||||
if 'image_id' in dict(inst):
|
||||
image_ref = inst['image_id']
|
||||
if str(image_ref).isdigit():
|
||||
image_ref = int(image_ref)
|
||||
response['imageRef'] = image_ref
|
||||
image_href = inst['image_id']
|
||||
if str(image_href).isdigit():
|
||||
image_href = int(image_href)
|
||||
response['imageRef'] = image_href
|
||||
|
||||
def _build_flavor(self, response, inst):
|
||||
if "instance_type" in dict(inst):
|
||||
|
||||
@@ -130,7 +130,7 @@ class API(base.Base):
|
||||
raise quota.QuotaError(msg, "MetadataLimitExceeded")
|
||||
|
||||
def create(self, context, instance_type,
|
||||
image_ref, kernel_id=None, ramdisk_id=None,
|
||||
image_href, kernel_id=None, ramdisk_id=None,
|
||||
min_count=1, max_count=1,
|
||||
display_name='', display_description='',
|
||||
key_name=None, key_data=None, security_group='default',
|
||||
@@ -157,7 +157,7 @@ class API(base.Base):
|
||||
self._check_metadata_properties_quota(context, metadata)
|
||||
self._check_injected_file_quota(context, injected_files)
|
||||
|
||||
(image_service, image_id) = nova.image.get_image_service(image_ref)
|
||||
(image_service, image_id) = nova.image.get_image_service(image_href)
|
||||
image = image_service.show(context, image_id)
|
||||
|
||||
os_type = None
|
||||
@@ -201,7 +201,7 @@ class API(base.Base):
|
||||
|
||||
base_options = {
|
||||
'reservation_id': utils.generate_uid('r'),
|
||||
'image_id': image_ref,
|
||||
'image_id': image_href,
|
||||
'kernel_id': kernel_id or '',
|
||||
'ramdisk_id': ramdisk_id or '',
|
||||
'state': 0,
|
||||
|
||||
@@ -284,7 +284,7 @@ class DiskNotFound(NotFound):
|
||||
|
||||
|
||||
class InvalidImageRef(Invalid):
|
||||
message = _("Invalid image ref %(image_ref)s.")
|
||||
message = _("Invalid image ref %(image_href)s.")
|
||||
|
||||
|
||||
class ImageNotFound(NotFound):
|
||||
|
||||
@@ -28,14 +28,14 @@ from nova import flags
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
def _parse_image_ref(image_ref):
|
||||
def _parse_image_ref(image_href):
|
||||
"""Parse an image href into composite parts.
|
||||
|
||||
:param image_ref: href of an image
|
||||
:param image_href: href of an image
|
||||
:returns: a tuple of the form (image_id, host, port)
|
||||
|
||||
"""
|
||||
o = urlparse(image_ref)
|
||||
o = urlparse(image_href)
|
||||
port = o.port or 80
|
||||
host = o.netloc.split(':', 1)[0]
|
||||
image_id = int(o.path.split('/')[-1])
|
||||
@@ -47,25 +47,25 @@ def get_default_image_service():
|
||||
return ImageService()
|
||||
|
||||
|
||||
def get_image_service(image_ref):
|
||||
"""Get the proper image_service and id for the given image_ref.
|
||||
def get_image_service(image_href):
|
||||
"""Get the proper image_service and id for the given image_href.
|
||||
|
||||
The image_ref param can be an href of the form
|
||||
The image_href param can be an href of the form
|
||||
http://myglanceserver:9292/images/42, or just an int such as 42. If the
|
||||
image_ref is an int, then the default image service is returned.
|
||||
image_href is an int, then the default image service is returned.
|
||||
|
||||
:param image_ref: image ref/id for an image
|
||||
:param image_href: image ref/id for an image
|
||||
:returns: a tuple of the form (image_service, image_id)
|
||||
|
||||
"""
|
||||
image_ref = image_ref or 0
|
||||
if str(image_ref).isdigit():
|
||||
return (get_default_image_service(), int(image_ref))
|
||||
image_href = image_href or 0
|
||||
if str(image_href).isdigit():
|
||||
return (get_default_image_service(), int(image_href))
|
||||
|
||||
try:
|
||||
(image_id, host, port) = _parse_image_ref(image_ref)
|
||||
(image_id, host, port) = _parse_image_ref(image_href)
|
||||
except:
|
||||
raise exception.InvalidImageRef(image_ref=image_ref)
|
||||
raise exception.InvalidImageRef(image_href=image_href)
|
||||
glance_client = nova.image.glance.GlanceClient(host, port)
|
||||
image_service = nova.image.glance.GlanceImageService(glance_client)
|
||||
return (image_service, image_id)
|
||||
|
||||
@@ -584,12 +584,12 @@ class ServersTest(test.TestCase):
|
||||
def test_create_instance_v1_1(self):
|
||||
self._setup_for_create_instance()
|
||||
|
||||
image_ref = 'http://localhost/v1.1/images/2'
|
||||
image_href = 'http://localhost/v1.1/images/2'
|
||||
flavor_ref = 'http://localhost/v1.1/flavors/3'
|
||||
body = {
|
||||
'server': {
|
||||
'name': 'server_test',
|
||||
'imageRef': image_ref,
|
||||
'imageRef': image_href,
|
||||
'flavorRef': flavor_ref,
|
||||
'metadata': {
|
||||
'hello': 'world',
|
||||
@@ -611,16 +611,16 @@ class ServersTest(test.TestCase):
|
||||
self.assertEqual('server_test', server['name'])
|
||||
self.assertEqual(1, server['id'])
|
||||
self.assertEqual(flavor_ref, server['flavorRef'])
|
||||
self.assertEqual(image_ref, server['imageRef'])
|
||||
self.assertEqual(image_href, server['imageRef'])
|
||||
self.assertEqual(res.status_int, 200)
|
||||
|
||||
def test_create_instance_v1_1_bad_href(self):
|
||||
self._setup_for_create_instance()
|
||||
|
||||
image_ref = 'http://localhost/v1.1/images/asdf'
|
||||
image_href = 'http://localhost/v1.1/images/asdf'
|
||||
flavor_ref = 'http://localhost/v1.1/flavors/3'
|
||||
body = dict(server=dict(
|
||||
name='server_test', imageRef=image_ref, flavorRef=flavor_ref,
|
||||
name='server_test', imageRef=image_href, flavorRef=flavor_ref,
|
||||
metadata={'hello': 'world', 'open': 'stack'},
|
||||
personality={}))
|
||||
req = webob.Request.blank('/v1.1/servers')
|
||||
@@ -633,12 +633,12 @@ class ServersTest(test.TestCase):
|
||||
def test_create_instance_v1_1_local_href(self):
|
||||
self._setup_for_create_instance()
|
||||
|
||||
image_ref = 2
|
||||
image_id = 2
|
||||
flavor_ref = 'http://localhost/v1.1/flavors/3'
|
||||
body = {
|
||||
'server': {
|
||||
'name': 'server_test',
|
||||
'imageRef': image_ref,
|
||||
'imageRef': image_id,
|
||||
'flavorRef': flavor_ref,
|
||||
},
|
||||
}
|
||||
@@ -653,7 +653,7 @@ class ServersTest(test.TestCase):
|
||||
server = json.loads(res.body)['server']
|
||||
self.assertEqual(1, server['id'])
|
||||
self.assertEqual(flavor_ref, server['flavorRef'])
|
||||
self.assertEqual(image_ref, server['imageRef'])
|
||||
self.assertEqual(image_id, server['imageRef'])
|
||||
self.assertEqual(res.status_int, 200)
|
||||
|
||||
def test_create_instance_with_admin_pass_v1_0(self):
|
||||
@@ -680,12 +680,12 @@ class ServersTest(test.TestCase):
|
||||
def test_create_instance_with_admin_pass_v1_1(self):
|
||||
self._setup_for_create_instance()
|
||||
|
||||
image_ref = 'http://localhost/v1.1/images/2'
|
||||
image_href = 'http://localhost/v1.1/images/2'
|
||||
flavor_ref = 'http://localhost/v1.1/flavors/3'
|
||||
body = {
|
||||
'server': {
|
||||
'name': 'server_test',
|
||||
'imageRef': image_ref,
|
||||
'imageRef': image_href,
|
||||
'flavorRef': flavor_ref,
|
||||
'adminPass': 'testpass',
|
||||
},
|
||||
@@ -702,12 +702,12 @@ class ServersTest(test.TestCase):
|
||||
def test_create_instance_with_empty_admin_pass_v1_1(self):
|
||||
self._setup_for_create_instance()
|
||||
|
||||
image_ref = 'http://localhost/v1.1/images/2'
|
||||
image_href = 'http://localhost/v1.1/images/2'
|
||||
flavor_ref = 'http://localhost/v1.1/flavors/3'
|
||||
body = {
|
||||
'server': {
|
||||
'name': 'server_test',
|
||||
'imageRef': image_ref,
|
||||
'imageRef': image_href,
|
||||
'flavorRef': flavor_ref,
|
||||
'adminPass': '',
|
||||
},
|
||||
@@ -1658,7 +1658,7 @@ b25zLiINCg0KLVJpY2hhcmQgQmFjaA==""",
|
||||
request = self.deserializer.deserialize(serial_request)
|
||||
self.assertEqual(request, expected)
|
||||
|
||||
def test_request_xmlser_with_flavor_image_ref(self):
|
||||
def test_request_xmlser_with_flavor_image_href(self):
|
||||
serial_request = """
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1"
|
||||
name="new-server-test"
|
||||
|
||||
@@ -208,16 +208,16 @@ class _IntegratedTestBase(test.TestCase):
|
||||
LOG.debug("Image: %s" % image)
|
||||
|
||||
if 'imageRef' in image:
|
||||
image_ref = image['imageRef']
|
||||
image_href = image['imageRef']
|
||||
else:
|
||||
# NOTE(justinsb): The imageRef code hasn't yet landed
|
||||
LOG.warning("imageRef not yet in images output")
|
||||
image_ref = image['id']
|
||||
image_href = image['id']
|
||||
|
||||
image_ref = 'http://fake.server/%s' % image_ref
|
||||
image_href = 'http://fake.server/%s' % image_href
|
||||
|
||||
# We now have a valid imageId
|
||||
server['imageRef'] = image_ref
|
||||
server['imageRef'] = image_href
|
||||
|
||||
# Set a valid flavorId
|
||||
flavor = self.api.get_flavors()[0]
|
||||
|
||||
@@ -302,7 +302,7 @@ class CloudTestCase(test.TestCase):
|
||||
def test_console_output(self):
|
||||
instance_type = FLAGS.default_instance_type
|
||||
max_count = 1
|
||||
kwargs = {'image_ref': 'ami-1',
|
||||
kwargs = {'image_href': 'ami-1',
|
||||
'instance_type': instance_type,
|
||||
'max_count': max_count}
|
||||
rv = self.cloud.run_instances(self.context, **kwargs)
|
||||
@@ -318,7 +318,7 @@ class CloudTestCase(test.TestCase):
|
||||
greenthread.sleep(0.3)
|
||||
|
||||
def test_ajax_console(self):
|
||||
kwargs = {'image_ref': 'ami-1'}
|
||||
kwargs = {'image_href': 'ami-1'}
|
||||
rv = self.cloud.run_instances(self.context, **kwargs)
|
||||
instance_id = rv['instancesSet'][0]['instanceId']
|
||||
greenthread.sleep(0.3)
|
||||
|
||||
@@ -150,7 +150,7 @@ class ComputeTestCase(test.TestCase):
|
||||
ref = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=instance_types.get_default_instance_type(),
|
||||
image_ref=None,
|
||||
image_href=None,
|
||||
security_group=['testgroup'])
|
||||
try:
|
||||
self.assertEqual(len(db.security_group_get_by_instance(
|
||||
@@ -168,7 +168,7 @@ class ComputeTestCase(test.TestCase):
|
||||
ref = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=instance_types.get_default_instance_type(),
|
||||
image_ref=None,
|
||||
image_href=None,
|
||||
security_group=['testgroup'])
|
||||
try:
|
||||
db.instance_destroy(self.context, ref[0]['id'])
|
||||
@@ -184,7 +184,7 @@ class ComputeTestCase(test.TestCase):
|
||||
ref = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=instance_types.get_default_instance_type(),
|
||||
image_ref=None,
|
||||
image_href=None,
|
||||
security_group=['testgroup'])
|
||||
|
||||
try:
|
||||
|
||||
@@ -201,7 +201,7 @@ class QuotaTestCase(test.TestCase):
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
instance_type=inst_type,
|
||||
image_ref=1)
|
||||
image_href=1)
|
||||
for instance_id in instance_ids:
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
@@ -215,7 +215,7 @@ class QuotaTestCase(test.TestCase):
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
instance_type=inst_type,
|
||||
image_ref=1)
|
||||
image_href=1)
|
||||
for instance_id in instance_ids:
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
@@ -271,7 +271,7 @@ class QuotaTestCase(test.TestCase):
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
instance_type=inst_type,
|
||||
image_ref='fake',
|
||||
image_href='fake',
|
||||
metadata=metadata)
|
||||
|
||||
def test_allowed_injected_files(self):
|
||||
@@ -284,14 +284,14 @@ class QuotaTestCase(test.TestCase):
|
||||
api = compute.API(image_service=self.StubImageService())
|
||||
inst_type = instance_types.get_instance_type_by_name('m1.small')
|
||||
api.create(self.context, min_count=1, max_count=1,
|
||||
instance_type=inst_type, image_ref='3',
|
||||
instance_type=inst_type, image_href='3',
|
||||
injected_files=files)
|
||||
|
||||
def test_no_injected_files(self):
|
||||
FLAGS.image_service = 'nova.image.fake.FakeImageService'
|
||||
api = compute.API(image_service=self.StubImageService())
|
||||
inst_type = instance_types.get_instance_type_by_name('m1.small')
|
||||
api.create(self.context, instance_type=inst_type, image_ref='3')
|
||||
api.create(self.context, instance_type=inst_type, image_href='3')
|
||||
|
||||
def test_max_injected_files(self):
|
||||
files = []
|
||||
|
||||
@@ -32,12 +32,12 @@ FLAGS = flags.FLAGS
|
||||
LOG = logging.getLogger('nova.virt.images')
|
||||
|
||||
|
||||
def fetch(image_ref, path, _user, _project):
|
||||
def fetch(image_href, path, _user, _project):
|
||||
# TODO(vish): Improve context handling and add owner and auth data
|
||||
# when it is added to glance. Right now there is no
|
||||
# auth checking in glance, so we assume that access was
|
||||
# checked before we got here.
|
||||
(image_service, image_id) = nova.image.get_image_service(image_ref)
|
||||
(image_service, image_id) = nova.image.get_image_service(image_href)
|
||||
with open(path, "wb") as image_file:
|
||||
elevated = context.get_admin_context()
|
||||
metadata = image_service.get(elevated, image_id, image_file)
|
||||
|
||||
@@ -442,7 +442,7 @@ class LibvirtConnection(driver.ComputeDriver):
|
||||
virt_dom.detachDevice(xml)
|
||||
|
||||
@exception.wrap_exception
|
||||
def snapshot(self, instance, image_ref):
|
||||
def snapshot(self, instance, image_href):
|
||||
"""Create snapshot from a running VM instance.
|
||||
|
||||
This command only works with qemu 0.14+, the qemu_img flag is
|
||||
@@ -460,7 +460,7 @@ class LibvirtConnection(driver.ComputeDriver):
|
||||
metadata = {'disk_format': base['disk_format'],
|
||||
'container_format': base['container_format'],
|
||||
'is_public': False,
|
||||
'name': '%s.%s' % (base['name'], image_ref),
|
||||
'name': '%s.%s' % (base['name'], image_href),
|
||||
'properties': {'architecture': base['architecture'],
|
||||
'kernel_id': instance['kernel_id'],
|
||||
'image_location': 'snapshot',
|
||||
@@ -503,7 +503,7 @@ class LibvirtConnection(driver.ComputeDriver):
|
||||
# Upload that image to the image service
|
||||
with open(out_path) as image_file:
|
||||
image_service.update(elevated,
|
||||
image_ref,
|
||||
image_href,
|
||||
metadata,
|
||||
image_file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user