ZertoAVSModule.psm1
using module Microsoft.AVS.Management Function TestConnection{ return "TestConnection" } Function runSSHCommands { [CmdletBinding()] 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) { $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 } } Function Get-HostTempFolderInfo { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name to connect with SSH")][string]$Hostname ) process { $Command="vdf" return runSSHCommands -Hostname $Hostname -Commands $Command } } Function EnsureConnectivity { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name to connect with SSH")][string]$Hostname ) process { $Command="echo testing123" return runSSHCommands -Hostname $Hostname -Commands $Command } } Function Get-HostEsxiVersion { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name to connect with SSH")][string]$Hostname ) process { $Command="vmware -l" return runSSHCommands -Hostname $Hostname -Commands $Command } } Function ChangeRcLocal { 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 { $Commands = 'grep -v ZeRTO /etc/rc.local > /tmp/rc.local', 'echo \#ZeRTO\ >> /tmp/rc.local', ('echo sh /vmfs/volumes/{0}/zagentid/{1}/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' return runSSHCommands -Hostname $Hostname -Commands $Commands } } Function InstallDriverForEsxi67AndAbove { 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 = "Install driver script (zloadmod.sh - tweakable)")] [string]$ZvmDriverInstallScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "Helper functions script - zincl.sh")] [string]$ZvmDriverHelperFuncsScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "Init or load the driver")] [string]$isInit, [Parameter(Mandatory=$true, HelpMessage = "Esxi version")] [string]$EsxiVersion ) Process { $FullRemoteFileLocation = ('/vmfs/volumes/{0}/zagentid/{1}' -f $DatastoreUuid, $BiosUuid) $RemoteLoadmodFileName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverInstallScriptFileName) $RemoteLoadmodFileHelperName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverHelperFuncsScriptFileName) $InstallScriptTempPath = ('/tmp/{0}' -f $ZvmDriverInstallScriptFileName) $InstallScriptHelperTempPath = ('/tmp/{0}' -f $ZvmDriverHelperFuncsScriptFileName) $Commands = ('cp {0} {1}' -f $RemoteLoadmodFileName, $InstallScriptTempPath), ('cp {0} {1}' -f $RemoteLoadmodFileHelperName, $InstallScriptHelperTempPath), ('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 } } Function DefaultInstallDriver { 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 = "Install driver script (zloadmod.sh - tweakable)")] [string]$ZvmDriverInstallScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "Init or load the driver")] [string]$isInit, [Parameter(Mandatory=$true, HelpMessage = "Esxi version")] [string]$EsxiVersion ) process { $FullRemoteFileLocation = ('/vmfs/volumes/{0}/zagentid/{1}' -f $DatastoreUuid, $BiosUuid) $RemoteLoadmodFileName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverInstallScriptFileName) $Commands = ('chmod a+x {0}' -f $RemoteLoadmodFileName), ('{0} {1} {2} {3} 1 {4} > /etc/vmware/zloadmod.txt' -f $RemoteLoadmodFileName, $isInit, $DatastoreUuid, $BiosUuid, $EsxiVersion) return runSSHCommands -Hostname $Hostname -Commands $Commands } } Function UninstallDriverForEsxi67AndAbove { 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, [Parameter(Mandatory=$true, HelpMessage = "Uninstall driver script (zunloadmod.sh - tweakable)")] [string]$ZvmDriverUninstallSctiptFileName, [Parameter(Mandatory=$true, HelpMessage = "Helper functions script - zincl.sh")] [string]$ZvmDriverHelperFuncsScriptFileName ) process { $FullRemoteFileLocation = ('/vmfs/volumes/{0}/zagentid/{1}' -f $DatastoreName, $BiosUuid) $RemoteUnloadmodFileName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverUninstallSctiptFileName) $RemoteLoadmodFileHelperName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverHelperFuncsScriptFileName) $UninstallScriptTempPath = ('/tmp/{0}' -f $ZvmDriverUninstallSctiptFileName) $ScriptHelperTempPath = ('/tmp/{0}' -f $ZvmDriverHelperFuncsScriptFileName) $Commands = ('cp {0} {1}' -f $RemoteUnloadmodFileName, $UninstallScriptTempPath), ('cp {0} {1}' -f $RemoteLoadmodFileHelperName, $scriptHelperTempPath), ('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 } } Function DefaultUninstallDriver { 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, [Parameter(Mandatory=$true, HelpMessage = "Uninstall driver script (zunloadmod.sh - tweakable)")] [string]$ZvmDriverUninstallSctiptFileName ) process { $FullRemoteFileLocation = ('/vmfs/volumes/{0}/zagentid/{1}' -f $DatastoreName, $BiosUuid) $RemoteUnloadmodFileName = ('{0}/{1}' -f $FullRemoteFileLocation, $ZvmDriverUninstallSctiptFileName) $Commands = ('chmod a+x {0}' -f $RemoteUnloadmodFileName), ('{0} cleanup > /etc/vmware/zunloadmod.txt' -f $RemoteUnloadmodFileName) return runSSHCommands -Hostname $Hostname -Commands $Commands } } |