From ab143dd7795f18b8542258ff5e029f37e4a22325 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Wed, 7 Feb 2018 15:39:46 +0000 Subject: [PATCH 1/6] Fixed #468 --- module/PowerNSX.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 2f708f66..274df69e 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -7616,7 +7616,6 @@ function New-NsxController { } # Check for presence of optional controller name - if ($PSBoundParameters.ContainsKey("ControllerName")) {Add-XmlElement -xmlRoot $ControllerSpec -xmlElementName "name" -xmlElementText $ControllerName.ToString()} if ($PSBoundParameters.ContainsKey("Password") -and ($Ctrlcount.count -eq 0)) {Add-XmlElement -xmlRoot $ControllerSpec -xmlElementName "password" -xmlElementText $Password.ToString()} Add-XmlElement -xmlRoot $ControllerSpec -xmlElementName "datastoreId" -xmlElementText $DataStore.ExtensionData.Moref.value.ToString() Add-XmlElement -xmlRoot $ControllerSpec -xmlElementName "networkId" -xmlElementText $PortGroup.ExtensionData.Moref.Value.ToString() From 9f9da50e39f68dc0896dbfe2561190f624ef3672 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Wed, 7 Feb 2018 22:06:11 +0000 Subject: [PATCH 2/6] Fix for #470 --- module/PowerNSX.psm1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 274df69e..4a1ce7b7 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -8954,11 +8954,13 @@ function Get-NsxSegmentIdRange { $URI = "/api/2.0/vdn/config/segments" $response = invoke-nsxrestmethod -method "get" -uri $URI -connection $connection - switch ( $PSCmdlet.ParameterSetName ) { - "Name" { $response.segmentRanges.segmentRange | where-object { $_.name -eq $Name } } - "UniversalOnly" { $response.segmentRanges.segmentRange | where-object { $_.isUniversal -eq "true" } } - "LocalOnly" { $response.segmentRanges.segmentRange | where-object { $_.isUniversal -eq "false" } } - Default { $response.segmentRanges.segmentRange } + if(([bool](($response.segmentRanges).PSobject.Properties.name -match "segmentRange"))){ + switch ( $PSCmdlet.ParameterSetName ) { + "Name" { $response.segmentRanges.segmentRange | where-object { $_.name -eq $Name } } + "UniversalOnly" { $response.segmentRanges.segmentRange | where-object { $_.isUniversal -eq "true" } } + "LocalOnly" { $response.segmentRanges.segmentRange | where-object { $_.isUniversal -eq "false" } } + Default { $response.segmentRanges.segmentRange } + } } } } From b21e28087af7eb735687497379b6354460be4739 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Thu, 8 Feb 2018 10:51:33 +0000 Subject: [PATCH 3/6] adding get-nsxcontrollersyslog --- module/PowerNSX.psm1 | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 4a1ce7b7..f1cef38d 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -7906,6 +7906,62 @@ function Invoke-NsxControllerStateUpdate { Write-progress -activity "Controller Update State." -completed } +function Get-NsxControllerSyslog { + + <# + .SYNOPSIS + Retrieves NSX Controller Syslog Configuration. + + .DESCRIPTION + An NSX Controller is a member of the NSX Controller Cluster, and forms the + highly available distributed control plane for NSX Logical Switching and NSX + Logical Routing. + + The Get-NsxControllerSyslog cmdlet retrieves the NSX Controller Syslog configuratiob via the NSX API. + + .EXAMPLE + Get-NsxControllerSyslog + + Retreives all NSX Controller Syslog Configuration objects from NSX manager + + .EXAMPLE + Get-NsxController -objectId Controller-1 + + Returns a specific NSX Controller Syslog Configuration object from NSX manager + #> + + param ( + [Parameter (Mandatory=$false,Position=1)] + #ObjectId of the NSX Controller to return. + [string]$ObjectId, + [Parameter (Mandatory=$False)] + #PowerNSX Connection object + [ValidateNotNullOrEmpty()] + [PSCustomObject]$Connection=$defaultNSXConnection + + ) + + if($ObjectId) { + $controllers = Get-NSXController -ObjectId $ObjectId + } else { + $controllers = Get-NSXController + } + + foreach($controller in $controllers) { + $URI = "/api/2.0/vdn/controller/$($controller.Id)/syslog" + + [System.Xml.XmlDocument]$response = invoke-nsxrestmethod -method "get" -uri $URI -connection $connection + + if ((Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $response -Query 'descendant::controllers/controller')) { + if ( $PsBoundParameters.containsKey('objectId')) { + $response.controllers.controller | where-object { $_.Id -eq $ObjectId } + } else { + $response.controllers.controller + } + } + } +} + function New-NsxIpPool { <# From 891a25d43791cc6bb27657e0804591cd470f2b99 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Fri, 9 Feb 2018 12:32:11 +0000 Subject: [PATCH 4/6] Get and Set-NSXControllerSyslog working --- .DS_Store | Bin 0 -> 8196 bytes module/PowerNSX.psm1 | 117 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..096b076a9c0ba6cc2baa2ef85504216c23e6aa4f GIT binary patch literal 8196 zcmeHMTWl0n7(U-p%1k@ZX|1pnC%d&&5KCwgXeuJx8*)t>wx#7FWp-zT(b<`@GrI*! zNj1@E3=!V|jhDn1gO?WteN3<-0RIsZB5 zKmUKu`Q|(4>_5vGLr=lzU@XoUljz}6t)=W=64&!*PKt#sRU|?7jM>c0OnBoN+s(}B z9W_Js)7K8vK zc?b|BDpMQ~*d#-l3gxtrfhqYE(E~zLgdqlmIq8$UJIPcir-c;e48oit92sGRf?#yA zO9tH;QbI;~gg}JATm<;`sb)FmGJ_Q=;`h%pi)4zSRQg+d#0>s_F3k{nA+IuI=*f>Wv;Rj zyhn0Ot@CKjJF>1bm^Zn8BYFEguA8G8J>a={zc+9;YLS1@OD%ZjUXz?!MYE4wdn)8hOO_>8u3o#o^Wju~sZOnL zP#Tq`BSp)zGPXH9VHy6h{koSm9m8^t9w1m9-+J6K^Kw1fnB$XP}`nqJZrW`V8276qCdo$DzBstKuHf!2JuIbI2lpACaOlpnR zCabzMNqYA|i?%`8B&mixZ0i}*7EN8sW=Y*8j}!&sqOnogD#@c+ zHiW@H)ze;c1haLwcUn6Q)(&Gq9wIj6aySu zQthH9(;cL-^{kKWW=B|_O|rA>JbQz^&n~ko>{Ip?E3xbBC-xiro!wx6u$zcMLIax6 zf>zvzRcOZ+Y()y)*ol1@!61Lf6(?fh5#tes3G55L64&XsraY?3Fo zJ-TiCj@y{z*OqV+-PL&a(q+lkHS0EXJ<>Dt{wrSlKgk!cP0%TzS(!$`>z>8mlGp-D zVwl)yo|tbZsEhcnkxDC;H^me8CRR#BGBvEOO588eHc(@MuLs%^in@RpF9+534ke*3 zByvkZb>k*QQLBjkLi^BW(pD4Cg?6h(T1GlPjIt_GD@*^8vtO{Q>__%1vGpeV3)QGa z9L>bjwdf?CcB2pd*oFZNVlUDd#$k+wjLpHtapZ}$r*Q_;cnVMB1)L?$p2JJHNSu8Y zuiy=zBrt^;NI!CF!%{e&EPsgg}JAZG!-+`qF(pG@bd5ULI>F={Z6VPrTo>kbwzhK{!q_2**jz h{9#DtBz5IBsZdS}NiCHA_YVQl{U6=`0rT$c>~E&%CN%&6 literal 0 HcmV?d00001 diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index f1cef38d..b977e9be 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -7948,20 +7948,123 @@ function Get-NsxControllerSyslog { } foreach($controller in $controllers) { - $URI = "/api/2.0/vdn/controller/$($controller.Id)/syslog" + try { + $URI = "/api/2.0/vdn/controller/$($controller.Id)/syslog" - [System.Xml.XmlDocument]$response = invoke-nsxrestmethod -method "get" -uri $URI -connection $connection + [System.Xml.XmlDocument]$response = invoke-nsxrestmethod -method "get" -uri $URI -connection $connection - if ((Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $response -Query 'descendant::controllers/controller')) { - if ( $PsBoundParameters.containsKey('objectId')) { - $response.controllers.controller | where-object { $_.Id -eq $ObjectId } - } else { - $response.controllers.controller + if ((Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $response -Query 'descendant::controllerSyslogServer')) { + $response.controllerSyslogServer + } + } + catch { + if(!($_ -match "
Syslog server is not configured for controller $($controller.Id).
")) { + throw $_ } } } } +function Set-NsxControllerSyslog { + + <# + .SYNOPSIS + Configures NSX Controller Syslog Configuration. + + .DESCRIPTION + An NSX Controller is a member of the NSX Controller Cluster, and forms the + highly available distributed control plane for NSX Logical Switching and NSX + Logical Routing. + + The Set-NsxControllerSyslog cmdlet configures the NSX Controller Syslog via the NSX API. + + .EXAMPLE + Get-NSXController | Set-NsxControllerSyslog -Server + + Retreives all NSX Controller Syslog Configuration objects from NSX manager + + .EXAMPLE + Get-NsxController -objectId Controller-1 + + Returns a specific NSX Controller Syslog Configuration object from NSX manager + #> + + [CmdletBinding(DefaultParameterSetName="Object")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidDefaultValueSwitchParameter","")] # Cant remove without breaking backward compatibility + param ( + [Parameter (Mandatory=$true, ValueFromPipeline=$true,Position=1, ParameterSetName="Object")] + #PowerNSX Controller object obtained via Get-NsxController + [ValidateScript({ ValidateController $_ })] + [System.Xml.XmlElement]$Controller, + [Parameter (Mandatory=$true,ParameterSetName="objectId")] + #ObjectID of the controller to remove + [ValidateNotNullorEmpty()] + [string]$objectId, + [Parameter (Mandatory=$true)] + #Syslog Server IP + [ValidateNotNullorEmpty()] + [string]$SyslogServer, + [Parameter (Mandatory=$true)] + #Syslog Port + [ValidateNotNullorEmpty()] + [string]$Port, + [Parameter (Mandatory=$true)] + #Syslog Protocol + [ValidateSet('TCP','UDP')] + [string]$Protocol, + [Parameter (Mandatory=$true)] + #Syslog Logging Level + [ValidateSet('INFO','WARN','ERROR')] + [string]$Level, + [Parameter (Mandatory=$False)] + #PowerNSX Connection object + [ValidateNotNullOrEmpty()] + [PSCustomObject]$Connection=$defaultNSXConnection + ) + begin{} + + process { + if ( $PSCmdlet.ParameterSetName -ne "objectId" ) { + $objectId = $Controller.id + } + + #Construct the XML + [System.XML.XMLDocument]$xmlDoc = New-Object System.XML.XMLDocument + [System.XML.XMLElement]$xmlSyslog = $XMLDoc.CreateElement("controllerSyslogServer") + $xmlDoc.Appendchild($xmlSyslog) | out-null + + #Mandatory and default params + Add-XmlElement -xmlRoot $xmlSyslog -xmlElementName "syslogServer" -xmlElementText $syslogServer + Add-XmlElement -xmlRoot $xmlSyslog -xmlElementName "port" -xmlElementText $port + Add-XmlElement -xmlRoot $xmlSyslog -xmlElementName "protocol" -xmlElementText $protocol + Add-XmlElement -xmlRoot $xmlSyslog -xmlElementName "level" -xmlElementText $level + + try { + Write-Progress -activity "Configuring Syslog Server" + $URI = "/api/2.0/vdn/controller/$($objectId)/syslog" + $existingConfig = Get-NsxControllerSyslog -ObjectId $ObjectId -Connection $connection + if($existingConfig) { + # Delete existing configuration before posting the new one + $delete = invoke-NsxWebRequest -method "delete" -uri $URI -connection $connection + } + #Do the post + $body = $xmlSyslog.OuterXml + $response = invoke-NsxWebRequest -method "post" -uri $URI -body $body -connection $connection + Write-progress -activity "Configuring Syslog Server" -completed + + Get-NsxControllerSyslog -objectId $objectId -connection $connection + } + catch { + throw "Unable to configure NSX Controller Syslog - $_" + } + finally{} + + + } + + end{} +} + function New-NsxIpPool { <# From 34c13e3005379c245b253137c3219882b6f42c27 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Fri, 9 Feb 2018 16:31:03 +0000 Subject: [PATCH 5/6] Added remove-nsxcontrollersyslog and tidied help text --- .DS_Store | Bin 8196 -> 0 bytes module/PowerNSX.psm1 | 138 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 111 insertions(+), 27 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 096b076a9c0ba6cc2baa2ef85504216c23e6aa4f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMTWl0n7(U-p%1k@ZX|1pnC%d&&5KCwgXeuJx8*)t>wx#7FWp-zT(b<`@GrI*! zNj1@E3=!V|jhDn1gO?WteN3<-0RIsZB5 zKmUKu`Q|(4>_5vGLr=lzU@XoUljz}6t)=W=64&!*PKt#sRU|?7jM>c0OnBoN+s(}B z9W_Js)7K8vK zc?b|BDpMQ~*d#-l3gxtrfhqYE(E~zLgdqlmIq8$UJIPcir-c;e48oit92sGRf?#yA zO9tH;QbI;~gg}JATm<;`sb)FmGJ_Q=;`h%pi)4zSRQg+d#0>s_F3k{nA+IuI=*f>Wv;Rj zyhn0Ot@CKjJF>1bm^Zn8BYFEguA8G8J>a={zc+9;YLS1@OD%ZjUXz?!MYE4wdn)8hOO_>8u3o#o^Wju~sZOnL zP#Tq`BSp)zGPXH9VHy6h{koSm9m8^t9w1m9-+J6K^Kw1fnB$XP}`nqJZrW`V8276qCdo$DzBstKuHf!2JuIbI2lpACaOlpnR zCabzMNqYA|i?%`8B&mixZ0i}*7EN8sW=Y*8j}!&sqOnogD#@c+ zHiW@H)ze;c1haLwcUn6Q)(&Gq9wIj6aySu zQthH9(;cL-^{kKWW=B|_O|rA>JbQz^&n~ko>{Ip?E3xbBC-xiro!wx6u$zcMLIax6 zf>zvzRcOZ+Y()y)*ol1@!61Lf6(?fh5#tes3G55L64&XsraY?3Fo zJ-TiCj@y{z*OqV+-PL&a(q+lkHS0EXJ<>Dt{wrSlKgk!cP0%TzS(!$`>z>8mlGp-D zVwl)yo|tbZsEhcnkxDC;H^me8CRR#BGBvEOO588eHc(@MuLs%^in@RpF9+534ke*3 zByvkZb>k*QQLBjkLi^BW(pD4Cg?6h(T1GlPjIt_GD@*^8vtO{Q>__%1vGpeV3)QGa z9L>bjwdf?CcB2pd*oFZNVlUDd#$k+wjLpHtapZ}$r*Q_;cnVMB1)L?$p2JJHNSu8Y zuiy=zBrt^;NI!CF!%{e&EPsgg}JAZG!-+`qF(pG@bd5ULI>F={Z6VPrTo>kbwzhK{!q_2**jz h{9#DtBz5IBsZdS}NiCHA_YVQl{U6=`0rT$c>~E&%CN%&6 diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index b977e9be..947d40fe 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -7920,56 +7920,62 @@ function Get-NsxControllerSyslog { The Get-NsxControllerSyslog cmdlet retrieves the NSX Controller Syslog configuratiob via the NSX API. .EXAMPLE - Get-NsxControllerSyslog + Get-NSXController | Get-NsxControllerSyslog - Retreives all NSX Controller Syslog Configuration objects from NSX manager + Retreives all NSX Controller objects from NSX manager and returns the syslog configuration .EXAMPLE - Get-NsxController -objectId Controller-1 + Get-NsxControllerSyslog -objectId Controller-1 - Returns a specific NSX Controller Syslog Configuration object from NSX manager + Returns a specific NSX Controller syslog configuration object from NSX manager #> param ( - [Parameter (Mandatory=$false,Position=1)] - #ObjectId of the NSX Controller to return. - [string]$ObjectId, + [Parameter (Mandatory=$true, ValueFromPipeline=$true,Position=1, ParameterSetName="Object")] + #PowerNSX Controller object obtained via Get-NsxController + [ValidateScript({ ValidateController $_ })] + [System.Xml.XmlElement]$Controller, + [Parameter (Mandatory=$true,ParameterSetName="objectId")] + #ObjectID of the controller to get + [ValidateNotNullorEmpty()] + [string]$objectId, [Parameter (Mandatory=$False)] #PowerNSX Connection object [ValidateNotNullOrEmpty()] [PSCustomObject]$Connection=$defaultNSXConnection ) + begin {} - if($ObjectId) { - $controllers = Get-NSXController -ObjectId $ObjectId - } else { - $controllers = Get-NSXController - } - - foreach($controller in $controllers) { + process { + if ( $PSCmdlet.ParameterSetName -ne "objectId" ) { + $objectId = $Controller.id + } try { - $URI = "/api/2.0/vdn/controller/$($controller.Id)/syslog" - + $URI = "/api/2.0/vdn/controller/$($objectId)/syslog" [System.Xml.XmlDocument]$response = invoke-nsxrestmethod -method "get" -uri $URI -connection $connection - + write-host $response if ((Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $response -Query 'descendant::controllerSyslogServer')) { $response.controllerSyslogServer } } catch { - if(!($_ -match "
Syslog server is not configured for controller $($controller.Id).
")) { + if(($_ -match "
Syslog server is not configured for controller $($objectId).
")) { + Write-Warning "Syslog server is not configured for controller $($objectId)." + } else { throw $_ } } } + + end {} } function Set-NsxControllerSyslog { <# .SYNOPSIS - Configures NSX Controller Syslog Configuration. + Configures or updates NSX Controller Syslog Configuration. .DESCRIPTION An NSX Controller is a member of the NSX Controller Cluster, and forms the @@ -7979,14 +7985,14 @@ function Set-NsxControllerSyslog { The Set-NsxControllerSyslog cmdlet configures the NSX Controller Syslog via the NSX API. .EXAMPLE - Get-NSXController | Set-NsxControllerSyslog -Server + Get-NSXController | Set-NsxControllerSyslog -Server 192.168.1.20 -Port 514 -Protocol UDP -Level INFO - Retreives all NSX Controller Syslog Configuration objects from NSX manager + Gets all NSX Controllers from NSX Manager and sets the syslog configuration on each of them. .EXAMPLE - Get-NsxController -objectId Controller-1 + Get-NsxController -objectId Controller-1 | Set-NSXControllerSyslog -Server 192.168.1.20 -Port 514 -Protocol UDP -Level INFO - Returns a specific NSX Controller Syslog Configuration object from NSX manager + Gets a specific NSX Controller from NSX Manager and sets the syslog configuration. #> [CmdletBinding(DefaultParameterSetName="Object")] @@ -7997,7 +8003,7 @@ function Set-NsxControllerSyslog { [ValidateScript({ ValidateController $_ })] [System.Xml.XmlElement]$Controller, [Parameter (Mandatory=$true,ParameterSetName="objectId")] - #ObjectID of the controller to remove + #ObjectID of the controller to update [ValidateNotNullorEmpty()] [string]$objectId, [Parameter (Mandatory=$true)] @@ -8042,10 +8048,9 @@ function Set-NsxControllerSyslog { try { Write-Progress -activity "Configuring Syslog Server" $URI = "/api/2.0/vdn/controller/$($objectId)/syslog" - $existingConfig = Get-NsxControllerSyslog -ObjectId $ObjectId -Connection $connection + $existingConfig = Get-NsxControllerSyslog -ObjectId $ObjectId -Connection $connection -warningaction SilentlyContinue if($existingConfig) { - # Delete existing configuration before posting the new one - $delete = invoke-NsxWebRequest -method "delete" -uri $URI -connection $connection + Remove-NsxControllerSyslog -ObjectId $ObjectId -Connection $connection -Confirm:$false } #Do the post $body = $xmlSyslog.OuterXml @@ -8065,6 +8070,85 @@ function Set-NsxControllerSyslog { end{} } +function Remove-NsxControllerSyslog { + + <# + .SYNOPSIS + Removes NSX Controller Syslog Configuration. + + .DESCRIPTION + An NSX Controller is a member of the NSX Controller Cluster, and forms the + highly available distributed control plane for NSX Logical Switching and NSX + Logical Routing. + + The Remove-NsxControllerSyslog cmdlet removes the NSX Controller Syslog configuration via the NSX API. + + .EXAMPLE + Get-NsxControllerSyslog | Remove-NSXControllerSyslog + + Removes syslog configuration from all Controller objects from NSX manager + + .EXAMPLE + Remove-NsxController -objectId Controller-1 + + Removes the syslog configuration from a specific NSX Controller object from NSX manager + #> + + [CmdletBinding(DefaultParameterSetName="Object")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidDefaultValueSwitchParameter","")] # Cant remove without breaking backward compatibility + param ( + [Parameter (Mandatory=$true, ValueFromPipeline=$true,Position=1, ParameterSetName="Object")] + #PowerNSX Controller object obtained via Get-NsxController + [ValidateScript({ ValidateController $_ })] + [System.Xml.XmlElement]$Controller, + [Parameter (Mandatory=$true,ParameterSetName="objectId")] + #ObjectID of the controller to update + [ValidateNotNullorEmpty()] + [string]$objectId, + [Parameter (Mandatory=$False)] + #Prompt for confirmation. Specify as -confirm:$false to disable confirmation prompt + [switch]$Confirm=$true, + [Parameter (Mandatory=$False)] + #PowerNSX Connection object + [ValidateNotNullOrEmpty()] + [PSCustomObject]$Connection=$defaultNSXConnection + + ) + begin {} + + process { + if ( $PSCmdlet.ParameterSetName -ne "objectId" ) { + $objectId = $Controller.id + } + + if ( $confirm ) { + $message = "Controller syslog messages will no longer be sent to a syslog server." + $question = "Proceed with removal of Syslog configuration for $($objectId)?" + + $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes')) + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No')) + + $decision = $Host.UI.PromptForChoice($message, $question, $choices, 1) + } + else { $decision = 0 } + if ($decision -eq 0) { + try { + $URI = "/api/2.0/vdn/controller/$($objectId)/syslog" + $existingConfig = Get-NsxControllerSyslog -ObjectId $ObjectId -Connection $connection -warningaction SilentlyContinue + if($existingConfig) { + # Delete existing configuration before posting the new one + $delete = invoke-NsxWebRequest -method "delete" -uri $URI -connection $connection + } + } + catch { + } + } + } + + end {} +} + function New-NsxIpPool { <# From 932b85071622794895d29dd571651e66ecbb4b94 Mon Sep 17 00:00:00 2001 From: Sam McGeown Date: Thu, 15 Feb 2018 09:41:52 +0000 Subject: [PATCH 6/6] Added tests to 15.controller.tests.ps1 for syslog functions. Corrected typo in help text for syslog functions --- module/PowerNSX.psm1 | 4 +-- tests/integration/15.Controller.Tests.ps1 | 32 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 947d40fe..78ffc405 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -7985,12 +7985,12 @@ function Set-NsxControllerSyslog { The Set-NsxControllerSyslog cmdlet configures the NSX Controller Syslog via the NSX API. .EXAMPLE - Get-NSXController | Set-NsxControllerSyslog -Server 192.168.1.20 -Port 514 -Protocol UDP -Level INFO + Get-NSXController | Set-NsxControllerSyslog -syslogServer 192.168.1.20 -Port 514 -Protocol UDP -Level INFO Gets all NSX Controllers from NSX Manager and sets the syslog configuration on each of them. .EXAMPLE - Get-NsxController -objectId Controller-1 | Set-NSXControllerSyslog -Server 192.168.1.20 -Port 514 -Protocol UDP -Level INFO + Get-NsxController -objectId Controller-1 | Set-NSXControllerSyslog -syslogServer 192.168.1.20 -Port 514 -Protocol UDP -Level INFO Gets a specific NSX Controller from NSX Manager and sets the syslog configuration. #> diff --git a/tests/integration/15.Controller.Tests.ps1 b/tests/integration/15.Controller.Tests.ps1 index 2de241c6..971548be 100644 --- a/tests/integration/15.Controller.Tests.ps1 +++ b/tests/integration/15.Controller.Tests.ps1 @@ -56,6 +56,38 @@ Describe -Tag 'Slow' "Controller" { {Invoke-NsxControllerStateUpdate -Wait -WaitTimeout 300} | should not throw } + It "Can set controller syslog configuration" { + {$script:ControllerSyslog = Get-NSXController -ObjectId $ctrl.id | Set-NsxControllerSyslog -syslogServer "192.168.1.20" -Port "514" -Protocol "UDP" -Level "INFO" } | should not throw + $ControllerSyslog | should not be $null + $ControllerSyslog.syslogServer | should be "192.168.1.20" + $ControllerSyslog.port | should be "514" + $ControllerSyslog.protocol | should be "UDP" + $ControllerSyslog.level | should be "INFO" + } + + It "Can get controller syslog configuration" { + {$script:ControllerSyslog = Get-NSXControllerSyslog -ObjectId $ctrl.id} | should not throw + $ControllerSyslog | should not be $null + $ControllerSyslog.syslogServer | should be "192.168.1.20" + $ControllerSyslog.port | should be "514" + $ControllerSyslog.protocol | should be "UDP" + $ControllerSyslog.level | should be "INFO" + } + + It "Can update controller syslog configuration" { + {$script:ControllerSyslog = Get-NSXController -ObjectId $ctrl.id | Set-NsxControllerSyslog -syslogServer "192.168.1.21" -Port "515" -Protocol "TCP" -Level "WARN" } | should not throw + $ControllerSyslog | should not be $null + $ControllerSyslog.syslogServer | should be "192.168.1.21" + $ControllerSyslog.port | should be "515" + $ControllerSyslog.protocol | should be "TCP" + $ControllerSyslog.level | should be "WARN" + } + + It "Can delete controller syslog configuration" { + {Get-NsxControllerSyslog -ObjectId $ctrl.id | Remove-NSXControllerSyslog} | should not throw + Get-NSXControllerSyslog -ObjectId $ctrl.id | should be $null + } + AfterAll {