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

[Hyper-V Extension] Add ability for the Hyper-V extension to create VMs from the VM gallery #2438

Merged
merged 4 commits into from
Mar 26, 2024

Conversation

bbonaby
Copy link
Contributor

@bbonaby bbonaby commented Mar 20, 2024

Summary of the pull request

This PR adds creation to the Hyper-V extension. For V1 we're utilizing the images within the Hyper-V VM gallery. These images are hosted by microsoft and can be located here: https://go.microsoft.com/fwlink/?linkid=851584. The following was added to the extension:

  1. The Hyper-V extension now uses the IHttpFactory to create and use the .Net HttpClient for its interactions with the web. E.g Downloading the image icon json and the disk images.
  2. A DownloaderService was added to handle downloading disk images from the VM gallery
  3. An ArchiveProviderFactory was created to allow us to uses different archiving solutions depending on the extension of the archive
  4. Added a VMGalleryService to handle things related to the VM gallery itself
  5. The Hyper-V Provider now supports creation and returns a VMGalleryVMCreationOperation that implements Dev Home's ICreateComputeSystem interface and a supplemental factory delegate was created to help with the creation of this operation.
  6. Various Classes were created to represent data in the Json we receive from the VM Gallery. These are used to serialize and deserialize contents within the gallery easier

The flow is the following:

  • Dev Home calls the Providers CreateCreateComputeSystemOperation method with input from the user. Which returns an ICreateComputeSystemOperation (Our VMGalleryVMCreationOperation).
  • Dev Home attaches its progress handlers
  • Dev Home Calls the interfaces StartAsync method which starts the asynchronous operation.
    • The VMGalleryVMCreationOperation uses the VMGalleryService to retrieve the VM Gallery Json from the Web if the extension has not already done so yet
    • It then starts the download of the user selected image from the gallery (if it does not exist). The images are contained within a zip file. Each downloadable item in the gallery Json contains a sha256 hash, which we can use as a checksum, to confirm the contents of the file have not been tampered with.
      • If the file exists and the hash of the file does not match the hash provided by the gallery we remove the file.
      • If the file exists and the hash is valid we reuse the file.
    • If the file doesn't exist we download the file and place it into the users local appdata temp folder.
    • We check the hash of the newly downloaded file to confirm it matches the hash given by the gallery. If it doesn't we stop the creation process
    • Next we extract the virtual disk file from the archive file, giving the virtual disk file a name provided by the user and place it in the Hyper-V Hosts default virtual disk path
    • Next we use our HyperVManager service to create the VM
    • If all of this succeeds we return the virtual machine object back to Dev Home with the CreateComputeSystemResult's provider status set to success
    • For failures we use the failure constructor and send this back to Dev Home.

References and relevant issues

Detailed description of the pull request / Additional comments

Validation steps performed

Note When I add the UX code to Dev Home, I intend to update this so the User can cancel the operation.
I also noted that some of the unit tests are broken, but will fix in a subsequent PR.

I added new unit tests and an integration test to confirm this is all working as intended.

PR checklist

@bbonaby bbonaby force-pushed the user/bbonaby/add-hyper-v-creation branch from f1be31d to 249da9d Compare March 20, 2024 16:18
@bbonaby bbonaby marked this pull request as ready for review March 20, 2024 17:11
@kanismohammed kanismohammed self-requested a review March 26, 2024 00:22
@bbonaby bbonaby merged commit 78d0fb7 into main Mar 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Hyper-V Extension] Add ability for the Hyper-V extension to create VMs from the VM gallery
4 participants