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

Commit

Permalink
fixed de-serialization bugs. fixed quota behavior. fixed show only da…
Browse files Browse the repository at this point in the history
…tabases of currently selected sql offer
  • Loading branch information
bgelens committed Feb 19, 2016
1 parent 738f5e7 commit 9d260ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions WapTenantPublicAPI.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'WapTenantPublicAPI'

# Version number of this module.
ModuleVersion = '0.0.5.1'
ModuleVersion = '0.0.5.2'

# ID used to uniquely identify this module
GUID = 'eaa28acf-4a1e-4d0e-96dd-fa36de33a658'
Expand Down Expand Up @@ -92,7 +92,7 @@ PrivateData = @{
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()
Tags = @('WAPack','VMRole','AzurePack','PSModule','DBaaS')

# A URL to the license for this module.
LicenseUri = 'https://github.com/bgelens/WAPTenantPublicAPI/blob/master/LICENSE'
Expand Down
48 changes: 28 additions & 20 deletions WapTenantPublicAPI.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ function GetWAPSubscriptionQuota {
}
if ($Servicetype -eq 'sqlservers') {
PreFlight -IncludeConnection -IncludeSubscription -IncludeSQLOffer
$BaseQuota = (Get-WAPSubscription -Id $Subscription.SubscriptionID | Select-Object -ExpandProperty Services | ?{$_.Type -eq $Servicetype}).BaseQuotaSettings
foreach ($B in $BaseQuota.value) {
$B | ConvertFrom-Json
$BaseQuota = (Get-WAPSubscription -Id $Subscription.SubscriptionID | Select-Object -ExpandProperty Services | ?{$_.Type -eq $Servicetype}).BaseQuotaSettings.Value | ConvertFrom-Json
foreach ($B in $BaseQuota) {
$B
}
}

Expand Down Expand Up @@ -2472,12 +2472,15 @@ function Get-WAPSQLDatabase {
IgnoreSSL
}

PreFlight -IncludeConnection -IncludeSubscription
PreFlight -IncludeConnection -IncludeSubscription -IncludeSQLOffer

$URI = '{0}:{1}/{2}/services/sqlservers/databases' -f $PublicTenantAPIUrl,$Port,$Subscription.SubscriptionId
Write-Verbose -Message "Constructed SQL Database URI: $URI"
$Databases = Invoke-RestMethod -Uri $URI -Headers $Headers -Method Get
foreach ($D in $Databases) {
if ($D.Edition -ne $SQLOffer.Edition) {
continue
}
if ($PSCmdlet.ParameterSetName -eq 'Name' -and $D.Name -ne $Name) {
continue
}
Expand Down Expand Up @@ -2524,15 +2527,15 @@ function Get-WAPSQLOffer {
$URI = '{0}:{1}/{2}/services/sqlservers' -f $PublicTenantAPIUrl,$Port,$Subscription.SubscriptionId
Write-Verbose -Message "Constructed SQL Offer URI: $URI"

$Offers = Invoke-RestMethod -Uri $URI -Headers $Headers -Method Get
foreach ($O in $Offers.QuotaSettings.Value) {
$Obj = $O | ConvertFrom-Json
if ($PSCmdlet.ParameterSetName -eq 'Named' -and $Obj.displayName -ne $Name) {
$Offers = (Invoke-RestMethod -Uri $URI -Headers $Headers -Method Get).QuotaSettings.value | ConvertFrom-Json
foreach ($O in $Offers) {
Write-Verbose -Message "Processing: $O"
if ($PSCmdlet.ParameterSetName -eq 'Named' -and $O.displayName -ne $Name) {
continue
}
$OutputObj = $Obj | Add-Member -MemberType AliasProperty -Name Edition -Value displayName -PassThru
$OutputObj.PSObject.TypeNames.Insert(0,'WAP.SQLOffer')
Write-Output -InputObject $OutputObj
$O = $O | Add-Member -MemberType AliasProperty -Name Edition -Value displayName -PassThru
$O.PSObject.TypeNames.Insert(0,'WAP.SQLOffer')
Write-Output -InputObject $O
}
} catch {
Write-Error -ErrorRecord $_
Expand Down Expand Up @@ -2652,7 +2655,7 @@ function New-WAPSQLDatabase {
$URI = '{0}:{1}/{2}/services/sqlservers/databases' -f $PublicTenantAPIUrl,$Port,$Subscription.SubscriptionId
Write-Verbose -Message "Constructed SQL Database URI: $URI"

$Quota = GetWAPSubscriptionQuota -Servicetype sqlservers
$Quota = GetWAPSubscriptionQuota -Servicetype sqlservers | ?{$_.groupName -eq $SQLOffer.groupName}

$DBConfig = @{
Name = $Name
Expand All @@ -2664,9 +2667,12 @@ function New-WAPSQLDatabase {
IsContained = $true
}
if ($WindowsAuthentication) {
# // TODO: Builtin check if Windows auth is supported Edition: supportedAuthenticationModes = 3 (quota has this value)
$DBConfig.Add('AuthenticationMode','Windows')
$DBConfig.Add('AdminLogon',$WindowsAccount)
if ($Quota.supportedAuthenticationModes -eq 3) {
$DBConfig.Add('AuthenticationMode','Windows')
$DBConfig.Add('AdminLogon',$WindowsAccount)
} else {
throw "SQL Offer $($SQLOffer.Edition) does not support Windows Authentication"
}
} else {
$DBConfig.Add('Password', $Credential.GetNetworkCredential().Password)
$DBConfig.Add('AdminLogon', $Credential.UserName)
Expand Down Expand Up @@ -2776,10 +2782,12 @@ function Resize-WAPSQLDatabase {

PreFlight -IncludeConnection -IncludeSubscription -IncludeSQLOffer

$Quota = GetWAPSubscriptionQuota -Servicetype sqlservers

if ($SizeMB -lt $Quota.resourceSize -or $SizeMB -gt $SQLOffer.resourceSizeLimit) {
throw "Specify a size between $($Quota.resourceSize) and $($SQLOffer.resourceSizeLimit)"
if ($SizeMB -lt $Database.BaseSizeMB) {
throw "Value specified $SizeMB is less then the minimum size of the database $($Database.BaseSizeMB)"
}

if ($SizeMB -gt $Database.Quota) {
throw "Value specified $SizeMB is greater then the maximum size of the database $($Database.Quota)"
}

if ($PSCmdlet.ShouldProcess($Database.Name)) {
Expand Down Expand Up @@ -2832,7 +2840,7 @@ function Remove-WAPSQLDatabase {
IgnoreSSL
}
if (!($Database.pstypenames.Contains('WAP.SQLDatabase'))) {
throw 'Object bound to Database parameter is of the wrong type'
throw 'Object bound to Database parameter is of the wrong type'
}

PreFlight -IncludeConnection -IncludeSubscription -IncludeSQLOffer
Expand Down

0 comments on commit 9d260ed

Please sign in to comment.