Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific image versions directly for virtual machines #808

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,8 @@ def exec_module(self, **kwargs):

if self.image and isinstance(self.image, dict):
if all(key in self.image for key in ('publisher', 'offer', 'sku', 'version')):
marketplace_image = self.get_marketplace_image_version()

if self.image['version'] == 'latest':
self.image['version'] = marketplace_image.name
self.image['version'] = self.get_latest_marketplace_image_version()
self.log("Using image version {0}".format(self.image['version']))

image_reference = self.compute_models.ImageReference(
Expand Down Expand Up @@ -2034,7 +2032,7 @@ def delete_vm_storage(self, vhd_uris):
self.fail("Error deleting blob {0}:{1} - {2}".format(container_name, blob_name, str(exc)))
return True

def get_marketplace_image_version(self):
def get_latest_marketplace_image_version(self):
try:
versions = self.compute_client.virtual_machine_images.list(self.location,
self.image['publisher'],
Expand All @@ -2048,11 +2046,7 @@ def get_marketplace_image_version(self):
self.image['sku'],
str(exc)))
if versions and len(versions) > 0:
if self.image['version'] == 'latest':
return versions[len(versions) - 1]
for version in versions:
if version.name == self.image['version']:
return version
return versions[len(versions) - 1].name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If version is specified and cannot be obtained through the first one, the PR function is similar to #767. Thank you very much!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my changes the version lookup will only happen when "latest" is used. Otherwise the user specified version is used directly. I think it doesn't make much sense to get all versions of an image to check if the specified version is listed or not.


self.fail("Error could not find image {0} {1} {2} {3}".format(self.image['publisher'],
self.image['offer'],
Expand Down