Public/System.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#
# Copyright 2019, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

function Get-ArubaCXSystem {

    <#
        .SYNOPSIS
        Get System info about ArubaCX Switch

        .DESCRIPTION
        Get System Info (name, dns_servers...)

        .EXAMPLE
        Get-ArubaCXSystem

        Get system info on the switch

    #>

    Param(
        [Parameter(Mandatory = $false)]
        [ValidateRange(1, 4)]
        [Int]$depth,
        [Parameter(Mandatory = $false)]
        [ValidateSet("configuration", "status", "statistics", "writable")]
        [String]$selector,
        [Parameter(Mandatory = $false)]
        [String[]]$attributes,
        [Parameter(Mandatory = $false)]
        [switch]$vsx_peer,
        [Parameter (Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection = $DefaultArubaCXConnection
    )

    Begin {
    }

    Process {

        $invokeParams = @{ }
        if ( $PsBoundParameters.ContainsKey('depth') ) {
            $invokeParams.add( 'depth', $depth )
        }
        if ( $PsBoundParameters.ContainsKey('selector') ) {
            $invokeParams.add( 'selector', $selector )
        }
        if ( $PsBoundParameters.ContainsKey('attributes') ) {
            $invokeParams.add( 'attributes', $attributes )
        }
        if ( $PsBoundParameters.ContainsKey('vsx_peer') ) {
            $invokeParams.add( 'vsx_peer', $true )
        }

        $uri = "system"

        $response = invoke-ArubaCXRestMethod -method "GET" -uri $uri -connection $connection @invokeParams
        $response
    }

    End {
    }
}

function Set-ArubaCXSystem {

    <#
        .SYNOPSIS
        Configure System info on ArubaCX Switch

        .DESCRIPTION
        Configure System info (Hostname, Banner...)

        .EXAMPLE
        Set-ArubaCXSystem -hostname "My ArubaCX Switch"

        Configure hostname

        .EXAMPLE
        Set-ArubaCXSystem -banner "Welcome on PowerArubaCX Switch"

        Configure Banner

        .EXAMPLE
        Set-ArubaCXSystem -timezone Europe/Paris

        Configure Timezone

        .EXAMPLE
        $system = Get-ArubaCXSystem -selector writable
        PS >$system.usb_disable = $true
        PS > $system | Set-ArubaCXSystem -use_pipeline

        Configure some system variable (usb_disable) no available on parameter using pipeline (can be only with selector equal writable)
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')]
    Param(
        [Parameter (Mandatory = $false, ValueFromPipeline = $true, Position = 1)]
        [ValidateScript( { Confirm-ArubaCXSystem $_ })]
        [psobject]$system,
        [Parameter (Mandatory = $false)]
        [string]$hostname,
        [Parameter (Mandatory = $false)]
        [string]$banner,
        [Parameter (Mandatory = $false)]
        #add Check of timezone ? very long list..
        [string]$timezone,
        [Parameter (Mandatory = $false)]
        [switch]$use_pipeline,
        [Parameter (Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection = $DefaultArubaCXConnection
    )


    Begin {
    }

    Process {

        $uri = "system"

        if ($use_pipeline) {
            $_system = $system
        }
        else {
            $_system = Get-ArubaCXSystem -selector writable -connection $connection
        }

        if ( $PsBoundParameters.ContainsKey('hostname') ) {
            $_system.hostname = $hostname
        }
        if ( $PsBoundParameters.ContainsKey('banner') ) {
            $_system.other_config.banner = $banner
        }
        if ( $PsBoundParameters.ContainsKey('timezone') ) {
            $_system.timezone = $timezone
        }

        if ($PSCmdlet.ShouldProcess($_system.hostname, 'Configure System Settings')) {
            Invoke-ArubaCXRestMethod -method "PUT" -body $_system -uri $uri -connection $connection
        }

        Get-ArubaCXSystem -connection $connection
    }

    End {
    }
}