当前位置: 首页>>代码示例>>Python>>正文


Python InventoryUtils.ensureConnection方法代码示例

本文整理汇总了Python中InventoryUtils.ensureConnection方法的典型用法代码示例。如果您正苦于以下问题:Python InventoryUtils.ensureConnection方法的具体用法?Python InventoryUtils.ensureConnection怎么用?Python InventoryUtils.ensureConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InventoryUtils的用法示例。


在下文中一共展示了InventoryUtils.ensureConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: releaseResources

# 需要导入模块: import InventoryUtils [as 别名]
# 或者: from InventoryUtils import ensureConnection [as 别名]
def releaseResources(Framework):
	logger.debug('Releasing resources')
	# we try to remove lock if lock was acquired and not unlocked yet
	logger.debug('Releasing scanner node lock if not unlocked yet')
	logger.debug('LockUtils.ScannerNodeSetLock in Framework: ', Framework.getProperty(LockUtils.ScannerNodeSetLock))
	logger.debug('LockUtils.ScannerNodeUnSetLock in Framework: ', Framework.getProperty(LockUtils.ScannerNodeUnSetLock))
	if Framework.getProperty(LockUtils.ScannerNodeSetLock) and not Framework.getProperty(LockUtils.ScannerNodeUnSetLock):
		if InventoryUtils.ensureConnection(Framework):
			LockUtils.releaseScannerLock(Framework)
		else:
			logger.debug('Failed to remove lock as failed to connect to host')
	else:
		logger.debug('Not removing lock as lock was not acquired or already unlocked')
	if Framework.getProperty(InventoryUtils.STATE_PROPERTY_CLEAN_UP_STATE_FINALLY):
		logger.debug('Clear up state saved in DB')
		Framework.clearState()
		Framework.setProperty(InventoryUtils.STATE_PROPERTY_CLEAN_UP_STATE_FINALLY, '')
	logger.debug('Releasing shell connection to the remote node if not released yet')
	InventoryUtils.releaseConnection(Framework)
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:21,代码来源:ReleaseResources.py

示例2: downloadLogsIfNeeded

# 需要导入模块: import InventoryUtils [as 别名]
# 或者: from InventoryUtils import ensureConnection [as 别名]
def downloadLogsIfNeeded(Framework):
    platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
    logger.debug('Checking if to print install/uninstall logs')
    downloadMigrateLog = Framework.getProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE)
    downloadInstallLog = Framework.getProperty(AgentUtils.DOWNLOAD_INSTALL_LOG_FILE)
    downloadUnInstallLog = Framework.getProperty(AgentUtils.DOWNLOAD_UNINSTALL_LOG_FILE)
    if not downloadMigrateLog and not downloadInstallLog and not downloadUnInstallLog:
        logger.debug('Migrate/Install/UnInstall log should not be downloaded')
        return

    try:
        logger.debug('Releasing old connection')
        InventoryUtils.releaseConnection(Framework)
        logger.debug('Preparing framework for new connection')
        AgentUtils.prepareFrameworkForShellOrAgentConnect(Framework)
    except:
        errorMessage = str(sys.exc_info()[1])
        logger.debugException('Failed to initialize connection for downloading agent log files' + errorMessage)
        return

    if downloadMigrateLog:
        # If need to download migrate log, we need to connect to DDMi agent as well
        Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, str('true'))

    if not InventoryUtils.ensureConnection(Framework):
        logger.debug('Failed to connect to the remote machine, no logs available')
    else:
        ip_address = Framework.getTriggerCIData('ip_address')
        localInstallFile = None
        localUnInstallFile = None
        try:
            try:
                agentsConfigFile = Framework.getConfigFile(CollectorsConstants.AGENTSSBYPLATFORM_FILE_NAME)
                BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)
                architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE)
                agentPlatformConfig = agentsConfigFile.getPlatformConfiguration(platform, architecture)
                ip_address_str = str(ip_address)
                if (ip_address_str.find(':') <> -1):
                    ip_address_str = ip_address_str.replace(':','-')

                if downloadMigrateLog:
                    logger.debug('Download the migrate log')
                    installLogFile = agentPlatformConfig.getUpgradeLogFile()
                    localInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile)
                    getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile)
                if downloadInstallLog:
                    logger.debug('Download the install/update log')
                    if AgentUtils.isUpgradeByUDAgent(Framework):
                        installLogFile = agentPlatformConfig.getUpgradeLogFile()
                    else:
                        installLogFile = agentPlatformConfig.getInstallLogFile()
                    localInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile)
                    getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile)
                if downloadUnInstallLog:
                    logger.debug('Download the uninstall log')
                    unInstallLogFile = agentPlatformConfig.getUnInstallLogFile()
                    localUnInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + unInstallLogFile)
                    getLogFileContent(Framework, localUnInstallFile, str(BASEDIR) + unInstallLogFile)
            except:
                errorMessage = str(sys.exc_info()[1])
                logger.debugException(errorMessage)
                Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_FAILED_EXECUTE_STEP, ['FinalizeAndReleaseResources', errorMessage])
        finally:
            try:
                if localInstallFile and not localInstallFile.delete():
                    logger.debug('File was not deleted:' + localInstallFile.getCanonicalPath())
            except:
                logger.debugException('Failed to delete ' + localInstallFile.getCanonicalPath())
            try:
                logger.debug('Going to delete file ' + localInstallFile.getCanonicalPath())
                if localUnInstallFile and not localUnInstallFile.delete():
                    logger.debug('File was not deleted:' + localUnInstallFile.getCanonicalPath())
            except:
                logger.debugException('Failed to delete ' + localUnInstallFile.getCanonicalPath())
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:76,代码来源:FinalizeAndReleaseResources.py


注:本文中的InventoryUtils.ensureConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。