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

Added Quota functionality #8

wants to merge 2 commits into from

Conversation

istairbn
Copy link
Collaborator

@istairbn istairbn commented Jul 5, 2017

Needed to be able to determine whether or not an API call would succeed due to quotas.

Get-WAPSubscriptionQuota pulls the quota and returns an object with nulls. Give it a Subscription - if there isn't one, it'll get the quota objects for all of them. You can use this for reporting purposes too.

Get-WAPVMRoleQuotaRequest takes a Subscription and VMRoleSizeProfile (or a name of one). It checks to see if the amount of those Node sizes will break the bank. Utilmately the WithinQuota boolean is what you need.

I've tested it and it all works, can you just do a quick code review to confirm you're happy @bgelens :)

Copy link
Owner

@bgelens bgelens left a comment

Choose a reason for hiding this comment

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

Hey Ben, got some points.

@@ -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 :)

PS C:\>Get-WAPSubscriptionQuota -Subscription $Sub
#>
[CmdletBinding()]
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

[CmdletBinding()]
Param(
[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

Param(
[Parameter(
Mandatory=$False,
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 ;) )

[Parameter(
Mandatory=$False,
ValueFromPipeline=$True,
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?

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

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?

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

[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

Copy link
Owner

@bgelens bgelens left a comment

Choose a reason for hiding this comment

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

Been on holiday for a while.. sorry :)
Could you fix these final things. Then you can go ahead and merge it!

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

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?

[CmdletBinding()]
param(
[Parameter(
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.

No need to add $true

[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] is enough.

ValueFromPipelineByPropertyName = $true
)]
[System.Management.Automation.PSTypeName('WAP.Subscription')]
[PSCustomObject] $Subscription = (Get-WAPSubscription)
Copy link
Owner

Choose a reason for hiding this comment

The 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:

[Parameter(Attributes)]
[System.Management.Automation.PSTypeName('WAP.Subscription')] $Subscription

Mandatory,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = "Size-Object"
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants