-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSet-DCNMInterfaceAdminState.ps1
83 lines (73 loc) · 3.16 KB
/
Set-DCNMInterfaceAdminState.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function Set-DCNMInterfaceAdminState {
<#
.SYNOPSIS
Perform a shutdown/no shutdonw on interfaces
.DESCRIPTION
This cmdlet will invoke a REST POST against the DCNM Interface adminstatus
.EXAMPLE
Set-DCNMInterfaceAdminState -Fabric site3 -SwitchName SPINE-4 -Interface ethernet1/19 -Enabled false
.EXAMPLE
Set-DCNMInterfaceAdminState -Fabric site3 -SwitchName LEAF-12 -Interface vlan100 -Enabled true
.EXAMPLE
Set-DCNMInterfaceAdminState -Fabric site3 -SwitchName AG-2 -Interface vlan100,vlan200,eth1/100 -Enabled false
.PARAMETER Fabric
Name of the fabric
.PARAMETER SwitchName
Name of the switch
.PARAMETER Interface
Full interface name
.PARAMETER Enabled
Enables or disables the interfaces; true or false
/#>
param
(
[Parameter(Mandatory=$false)]
[ValidateSet("true","false")]
[string]$Enabled,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("fabricName")]
[string]$Fabric,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("sysName","logicalName")]
[string]$SwitchName,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true)]
[Alias("ifName")]
[string]$Interface,
[Parameter(Mandatory=$false, DontShow)]
[switch]$JSON
)
Begin {
$ifShut = @()
$ifNoSh = @()
}
Process {
$uri = "$Global:DCNMHost/rest/interface/adminstatus"
if (!(Get-Variable DCNMSwitch_$Fabric -ErrorAction SilentlyContinue)) {Get-DCNMSwitch -fabricName $Fabric | Out-Null}
$serial = ((Get-Variable DCNMSwitch_$Fabric -ValueOnly) | Where-Object -Property logicalName -EQ $SwitchName).serialNumber
[string]$Interface = $Interface.Split(',')
foreach ($i in $Interface) {
$i = $i.ToLower().Replace('eth(\d)','ethernet$1')
$ifName = New-Object -TypeName psobject
$ifName | Add-Member -Type NoteProperty -Name serialNumber -Value $serial
$ifName | Add-Member -Type NoteProperty -Name ifName -Value $i
if ($Enabled -eq 'true') {$ifNoSh += $ifName}
if ($Enabled -eq 'false') {$ifShut += $ifName}
}
}
End {
if ($ifNoSh) {
$body = New-Object -TypeName psobject
$body | Add-Member -Type NoteProperty -Name operation -Value noshut
$body | Add-Member -Type NoteProperty -Name interfaces -Value $ifNosh
if ($JSON) {$uri ; $Global:DCNM_JSON = (ConvertTo-Json -InputObject $body -Depth 10) ; $Global:DCNM_JSON} else {
$response = New-DCNMObject -uri $uri -object (ConvertTo-Json -InputObject $body -Depth 10) ; $response}
}
if ($ifShut) {
$body = New-Object -TypeName psobject
$body | Add-Member -Type NoteProperty -Name operation -Value shut
$body | Add-Member -Type NoteProperty -Name interfaces -Value $ifShut
if ($JSON) {$uri ; $Global:DCNM_JSON = (ConvertTo-Json -InputObject $body -Depth 10) ; $Global:DCNM_JSON} else {
$response = New-DCNMObject -uri $uri -object (ConvertTo-Json -InputObject $body -Depth 10) ; $response}
}
}
}