-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-DCNMVlan.ps1
86 lines (76 loc) · 3.42 KB
/
New-DCNMVlan.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
84
85
86
function New-DCNMVlan {
<#
.SYNOPSIS
Creates a new VLAN
.DESCRIPTION
This cmdlet will invoke a REST POST against the DCNM policies > bulk-create API
.EXAMPLE
New-DCNMVlan -Fabric site1 -Switch SW-1 -VlanName TEST_VLAN -VlanID 1126
.EXAMPLE
New-DCNMVlan -Fabric site2 -Switch 'Leaf-2,Leaf-3' -VlanName TEST_VLAN2 -VlanID 101 -VNI 30303
.EXAMPLE
Get-DCNMSwitch -fabricName site3 -SwitchRole Leaf | New-DCNMVlan -VlanName SomeVlan -VlanID 2020 -Mode FabricPath
.PARAMETER Fabric
Fabric name
.PARAMETER Name
VLAN name
.PARAMETER VNI
VNI number
.PARAMETER Mode
Classic Ethernet (CE) or FabricPath
/#>
param
(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("fabricName")]
[string]$Fabric,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("logicalName")]
[string]$SwitchName,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[Alias("Name")]
[string]$VlanName,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[ValidateRange(2,3967)]
[Alias("Id")]
[int]$VlanID,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[ValidateRange(1,16777214)]
[int]$VNI,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[ValidateSet("CE","FABRICPATH")]
[string]$VlanMode="CE",
[Parameter(Mandatory=$false, DontShow)]
[switch]$JSON
)
Begin {}
Process {
$response=@()
$uri = "$Global:DCNMHost/rest/control/policies/bulk-create"
$body =@()
$nvPairs =@()
if (!(Get-Variable DCNMSwitch_$Fabric -ErrorAction SilentlyContinue)) {Get-DCNMSwitch -fabricName $Fabric | Out-Null}
$SwitchList = @()
$SwitchName.Split(',') | ForEach-Object {
$SwitchList += (((Get-Variable DCNMSwitch_$Fabric -ValueOnly) | Where-Object -Property logicalName -EQ $_).serialNumber)
}
$nvPairs = New-Object -TypeName psobject
$nvPairs | Add-Member -Type NoteProperty -Name 'VLAN' -Value $VlanId.ToString()
$nvPairs | Add-Member -Type NoteProperty -Name 'NAME' -Value $VlanName
$nvPairs | Add-Member -Type NoteProperty -Name 'MODE' -Value $VlanMode
if (!$VNI) {$nvPairs | Add-Member -Type NoteProperty -Name 'VNI' -Value ''} else {
$nvPairs | Add-Member -Type NoteProperty -Name 'VNI' -Value $VNI.ToString()}
$body = New-Object -TypeName psobject
$body | Add-Member -Type NoteProperty -Name 'source' -Value ''
$body | Add-Member -Type NoteProperty -Name 'serialNumber' -Value ($SwitchList -join ',')
$body | Add-Member -Type NoteProperty -Name 'entityType' -Value "SWITCH"
$body | Add-Member -Type NoteProperty -Name 'entityName' -Value "SWITCH"
$body | Add-Member -Type NoteProperty -Name 'templateName' -Value "create_vlan"
$body | Add-Member -Type NoteProperty -Name 'priority' -Value "500"
$body | Add-Member -Type NoteProperty -Name 'description' -Value $VlanName
$body | Add-Member -Type NoteProperty -Name 'nvPairs' -Value $nvPairs
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}
}
End {}
}