Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
devblackops committed Jul 2, 2018
2 parents f89ff7a + 07b384e commit 8cd3c43
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.6.0 (2017-10-31)
* Features
* PR82 - Added Get-NSCurrentTime, Get-NSlicenseExpiration, and Update-NSAppliance functions (via @ryancbutler)

## 1.5.0 (2017-07-25)
* Features
* PR57 - Added -Graceful parameter to the Disable-NSLBServer (via @daimhin)
Expand Down
11 changes: 7 additions & 4 deletions NetScaler/NetScaler.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'NetScaler.psm1'

# Version number of this module.
ModuleVersion = '1.5.0'
ModuleVersion = '1.6.0'

# ID used to uniquely identify this module
GUID = 'bd4390dc-a8ad-4bce-8d69-f53ccf8e4163'
Expand Down Expand Up @@ -111,6 +111,7 @@ FunctionsToExport = @(
'Get-NSCSPolicy',
'Get-NSCSVirtualServer',
'Get-NSCSVirtualServerResponderPolicyBinding',
'Get-NSCurrentTime',
'Get-NSDnsNameServer',
'Get-NSDnsSuffix',
'Get-NSFeature',
Expand All @@ -137,6 +138,7 @@ FunctionsToExport = @(
'Get-NSLBVirtualServerTrafficPolicyBinding',
'Get-NSLDAPAuthenticationPolicy',
'Get-NSLDAPAuthenticationServer',
'Get-NSLicenseExpiration',
'Get-NSMode',
'Get-NSNTPServer',
'Get-NSResponderAction',
Expand Down Expand Up @@ -209,7 +211,8 @@ FunctionsToExport = @(
'Set-NSResponderAction',
'Set-NSSSLProfile',
'Set-NSTimeZone',
'Set-NSVPNVirtualServerTheme'
'Set-NSVPNVirtualServerTheme',
'Update-NSAppliance'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down Expand Up @@ -269,5 +272,5 @@ PrivateData = @{

}





47 changes: 47 additions & 0 deletions NetScaler/Public/Get-NSCurrentTime.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<#
Copyright 2017 Ryan Butler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>
function Get-NSCurrentTime {
<#
.SYNOPSIS
Retrieve the current NetScaler Time and returns as date object
.DESCRIPTION
Retrieve the current NetScaler Time and returns as date object
.PARAMETER Session
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance
.EXAMPLE
Get-NSCurrentTime -Session $Session
.NOTES
Author: Ryan Butler - @ryan_c_butler
Date Created: 09-07-2017
#>
[CmdletBinding()]
param (
$Session = $Script:Session
)

begin {
_AssertSessionActive
}

process {
$response = _InvokeNSRestApi -Session $Session -Method GET -Type nsconfig
$currentdatestr = $response.nsconfig.systemtime
Write-Verbose "systemtime: $currentdatestr"
$date = Get-Date -Date '1/1/1970'
$nsdate = $date.AddSeconds($currentdatestr)
$nsdate
}
}
101 changes: 101 additions & 0 deletions NetScaler/Public/Get-NSLicenseExpiration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<#
Copyright 2017 Ryan Butler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Get-NSLicenseExpiration {
<#
.SYNOPSIS
Grabs Netscaler license expiration information via REST
.DESCRIPTION
Grabs Netscaler license expiration information via REST.
.PARAMETER Session
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance
.EXAMPLE
Get-NSlicenseExpiration -Session $Session
.NOTES
Author: Ryan Butler - @ryan_c_butler
Date Created: 09-07-2017
#>
[CmdletBinding()]
param (
$Session = $Script:Session
)

begin{
_AssertSessionActive
# Grabs current time from Netscaler
$currentnstime = Get-NSCurrentTime -Session $Session
$results = @()
}

process {
try {
$lics = Get-NSSystemFile -Session $Session -Filelocation '/nsconfig/license' | Where-Object {$_.filename -like '*.lic'}
} catch{
throw 'Error reading license(s)'
}

foreach ($lic in $lics) {
Write-verbose "Reading [$($lic.filename)]"

# Converts returned value from BASE64 to UTF8
$lic = Get-NSSystemFile -Session $Session -Filelocation '/nsconfig/license' -Filename $lic.filename
$info = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($lic.filecontent))

# Grabs needed line that has licensing information
$lines = $info.Split("`n") | Where-Object {$_ -like '*INCREMENT*'}

# Parses needed date values from string
$licdates = @()
foreach ($line in $lines) {
$licdate = $line.Split()

if ($licdate[4] -like 'permanent') {
$expire = 'PERMANENT'
} else {
$expire = [datetime]$licdate[4]
}

# Adds date to object
$temp = [pscustomobject]@{
expdate = $expire
feature = $licdate[1]
}
$licdates += $temp
}

foreach ($date in $licdates) {
if ($date.expdate -like 'PERMANENT') {
$expires = 'PERMANENT'
$span = '9999'
} else {
$expires = ($date.expdate).ToShortDateString()
$span = (New-TimeSpan -Start $currentnstime -End $date.expdate).Days
}

$temp = [pscustomobject]@{
Expires = $expires
Feature = $date.feature
DaysLeft = $span
LicenseFile = $lic.filename
}
$results += $temp
}
}

$results
}
}

85 changes: 85 additions & 0 deletions NetScaler/Public/Update-NSAppliance.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<#
Copyright 2017 Ryan Butler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Update-NSAppliance {
<#
.SYNOPSIS
Updates a Netscaler and uses firmware from a remote location.
.DESCRIPTION
Updates a Netscaler and uses firmware from a remote location.
.PARAMETER Session
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance
.PARAMETER Url
URL for Netscaler firmware (MANDATORY)
.PARAMETER NoReboot
Don't reboot after upgrade
.PARAMETER NoCallhome
Don't enable CallHome
.EXAMPLE
Update-NSAppliance -Session $Session -url "https://mywebserver/build-11.1-47.14_nc.tgz"
.NOTES
Author: Ryan Butler - @ryan_c_butler
Date Created: 09-07-2017
Will probably fail with VPX Express due to API timeout
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Url,

$Session = $Script:Session,

[switch]$NoReboot,

[switch]$NoCallhome
)

begin {
_AssertSessionActive
}

process {
if (-not $nocallhome) {
Write-Verbose -Message 'Enabling callhome'
$ch = $true
} else {
Write-Verbose -Message 'Disabling callhome'
$ch = $false
}

if (-not $NoReboot) {
Write-Verbose -Message 'Rebooting NS Appliance'
$reboot = $true
} else {
Write-Verbose -Message 'Skipping reboot'
$reboot = $false
}

# Build upgrade payload
$payload = @{
'url' = $Url
'y' = $reboot
'l' = $ch
}

# Attempt upgrade
try {
_InvokeNSRestApi -Session $Session -Method POST -Type install -Payload $payload
} catch{
throw $_
}
}
}
2 changes: 1 addition & 1 deletion Tests/Meta/Help.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Get module commands
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module
Import-Module $env:BHPSModulePath -Verbose:$false -ErrorAction Stop
Import-Module $env:BHModulePath -Verbose:$false -ErrorAction Stop
$moduleVersion = (Test-ModuleManifest $env:BHPSModuleManifest | select -ExpandProperty Version).ToString()
$ms = [Microsoft.PowerShell.Commands.ModuleSpecification]@{ ModuleName = $env:BHProjectName; RequiredVersion = $moduleVersion }
$commands = Get-Command -FullyQualifiedModule $ms -CommandType Cmdlet, Function, Workflow # Not alias
Expand Down

0 comments on commit 8cd3c43

Please sign in to comment.