Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ShouldProcess for PowerArubaSW #120

Merged
merged 31 commits into from
Dec 6, 2021

Conversation

blurpiflurp
Copy link

@blurpiflurp blurpiflurp commented Dec 1, 2020

Hi!

This proposed change adds support for -confirm:$false instead of using internal logic and "-noconfirm" flags.

However you might want to work a bit with the message displayed if its not to your liking.

PS > Remove-ArubaSWVLAN -id 10

Confirm
Are you sure you want to perform this action?
Performing the operation "Remove VLAN" on target "Vlan ID 10".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): n
PS > Remove-ArubaSWVLAN -id 10 -Confirm:$false
PS >

@blurpiflurp
Copy link
Author

I've also updated the vlan tests and also the help section of the cmdlet.

@alagoutte
Copy link
Collaborator

Hi,

yes, i need to use ShouldProcess for all (remove) command !

What do you have make change on Connection.ps1 ?

@blurpiflurp
Copy link
Author

blurpiflurp commented Dec 1, 2020

It should have been a separate pull.

I changed it so it uses write-verbose if you specify -verbose instead of having “noverbose” flag on it.

And I also added so the name of the switch is added to the connection so if for instance you have 100 switches you can do
$arubaswitchcollection|where name -eq 'switch1' or when adding vlans you get which switch you're adding it to.

I've made a small function that imports vlans from an excel file and adds them to a collection of switches. When doing this its preferable that errors etc refers to a specific switch. Or for instance see this code that I use for cleaning up a lab I was doing.

function Remove-ArubaLabVLAN {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
    Param(
        [Parameter (Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection = $DefaultArubaSWConnection
    )
    Begin {
    }

    Process {
        if ($null -eq $connection -or [string]::IsNullOrEmpty($connection)) {
            write-error "No ArubaSwitch specified"
            return
        }
        if ($connection.count -gt 1 -and $connection.GetType().basetype.name -eq 'Array') {
            $buff = foreach ($aconn in $connection) {
                Remove-ArubaLabVLAN -connection $aconn
            }
            $buff
        } else {
            Write-Progress -activity "Remove Vlan on $($connection.Name)" -id 4 -percentcomplete 0
            $tot = 8
            foreach ($id in @(601..608)) {
                $count = $id-600
                $uri = "rest/v4/vlans/${id}"
                $target = "{0} on {1}" -f $id, $connection.Name
                if ($PSCmdlet.ShouldProcess($target, "Remove VLAN")) {
                    Write-Progress -activity "Remove Vlan on $($connection.Name)" -status $id -id 4 -percentcomplete $($count/$tot*100)
                    $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection
                    Write-Progress -activity "Remove Vlan on $($connection.name)" -id 4 -percentcomplete $($count/$tot*100)
                }
            }
        }
    }

    End {
    }
}

@alagoutte
Copy link
Collaborator

It should have been a separate pull.
Yes please !

I changed it so it uses write-verbose if you specify -verbose instead of having “noverbose” flag on it.

Yes, it is not a good idea to have noverbose flag...

And I also added so the name of the switch is added to the connection so if for instance you have 100 switches you can do
$arubaswitchcollection|where name -eq 'switch1' or when adding vlans you get which switch you're adding it to.

I've made a small function that imports vlans from an excel file and adds them to a collection of switches. When doing this its preferable that errors etc refers to a specific switch. Or for instance see this code that I use for cleaning up a lab I was doing.

function Remove-ArubaLabVLAN {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
    Param(
        [Parameter (Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection = $DefaultArubaSWConnection
    )
    Begin {
    }

    Process {
        if ($null -eq $connection -or [string]::IsNullOrEmpty($connection)) {
            write-error "No ArubaSwitch specified"
            return
        }
        if ($connection.count -gt 1 -and $connection.GetType().basetype.name -eq 'Array') {
            $buff = foreach ($aconn in $connection) {
                Remove-ArubaLabVLAN -connection $aconn
            }
            $buff
        } else {
            Write-Progress -activity "Remove Vlan on $($connection.Name)" -id 4 -percentcomplete 0
            $tot = 8
            foreach ($id in @(601..608)) {
                $count = $id-600
                $uri = "rest/v4/vlans/${id}"
                $target = "{0} on {1}" -f $id, $connection.Name
                if ($PSCmdlet.ShouldProcess($target, "Remove VLAN")) {
                    Write-Progress -activity "Remove Vlan on $($connection.Name)" -status $id -id 4 -percentcomplete $($count/$tot*100)
                    $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection
                    Write-Progress -activity "Remove Vlan on $($connection.name)" -id 4 -percentcomplete $($count/$tot*100)
                }
            }
        }
    }

    End {
    }
}

ok interesting...

@alagoutte
Copy link
Collaborator

can you split your patch (and make a another PR for connection stuff ?)

@blurpiflurp
Copy link
Author

Yeah I'm working on a larger patch for more stuff so will do in a couple of days and we will see what you approve :)

@alagoutte alagoutte changed the title Update Vlans.ps1 Update ShouldProcess for Vlans and remove -noverbose for Connection Nov 12, 2021
oitptobbe added 3 commits November 30, 2021 21:31
Hi!

This proposed change adds support for -confirm:$false instead of using internal logic and "-noconfirm" flags.

However you might want to work a bit with the message displayed if its not to your liking.

PS > Remove-ArubaSwitchVLAN -id 10

Confirm
Are you sure you want to perform this action?
Performing the operation "Remove VLAN" on target "Vlan ID 10".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): n
PS > Remove-ArubaSwitchVLAN -id 10 -Confirm:$false
PS >
@alagoutte alagoutte changed the title Update ShouldProcess for Vlans and remove -noverbose for Connection Update ShouldProcess for PowerArubaSW Dec 1, 2021
@alagoutte alagoutte merged commit 1454ae9 into PowerAruba:master Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants