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

New-LabVM #40

Merged
merged 28 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6042e0f
Initial quick VM implementation
iainbrighton Nov 27, 2015
e9c7351
Removes hard-coded module name
iainbrighton Dec 2, 2015
fa678a4
Merge branch 'dev' of https://github.com/VirtualEngine/Lab into Issue29
iainbrighton Dec 9, 2015
5d02fef
Adds LabVMDefaults parameters to New-LabQuickVM
iainbrighton Dec 9, 2015
65c9d53
Merge branch 'dev' into Issue29
iainbrighton Dec 13, 2015
9bf328a
Renames Set/Get-LabVMDefaults to Set/Get-LabVMDefault
iainbrighton Dec 13, 2015
fa25b2c
Renames New-LabQuickVM to New-LabVM
iainbrighton Dec 13, 2015
46431d2
Converts to space indentation
iainbrighton Dec 14, 2015
0c75a12
Adds additional debugging information
iainbrighton Dec 15, 2015
ed27751
Updates New-LabVM help and adds multiple switch support
iainbrighton Dec 16, 2015
ddcdfe3
Merge branch 'dev' into Issue29
iainbrighton Dec 16, 2015
867a776
Adds Remove-LabVM function
iainbrighton Dec 16, 2015
0a20e1e
Adds bootstrapping back into the Quick VM functionality to enable adm…
iainbrighton Dec 17, 2015
1c5d9db
Formatting changes
iainbrighton Dec 22, 2015
2468eff
Adds CustomBootstrapOrder and ShouldProcess attribute to Set-LabVMDef…
iainbrighton Dec 22, 2015
4addd01
Adds CustomBootstrap for bundled client OS media
iainbrighton Dec 22, 2015
e99169d
Adds ShouldProcess to New-LabImage
iainbrighton Dec 22, 2015
74c7f2b
Adds CustomData to New-LabVM
iainbrighton Dec 22, 2015
d2a10cc
Adds CustomBootstrapOrder property to SetLabVMDiskFile
iainbrighton Dec 22, 2015
b22bcfe
Merge branch 'dev' into Issue29
iainbrighton Dec 22, 2015
142e903
Adds ResolveCustomBootstrap function
iainbrighton Dec 30, 2015
d49e932
Fixes bug in Get-LabMedia where custom media was not always coerced i…
iainbrighton Dec 30, 2015
b3e5a39
Adds GetFormattedMessage
iainbrighton Dec 30, 2015
d767072
Updates Example.psd1, removing the custom bootstrap as it's now imple…
iainbrighton Dec 30, 2015
b3c8bdc
Formatting updates
iainbrighton Jan 3, 2016
3cb4e06
Updates test coverage
iainbrighton Jan 3, 2016
6b92577
Merge branch 'dev' into Issue29
iainbrighton Jan 4, 2016
674bdf2
Creates missing Internal switches in New-LabVM
iainbrighton Jan 6, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.sln
*.suo
*.pssproj
.vscode/settings.json
38 changes: 33 additions & 5 deletions Config/Media.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"Microsoft-NanoServer-DNS-Package"
]
},
"Hotfixes": null
"Hotfixes": []
},
{
"Id": "2012R2_x64_Standard_EN_Eval",
Expand Down Expand Up @@ -259,7 +259,14 @@
"Uri": "http://download.microsoft.com/download/B/9/9/B999286E-0A47-406D-8B3D-5B5AD7373A4A/9600.17050.WINBLUE_REFRESH.140317-1640_X64FRE_ENTERPRISE_EVAL_EN-US-IR3_CENA_X64FREE_EN-US_DV9.ISO",
"Checksum": "EE63618E3BE220D86B993C1ABBCF32EB",
"CustomData": {
"WindowsOptionalFeature": ["NetFx3"]
"WindowsOptionalFeature": ["NetFx3"],
"CustomBootstrap": [
"## Unattend.xml will set the Administrator password, but it won't enable the account on client OSes",
"NET USER Administrator /active:yes;",
"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;",
"## Kick-start PowerShell remoting on clients to permit applying DSC configurations",
"Enable-PSRemoting -SkipNetworkProfileCheck -Force;"
]
},
"Hotfixes": [
{
Expand Down Expand Up @@ -302,7 +309,14 @@
"Uri": "http://download.microsoft.com/download/B/9/9/B999286E-0A47-406D-8B3D-5B5AD7373A4A/9600.17050.WINBLUE_REFRESH.140317-1640_X86FRE_ENTERPRISE_EVAL_EN-US-IR3_CENA_X86FREE_EN-US_DV9.ISO",
"Checksum": "B2ACCD5F135C3EEDE256D398856AEEAD",
"CustomData": {
"WindowsOptionalFeature": ["NetFx3"]
"WindowsOptionalFeature": ["NetFx3"],
"CustomBootstrap": [
"## Unattend.xml will set the Administrator password, but it won't enable the account on client OSes",
"NET USER Administrator /active:yes;",
"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;",
"## Kick-start PowerShell remoting on clients to permit applying DSC configurations",
"Enable-PSRemoting -SkipNetworkProfileCheck -Force;"
]
},
"Hotfixes": [
{
Expand Down Expand Up @@ -341,7 +355,14 @@
"Uri": "http://download.microsoft.com/download/C/3/9/C399EEA8-135D-4207-92C9-6AAB3259F6EF/10240.16384.150709-1700.TH1_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO",
"Checksum": "6CD2F47F2C32FAA7BE85F1DC81AF3220",
"CustomData": {
"WindowsOptionalFeature": ["NetFx3"]
"WindowsOptionalFeature": ["NetFx3"],
"CustomBootstrap": [
"## Unattend.xml will set the Administrator password, but it won't enable the account on client OSes",
"NET USER Administrator /active:yes;",
"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;",
"## Kick-start PowerShell remoting on clients to permit applying DSC configurations",
"Enable-PSRemoting -SkipNetworkProfileCheck -Force;"
]
},
"Hotfixes": [ ]
},
Expand All @@ -355,7 +376,14 @@
"Uri": "http://download.microsoft.com/download/C/3/9/C399EEA8-135D-4207-92C9-6AAB3259F6EF/10240.16384.150709-1700.TH1_CLIENTENTERPRISEEVAL_OEMRET_X86FRE_EN-US.ISO",
"Checksum": "5531E6EE40A69E22A7386864A9087CDD",
"CustomData": {
"WindowsOptionalFeature": ["NetFx3"]
"WindowsOptionalFeature": ["NetFx3"],
"CustomBootstrap": [
"## Unattend.xml will set the Administrator password, but it won't enable the account on client OSes",
"NET USER Administrator /active:yes;",
"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;",
"## Kick-start PowerShell remoting on clients to permit applying DSC configurations",
"Enable-PSRemoting -SkipNetworkProfileCheck -Force;"
]
},
"Hotfixes": [ ]
}]
3 changes: 2 additions & 1 deletion Config/VMDefaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"ClientCertificatePath": "%ALLUSERSPROFILE%\\VirtualEngineLab\\Certificates\\LabClient.pfx",
"RootCertificatePath": "%ALLUSERSPROFILE%\\VirtualEngineLab\\Certificates\\LabRoot.cer",
"BootOrder": 99,
"BootDelay": 0
"BootDelay": 0,
"CustomBootstrapOrder": "MediaFirst"
}
55 changes: 55 additions & 0 deletions Lib/BootStrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,58 @@ function SetBootStrap {
Set-Content -Path $bootStrapPath -Value $bootStrap -Encoding UTF8 -Force;
} #end process
} #end function SetBootStrap

function ResolveCustomBootStrap {
<#
.SYNOPSIS
Resolves the media and node custom bootstrap, using the specified CustomBootstrapOrder
#>
[CmdletBinding()]
[OutputType([System.String])]
param (
## Custom bootstrap order
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateSet('ConfigurationFirst','ConfigurationOnly','Disabled','MediaFirst','MediaOnly')]
[System.String] $CustomBootstrapOrder,

## Node/configuration custom bootstrap script
[Parameter(ValueFromPipelineByPropertyName)]
[AllowNull()] [System.String] $ConfigurationCustomBootStrap,

## Media custom bootstrap script
[Parameter(ValueFromPipelineByPropertyName)]
[AllowNull()] [System.String[]] $MediaCustomBootStrap
)
begin {
if ([System.String]::IsNullOrWhiteSpace($ConfigurationCustomBootStrap)) {
$ConfigurationCustomBootStrap = "";
}
## Convert the string[] into a multi-line string
if ($MediaCustomBootstrap) {
$mediaBootstrap = [System.String]::Join("`r`n", $MediaCustomBootStrap);
}
else {
$mediaBootstrap = "";
}
} #end begin
process {
switch ($CustomBootstrapOrder) {
'ConfigurationFirst' {
$bootStrap = "{0}`r`n{1}" -f $ConfigurationCustomBootStrap, $mediaBootstrap;
}
'ConfigurationOnly' {
$bootStrap = $ConfigurationCustomBootStrap;
}
'MediaFirst' {
$bootStrap = "{0}`r`n{1}" -f $mediaBootstrap, $ConfigurationCustomBootStrap;
}
'MediaOnly' {
$bootStrap = $mediaBootstrap;
}
Default {
#Disabled
}
} #end switch
return $bootStrap;
} #end process
} #end function ResolveCustomBootStrap
19 changes: 16 additions & 3 deletions Lib/ConfigurationData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,22 @@ function GetConfigurationData {
$configurationPath = ResolveConfigurationDataPath -Configuration $Configuration -IncludeDefaultPath;
$expandedPath = [System.Environment]::ExpandEnvironmentVariables($configurationPath);
if (Test-Path -Path $expandedPath) {
return Get-Content -Path $expandedPath -Raw | ConvertFrom-Json;
$configurationData = Get-Content -Path $expandedPath -Raw | ConvertFrom-Json;

switch ($Configuration) {
'VM' {
## This property may not be present in the original VM default file TODO: Could be deprecated in the future
if ($configurationData.PSObject.Properties.Name -notcontains 'CustomBootstrapOrder') {
[ref] $null = Add-Member -InputObject $configurationData -MemberType NoteProperty -Name 'CustomBootstrapOrder' -Value 'MediaFirst';
}
}
Default {
## Do nothing
}
} #end switch
return $configurationData;
}
}
} #end process
} #end function GetConfigurationData

function SetConfigurationData {
Expand All @@ -95,7 +108,7 @@ function SetConfigurationData {
$configurationPath = ResolveConfigurationDataPath -Configuration $Configuration;
$expandedPath = [System.Environment]::ExpandEnvironmentVariables($configurationPath);
[ref] $null = NewDirectory -Path (Split-Path -Path $expandedPath -Parent);
Set-Content -Path $expandedPath -Value (ConvertTo-Json -InputObject $InputObject) -Force;
Set-Content -Path $expandedPath -Value (ConvertTo-Json -InputObject $InputObject) -Force -Confirm:$false;
}
} #end function SetConfigurationData

Expand Down
2 changes: 1 addition & 1 deletion Lib/DscResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ImportDscResource {
)
process {
## Check whether the resource is already imported/registered
WriteVerbose ($localized.CheckingDscResource -f $ModuleName, $ResourceName);
Write-Debug ($localized.CheckingDscResource -f $ModuleName, $ResourceName);
$testCommandName = 'Test-{0}TargetResource' -f $Prefix;
if (-not (Get-Command -Name $testCommandName -ErrorAction SilentlyContinue)) {
if ($UseDefault) {
Expand Down
35 changes: 27 additions & 8 deletions Lib/Internal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,59 @@ function InvokeExecutable {
} #end process
} #end function InvokeExecutable

function WriteVerbose {
function GetFormattedMessage {
<#
.SYNOPSIS
Wrapper around Write-Verbose that adds a timestamp to the output.
Generates a formatted output message.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)] [System.String] $Message
[Parameter(Mandatory, ValueFromPipeline)]
[System.String] $Message
)
process {
if (($labDefaults.CallStackLogging) -and ($labDefaults.CallStackLogging -eq $true)) {
$parentCallStack = (Get-PSCallStack)[1]; # store the parent Call Stack
$functionName = $parentCallStack.FunctionName;
$lineNumber = $parentCallStack.ScriptLineNumber;
$scriptName = ($parentCallStack.Location -split ':')[0];
$verboseMessage = '[{0}] [Script:{1}] [Function:{2}] [Line:{3}] {4}' -f (Get-Date).ToLongTimeString(), $scriptName, $functionName, $lineNumber, $Message;
$formattedMessage = '[{0}] [Script:{1}] [Function:{2}] [Line:{3}] {4}' -f (Get-Date).ToLongTimeString(), $scriptName, $functionName, $lineNumber, $Message;
}
else {
$verboseMessage = '[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message;
$formattedMessage = '[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message;
}
return $formattedMessage;
} #end process
} #end function GetFormattedMessage

function WriteVerbose {
<#
.SYNOPSIS
Wrapper around Write-Verbose that adds a timestamp and/or call stack information to the output.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[System.String] $Message
)
process {
$verboseMessage = GetFormattedMessage -Message $Message;
Write-Verbose -Message $verboseMessage;
}
} #end function WriteVerbose

function WriteWarning {
<#
.SYNOPSIS
Wrapper around Write-Warning that adds a timestamp to the output.
Wrapper around Write-Warning that adds a timestamp and/or call stack information to the output.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)] [System.String] $Message
[Parameter(Mandatory, ValueFromPipeline)]
[System.String] $Message
)
process {
Write-Warning -Message ('[{0}] {1}' -f (Get-Date).ToLongTimeString(), $Message);
$warningMessage = GetFormattedMessage -Message $Message;
Write-Warning -Message $warningMessage;
}
} #end function WriteWarning
27 changes: 18 additions & 9 deletions Resources.psd1
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
ConvertFrom-StringData -StringData @'
DownloadingResource = Downloading resource '{0}' to '{1}'.
DownloadingResource = Downloading resource '{0}' to '{1}'.
DownloadingActivity = Downloading '{0}'.
DownloadStatus = {0:N0} of {1:N0} bytes ({2} %).
UsingProxyServer = Using proxy server '{0}'.
CopyingResource = Copying resource '{0}' to '{1}'.
MissingResourceFile = Resource '{0}' does not exist.
ResourceChecksumNotSpecified = Resource '{0}' checksum was not specified.
ResourceChecksumNotSpecified = Resource '{0}' checksum was not specified.
ResourceChecksumMatch = Resource '{0}' checksum matches '{1}'.
ResourceChecksumMismatch = Resource '{0}' checksum does not match '{1}'.
ResourceChecksumMismatch = Resource '{0}' checksum does not match '{1}'.
CalculatingResourceChecksum = Calculating resource '{0}' checksum.
WritingResourceChecksum = Writing checksum '{0}' to resource '{1}'.
CreatingDirectory = Creating directory '{0}'.
RemovingDirectory = Removing directory '{0}'.
DirectoryExists = Directory '{0}' already exists.
RenamingPath = Renaming '{0}' to '{1}'.
WritingResourceChecksum = Writing checksum '{0}' to resource '{1}'.
CreatingDirectory = Creating directory '{0}'.
RemovingDirectory = Removing directory '{0}'.
DirectoryExists = Directory '{0}' already exists.
RenamingPath = Renaming '{0}' to '{1}'.
TestingPathExists = Testing directory '{0}' exists.
ExpandingArchive = Expanding archive '{0}' to '{1}'.
ExpandingArchive = Expanding archive '{0}' to '{1}'.
PendingRebootWarning = A pending reboot is required. Please reboot the system and re-run the configuration.
CheckingDscResource = Checking DSC Resource '{0}\\{1}'.
ImportingDscResource = Importing DSC Resource '{0}\\{1}'.
Expand Down Expand Up @@ -98,10 +98,15 @@ ConvertFrom-StringData -StringData @'
RemovingCustomMediaEntry = Removing '{0}' media entry.
SavingConfiguration = Saving configuration '{0}'.
PerformingOperationOnTarget = Performing the operation '{0}' on target '{1}'.
SettingVMDefaults = Setting VM defaults.
ResettingConfigurationDefaults = Resetting '{0}' configuration settings to default.
LocatingWimImageName = Locating WIM image '{0}' name.
LocatingWimImageIndex = Locating WIM image '{0}' index.
MediaFileCachingDisabled = Caching of file-based media is disabled. Skipping media '{0}' download.
CreatingQuickVM = Creating quick VM '{0}' using media '{1}'.
RemovingQuickVM = Removing quick VM '{0}'.
ResettingVM = Resetting VM '{0}'.
CreatingInternalVirtualSwitch = Creating Internal '{0}' virtual switch.

NoCertificateFoundWarning = No '{0}' certificate was found.
CannotLocateLcmFileWarning = Cannot locate LCM configuration file '{0}'. No DSC Local Configuration Manager configuration will be applied.
Expand All @@ -112,6 +117,7 @@ ConvertFrom-StringData -StringData @'
NoCustomMediaFoundWarning = No custom media '{0}' registered.
UnsupportedConfigurationWarning = Configuration '{0}' is not supported by {1}.
ShouldProcessWarning = Are you sure you want to perform this action?
MissingVirtualSwitchWarning = Virtual switch '{0}' is missing.

InvalidPathError = {0} path '{1}' is invalid.
InvalidDestinationPathError = Invalid destination path '{0}' specified.
Expand Down Expand Up @@ -140,4 +146,7 @@ ConvertFrom-StringData -StringData @'
MediaAlreadyRegisteredError = Media Id '{0}' is already registered. Use {1} to override the existing media entry.
CannotProcessCommandError = Cannot process command because of one or more missing mandatory parameters: {0}.
CannotBindArgumentError = Cannot bind argument to parameter '{0}' because it is an empty string.
StartMemLessThanMinMemError = Startup memory '{0}' cannot be less than minimum memory '{1}'.
StartMemGreaterThanMaxMemError = Startup memory '{0}' cannot be greater than maximum memory '{1}'.
SwitchDoesNotExistError = Virtual switch '{0}' cannot be found.
'@
6 changes: 4 additions & 2 deletions Src/LabImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function New-LabImage {
.SYNOPSIS
Creates a new master/parent image.
#>
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess)]
[OutputType([System.IO.FileInfo])]
param (
## Lab media Id
Expand All @@ -80,6 +80,8 @@ function New-LabImage {
process {
## Download media if required..
[ref] $null = $PSBoundParameters.Remove('Force');
[ref] $null = $PSBoundParameters.Remove('WhatIf');
[ref] $null = $PSBoundParameters.Remove('Confirm');
$media = ResolveLabMedia @PSBoundParameters;
$mediaFileInfo = InvokeLabMediaImageDownload -Media $media;

Expand All @@ -105,7 +107,7 @@ function New-LabImage {
}

## Create disk image and refresh PSDrives
$image = NewDiskImage -Path $imagePath -PartitionStyle $partitionStyle -Passthru -Force # -ErrorAction Stop;
$image = NewDiskImage -Path $imagePath -PartitionStyle $partitionStyle -Passthru -Force -ErrorAction Stop;
[ref] $null = Get-PSDrive;

## Apply WIM (ExpandWindowsImage) and add specified features
Expand Down
Loading