Support booting cloud-images by name or id

The docs say we support this, but the code doesn't.

Also, self._cloud_image.name == self._label._cloud_image and is
essentially a foreign key. That's hard to read at the call site, so just
use self._cloud_image.

We have a cloud id if it's a disk image- so wrap that in a dict. Pass
the other one through unmodified so that we'll search for it.

We also don't have any codepaths using image_name, nor a reason to
distinguish.

Change-Id: I4aa9bd8e7c578ae63d05df453b9886c710a092c0
This commit is contained in:
Monty Taylor 2017-06-10 08:49:43 -05:00
parent a0159428d7
commit 8c59361032
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 15 additions and 9 deletions

View File

@ -277,7 +277,7 @@ class NodeLauncher(threading.Thread, StatsReporter):
)
config_drive = self._diskimage.config_drive
image_external_id = cloud_image.external_id
image_external = dict(id=cloud_image.external_id)
image_id = "{path}/{upload_id}".format(
path=self._zk._imageUploadPath(cloud_image.image_name,
cloud_image.build_id,
@ -288,8 +288,14 @@ class NodeLauncher(threading.Thread, StatsReporter):
else:
# launch using unmanaged cloud image
config_drive = self._cloud_image.config_drive
image_external_id = self._label.cloud_image
image_id = self._label.cloud_image
# These are different values for zk, but it's all the same
# for cloud-images.
# image_external is what we use for OpenStack.
# image_id is what we record in the node for zk.
# image_name is what we log, so matches the config.
image_external = self._cloud_image.name
image_id = self._cloud_image.name
image_name = self._cloud_image.name
hostname = self._provider.hostname_format.format(
@ -308,7 +314,7 @@ class NodeLauncher(threading.Thread, StatsReporter):
server = self._manager.createServer(
hostname,
image_id=image_external_id,
image=image_external,
min_ram=self._label.min_ram,
flavor_name=self._label.flavor_name,
key_name=self._label.key_name,

View File

@ -185,17 +185,17 @@ class ProviderManager(object):
with shade_inner_exceptions():
return self._client.delete_image(name)
def createServer(self, name, image_id=None, image_name=None,
def createServer(self, name, image,
flavor_name=None, min_ram=None,
az=None, key_name=None, config_drive=True,
nodepool_node_id=None, nodepool_image_name=None,
networks=None, boot_from_volume=False, volume_size=50):
if not networks:
networks = []
if image_name:
image = self.findImage(image_name)
else:
image = {'id': image_id}
if not isinstance(image, dict):
# if it's a dict, we already have the cloud id. If it's not,
# we don't know if it's name or ID so need to look it up
image = self.findImage(image)
flavor = self.findFlavor(flavor_name=flavor_name, min_ram=min_ram)
create_args = dict(name=name,
image=image,