This commit is contained in:
troettinger 2017-11-28 20:30:53 +01:00
Родитель 68d825a8c2
Коммит 07abfade62
3 изменённых файлов: 219 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,166 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE.txt in the project root for license information.
<#
.SYNOPSIS
List all Azure Marketplace Items available for syndication and allows to download them
Requires an Azure Stack System to be registered for the subscription used to login
#>
function Sync-AzSOfflineMarketplaceItem{
[CmdletBinding(DefaultParameterSetName='SyncOfflineAzsMarketplaceItem')]
Param(
[Parameter(Mandatory=$false, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $Cloud = "AzureCloud",
[Parameter(Mandatory=$true, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $Destination,
[Parameter(Mandatory=$true, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $AzureTenantID,
[Parameter(Mandatory=$true, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $AzureSubscriptionID
)
$azureAccount = Add-AzureRmAccount -subscriptionid $AzureSubscriptionID -TenantId $AzureTenantID
$azureEnvironment = Get-AzureRmEnvironment -Name $Cloud
$resources=Get-AzureRmResource
$resource=$resources.resourcename
$registrations=$resource|where-object {$_ -like "AzureStack*"}
$registration = $registrations[0]
# Retrieve the access token
$tokens = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.TokenCache.ReadItems()
$token = $tokens |Where Resource -EQ $azureEnvironment.ActiveDirectoryServiceEndpointResourceId |Where DisplayableId -EQ $azureAccount.Context.Account.Id |Sort ExpiresOn |Select -Last 1
$uri1 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$($Registration.ToString())/products?api-version=2016-01-01"
$Headers = @{ 'authorization'="Bearer $($Token.AccessToken)"}
$products = (Invoke-RestMethod -Method GET -Uri $uri1 -Headers $Headers).value
$Marketitems=foreach ($product in $products)
{
switch($product.properties.productKind)
{
'virtualMachine'
{
Write-output ([pscustomobject]@{
Id = $product.name.Split('/')[-1]
Type = "Virtual Machine"
Name = $product.properties.displayName
Description = $product.properties.description
Publisher = $product.properties.publisherDisplayName
Version = $product.properties.offerVersion
Size = Set-String -size $product.properties.payloadLength
})
}
'virtualMachineExtension'
{
Write-output ([pscustomobject]@{
Id = $product.name.Split('/')[-1]
Type = "Virtual Machine Extension"
Name = $product.properties.displayName
Description = $product.properties.description
Publisher = $product.properties.publisherDisplayName
Version = $product.properties.productProperties.version
Size = Set-String -size $product.properties.payloadLength
})
}
Default
{
Write-Warning "Unknown product kind '$_'"
}
}
}
$Marketitems|Out-GridView -Title 'Azure Marketplace Items' -PassThru|foreach{
$productid=$_.id
# get name of azpkg
$uri2 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$($productid)?api-version=2016-01-01"
Write-Debug $URI2
$Headers = @{ 'authorization'="Bearer $($Token.AccessToken)"}
$productDetails = Invoke-RestMethod -Method GET -Uri $uri2 -Headers $Headers
$azpkgName = $productDetails.properties.galleryItemIdentity
# get download location for apzkg
$uri3 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$productid/listDetails?api-version=2016-01-01"
$uri3
$downloadDetails = Invoke-RestMethod -Method POST -Uri $uri3 -Headers $Headers
#Create Legal Terms POPUP
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup($productDetails.properties.description, `
0,"Legal Terms",4)
If ($intAnswer -eq 6)
{
# download azpkg
$azpkgsource = $downloadDetails.galleryPackageBlobSasUri
$FileExists=Test-Path "$destination\$azpkgName.azpkg"
$DestinationCheck=Test-Path $destination
If ($DestinationCheck -eq $false)
{
new-item -ItemType Directory -force $destination} else{}
If ($FileExists -eq $true) {Remove-Item "$destination\$azpkgName.azpkg" -force} else {
New-Item "$destination\$azpkgName.azpkg"}
$azpkgdestination = "$destination\$azpkgName.azpkg"
Start-BitsTransfer -source $azpkgsource -destination $azpkgdestination -Priority High
# download vhd
$vhdName = $productDetails.properties.galleryItemIdentity
$vhdSource = $downloadDetails.properties.osDiskImage.sourceBlobSasUri
If ([string]::IsNullOrEmpty($vhdsource)) {exit} else {
$FileExists=Test-Path "$destination\$productid.vhd"
If ($FileExists -eq $true) {Remove-Item "$destination\$productid.vhd" -force} else {
New-Item "$destination\$productid.vhd" }
$vhdDestination = "$destination\$productid.vhd"
Start-BitsTransfer -source $vhdSource -destination $vhdDestination -Priority High
}
}
else {
$a.popup("Legal Terms not accpeted, canceling")
}
}
}
function Set-String {
param (
[parameter(mandatory=$true)]
[long] $size
)
if ($size -gt 1073741824) {
return [string]([math]::Round($size / 1073741824)) + " GB"
} elseif ($size -gt 1048576) {
return [string]([math]::Round($size / 1048576)) + " MB"
} else {return "<1 MB"}
}
Export-ModuleMember -Function Sync-AzSOfflineMarketplaceItem

Двоичные данные
Syndication/demosyndicate.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.3 MiB

53
Syndication/readme.md Normal file
Просмотреть файл

@ -0,0 +1,53 @@
# Offline Marketplace Syndication
When Azure Stack is deployed in disconnect mode (Without Internet connectivity) you can
not use the build in portal feature to syndicate Azure Market place items and make them
available to your users.
This Tool allows you to download Azure Marketplace Items with a machine that has internet connectivity and side load them.
The downloaded needs to transferred to machine with has connectivity to the Azure Stack deployment and imported.
![](demosyndicate.gif)
## Requirements
- Azure Stack RP registered within your Azure Subscription
- Azure Subscription used to register Azure Stack System (Multi Node or ASDK)
- AzureRM 1.2.11 PowerShell needs to be installed
(https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-powershell-configure-quickstart)
## Import the Module
```powershell
Import-Module .\AzureStack.MarketplaceSyndication.psm1
```
## Launch the Tool
```powershell
Sync-AzSOfflineMarketplaceItem -destination c:\donwloadfolder -AzureTenantID "Value" -AzureSubscriptionID "SubsciptionID"
```
## Optional Parameters
Parameter: Cloud
Default: AzureCloud
Description: Once Azure Stack RP is available in other Clouds you can specify which one to use
## Importing into Azure Stack
Once the download has been transferred to a machine that can access Azure Stack, you need to import the VHD and publish the Gallery Item.
## Importing the VHD
You can use the Portal or PowerShell.
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-add-vm-image
## Publishing the Gallery Item
You need to use PowerShell
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-create-and-publish-marketplace-item