Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Added Quota functionality #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ C:\>Get-WAPCloudService -Name DCs | Get-WAPVMRoleVM
#get additional information for VM Role deployed VM instance
Get-WAPCloudService -Name DCs | Get-WAPVMroleVM -VMMEnhanced

#get quotas of your subscriptions
Get-WAPSubscriptionQuota

#Confirm whether a specific request will meet a quota.
Get-WAPSubscription -Name "MySubscription" | Get-WAPVMRoleQuotaRequest -Size "Large" -NumberOfNodes 4

#connect to VM Role VM instances over RDP
C:\>Get-WAPCloudService -Name DCs | Get-WAPVMRoleVM | Connect-WAPVMRDP

Expand Down
186 changes: 186 additions & 0 deletions WapTenantPublicAPI.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,192 @@ function GetWAPSubscriptionQuota {

}

function Get-WAPSubscriptionQuota{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space between function name and opening curly

Did you know there is already GetWAPSubscriptionQuota helper function? Could you investigate to what extent the logic is duplicate and if one can replace the other entirely or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did notice that. It seems to only be designed to work with SQL servers. I haven't got any of those yet so I can't outright test the function.

The internal function simply returns basequotasettings but only for SQL servers. It assumes you've selected a subscription.

My one collects subscription.service.basequotasettings.clouds.cloud.quota as well as calculating the current consumption. It takes Subscription Objects as inputs.

So they both have radically different views on what we are getting the Quota for (one is SQL, one is VM provisioning).

Possible options:

  1. Expand the WAP.Quota object to include SQL so that if it's a SQL subscription, it includes the relavant parts.

  2. Rename them to make the names clearer - perhaps Get-WAPSQLQuota and Get-WAPSubscriptionCloudQuota

Since the original helper function is never exported, we can be confident that renaming the old one won't dramatically break anything :)

<#
.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()]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything inside the function should be indented 1 level

Param(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase p

[Parameter(
Mandatory=$False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add Mandatory=$false. It's sufficient to not specify it if it's not mandatory ;).
If a Parameter is Mandatory, it should just have the word Mandatory without = $true

ValueFromPipeline=$True,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowercase t on $True and there should be spaces surrounding '=' (everywhere ;) )

ValueFromPipelineByPropertyName=$True,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What object has the property Subscription that can be bound by this attribute spec?

Position=0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike positional binding as you need to assure backwards compat all the time. (keep it in if you want, just my 2 cts)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood and agreed!

)]
[System.Management.Automation.PSTypeName('WAP.Subscription')]
$Subscription = (Get-WAPSubscription)
)
process{
ForEach ($Sub in $Subscription){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between ){

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"){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use more spaces overall 😄

[xml]$Data = $Setting.Value
$Output = $Data.Clouds.Cloud.Quota
$Object = New-Object -Type PsObject -Property @{
SubscriptionName=$Sub.SubscriptionName;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent one level. You can replace the new-object by the [pscustomobject] type accelerator

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)

#>
Param(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmdletbinding missing and same lower case and indent comments as the other function

What is the default parametersetname?

[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
Position=0,
ParameterSetName = "Size-Object"
)]
[System.Management.Automation.PSTypeName('WAP.VMRoleSizeProfile')]
$VMRoleSizeProfile,

[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
Position=0,
ParameterSetName = "Size-Name"
)]
[string]
$Size,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please construct parameter specifications similar to overall style
[type] $Name


[Parameter(
Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
Position=1
)]
[System.Management.Automation.PSTypeName('WAP.Subscription')]
$Subscription = (Get-WAPSubscription),

[Parameter(
Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
Position=2
)]
[int]
$NumberOfNodes = 1
)
begin{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for begin if it's empty


}
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
$RequestObject = New-Object -TypeName PsObject -Property @{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
Expand Down