This repository has been archived by the owner on Oct 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Added Quota functionality #8
Open
istairbn
wants to merge
2
commits into
master
Choose a base branch
from
Quota-Work
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ function IgnoreSSL { | |
$Provider = New-Object -TypeName Microsoft.CSharp.CSharpCodeProvider | ||
$null = $Provider.CreateCompiler() | ||
$Params = New-Object -TypeName System.CodeDom.Compiler.CompilerParameters | ||
$Params.GenerateExecutable = $False | ||
$Params.GenerateInMemory = $True | ||
$Params.IncludeDebugInformation = $False | ||
$Params.GenerateExecutable = $false | ||
$Params.GenerateInMemory = $true | ||
$Params.IncludeDebugInformation = $false | ||
$Params.ReferencedAssemblies.Add('System.DLL') > $null | ||
$TASource=@' | ||
namespace Local.ToolkitExtensions.Net.CertificatePolicy | ||
|
@@ -53,7 +53,7 @@ function TestJWTClaimNotExpired { | |
if ($Token.split('.').count -ne 3) { | ||
throw 'Invalid token passed, run Get-WAPToken to fetch a new one' | ||
} | ||
$TokenData = $token.Split('.')[1] | ForEach-Object -Process { | ||
$TokenData = $token.Split('.')[1] | foreach-Object -Process { | ||
$data = $_ -as [String] | ||
$data = $data.Replace('-', '+').Replace('_', '/') | ||
switch ($data.Length % 4) { | ||
|
@@ -549,6 +549,208 @@ function GetWAPSubscriptionQuota { | |
|
||
} | ||
|
||
function Get-WAPSubscriptionQuota { | ||
<# | ||
.SYNOPSIS | ||
Retrieves a VM Role Quota information object (WAP.Quota). | ||
|
||
.PARAMETER Subscription | ||
The Subscription(s) you wish to collect quota information for. | ||
|
||
.EXAMPLE | ||
PS C:\>$URL = 'https://publictenantapi.mydomain.com' | ||
PS C:\>$creds = Get-Credential | ||
PS C:\>Get-WAPToken -Credential $creds -URL 'https://sts.adfs.com' -ADFS | ||
PS C:\>Connect-WAPAPI -URL $URL | ||
PS C:\>$Sub = Get-WAPSubscription -Name MySubscription | ||
PS C:\>Get-WAPSubscriptionQuota -Subscription $Sub | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter( | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[System.Management.Automation.PSTypeName('WAP.Subscription')] | ||
[PSCustomObject] $Subscription = (Get-WAPSubscription) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the Datatype for this. So you'll end up with:
|
||
) | ||
process{ | ||
|
||
foreach ( $Sub in $Subscription ) { | ||
Select-WAPSubscription -Subscription $Sub | ||
|
||
$VMs = Get-WAPVM | ||
$Cores = $Vms.CpuCount | Measure-Object -Sum | ||
$Memory = $Vms.Memory | Measure-Object -Sum | ||
$Services = $Sub.Services | Select BaseQuotaSettings | ||
|
||
foreach ( $Service in $Services ) { | ||
|
||
$BaseQuotaSettings = $Service.BaseQuotaSettings | ||
|
||
foreach ( $Setting in $BaseQuotaSettings ) { | ||
|
||
if ( $Setting.Key -eq "Clouds" ) { | ||
|
||
[xml]$Data = $Setting.Value | ||
$Output = $Data.Clouds.Cloud.Quota | ||
|
||
[pscustomobject] $Object = @{ | ||
SubscriptionName = $Sub.SubscriptionName; | ||
CurrentVms = $Cores.Count; | ||
CurrentCores = $Cores.Sum; | ||
CurrentMemory = $Memory.Sum; | ||
QuotaRoleVMCount = $Output.RoleVMCount; | ||
QuotaMemberVMCount = $Output.MemberVMCount; | ||
QuotaRoleCPUCount = $Output.RoleCPUCount; | ||
QuotaMemberCPUCount = $Output.MemberCPUCount; | ||
QuotaMemberMemory = $Output.MemberMemoryMB; | ||
QuotaRoleMemory = $Output.RoleMemoryMB; | ||
QuotaRoleStorageGB = $Output.RoleStorageGB; | ||
QuotaMemberStorageGB = $Output.MemberStorageGB | ||
} | ||
|
||
$Object.PSObject.TypeNames.Insert( 0,'WAP.QUOTA' ) | ||
|
||
Write-Output $Object | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function Get-WAPVMRoleQuotaRequest { | ||
<# | ||
.SYNOPSIS | ||
Gets a WAP.QuotaRequest object - determining whether or not a deployment will succeed. | ||
|
||
.PARAMETER VMRoleSizeProfile | ||
VM Size object to use as the basis.. Acquired via Get-WAPVMRoleVMSize. | ||
|
||
.PARAMETER Size | ||
VM Size name. Extra Small, Large, A7 etc. | ||
|
||
.PARAMETER Subscription | ||
WAP.SUbscription object to check. If left blank, returns the quota request for all of them. | ||
|
||
.EXAMPLE | ||
PS C:\>$URL = 'https://publictenantapi.mydomain.com' | ||
PS C:\>$creds = Get-Credential | ||
PS C:\>Get-WAPToken -Credential $creds -URL 'https://sts.adfs.com' -ADFS | ||
PS C:\>Connect-WAPAPI -URL $URL | ||
PS C:\>$Sub = Get-WAPSubscription -Name 'MySubscription' | ||
PS C:\>Get-WAPVMRoleQuotaRequest -Subscription $Sub -Size Large | ||
OR | ||
PS C:\>Get-WAPVMRoleQuotaRequest -Subscription $Sub -VMRoleSizeProfile (Get-WAPVMRoleVMSize -Name A7) | ||
|
||
#> | ||
[CmdletBinding( DefaultParameterSetName="Size-Name" )] | ||
param( | ||
[Parameter( | ||
Mandatory, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true, | ||
ParameterSetName = "Size-Object" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some comments as above. If you use string literals (no variable expansion), please use single quotes. |
||
)] | ||
[System.Management.Automation.PSTypeName('WAP.VMRoleSizeProfile')] | ||
[PSCustomObject] $VMRoleSizeProfile, | ||
|
||
[Parameter( | ||
Mandatory, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true, | ||
ParameterSetName = "Size-Name" | ||
)] | ||
[string] $Size, | ||
|
||
[Parameter( | ||
Mandatory, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[System.Management.Automation.PSTypeName('WAP.Subscription')] | ||
[PSCustomObject] $Subscription = (Get-WAPSubscription), | ||
|
||
[Parameter( | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[int] $NumberOfNodes = 1 | ||
) | ||
|
||
process{ | ||
foreach ( $Sub in $Subscription ) { | ||
|
||
Select-WAPSubscription $Sub | ||
|
||
if ($Size) { | ||
$VMRoleSizeProfile = Get-WAPVMRoleVMSize -Name $Size | ||
} | ||
|
||
if ( $VMRoleSizeProfile ) { | ||
$Size = $VMRoleSizeProfile.Name | ||
} | ||
|
||
$Limits = Get-WAPSubscriptionQuota -Subscription $Sub | ||
|
||
[pscustomobject] $RequestObject = @{ | ||
SubscriptionName=$Limits.SubscriptionName; | ||
Size=$Size; | ||
NumberOfNodes=$NumberOfNodes | ||
} | ||
|
||
if ( $Limits.QuotaRoleMemory ) { | ||
|
||
[int] $SizeMem = $VMRoleSizeProfile.MemoryInMB | ||
[int] $CurrentMemory = $Limits.CurrentMemory | ||
[int] $QuotaMemory = $Limits.QuotaRoleMemory | ||
[int] $ExtraMem = $SizeMem * $NumberOfNodes | ||
Write-Verbose "MemInRequest:$ExtraMem" | ||
$RequestedMemory = $CurrentMemory + ($SizeMem * $NumberOfNodes) | ||
|
||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name MemoryRequired -Value $RequestedMemory -Force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name QuotaMemory -Value $QuotaMemory -Force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name MemoryCheck -Value ( $QuotaMemory -ge $RequestedMemory ) -Force | ||
|
||
} | ||
|
||
if ( $Limits.QuotaRoleCPUCount ) { | ||
|
||
[int] $SizeCores = $VMRoleSizeProfile.CpuCount | ||
[int] $CurrentCores = $Limits.CurrentCores | ||
[int] $QuotaCores = $Limits.QuotaRoleCPUCount | ||
[int] $ExtraCores = $SizeCores * $NumberOfNodes | ||
Write-Verbose "CoresInRequest:$ExtraCores" | ||
$RequestedCores = $CurrentCores + ($SizeCores * $NumberOfNodes) | ||
|
||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name CoresRequired -Value $RequestedCores -Force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name QuotaCores -Value $QuotaCores -Force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name CoresCheck -Value ( $QuotaCores -ge $RequestedCores ) -Force | ||
|
||
} | ||
|
||
if ( $Limits.QuotaMemberVMCount ) { | ||
|
||
[int] $CurrentVMs = $Limits.CurrentVms | ||
[int] $QuotaVMs = $Limits.QuotaRoleVMCount | ||
Write-Verbose "VMsInRequest:$NumberOfNodes" | ||
$RequestedVMs = $CurrentVMs + $NumberOfNodes | ||
|
||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name RequestedVMs -Value $RequestedVMs -force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name QuotaVMs -Value $QuotaVMs -force | ||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name VMCheck -Value ( $QuotaVMs -ge $RequestedVMs ) -force | ||
|
||
} | ||
$Checks = @($RequestObject.CoresCheck,$RequestObject.MemoryCheck,$RequestObject.VMCheck) | ||
|
||
Add-Member -InputObject $RequestObject -MemberType NoteProperty -Name WithinQuota -Value ( @( $Checks ) -notcontains $false )-force | ||
$RequestObject.PSObject.TypeNames.Insert( 0,'WAP.QuotaRequest' ) | ||
Write-Output $RequestObject | ||
} | ||
} | ||
} | ||
|
||
function Get-WAPGalleryVMRole { | ||
<# | ||
.SYNOPSIS | ||
|
@@ -709,8 +911,8 @@ function Get-WAPVMRoleOSDisk { | |
Write-Verbose -Message "Constructed VHD URI: $URI" | ||
|
||
$Sections = $ViewDef.ViewDefinition.Sections | ||
$Categories = $Sections | ForEach-Object -Process {$_.Categories} | ||
$OSDiskParam = $Categories | ForEach-Object -Process {$_.Parameters} | Where-Object -FilterScript {$_.Type -eq 'OSVirtualHardDisk'} | ||
$Categories = $Sections | foreach-Object -Process {$_.Categories} | ||
$OSDiskParam = $Categories | foreach-Object -Process {$_.Parameters} | Where-Object -FilterScript {$_.Type -eq 'OSVirtualHardDisk'} | ||
|
||
$Images = Invoke-RestMethod -Uri $URI -Headers $Headers -Method Get | ||
Write-Verbose "Images are : $($Images.Value)" | ||
|
@@ -1715,8 +1917,8 @@ function New-WAPVMRoleParameterObject { | |
} | ||
if ($PSCmdlet.ShouldProcess($null,'Generating new ParameterObject')) { | ||
$Sections = $VMRole.ViewDef.ViewDefinition.Sections | ||
$Categories = $Sections | ForEach-Object -Process {$_.Categories} | ||
$ViewDefParams = $Categories | ForEach-Object -Process {$_.Parameters} | ||
$Categories = $Sections | foreach-Object -Process {$_.Categories} | ||
$ViewDefParams = $Categories | foreach-Object -Process {$_.Parameters} | ||
$Output = [pscustomobject]@{} | ||
foreach ($P in $ViewDefParams) { | ||
$p | Out-String | Write-Verbose | ||
|
@@ -1730,7 +1932,7 @@ function New-WAPVMRoleParameterObject { | |
} | ||
$values = $values.TrimEnd(',') | ||
if ($P.DefaultValue) { | ||
if(($result = Read-Host -Prompt "Press enter to accept default value $($P.DefaultValue) for $($P.Name). Valid entries: $values") -eq ''){ | ||
if (($result = Read-Host -Prompt "Press enter to accept default value $($P.DefaultValue) for $($P.Name). Valid entries: $values") -eq ''){ | ||
Add-Member -InputObject $Output -MemberType NoteProperty -Name $P.Name -Value $P.DefaultValue -Force | ||
} else { | ||
do { | ||
|
@@ -2034,7 +2236,7 @@ function New-WAPVMRoleDeployment { | |
throw 'Object bound to ParameterObject parameter is of the wrong type' | ||
} | ||
|
||
$ParameterObject | Get-Member -MemberType Properties | ForEach-Object -Process { | ||
$ParameterObject | Get-Member -MemberType Properties | foreach-Object -Process { | ||
if ($null -eq $ParameterObject.($_.name)) { | ||
throw "ParameterObject property: $($_.name) is NULL" | ||
} | ||
|
@@ -3916,7 +4118,7 @@ function Expand-WAPVMRoleVMDisk { | |
$SizeInMB = $Size * 1024 | ||
PreFlight -IncludeConnection -IncludeSubscription | ||
$ParentVM = Get-WapVMRoleVM -CloudServiceName $Disk.ParentCloudService | ||
If($ParentVM.RuntimeState -ne "Stopped"){ | ||
if ($ParentVM.RuntimeState -ne "Stopped"){ | ||
throw "Disk may not be expanded whilst machine is running" | ||
} | ||
# Note we copy the WAPack Tenant Portal behaviour where the $CloudServiceName and $VMRoleName are identical and there is only 1 VMRole per CloudService | ||
|
@@ -3995,7 +4197,7 @@ function New-WAPVMRoleVMDisk { | |
# Note we copy the WAPack Tenant Portal behaviour where the $CloudServiceName and $VMRoleName are identical and there is only 1 VMRole per CloudService | ||
$Service = Get-WAPCloudService -Name $CloudServiceName | ||
$ParentVM = $Service | Get-WapVMRoleVM | ||
If($ParentVM.RuntimeState -ne "Stopped"){ | ||
if ($ParentVM.RuntimeState -ne "Stopped"){ | ||
throw "Disk may not be added to running machine" | ||
} | ||
#Set the LUN | ||
|
@@ -4044,13 +4246,13 @@ function Invoke-WAPVMRoleVMDiskExpansion{ | |
|
||
This will stop the VM, expand the VHD named DDrive to 50GB and then restart the VM. | ||
#> | ||
[CmdletBinding(SupportsShouldProcess=$True)] | ||
[CmdletBinding(SupportsShouldProcess=$true)] | ||
Param( | ||
[Parameter(Mandatory=$True)] | ||
[Parameter(Mandatory=$true)] | ||
[PSCustomObject] | ||
$Disk, | ||
|
||
[Parameter(Mandatory=$True)] | ||
[Parameter(Mandatory=$true)] | ||
[int] | ||
[ValidateRange(1,2048)] | ||
$Size | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForEach-Object is a cmdlet. Should be PasCal case. I guess you did a search replace?