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

Allow creating gallery image versions from storage accounts #1466

Merged
merged 4 commits into from
Jun 11, 2024

Conversation

jeremycline
Copy link
Contributor

SUMMARY

It's possible to upload a VHD into a container in a storage account and then use that to import an image version. This adds a third way to specify an os_disk in the galleryimageversion plugin to support that approach.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

galleryimageversion

os_disk:
resource_group: myResourceGroup
storage_account: myStorageAccount
uri: "https://myStorageAccount.blob.core.windows.net/myContainer/myImage.vhd"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized after writing this that we could construct the URI by accepting two additional arguments, the container_name and blob_name, but I'm not sure if folks would prefer that two dropping the URI in there.

@@ -561,7 +586,7 @@ def exec_module(self, **kwargs):
elif isinstance(kwargs[key]['os_disk']['source'], dict):
if kwargs[key]['os_disk']['source'].get('id') is not None:
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = kwargs[key]['os_disk']['source'].get('id')
if kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
elif kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was a bug, I'm happy to pull it out into a separate commit/PR if folks would prefer that.

- Reference to os disk snapshot.
- Could be resource ID.
- Could be a dictionary containing I(resource_group) and I(name).
- Could be a dictionary containing I(resource_group), I(storage_account), and I(uri) if the snapshot is stored as a PageBlob in a storage account container.
Copy link
Collaborator

Choose a reason for hiding this comment

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

line too long

@@ -561,7 +586,7 @@ def exec_module(self, **kwargs):
elif isinstance(kwargs[key]['os_disk']['source'], dict):
if kwargs[key]['os_disk']['source'].get('id') is not None:
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = kwargs[key]['os_disk']['source'].get('id')
if kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
elif kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
kwargs[key]['os_disk']['source'].get('name') is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

@@ -570,6 +595,18 @@ def exec_module(self, **kwargs):
resource_group +
'/providers/Microsoft.Compute/snapshots/' +
kwargs[key]['os_disk']['source'].get('name'))
elif kwargs[key]['os_disk']['source'].get('uri') is not None and \
kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
Copy link
Collaborator

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

@@ -570,6 +595,18 @@ def exec_module(self, **kwargs):
resource_group +
'/providers/Microsoft.Compute/snapshots/' +
kwargs[key]['os_disk']['source'].get('name'))
elif kwargs[key]['os_disk']['source'].get('uri') is not None and \
kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
kwargs[key]['os_disk']['source'].get('storage_account') is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

self.subscription_id +
'/resourceGroups/' +
resource_group +
'/providers/Microsoft.Storage/storageAccounts/' +
Copy link
Collaborator

Choose a reason for hiding this comment

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

line too long

@jeremycline
Copy link
Contributor Author

Hi, thanks for the review!

I attempted to address the style comments. If it's still not looking right, is there a style guide for the project I should follow, or a linter? I did my best to follow the existing style of the file.

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

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

Update test case! Thank you very much!

- name: East US
regional_replica_count: 1
storage_account_type: Standard_LRS
storage_profile:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Parameter definition sequence: storage_profile -> os_disk -> source -> uri

os_disk_image:
disk_encryption_set_id: "{{ des_results.state.id }}"
storage_account_type: Standard_ZRS
storage_profile:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Parameter definition sequence: storage_profile -> os_disk -> source -> uri


383     storage_profile:
384       os_disk:
385         source:
386           resource_group: "{{ resource_group }}"
387           storage_account: '{{ vms_output.vms[0].storage_account_name }}'
388           uri: 'https://{{ vms_output.vms[0].storage_account_name }}.blob.core.windows.net/{{ vms_output.vms[0].stor    age_container_name }}/{{ vms_output.vms[0].storage_blob_name }}'

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jeremycline The output variable on line 377 should be the one obtained by the VM on line 108. But lines 108 through 380 also register other output variables. So should pay attention to 120, 377, 378 this variable value acquisition! Thank you very much!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, it's being shadowed. My Ansible is very rusty, sorry. I think I've fixed it.

@Fred-sun Fred-sun added question Further information is requested medium_priority Medium priority work in In trying to solve, or in working with contributors labels Feb 29, 2024
@jeremycline
Copy link
Contributor Author

I think this should be ready for a re-review (time permitting, of course). We're using this in some automation in Fedora so I'd love it to be in the next release if possible. Thanks!

@jeremycline
Copy link
Contributor Author

Hi @Fred-sun,

Just wanted to check in if there's anything I can do to help move this along - we've been carrying this patch to upload Fedora images nightly for a couple months and it's been working fine, for what it's worth.

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jun 4, 2024

@jeremycline Ok, I will finish the PR review today. Thank you!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jun 4, 2024

@jeremycline Is the location of your test case improperly arranged? It is between line 307 and 387. Should we create a new name of galleryimageversion?

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jun 4, 2024

@jeremycline In addition, after the completion of the test, please delete the newly created galleryimage, otherwise there will be problems when deleting the gallery. Thank you!

It's possible to upload a VHD into a container in a storage account and
then use that to import an image version. This adds a third way to
specify an `os_disk` in the galleryimageversion plugin to support that
approach.
There's no functional change.
Add the missing "source" intermediate key in the example and test case,
and ensure the VM information isn't shadowed by later steps.
This also removes the image version at the end so the gallery can be
deleted.
@jeremycline
Copy link
Contributor Author

Thanks for the review!

I've given the image version a different name and ensured it's deleted with the other image version.

@Fred-sun
Copy link
Collaborator

Fred-sun commented Jun 5, 2024

@jeremycline Thanks for your update! I will recheck it and push for merged!

@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged and removed work in In trying to solve, or in working with contributors labels Jun 5, 2024
@xuzhang3 xuzhang3 merged commit 0acfac2 into ansible-collections:dev Jun 11, 2024
@jeremycline jeremycline deleted the image-version-from-vhd branch June 11, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority question Further information is requested ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants