def upgradeConfigFile(scannerPlatformConfig, Framework): logger.debug('Installing configuration file') #copying local scanner executable and config file to the remove machine BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) #scanner config local file scannerConfigPerPlatformSettings = Framework.getParameter('ScannerConfigurationFile') scannerConfig = ScannerConfigurationUtil.getInstance().loadScannerConfigurationPerPlatformWrapper(scannerConfigPerPlatformSettings) platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE) scannerConfigFile = scannerConfig.getScannerNameForPlatform(platform, architecture) logger.debug('Config file to be used:', scannerConfigFile) #scanner config remote file scannerRemoteConfigFile = scannerPlatformConfig.getScannerRemoteConfigFileName() scannerConfigLocalpath = CollectorsParameters.PROBE_MGR_SCANNER_CONFIG_DIR + scannerConfigFile logger.debug('Scanner config file local path:', scannerConfigLocalpath) if not checkResourceExists(Framework, scannerConfigLocalpath): return 0 scannerConfigRemotePath = BASEDIR + scannerRemoteConfigFile if not InventoryUtils.copyLocalFileToRemote(Framework, scannerConfigLocalpath, scannerConfigRemotePath): Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) return 0 Framework.setProperty(InventoryUtils.SCANNER_CONFIG_REMOTE_PATH, scannerConfigRemotePath) return 1
def upgradeScannerExecutable(scannerPlatformConfig, Framework, shell): logger.debug('Installing scanner') #copying local scanner executable and config file to the remove machine BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) #scanner local executable file scannerExecutable = scannerPlatformConfig.getScannerExecutable() logger.debug('Scanner executable to be used:', scannerExecutable) #scanner remote executable file scannerRemoteExecutable = scannerPlatformConfig.getScannerRemoteExecutableName() #local location of scanner and config file scannerExecutableLocalPath = CollectorsParameters.PROBE_MGR_RESOURCES_DIR + 'ud_scanners' + str(File.separator) + scannerExecutable logger.debug('Scanner executable local path:', scannerExecutableLocalPath) if not checkResourceExists(Framework, scannerExecutableLocalPath): return 0 scannerExecutableRemotePath = BASEDIR + scannerRemoteExecutable if not InventoryUtils.copyLocalFileToRemote(Framework, scannerExecutableLocalPath, scannerExecutableRemotePath): Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) # Try to terminate scanner, if scanner process is stopping the upload logger.debug('Upload cannot proceed due to scanner process, terminate it.') terminateScanner(Framework, shell, scannerRemoteExecutable) return 0 # OK, now scanner file has already upgrade successful Framework.setProperty(InventoryUtils.SCANNER_UPGRADE_DATE, Date()) Framework.setProperty(InventoryUtils.SCANNER_UPGRADE_STATE, '1') Framework.setProperty(InventoryUtils.SCANNER_EXECUTABLE_REMOTE_PATH, scannerExecutableRemotePath) return 1
def upgradePrePostScript(scannersConfigFile, scannerPlatformConfig, Framework): logger.debug('Installing pre/post script') BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) unixConfig = scannersConfigFile.getPlatformConfiguration('unix', "") #whether run or not pre-scan and post-scan scripts isPrePostScriptAllowed = Boolean.parseBoolean(Framework.getParameter('IsPrePostScriptAllowed')) logger.debug("isPrePostScriptAllowed:", isPrePostScriptAllowed) if not isPrePostScriptAllowed: return isAllUnix = False preScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPreScanScriptLocalFile()) logger.debug('preScanScriptLocalPath:', preScanScriptLocalPath) if InventoryUtils.isUnix(platform) and not os.path.exists(preScanScriptLocalPath): logger.debug("No specific platform for the device, use all-unix.") isAllUnix = True preScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPreScanScriptLocalFile()) logger.debug("preScanScriptLocalPath:", preScanScriptLocalPath) postScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPostScanScriptLocalFile()) logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath) if InventoryUtils.isUnix(platform) and not os.path.exists(postScanScriptLocalPath): logger.debug("No specific platform for the device, use all-unix.") isAllUnix = True postScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPostScanScriptLocalFile()) logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath) preScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPreScanScriptRemoteFile() logger.debug('preScanScriptRemotePath:', preScanScriptRemotePath) postScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPostScanScriptRemoteFile() logger.debug('postScanScriptRemotePath:', postScanScriptRemotePath) if os.path.exists(preScanScriptLocalPath): InventoryUtils.copyLocalFileToRemote(Framework, preScanScriptLocalPath, preScanScriptRemotePath) if os.path.exists(postScanScriptLocalPath): InventoryUtils.copyLocalFileToRemote(Framework, postScanScriptLocalPath, postScanScriptRemotePath) # upgrade resource files for PrePostScript upgradePrePostScriptResource(isAllUnix, Framework) Framework.setProperty(InventoryUtils.SCANNER_PRE_SCAN_SCRIPT_REMOTE_PATH, preScanScriptRemotePath) Framework.setProperty(InventoryUtils.SCANNER_POST_SCAN_SCRIPT_REMOTE_PATH, postScanScriptRemotePath)
def restoreSWUtilizationConfiguration(Framework): InventoryUtils.releaseConnection(Framework) # Framework.setConnectedClient(None) InventoryUtils.acquireConnection(Framework) # try to restore ini files if existed BASEDIR = AgentPlatformParameters.getAgentConfigurationPath(Framework) pluginIniFile = Framework.getProperty("local_plugin_temp_file") discusgeIniFile = Framework.getProperty("local_discusge_temp_file") pluginIniFileSuccess = 1 if pluginIniFile and not InventoryUtils.copyLocalFileToRemote( Framework, pluginIniFile, BASEDIR + "plugin.tni", 0): pluginIniFileSuccess = 0 Framework.reportWarning( "restore plugin.ini file failed, will use default configuration") discusgeIniFileSuccess = 1 if discusgeIniFile and not InventoryUtils.copyLocalFileToRemote( Framework, discusgeIniFile, BASEDIR + "discusge.tni", 0): discusgeIniFileSuccess = 0 Framework.reportWarning( "restore discusge.ini file failed, will use default configuration") client = Framework.getConnectedClient() shell = shellutils.ShellUtils(client, skip_set_session_locale=True) if pluginIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD( Framework, BASEDIR, "plugin.tni", "plugin.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) if discusgeIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD( Framework, BASEDIR, "discusge.tni", "discusge.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) File(pluginIniFile).delete() File(discusgeIniFile).delete() Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def restoreSWUtilizationConfiguration(Framework): InventoryUtils.releaseConnection(Framework) # Framework.setConnectedClient(None) InventoryUtils.acquireConnection(Framework) # try to restore ini files if existed BASEDIR = AgentPlatformParameters.getAgentConfigurationPath(Framework) pluginIniFile = Framework.getProperty("local_plugin_temp_file") discusgeIniFile = Framework.getProperty("local_discusge_temp_file") pluginIniFileSuccess = 1 if pluginIniFile and not InventoryUtils.copyLocalFileToRemote(Framework, pluginIniFile, BASEDIR + "plugin.tni", 0): pluginIniFileSuccess = 0 Framework.reportWarning("restore plugin.ini file failed, will use default configuration") discusgeIniFileSuccess = 1 if discusgeIniFile and not InventoryUtils.copyLocalFileToRemote(Framework, discusgeIniFile, BASEDIR + "discusge.tni", 0): discusgeIniFileSuccess = 0 Framework.reportWarning("restore discusge.ini file failed, will use default configuration") client = Framework.getConnectedClient() shell = shellutils.ShellUtils(client, skip_set_session_locale=True) if pluginIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD(Framework, BASEDIR, "plugin.tni", "plugin.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) if discusgeIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD(Framework, BASEDIR, "discusge.tni", "discusge.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) File(pluginIniFile).delete() File(discusgeIniFile).delete() Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def upgradePrePostScriptResource(isAllUnix, Framework): logger.debug('Installing resource files for pre/post script') BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE) if isAllUnix: logger.debug("No specific platform for the device, use all-unix.") platform = 'unix' architecture = '' elif platform in ['aix', 'windows']: # since in PrePostScriptEditor, the aix and windows platforms have no architecture definitions, # so just ignore the architecture value for aix and windows architecture = '' #get all local file path from resource folder and generate remote file path prepostScanScriptResourcePathArray = getPrePostScriptResourcePathArray(BASEDIR, platform, architecture) if prepostScanScriptResourcePathArray is not None: # copy local resource files to remote for (resourceLocalPath, resourceRemotePath) in prepostScanScriptResourcePathArray: if os.path.exists(resourceLocalPath): InventoryUtils.copyLocalFileToRemote(Framework, resourceLocalPath, resourceRemotePath)