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

Add Remove-NsxServiceGroupMember cmdlet #448

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion module/Include.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ $FunctionsToExport = @(
'Add-NsxServiceGroupMember',
'Get-NsxServiceGroup',
'Get-NsxServiceGroupMember',
'Remove-NsxServiceGroupMember',
'Remove-NsxServiceGroup',
'Get-NsxLoadBalancerStats',
'Get-NsxFirewallSavedConfiguration',
Expand Down Expand Up @@ -346,4 +347,3 @@ $Common = @{
$CoreRequiredModules = @("PowerCLI.Vds","PowerCLI.ViCore")
$DesktopRequiredModules = @("VMware.VimAutomation.Core","VMware.VimAutomation.Vds")
$GalleryRequiredModules = @("VMware.VimAutomation.Core","VMware.VimAutomation.Vds")

71 changes: 71 additions & 0 deletions module/PowerNSX.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26657,6 +26657,77 @@ function Add-NsxServiceGroupMember {
end {}
}

function Remove-NsxServiceGroupMember {

<#
.SYNOPSIS
Removes a single Service, numerous Services, or a Service Group to a Service
Group
Copy link
Contributor

Choose a reason for hiding this comment

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

Reword : Removes one or more services or service groups from a service group.


.DESCRIPTION
Removes the defined Service or Service Group to an NSX Service Groups. Service
Copy link
Contributor

Choose a reason for hiding this comment

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

from an NSX Service Group_

groups contain a mixture of selected ports to represent a potential
grouping of like ports.

This cmdlet removes the defined Services or Service Groups within a Service
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unclear (all service groups? If you are implying that user can pass all servicegroups on the pipeline, thats a given...) - reword?

Group for specific or all Service Groups

.EXAMPLE
Get-NsxServiceGroup Heartbeat | Remove-NsxServiceGroupMember -Member $Service1

Remove all saved Service Group Members named Heartbeat in Service Group in $Service1
Copy link
Contributor

Choose a reason for hiding this comment

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

description is not clear. and you probably should show how you get $service1. Reword to something like 'Gets the service fred and removes it from the service group Heartbeat.


Get-NsxServiceGroup Service-Group-4 | Remove-NsxServiceGroupMember $Service1,$Service2 -Confirm:$false
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a new .EXAMPLE header.


Remove all saved Service Group Members named Heartbeat in Service Group in $Service1 and $Service2 without prompting for confirmation
Copy link
Contributor

Choose a reason for hiding this comment

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

again the comment is not so clear. There is no mention of heartbeat in the cli example?


#>

param (
#Mastergroup removed from Get-NsxServiceGroup
[Parameter (Mandatory=$true,ValueFromPipeline=$true)]
[ValidateScript({ ValidateServiceGroup $_ })]
[System.Xml.XmlElement]$ServiceGroup,
[Parameter (Mandatory=$False)]
#Prompt for confirmation. Specify as -confirm:$false to disable confirmation prompt
[switch]$Confirm=$true,
[Parameter (Mandatory=$true,Position=1)]
[ValidateScript({ ValidateServiceOrServiceGroup $_ })]
#The [] in XmlElement means it can expect more than one object!
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid programmer comments in the param block - these are visible to the user in get-help and should be used to explain what the param is. you can tell the user that you accept a collection if you want but do it in a user centric way.

[System.Xml.XmlElement[]]$Member,
[Parameter (Mandatory=$False)]
#PowerNSX Connection object
[ValidateNotNullOrEmpty()]
[PSCustomObject]$Connection=$defaultNSXConnection
)

begin {}

process{
foreach ($Mem in $Member){
if ( $confirm ) {
$message = "Removal of a Service Group Member is permanent."
$question = "Proceed with removal of Service Group Member $($Mem.name)?"

$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) {
$URI = "/api/2.0/services/applicationgroup/$($ServiceGroup.objectId)/members/$($Mem.objectId)"
$null = invoke-nsxwebrequest -method "DELETE" -uri $URI -connection $connection
Write-Progress -activity "Removing Service or Service Group $($Mem) to Service Group $($ServiceGroup)"
Copy link
Contributor

Choose a reason for hiding this comment

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

write-progress needs to have a 'before' and 'after' write-progress (with the latter specifying -completed) otherwise you get 'hanging' progress dialog.

}
}
}

end {}
}

function Get-NsxApplicableMember {

<#
Expand Down