Open bbonaby opened 11 months ago
FYI @PlagueHO
Thanks @bbonaby - love it!
We should probably combine the folder
and filename
parameters together because they would both need to be considered the key for the resource (otherwise you wouldn't be able to create two virtual disks in the same folder). Also, good to be explicit about the file extension and assume that if it is not included then the resource won't add it.
We should also add an Ensure
parameter to enable detachment and removal of a VHD if it shouldn't exist - e.g. See example here: https://github.com/dsccommunity/StorageDsc/wiki/MountImage
updated the issue to reflect whats in the PR now.
Resource proposal
Currently there is no way to create a standalone virtual disk in PowerShell on Windows client machines outside of using the New-VHD cmdlet. The problem with New-VHD is that its needs the Hyper-V feature enabled in Windows. For machines without this feature enabled like freshly installed Windows client boxes, this feature isn't enabled by default and enabling it would require a reboot. We should be able to create a virtual disk just like using the legacy disk management tool using DSC without this requirement.
Another way to create a virtual disk in PowerShell is to use the New-VirtualDisk cmdlet. However, this attempts to create a virtual disk in a storage pool and a requirement for storage pools is that two or more separate disks other than the disk Windows is installed on needs to be available. Another issue is that the disks in question have to have their 'Can-pool' flag set to true, which isn't always the case, and a destructive operation may be required to achieve this.
I suggest we create a DSC that utilizes a generic way that does not utilize these methods. Here are some requirements I believe the initial Vhd resource should have:
I believe utilizing the win32 api's CreateVirtualDisk and AttachVirtualDisk is simple for this job. We can have a new virtual disk powershell function and an Add function to attach them. Inside both we would just use imported C# using the add-type cmdlet. The C# code would just have the win32 imported functions, structs and enums needed to achieve this. I've prototyped this in this forked branch
The Purpose of the resource would be to ensure that a virtual disk with parameters from 'a' to 'd' is created. We don't need to add a detach methods because that can be done via DSC_MountImage. The difference here is that the virtual disk is created and mounted at the same time, with the added benefit of allowing for the auto attach capability.
example of how the resource would work:
Proposed properties
Special considerations or limitations
Something to consider is that if the virtual disk file is dismounted from the system and moved to a different location. The DSC would likely create a new one. This is the nature of the virtual disk being a file that is portable.