Debian Codegraph @

ansible_collections/lowlydba/sqlserver/plugins/modules/resource_governor.ps1

raw
1 #!powershell
2 # -*- coding: utf-8 -*-
3
4 # (c) 2022, John McCall (@lowlydba)
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 #AnsibleRequires -CSharpUtil Ansible.Basic
8 #AnsibleRequires -PowerShell ansible_collections.lowlydba.sqlserver.plugins.module_utils._SqlServerUtils
9 #Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="2.0.0" }
10
11 $ErrorActionPreference = "Stop"
12
13 $spec = @{
14 supports_check_mode = $true
15 options = @{
16 enabled = @{type = 'bool'; required = $false; default = $true }
17 classifier_function = @{type = 'str'; required = $false }
18 }
19 }
20
21 # Get Csharp utility module
22 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec, @(Get-LowlyDbaSqlServerAuthSpec))
23
24 $sqlInstance, $sqlCredential = Get-SqlCredential -Module $module
25 $enabled = $module.Params.enabled
26 $classifierFunction = $module.Params.classifier_function
27 $checkMode = $module.CheckMode
28 $module.Result.changed = $false
29 $PSDefaultParameterValues = @{ "*:EnableException" = $true; "*:Confirm" = $false; "*:WhatIf" = $checkMode }
30
31 try {
32 $rg = Get-DbaResourceGovernor -SqlInstance $sqlInstance -SqlCredential $sqlCredential
33 $rgClassifierFunction = $rg.ClassifierFunction
34
35 if ($rg.Enabled -ne $enabled) {
36 $change = $true
37 }
38 if ($classifierFunction -ne "NULL" -and $rgClassifierFunction -ne $classifierFunction) {
39 $change = $true
40 }
41 if ($classifierFunction -eq "NULL" -and $null -ne $rgClassifierFunction) {
42 $change = $true
43 }
44
45 if ($change) {
46 $rgSplat = @{
47 SqlInstance = $sqlInstance
48 SqlCredential = $sqlCredential
49 ClassifierFunction = $classifierFunction
50 }
51 if ($enabled) {
52 $rgSplat.Add("Enabled", $true)
53 }
54 else {
55 $rgSplat.Add("Disabled", $true)
56 }
57 $output = Set-DbaResourceGovernor @rgSplat
58 $module.Result.changed = $true
59 }
60
61 if ($null -ne $output) {
62 $resultData = ConvertTo-SerializableObject -InputObject $output
63 $module.Result.data = $resultData
64 }
65 $module.ExitJson()
66 }
67 catch {
68 $module.FailJson("Setting resource governor failed.", $_)
69 }