Refactor to Sampler/DSC Community layout and expand REST v0 coverage#14
Open
rcfmartin wants to merge 403 commits into
Open
Refactor to Sampler/DSC Community layout and expand REST v0 coverage#14rcfmartin wants to merge 403 commits into
rcfmartin wants to merge 403 commits into
Conversation
…b on lookup failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why the refactor
I use this module in my home lab and at work, so rather than build a new module from scratch, I decided to fork this one and contribute the work back to the community.
Heads-up: this is a big PR, and I'm sorry about that. I need this to be production-ready where I'm running it, which meant bringing the whole repo up to the DSC Community style guidelines in one pass rather than chipping away at it piecemeal. The diff is large, but the individual commits are small and narrowly scoped (one file each, one-line messages), so I tried to make it easier to digest. Also, I tried to follow patterns that were already there as much as possible.
The original module stuffed every function into a handful of big
src/<topic>.ps1files. That works, but it makes it harder to review changes, add tests, and plug the repo into a standard build pipeline. Moving to the layout Sampler scaffolds, which matches the DSC Community guidelines above, gives us:src/formats/*.ps1xmland registered in the manifest,tests/Unit/,Invoke-Build-basedbuild.ps1plusbuild.yamlso ResolveDependency / Build / Test / Publish are all one-liners.Building the module
First time on a fresh checkout, let Sampler bootstrap its own dependencies:
That drops the tooling (PSDepend, InvokeBuild, Pester, ModuleBuilder, etc.) into
./output/RequiredModules/. After that,./build.ps1on its own runs the full build and test pipeline. The built module ends up under./output/module/xo-powershell/<version>/, so you can import it directly for local testing:Documentation generation
The build also uses PlatyPS to keep the cmdlet documentation in sync. During a normal
./build.ps1run PlatyPS reads each cmdlet's comment-based help and regenerates the matchingdocs/*.mdandabout_*.help.txtfiles, so everything underdocs/is a build artefact so nobody needs to hand-edit it.Publishing to the PowerShell Gallery
build.yamlalready has apublishtask list set up:Once you're happy with the build output, you can wire
./build.ps1 -Tasks publishinto a pipeline (Azure Pipelines, GitHub Actions, whatever you prefer) and it'll:publish_module_to_gallery.All the pipeline needs is a
GalleryApiKey(orNuGetApiKey) secret plus aGitHubToken, then two steps:./build.ps1 -ResolveDependencyfollowed by./build.ps1 -Tasks publishon your release branch or tag. No more source changes required.Module layout
src/went from a handful of multi-function files to the standard Sampler layout:src/Public/*.ps1src/Private/*.ps1ConvertTo-Xo*Object,ConvertFrom-Xo*, internal helperssrc/formats/*.ps1xmlFormatsToProcesstests/Unit/Private/*.tests.ps1Cmdlet coverage
After the audit, the module covers more than 170 swagger endpoints. Verb breakdown:
GetExportSetConnect/DisconnectRemoveInvokeNewStop/ImportFixes to pre-existing code
Set-Xo*cmdlets (Host,Network,Pif,Pool,Sr,Vdi,Vif,Vm) were hittingPATCH /resource/{id}endpoints that the current XO REST API doesn't expose. Each one now emits aWrite-Warningexplaining the limitation and keeps its existing signature so nothing breaks for anyone still calling them.Get-XoPoolVmandGet-XoSrVdi— the/pools/{id}/vmsand/srs/{id}/vdisGETs don't exist either; both now delegate toGet-XoVm -PoolUuid/Get-XoVdi -SrUuid.Start-XoSchedule— uses the canonical/schedules/{id}/actions/runpath (was/schedules/{id}/run).Invoke-XoPoolAction— two bugs fixed. The URI interpolation was treating$Action?sync=as a null-conditional expression and collapsing the action name, and the body was being sent withoutContent-Type: application/json, so XO couldn't parse it. JSON bodies now go out as UTF-8 bytes with the right header, and the response handler normalises task-href strings, bare task ids, and{id: …}objects back into anXoPowershell.TasksoNew-XoVm | Wait-XoTaskworks the way you'd expect.Get-XoEventSubscriptionwas removed — the REST API has no GET variant for subscriptions.VmUuid,TaskId,HostUuid, …) in nine format files.Format-Tableno longer shows a column labeledIDthat you can't actually address by property.Help quality
.SYNOPSIS,.DESCRIPTION(> 40 chars), a.PARAMETERentry per parameter (> 25 chars each), and at least one realistic.EXAMPLE.Get-Xo<Parent><Child>) got new help text with friendlier resource names and a pipeline example.Disable-XoHostnotes existing VMs keep running).Set-Xo*which replaces the whole tag list.Testing
ConvertTo-Xo*Object,ConvertFrom-Xo*,Set-XoObject,Format-XoSize,Invoke-XoRestMethod, andInvoke-XoPoolActionhelper has its own spec, with realistic input cribbed from the swagger examples.Known limitations (documented, not blockers)
Set-XoVm/Set-XoHost/ etc. until XO brings the PATCH endpoints back; the deprecation warnings are already in place.Get-XoUserAuthenticationTokenandNew-XoUserAuthenticationTokenonly work against the authenticated user's own account. Admin-targeted token ops return 403 from XO.VBDREST endpoint has no DELETE, so we useDisconnect-XoVbdfor cleanup, which is consistent with how VBDs get unplugged in XO.