HostConnectorModule.psm1
using module Microsoft.AVS.Management Function Test{ Write-Host "Test Host Connector Module !!!! " } Function Get-HostTempFolderInfo { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname ) $Command="vdf" $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command $Command return $SSHOut.ExitStatus, $SSHOut.Output } Function EnsureConnectivity { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname ) $Command="echo testing123" $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command $Command return $SSHOut.ExitStatus, $SSHOut.Output } Function Get-HostEsxiVersion { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname ) $Command="vmware -l" $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command $Command return $SSHOut.ExitStatus, $SSHOut.Output } Function ChangeRcLocal { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname, [Parameter(Mandatory=$true, HelpMessage = "Data Store Uuid")][string]$DatastoreUuid, [Parameter(Mandatory=$true, HelpMessage = "Bios Uuid")] [string]$BiosUuid ) Process { $cmd = ('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) $Commands = 'grep -v ZeRTO /etc/rc.local > /tmp/rc.local', 'echo \#ZeRTO\ >> /tmp/rc.local', $cmd, 'echo \#ZeRTO\ >> /tmp/rc.local', 'cp -f /tmp/rc.local /etc/rc.local' $SSHOut = (Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command ($Commands -join '&&')) return $SSHOut.ExitStatus, $SSHOut.Output } } Function InstallDriverForEsxi67AndAbove { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname, [Parameter(Mandatory=$true, HelpMessage = "Data Store Uuid")] [string]$DatastoreUuid, [Parameter(Mandatory=$true, HelpMessage = "Bios Uuid")] [string]$BiosUuid, [Parameter(Mandatory=$true, HelpMessage = "Name of ZVM driver install script")] [string]$ZvmDriverInstallScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "Name of ZVM driver helper funcs script")] [string]$ZvmDriverHelperFuncsScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "init or load")] [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) $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command ($Commands -join '&&') return $SSHOut.ExitStatus, $SSHOut.Output } } Function DefaultInstallDriver { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname, [Parameter(Mandatory=$true, HelpMessage = "Data Store Uuid")] [string]$DatastoreUuid, [Parameter(Mandatory=$true, HelpMessage = "Bios Uuid")] [string]$BiosUuid, [Parameter(Mandatory=$true, HelpMessage = "Name of ZVM driver install script")] [string]$ZvmDriverInstallScriptFileName, [Parameter(Mandatory=$true, HelpMessage = "init or load")] [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) $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command ($Commands -join '&&') return $SSHOut.ExitStatus, $SSHOut.Output } } Function UninstallDriverForEsxi67AndAbove { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname, [Parameter(Mandatory=$true, HelpMessage = "Data Store Name")] [string]$DatastoreName, [Parameter(Mandatory=$true, HelpMessage = "Bios Uuid")] [string]$BiosUuid, [Parameter(Mandatory=$true, HelpMessage = "ZVM Uninstall script file name")] [string]$ZvmDriverUninstallSctiptFileName, [Parameter(Mandatory=$true, HelpMessage = "Name of ZVM driver helper funcs script")] [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) $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command ($Commands -join '&&') return $SSHOut.ExitStatus, $SSHOut.Output } } Function DefaultUninstallDriver { param( [Parameter(Mandatory=$true, HelpMessage = "Host Name")][string]$Hostname, [Parameter(Mandatory=$true, HelpMessage = "Data Store Name")] [string]$DatastoreName, [Parameter(Mandatory=$true, HelpMessage = "Bios Uuid")] [string]$BiosUuid, [Parameter(Mandatory=$true, HelpMessage = "ZVM Uninstall script file name")] [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) $SSHOut = Invoke-SSHCommand -SSHSession $SSH_Sessions[$Hostname].Value -Command ($Commands -join '&&') return $SSHOut.ExitStatus, $SSHOut.Output } } |