HostConnector.ps1
using module Microsoft.AVS.Management $DriverScriptFolder = Join-Path $psScriptRoot "DriverScripts" $ZvmDriverInstallScriptFileName = "zloadmod.sh" $ZvmDriverHelperFuncsScriptFileName = "zincl.sh" $DestFolder = "/tmp" Function runSSHCommands { param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname, [Parameter(Mandatory = $true, HelpMessage = "Commands to execute")] [String[]]$Commands ) process { $Result = @() foreach ($Command in $Commands) { Write-Host $Command $SSH = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command $Command $Result += New-Object PSObject -Property @{ Cmd = $Command ExitStatus = $SSH.ExitStatus Output = $SSH.Output } } return $Result } } <# .DESCRIPTION This Cmdlet displays information about the available disk space .PARAMETER HostName Host Name to connect with ssh .EXAMPLE Get-HostTempFolderInfo -HostName xxx.xxx.xxx.xxx #> Function Get-HostTempFolderInfo { [CmdletBinding()] [AVSAttribute(5, UpdatesSDDC = $false)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname ) process { $Command = "vdf" return runSSHCommands -Hostname $Hostname -Commands $Command } } <# .DESCRIPTION This Cmdlet checks if the host is up and running .PARAMETER HostName Host Name to connect with ssh .EXAMPLE EnsureConnectivity -HostName xxx.xxx.xxx.xxx #> Function EnsureConnectivity { [CmdletBinding()] [AVSAttribute(5, UpdatesSDDC = $false)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname ) process { $Command = "echo testing123" return runSSHCommands -Hostname $Hostname -Commands $Command } } <# .DESCRIPTION This Cmdlet retrieves the ESXi version .PARAMETER HostName Host Name to connect with ssh .EXAMPLE Get-HostEsxiVersion -HostName xxx.xxx.xxx.xxx #> Function Get-HostEsxiVersion { [CmdletBinding()] [AVSAttribute(5, UpdatesSDDC = $false)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")][string]$Hostname ) process { $Command = "vmware -l" return runSSHCommands -Hostname $Hostname -Commands $Command } } <# .DESCRIPTION This Cmdlet is responsible for loading the driver when the host is booting. Rc.local file is executed after all the normal system services are started .PARAMETER HostName Host Name to connect with ssh .PARAMETER DatastoreUuid Datastore Uuid .PARAMETER BiosUuid "Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid" .EXAMPLE ChangeRcLocal -HostName xxx.xxx.xxx.xxx -DatastoreUuid xxx -BiosUuid xxx #> Function ChangeRcLocal { [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $true)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname, [Parameter(Mandatory = $true, HelpMessage = "Datastore Uuid")] [string]$DatastoreUuid, [Parameter(Mandatory = $true, HelpMessage = "Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid")] [string]$BiosUuid ) Process { $RemoteLoadmodFileName = Join-Path $DriverScriptFolder $ZvmDriverInstallScriptFileName $InstallScriptTempPath = ('/tmp/{0}' -f $ZvmDriverInstallScriptFileName) Set-SFTPItem -SessionId ($SFTP_Sessions[$Hostname]).Value -Destination $DestFolder -Path $RemoteLoadmodFileName -Force $Commands = 'grep -v ZeRTO /etc/rc.local > /tmp/rc.local', 'echo \#ZeRTO\ >> /tmp/rc.local', ('echo sh /tmp/zloadmod.sh load {0} {1} \> /etc/vmware/zloadmod.txt \2\>\&\1 \#ZeRTO\ >> /tmp/rc.local' -f $DatastoreUuid, $BiosUuid), 'echo \#ZeRTO\ >> /tmp/rc.local', 'cp -f /tmp/rc.local /etc/rc.local', ('rm {0}' -f $InstallScriptTempPath) return runSSHCommands -Hostname $Hostname -Commands $Commands } } <# .DESCRIPTION This Cmdlet installs the driver for ESXi 6.7 and above .PARAMETER HostName Host Name to connect with SSH .PARAMETER DatastoreUuid Datastore Uuid .PARAMETER BiosUuid Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid .PARAMETER IsInit Init or load the driver .PARAMETER EsxiVersion Esxi version .EXAMPLE InstallDriverForEsxi67AndAbove -HostName xxx.xxx.xxx.xxx -DatastoreUuid <UUID> -BiosUuid <UUID> -IsInit <init/load> -EsxiVersion xx #> Function InstallDriver { [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $true)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname, [Parameter(Mandatory = $true, HelpMessage = "Datastore Uuid")] [string]$DatastoreUuid, [Parameter(Mandatory = $true, HelpMessage = "Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid")] [string]$BiosUuid, [Parameter(Mandatory = $true, HelpMessage = "Init or load the driver")] [string]$IsInit, [Parameter(Mandatory = $true, HelpMessage = "Esxi version")] [string]$EsxiVersion ) Process { $RemoteLoadmodFileName = Join-Path $DriverScriptFolder $ZvmDriverInstallScriptFileName $RemoteLoadmodFileHelperName = Join-Path $DriverScriptFolder $ZvmDriverHelperFuncsScriptFileName $InstallScriptTempPath = ('/tmp/{0}' -f $ZvmDriverInstallScriptFileName) $InstallScriptHelperTempPath = ('/tmp/{0}' -f $ZvmDriverHelperFuncsScriptFileName) Set-SFTPItem -SessionId ($SFTP_Sessions[$Hostname]).Value -Destination $DestFolder -Path $RemoteLoadmodFileName -Force Set-SFTPItem -SessionId ($SFTP_Sessions[$Hostname]).Value -Destination $DestFolder -Path $RemoteLoadmodFileHelperName -Force $Commands = ('chmod a+x {0}' -f $InstallScriptTempPath), ('{0} {1} {2} {3} 1 {4} > /etc/vmware/zloadmod.txt' -f $InstallScriptTempPath, $IsInit, $DatastoreUuid, $BiosUuid, $EsxiVersion), ('rm {0}' -f $InstallScriptTempPath), ('rm {0}' -f $InstallScriptHelperTempPath) return runSSHCommands -Hostname $Hostname -Commands $Commands } } <# .DESCRIPTION This Cmdlet used to uninstall the driver for ESXi 6.7 and above .PARAMETER HostName Host Name to connect with SSH .PARAMETER DatastoreUuid Datastore Uuid .PARAMETER BiosUuid Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid .EXAMPLE UninstallDriver -HostName xxx.xxx.xxx.xxx -DatastoreUuid <UUID> -BiosUuid <UUID> #> Function UninstallDriver { [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $true)] param( [Parameter(Mandatory = $true, HelpMessage = "Host Name to connect with SSH")] [string]$Hostname, [Parameter(Mandatory = $true, HelpMessage = "Datastore Name")] [string]$DatastoreName, [Parameter(Mandatory = $true, HelpMessage = "Host Bios Uuid || mob-> Property Path: host.hardware.systemInfo.uuid")] [string]$BiosUuid ) process { $ZvmDriverUninstallSctiptFileName = "zunloadmod.sh" $RemoteUnloadmodFileName = Join-Path $DriverScriptFolder $ZvmDriverUninstallSctiptFileName $RemoteLoadmodFileHelperName = Join-Path $DriverScriptFolder $ZvmDriverHelperFuncsScriptFileName $UninstallScriptTempPath = ('/tmp/{0}' -f $ZvmDriverUninstallSctiptFileName) $ScriptHelperTempPath = ('/tmp/{0}' -f $ZvmDriverHelperFuncsScriptFileName) Set-SFTPItem -SessionId ($SFTP_Sessions[$Hostname]).Value -Destination $DestFolder -Path $RemoteUnloadmodFileName -Force Set-SFTPItem -SessionId ($SFTP_Sessions[$Hostname]).Value -Destination $DestFolder -Path $RemoteLoadmodFileHelperName -Force $Commands = ('chmod a+x {0}' -f $UninstallScriptTempPath), ('{0} cleanup > /etc/vmware/zunloadmod.txt' -f $UninstallScriptTempPath), ('rm {0}' -f $UninstallScriptTempPath), ('rm {0}' -f $ScriptHelperTempPath) return runSSHCommands -Hostname $Hostname -Commands $Commands } } |