Skip to content

Commit ed70648

Browse files
author
Anthony Clack
committed
Updated to allow offline use by pre-downloading MarketplaceItem.zip.
1 parent c315440 commit ed70648

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

ComputeAdmin/AzureStack.ComputeAdmin.psm1

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function Add-AzsVMImage {
135135
[Parameter(ParameterSetName = 'VMImageFromAzure')]
136136
[bool] $CreateGalleryItem = $true,
137137

138+
[Parameter(ParameterSetName = 'VMImageFromLocal')]
139+
[string] $MarketPlaceZipPath = '',
140+
138141
[switch] $Force
139142
)
140143

@@ -296,8 +299,8 @@ function Add-AzsVMImage {
296299
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName
297300
$container = Get-AzureStorageContainer -Name $containerName -ErrorAction SilentlyContinue
298301

299-
if ($CreateGalleryItem -eq $true -And $platformImage.Properties.ProvisioningState -eq 'Succeeded') {
300-
$GalleryItem = CreateGalleryItem -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -title $title -description $description
302+
if ($CreateGalleryItem -eq $true -And $platformImage.Properties.ProvisioningState -eq 'Succeeded') {
303+
$GalleryItem = CreateGalleryItem -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -title $title -description $description -MarketPlaceZipPath "$MarketPlaceZipPath"
301304
$null = $container| Set-AzureStorageBlobContent -File $GalleryItem.FullName -Blob $galleryItem.Name
302305
$galleryItemURI = '{0}{1}/{2}' -f $storageAccount.PrimaryEndpoints.Blob.AbsoluteUri, $containerName, $galleryItem.Name
303306

@@ -470,7 +473,11 @@ function New-AzsServer2016VMImage {
470473
[bool] $CreateGalleryItem = $true,
471474

472475
[Parameter()]
473-
[bool] $Net35 = $true
476+
[bool] $Net35 = $true,
477+
478+
[Parameter()]
479+
[string] $MarketPlaceZipPath
480+
474481
)
475482
begin {
476483
function CreateWindowsVHD {
@@ -657,10 +664,10 @@ function New-AzsServer2016VMImage {
657664

658665
if ($CreateGalleryItem) {
659666
$description = "This evaluation image should not be used for production workloads."
660-
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -title "Windows Server 2016 Datacenter Core Eval" -description $description -CreateGalleryItem $CreateGalleryItem
667+
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -title "Windows Server 2016 Datacenter Core Eval" -description $description -CreateGalleryItem $CreateGalleryItem -MarketPlaceZipPath "$MarketPlaceZipPath"
661668
}
662669
else {
663-
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -CreateGalleryItem $CreateGalleryItem
670+
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -CreateGalleryItem $CreateGalleryItem -MarketPlaceZipPath "$MarketPlaceZipPath"
664671
}
665672
}
666673
catch {
@@ -690,11 +697,11 @@ function New-AzsServer2016VMImage {
690697
Write-Verbose -Message "Server Full VHD already found."
691698
}
692699
if ($CreateGalleryItem) {
693-
$description = "This evaluation image should not be used for production workloads."
694-
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -title "Windows Server 2016 Datacenter Eval" -description $description -CreateGalleryItem $CreateGalleryItem
700+
$description = "This evaluation image should not be used for production workloads."
701+
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -title "Windows Server 2016 Datacenter Eval" -description $description -CreateGalleryItem $CreateGalleryItem -MarketPlaceZipPath "$MarketPlaceZipPath"
695702
}
696-
else {
697-
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -CreateGalleryItem $CreateGalleryItem
703+
else {
704+
Add-AzsVMImage -sku $sku -osDiskLocalPath $ImagePath @PublishArguments -CreateGalleryItem $CreateGalleryItem -MarketPlaceZipPath "$MarketPlaceZipPath"
698705
}
699706
}
700707
catch {
@@ -729,7 +736,9 @@ Function CreateGalleryItem {
729736

730737
[string] $Title,
731738

732-
[string] $Description
739+
[string] $Description,
740+
741+
[string] $MarketPlaceZipPath = ''
733742
)
734743
$workdir = '{0}{1}' -f [System.IO.Path]::GetTempPath(), [System.Guid]::NewGuid().ToString()
735744
New-Item $workdir -ItemType Directory | Out-Null
@@ -740,17 +749,43 @@ Function CreateGalleryItem {
740749
New-Item -ItemType directory -Path $extractedGalleryItemPath | Out-Null
741750
expand-archive -Path "$workdir\CustomizedVMGalleryItem.zip" -DestinationPath $extractedGalleryItemPath -Force
742751

743-
$maxAttempts = 5
744-
for ($retryAttempts = 1; $retryAttempts -le $maxAttempts; $retryAttempts++) {
745-
try {
746-
Write-Verbose -Message "Downloading Azure Stack Marketplace Item Generator Attempt $retryAttempts" -Verbose
747-
Invoke-WebRequest -Uri http://www.aka.ms/azurestackmarketplaceitem -OutFile "$workdir\MarketplaceItem.zip"
748-
break
752+
# Check if we were provided with the MarketPlace Item Generator File
753+
if ( $MarketPlaceZipPath -eq '' )
754+
{
755+
756+
$maxAttempts = 5
757+
for ($retryAttempts = 1; $retryAttempts -le $maxAttempts; $retryAttempts++) {
758+
try {
759+
Write-Verbose -Message "Downloading Azure Stack Marketplace Item Generator Attempt $retryAttempts" -Verbose
760+
Invoke-WebRequest -Uri http://www.aka.ms/azurestackmarketplaceitem -OutFile "$workdir\MarketplaceItem.zip"
761+
break
762+
}
763+
catch {
764+
if ($retryAttempts -ge $maxAttempts) {
765+
Write-Error "Failed to download Azure Stack Marketplace Item Generator" -ErrorAction Stop
766+
}
767+
}
749768
}
750-
catch {
751-
if ($retryAttempts -ge $maxAttempts) {
752-
Write-Error "Failed to download Azure Stack Marketplace Item Generator" -ErrorAction Stop
769+
}
770+
else
771+
{
772+
write-verbose -Message "Copying Marketplace Item Generator to working directory" -Verbose
773+
774+
# Copy the provided file into the working directory
775+
if ( Test-Path -Path "$MarketPlaceZipPath" )
776+
{
777+
try {
778+
Write-Verbose -Message "Copying Market Place Item Generator zip file into working directory" -Verbose
779+
copy-item -Path "$MarketPlaceZipPath" -Destination "$workdir\MarketplaceItem.zip"
753780
}
781+
catch
782+
{
783+
Write-Error "Failed to copy Market Place Item Generator zip into working directory: $_" -ErrorAction Stop
784+
}
785+
}
786+
else
787+
{
788+
Write-Error "Provided Market Place Item Generator zip file does not exist" -ErrorAction Stop
754789
}
755790
}
756791

0 commit comments

Comments
 (0)