зеркало из https://github.com/microsoft/lisa.git
Merge branch 'master' of https://github.com/iamshital/LISAv2
This commit is contained in:
Коммит
ba61cd7cb4
|
@ -0,0 +1,55 @@
|
|||
param
|
||||
(
|
||||
$JenkinsUser,
|
||||
$RemoteReceivedFolder = "Z:\ReceivedFiles",
|
||||
$fileNames
|
||||
)
|
||||
Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global }
|
||||
$folderToQuery = "$RemoteReceivedFolder\$JenkinsUser"
|
||||
if ($fileNames)
|
||||
{
|
||||
if ( ($fileNames -imatch "Delete All Files" ) )
|
||||
{
|
||||
$allFiles = Get-ChildItem "$folderToQuery"
|
||||
foreach ( $file in $allFiles.Name)
|
||||
{
|
||||
LogMsg "Removing $file..." -NoNewline
|
||||
$out = Remove-Item -Path "$folderToQuery\$file" -Force
|
||||
if ($?)
|
||||
{
|
||||
LogMsg " SUCCESS"
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg " Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($file in $fileNames.split(","))
|
||||
{
|
||||
if ( ( Test-Path -Path "$folderToQuery\$file"))
|
||||
{
|
||||
LogMsg "Removing $file..." -NoNewline
|
||||
$out = Remove-Item -Path "$folderToQuery\$file" -Force
|
||||
if ($?)
|
||||
{
|
||||
LogMsg " SUCCESS"
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg " Error"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg "$folderToQuery\$file does not exeists."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg "Please select at leat one file."
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
Param
|
||||
(
|
||||
$JenkinsUser,
|
||||
$RemoteReceivedFolder="Z:\ReceivedFiles",
|
||||
$htmlFilePath,
|
||||
$textFilePath,
|
||||
$cleanupFilesPath
|
||||
)
|
||||
|
||||
Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global }
|
||||
$folderToQuery = "$RemoteReceivedFolder\$JenkinsUser"
|
||||
|
||||
$htmlHeader = '
|
||||
<style type="text/css">
|
||||
.tg {border-collapse:collapse;border-spacing:0;border-color:#999;}
|
||||
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;}
|
||||
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;}
|
||||
.tg .tg-baqh{text-align:center;vertical-align:top}
|
||||
.tg .tg-90qj{font-weight:bold;background-color:#26ade4;color:#ffffff;text-align:center;vertical-align:top}
|
||||
.tg .tg-lqy6{text-align:right;vertical-align:top}
|
||||
.tg .tg-0ol0{font-weight:bold;background-color:#26ade4;color:#ffffff;text-align:right;vertical-align:top}
|
||||
.tg .tg-yw4l{vertical-align:top}
|
||||
.tg .tg-9hbo{font-weight:bold;vertical-align:top}
|
||||
.tg .tg-l2oz{font-weight:bold;text-align:right;vertical-align:top}
|
||||
.tg .tg-2nui{font-weight:bold;background-color:#ffffc7;text-align:right;vertical-align:top}
|
||||
</style>
|
||||
<table class="tg">
|
||||
<tr>
|
||||
<th class="tg-90qj">SR</th>
|
||||
<th class="tg-90qj">File Name</th>
|
||||
<th class="tg-90qj">Uploaded Date</th>
|
||||
<th class="tg-0ol0">Size</th>
|
||||
</tr>
|
||||
'
|
||||
|
||||
$htmlRow='
|
||||
<tr>
|
||||
<td class="tg-baqh">CURRENT_SERIAL</td>
|
||||
<td class="tg-yw4l">CURRENT_FILENAME</td>
|
||||
<td class="tg-lqy6">CURRENT_DATE</td>
|
||||
<td class="tg-lqy6">CURRENT_SIZE</td>
|
||||
</tr>
|
||||
'
|
||||
$htmlFooter='
|
||||
<tr>
|
||||
<td class="tg-9hbo"></td>
|
||||
<td class="tg-9hbo"></td>
|
||||
<td class="tg-l2oz">Total Usage</td>
|
||||
<td class="tg-2nui">TOTAL_USAGE</td>
|
||||
</tr>
|
||||
</table>
|
||||
'
|
||||
|
||||
$currentFiles = Get-ChildItem -Path $folderToQuery -Recurse -Verbose
|
||||
$SR = 1
|
||||
$htmlData = ""
|
||||
|
||||
function GetFileObject()
|
||||
{
|
||||
$object = New-Object -TypeName PSObject
|
||||
$object | Add-Member -MemberType NoteProperty -Name SR -Value $null
|
||||
$object | Add-Member -MemberType NoteProperty -Name FileName -Value $null
|
||||
$object | Add-Member -MemberType NoteProperty -Name LastWriteTime -Value $null
|
||||
$object | Add-Member -MemberType NoteProperty -Name Size -Value $null
|
||||
return $object
|
||||
}
|
||||
|
||||
$htmlData += $htmlHeader
|
||||
$totalSize = 0
|
||||
$allFileObjects = @()
|
||||
$cleanupFileList = "FileName="
|
||||
foreach ($file in $currentFiles)
|
||||
{
|
||||
$currentHTMLRow = $htmlRow
|
||||
$currentHTMLRow = $currentHTMLRow.Replace("CURRENT_SERIAL","$SR")
|
||||
$currentHTMLRow = $currentHTMLRow.Replace("CURRENT_FILENAME","$($file.Name)")
|
||||
$cleanupFileList += "$($file.Name),"
|
||||
$currentHTMLRow = $currentHTMLRow.Replace("CURRENT_DATE","$($file.LastWriteTime)")
|
||||
$currentFileSize = [math]::Round($($file.Length / 1024 / 1024 / 1024 ),3)
|
||||
$currentHTMLRow = $currentHTMLRow.Replace("CURRENT_SIZE","$currentFileSize GB")
|
||||
$totalSize += $file.Length
|
||||
$htmlData += $currentHTMLRow
|
||||
$fileObject = GetFileObject
|
||||
$fileObject.SR = $SR
|
||||
$fileObject.FileName = $($file.Name)
|
||||
$fileObject.LastWriteTime = $file.LastWriteTime
|
||||
$fileObject.Size = "$currentFileSize GB"
|
||||
$allFileObjects += $fileObject
|
||||
$SR += 1
|
||||
}
|
||||
if ( $currentFiles.Count -gt 0)
|
||||
{
|
||||
$totalSizeInGB = [math]::Round(($totalSize / 1024 / 1024 / 1024),3)
|
||||
|
||||
$currentHtmlFooter = $htmlFooter
|
||||
$currentHtmlFooter = $currentHtmlFooter.Replace("TOTAL_USAGE","$totalSizeInGB GB")
|
||||
$htmlData += $currentHtmlFooter
|
||||
Set-Content -Value $htmlData -Path $htmlFilePath -Force -Verbose
|
||||
Remove-Item -Path $textFilePath -Force -Verbose
|
||||
$allFileObjects | Out-File -FilePath $textFilePath -Force -Verbose -NoClobber
|
||||
Add-Content -Value "--------------------------------------------------------" -Path $textFilePath
|
||||
Add-Content -Value " Total : $totalSizeInGB GB" -Path $textFilePath
|
||||
$cleanupFileList = $cleanupFileList.TrimEnd(",")
|
||||
if ($currentFiles.Count -gt 2)
|
||||
{
|
||||
$cleanupFileList = $cleanupFileList.Replace("FileName=","FileName=Delete All Files,")
|
||||
}
|
||||
Set-Content -Value $cleanupFileList -Path $cleanupFilesPath -Force -Verbose
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentHtmlFooter = $htmlFooter
|
||||
$currentHtmlFooter = $currentHtmlFooter.Replace("TOTAL_USAGE","0 GB")
|
||||
$htmlData += $currentHtmlFooter
|
||||
Set-Content -Value $htmlData -Path $htmlFilePath -Force -Verbose
|
||||
Remove-Item -Path $textFilePath -Force -Verbose
|
||||
$allFileObjects | Out-File -FilePath $textFilePath -Force -Verbose -NoClobber
|
||||
Add-Content -Value "--------------------------------------------------------" -Path $textFilePath
|
||||
Add-Content -Value " Total : 0 GB" -Path $textFilePath
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
Param
|
||||
(
|
||||
$OutputFilePath = "Z:\Jenkins_Shared_Do_Not_Delete\userContent\common\VMSizes-ARM.txt"
|
||||
)
|
||||
Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global }
|
||||
try
|
||||
{
|
||||
$ExitCode = 1
|
||||
#region Update VM sizes
|
||||
LogMsg "Getting 'Microsoft.Compute' supported region list..."
|
||||
$allRegions = (Get-AzureRmLocation | Where-Object { $_.Providers.Contains("Microsoft.Compute")} | Sort-Object).Location
|
||||
$allRegions = $allRegions | Sort-Object
|
||||
$i = 1
|
||||
$allRegions | ForEach-Object { LogMsg "$i. $_"; $i++ }
|
||||
$RegionAndVMSize = "Region$tab`Size`n"
|
||||
foreach ( $NewRegion in $allRegions )
|
||||
{
|
||||
$currentRegionSizes = (Get-AzureRmVMSize -Location $NewRegion).Name | Sort-Object
|
||||
if ($currentRegionSizes)
|
||||
{
|
||||
LogMsg "Found $($currentRegionSizes.Count) sizes for $($NewRegion)..."
|
||||
$CurrentSizeCount = 1
|
||||
foreach ( $size in $currentRegionSizes )
|
||||
{
|
||||
LogMsg "|--Added $NewRegion : $CurrentSizeCount. $($size)..."
|
||||
$RegionAndVMSize += $NewRegion + $tab + $NewRegion + " " + $size + "`n"
|
||||
$CurrentSizeCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Set-Content -Value $RegionAndVMSize -Path $OutputFilePath -Force -NoNewline
|
||||
LogMsg "$OutputFilePath saved successfully."
|
||||
$ExitCode = 0
|
||||
#endregion
|
||||
}
|
||||
catch
|
||||
{
|
||||
$ExitCode = 1
|
||||
ThrowException ($_)
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMsg "Exiting with code: $ExitCode"
|
||||
exit $ExitCode
|
||||
}
|
||||
#endregion
|
|
@ -0,0 +1,74 @@
|
|||
Param
|
||||
(
|
||||
$OutputFilePath = "Z:\Jenkins_Shared_Do_Not_Delete\userContent\common\VMImages-ARM.txt",
|
||||
$Publishers = "Canonical,SUSE,Oracle,CoreOS,RedHat,OpenLogic,credativ,kali-linux,clear-linux-project"
|
||||
)
|
||||
Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global }
|
||||
try
|
||||
{
|
||||
$ExitCode = 1
|
||||
#region Update All ARM Images
|
||||
$tab = " "
|
||||
$Location = "northeurope"
|
||||
$allRMPubs = $Publishers.Split(",") | Sort-Object
|
||||
$ARMImages = "Publisher Offer SKU Version`n"
|
||||
foreach ( $newPub in $allRMPubs )
|
||||
{
|
||||
$offers = Get-AzureRmVMImageOffer -PublisherName $newPub -Location $Location
|
||||
if ($offers)
|
||||
{
|
||||
LogMsg "Found $($offers.Count) offers for $($newPub)..."
|
||||
foreach ( $offer in $offers )
|
||||
{
|
||||
$SKUs = Get-AzureRmVMImageSku -Location $Location -PublisherName $newPub -Offer $offer.Offer -ErrorAction SilentlyContinue
|
||||
LogMsg "|--Found $($SKUs.Count) SKUs for $($offer.Offer)..."
|
||||
foreach ( $SKU in $SKUs )
|
||||
{
|
||||
$rmImages = Get-AzureRmVMImage -Location $Location -PublisherName $newPub -Offer $offer.Offer -Skus $SKU.Skus
|
||||
LogMsg "|--|--Found $($rmImages.Count) Images for $($SKU.Skus)..."
|
||||
if ( $rmImages.Count -gt 1 )
|
||||
{
|
||||
$isLatestAdded = $false
|
||||
}
|
||||
else
|
||||
{
|
||||
$isLatestAdded = $true
|
||||
}
|
||||
foreach ( $rmImage in $rmImages )
|
||||
{
|
||||
if ( $isLatestAdded )
|
||||
{
|
||||
LogMsg "|--|--|--Added Version $($rmImage.Version)..."
|
||||
$ARMImages += $newPub + $tab + $offer.Offer + $tab + $SKU.Skus + $tab + $newPub + " " + $offer.Offer + " " + $SKU.Skus + " " + $rmImage.Version + "`n"
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg "|--|--|--Added Generalized version: latest..."
|
||||
$ARMImages += $newPub + $tab + $offer.Offer + $tab + $SKU.Skus + $tab + $newPub + " " + $offer.Offer + " " + $SKU.Skus + " " + "latest" + "`n"
|
||||
LogMsg "|--|--|--Added Version $($rmImage.Version)..."
|
||||
$ARMImages += $newPub + $tab + $offer.Offer + $tab + $SKU.Skus + $tab + $newPub + " " + $offer.Offer + " " + $SKU.Skus + " " + $rmImage.Version + "`n"
|
||||
$isLatestAdded = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$ARMImages = $ARMImages.TrimEnd("`n")
|
||||
LogMsg "Creating file $OutputFilePath..."
|
||||
Set-Content -Value $ARMImages -Path $OutputFilePath -Force -NoNewline
|
||||
LogMsg "$OutputFilePath Saved successfully."
|
||||
$ExitCode = 0
|
||||
#endregion
|
||||
}
|
||||
catch
|
||||
{
|
||||
$ExitCode = 1
|
||||
ThrowException ($_)
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMsg "Exiting with code: $ExitCode"
|
||||
exit $ExitCode
|
||||
}
|
||||
#endregion
|
Загрузка…
Ссылка в новой задаче