本文整理汇总了Python中InventoryUtils类的典型用法代码示例。如果您正苦于以下问题:Python InventoryUtils类的具体用法?Python InventoryUtils怎么用?Python InventoryUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InventoryUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StepMain
def StepMain(Framework):
InventoryUtils.executeStep(
Framework,
checkUpgradeRequired,
InventoryUtils.STEP_DOESNOT_REQUIRES_CONNECTION,
InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK,
)
示例2: useTempScanFile
def useTempScanFile(Framework):
tempScanFilePath = Framework.getProperty(InventoryUtils.STATE_PROPERTY_TEMP_SCAN_FILE)
if tempScanFilePath is None:
logger.debug("No scan file found from previous scanner execution")
return None
logger.debug("Using scan file from previous execution:", tempScanFilePath)
extension = InventoryUtils.getFileExtension(tempScanFilePath)
localScanFileName = InventoryUtils.generateScanFileName(Framework, extension)
# folder for scan files
localScanFileFolderPath = (
CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.INCOMING_FOLDER_NAME
)
downloadedScanFilesDir = File(localScanFileFolderPath)
downloadedScanFilesDir.mkdirs()
# this scan file will be created after downloading from remote machine
targetScanFile = File(downloadedScanFilesDir, localScanFileName)
logger.debug("Scan file from previous execution will be moved to ", targetScanFile.getCanonicalPath())
tempScanFile = File(tempScanFilePath)
if not tempScanFile.renameTo(targetScanFile):
return None
return targetScanFile
示例3: connectToRemoteNode
def connectToRemoteNode(Framework):
Framework.setProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR, Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_CONFIGURED_BASEDIR))
Framework.getConnectedClient().setOptionsDirectory(Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR))
if AgentUtils.isUpgradeProcess(Framework):
# we here means that destination data shows version different from OOTB installer version.
# need to recheck with real agent
logger.debug('Checking if real version of agent differs from OOTB installer version')
agentVersion = None
connectedUDACredentialId = None
installCredentialId = Framework.getParameter(AgentUtils.UDAGENT_CONNECT_CREDENTIAL_ID_PARAM)
logger.debug('Credential id will be used:', installCredentialId)
client = Framework.getConnectedClient()
if AgentUtils.isUpgradeByUDAgent(Framework):
agentVersion = client.getVersion()
connectedUDACredentialId = client.getCredentialId()
logger.debug('Credential id on remote:', connectedUDACredentialId)
AgentUtils.updateCallHomeParams(Framework)
AgentUtils.updateSWUtilization(Framework)
InventoryUtils.setConnectedClientIdentifier(Framework, client)
#Same version and same credential, skip upgrade
if AgentUtils.versionsEqual(Framework, agentVersion) and (not installCredentialId
or installCredentialId == connectedUDACredentialId):
logger.debug('Installed agent version equals to local installer version, skipping upgrade')
Framework.setProperty(InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, 'Upgrade not required, real installed agent version equals to the local installer version')
client.close()
elif Framework.getParameter("UpgradeAgent") == 'false':
logger.debug("Upgrade is not required because the job parameter 'UpgradeAgent' is false")
Framework.setProperty(InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, "Upgrade is not required because the job parameter 'UpgradeAgent' is false")
client.close()
else:
logger.debug('Installed agent version does not equal to local installer version, Going to execute agent upgrade')
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例4: downloadScanFile
def downloadScanFile(Framework):
targetScanFile = downloadRemoteScanFile(Framework)
if not targetScanFile:
logger.debug("Remote scan file was not downloaded, will try previously downloaded scan file(if exists)")
targetScanFile = useTempScanFile(Framework)
if not targetScanFile:
logger.debug("No scan file downloaded from previous execution, download file step failed")
Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_REMOTE_SCANFILE_NOT_FOUND, None)
return
logger.debug("Scan file was successfully downloaded to ", targetScanFile.getCanonicalPath())
# set download time to current time
Framework.setProperty(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILE_DOWNLOAD_TIME, Date())
# Check the drity files in sending folder
sendingFolder = (
CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.SENDING_FOLDER_NAME
)
deleteDirtyFile(File(sendingFolder, targetScanFile.getName()))
# delete temporary scan file from previous execution (if any)
tempScanFileFolder = (
CollectorsParameters.PROBE_MGR_TEMPDOWNLOAD
+ Framework.getDiscoveryJobId()
+ CollectorsParameters.FILE_SEPARATOR
)
tempScanFileName = InventoryUtils.generateScanFileName(Framework, InventoryUtils.SCANFILE_EXTENTION)
deleteDirtyFile(File(tempScanFileFolder, tempScanFileName))
tempScanFileName = InventoryUtils.generateScanFileName(Framework, InventoryUtils.SCANFILE_DELTA_EXTENTION)
deleteDirtyFile(File(tempScanFileFolder, tempScanFileName))
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例5: getRemoteScanLogFilelocation
def getRemoteScanLogFilelocation(Framework):
client = Framework.getConnectedClient()
remoteScanLogFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION)
if not InventoryUtils.isPathValid(remoteScanLogFileLocation):
options = LockUtils.getClientOptionsMap(client)
remoteScanLogFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME)
if InventoryUtils.isPathValid(remoteScanLogFileLocation):
Framework.setProperty(
InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_LOG_FILE_LOCATION, remoteScanLogFileLocation
)
logger.debug(
"Got agent option " + InventoryUtils.AGENT_OPTION_DISCOVERY_SCANLOGFILENAME + " ",
remoteScanLogFileLocation,
)
else:
logger.debug("Remote scan log file location from agent options:", remoteScanLogFileLocation)
else:
logger.debug("Got scan log file location from properties ", remoteScanLogFileLocation)
if remoteScanLogFileLocation is None:
remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
if remoteScanFileLocation is not None:
remoteScanLogFileLocation = os.path.splitext(remoteScanFileLocation)[0] + ".log"
return remoteScanLogFileLocation
示例6: downloadRemoteScanFile
def downloadRemoteScanFile(Framework):
remoteScanFileLocation = Framework.getProperty(InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION)
# download scanner log file before downloading scan file
downloadScanLogFile(Framework)
if remoteScanFileLocation is None:
logger.debug("No scan file to downloaded from current execution")
return None
logger.debug("About to download scan file from current execution:", remoteScanFileLocation)
extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
localScanFileName = InventoryUtils.generateScanFileName(Framework, extension)
# folder for scan files
localScanFileFolderPath = (
CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.INCOMING_FOLDER_NAME
)
downloadedScanFilesDir = File(localScanFileFolderPath)
downloadedScanFilesDir.mkdirs()
# this scan file will be created after downloading from remote machine
targetScanFile = File(downloadedScanFilesDir, localScanFileName)
# get file to the local machine
logger.debug("Scan file to be downloaded to location:", targetScanFile.getCanonicalPath())
if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, targetScanFile.getCanonicalPath()):
return None
return targetScanFile
示例7: StepMain
def StepMain(Framework):
# if we have shell credentials and we are able to connect with them then connect otherwise we should connect with agent
ip = Framework.getDestinationAttribute('ip_address')
domain = Framework.getDestinationAttribute('ip_domain')
codepage = Framework.getCodePage()
allShellProtocols = []
allShellCredentials = []
allShellIps = []
allShellCodePages = []
protocols = netutils.getAvailableProtocols(Framework, ClientsConsts.DDM_AGENT_PROTOCOL_NAME, ip, domain)
for protocol in protocols:
allShellProtocols.append(ClientsConsts.DDM_AGENT_PROTOCOL_NAME)
allShellCredentials.append(protocol)
allShellIps.append(ip)
allShellCodePages.append(codepage)
logger.debug('Will going to attempt to connect in this order: ', allShellCredentials)
Framework.setProperty(InventoryUtils.STATE_PROPERTY_CONNECTION_PROTOCOLS, allShellProtocols)
Framework.setProperty(InventoryUtils.STATE_PROPERTY_CONNECTION_CREDENIALS, allShellCredentials)
Framework.setProperty(InventoryUtils.STATE_PROPERTY_CONNECTION_IPS, allShellIps)
Framework.setProperty(InventoryUtils.STATE_PROPERTY_CONNECTION_CODEPAGES, allShellCodePages)
InventoryUtils.executeStep(Framework, connectToRemoteNode, InventoryUtils.STEP_REQUIRES_CONNECTION, InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)
示例8: unInstallAgent
def unInstallAgent(Framework):
protocolName = Framework.getProperty(InventoryUtils.STATE_PROPERTY_CONNECTED_SHELL_PROTOCOL_NAME)
logger.debug('Protocal name: ', protocolName)
client = Framework.getConnectedClient()
uduid = InventoryUtils.getUduid(client)
logger.debug('UD_UNIQUE_ID: ', uduid)
Framework.setProperty(InventoryUtils.ATTR_UD_UNIQUE_ID, uduid)
if protocolName == ClientsConsts.DDM_AGENT_PROTOCOL_NAME:
# Should release lock first if there will be no connected credential after agent uninstallation.
logger.debug('The connected credential is UDA. Try to release lock first.')
LockUtils.releaseScannerLock(Framework)
if AgentUtils.isAgentInstalled(Framework):
logger.debug('There is an agent in remote machine.')
# Run uninstall command.
shouldStop = AgentUtils.agentUnInstallRoutine(Framework)
if shouldStop != 0:
Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
logger.debug('Failed to uninstall agent.')
else:
logger.debug('There is no agent in remote machine. The job will be done.')
reason = 'There is no agent in remote machine'
Framework.setProperty(InventoryUtils.generateSkipStep('Check Agent UnInstalled'), reason)
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例9: connectToRemoteNode
def connectToRemoteNode(Framework):
if AgentUtils.isMigrateNeeded(Framework):
#setting connected client identifier
#using host name since uduid is stored in agent options and on old and new ddmi agent their location is different
logger.debug('Connected using uda.')
client = Framework.getConnectedClient()
sysInfo = client.getSysInfo()
hostName = sysInfo.getProperty('computerName')
Framework.setProperty(InventoryUtils.UD_HOSTNAME, hostName)
AgentUtils.setUdAgentProtocolForMigration(Framework, client.getCredentialId())
logger.debug('Migrate is going to be performed')
if client.hasShell():
logger.debug('The connected Agent already supports shell, assume it is a non-native agent.')
reason = 'The connected Agent already supports shell,it may be a non-native agent.'
Framework.setProperty(InventoryUtils.generateSkipStep('Install Non-Native UD Agent'), reason)
#Framework.setProperty(InventoryUtils.generateSkipStep('Check Non-Native Agent Installed'), reason)
platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
if platform == 'windows':
# In windows, it is native already if it has shell.
logger.debug('This is windows, it must be native agent.')
Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, '')
reason = 'Native installation is used for Windows platform.'
Framework.setProperty(InventoryUtils.generateSkipStep('Init Update from Non-Native to Native'), reason)
Framework.setProperty(InventoryUtils.generateSkipStep('Install Native UD Agent'), reason)
else:
logger.debug('The connected client does NOT support the shell capability. This is DDMi agent!')
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例10: StepMain
def StepMain(Framework):
Framework.setProperty(InventoryUtils.STATE_PROPERTY_PLATFORM_CONFIGFILE,
CollectorsConstants.AGENTSSBYPLATFORM_FILE_NAME)
Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, String('true'))
Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE_JOB, String('true'))
InventoryUtils.executeStep(Framework, initMigrate, InventoryUtils.STEP_DOESNOT_REQUIRES_CONNECTION,
InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)
示例11: releaseScannerLock
def releaseScannerLock(Framework):
logger.debug('Finally, Starting Unlock Scanner Node')
if not LockUtils.releaseScannerLock(Framework):
Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
else:
logger.debug('Unlock Scanner Node finished')
Framework.setProperty(LockUtils.ScannerNodeUnSetLock, LockUtils.ScannerNodeUnSetLock)
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
logger.debug('Releasing connection after unlock scan node')
InventoryUtils.releaseConnection(Framework)
示例12: StepMain
def StepMain(Framework):
Framework.setProperty(
InventoryUtils.STATE_PROPERTY_PLATFORM_CONFIGFILE, CollectorsConstants.SCANNERSBYPLATFORM_FILE_NAME
)
InventoryUtils.executeStep(
Framework,
connectToRemoteNode,
InventoryUtils.STEP_REQUIRES_CONNECTION,
InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK,
)
示例13: InitUninstallAgent
def InitUninstallAgent(Framework):
removeData = Framework.getParameter('RemoveAgentData')
if removeData.lower() == 'true':
logger.debug('Skip step Unlock Scanner Node because the lock will be removed by step Remove Agent Data.')
reason = 'The lock will be removed by step Remove Agent Data'
Framework.setProperty(InventoryUtils.generateSkipStep('Unlock Scanner Node'), reason)
else:
logger.debug('Skip step Remove Agent Data because the parameter RemoveAgentData is not true')
reason = 'Do not need remove agent data'
Framework.setProperty(InventoryUtils.generateSkipStep('Remove Agent Data'), reason)
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
示例14: checkScanFileExistance
def checkScanFileExistance(Framework):
# this step is always finished with success since we DON'T require scan file from previous execution, just nice to have
Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
DownloadScanFileBeforeExecution = Boolean.parseBoolean(Framework.getParameter('DownloadScanFileBeforeExecution'))
if DownloadScanFileBeforeExecution:
try:
client = Framework.getConnectedClient()
options = LockUtils.getClientOptionsMap(client)
previousExecutionStarted = options.get(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED)
if (previousExecutionStarted is None) or (len(previousExecutionStarted.strip()) == 0):
logger.debug('Previous execution timestamp no found, continuing with workflow')
return
remoteScanFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME)
if not InventoryUtils.isPathValid(remoteScanFileLocation):
logger.debug('No scan file path found on remote machine, continuing with workflow')
return
lastSuccessExecuton = Framework.getState().getJobLastSuccessfulRun()
logger.debug('Last success execution ' + str(lastSuccessExecuton))
logger.debug('Remote scan file execution ' + str(previousExecutionStarted))
if long(lastSuccessExecuton) > long(previousExecutionStarted):
logger.debug('Scan file on probe side is newer than on remote machine, skipping downloading')
return
logger.debug('Last success execution ' + str(lastSuccessExecuton) + ' older than scan file on remote machine ' + str(remoteScanFileLocation) + '. Going to download scan file:' + str(remoteScanFileLocation))
tempScanFileFolder = CollectorsParameters.PROBE_MGR_TEMPDOWNLOAD + Framework.getDiscoveryJobId() + CollectorsParameters.FILE_SEPARATOR
File(tempScanFileFolder).mkdirs()
extension = InventoryUtils.getFileExtension(remoteScanFileLocation)
tempScanFileName = InventoryUtils.generateScanFileName(Framework, extension)
tempScanFile = File(tempScanFileFolder, tempScanFileName)
tempScanFilePath = tempScanFile.getCanonicalPath()
logger.debug('Try to download scan file to the:', tempScanFilePath)
if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, tempScanFilePath, 0):
logger.debug('Failed to download scan file before current execution')
Framework.setProperty(InventoryUtils.STATE_PROPERTY_TEMP_SCAN_FILE, tempScanFilePath)
except:
reason = str(sys.exc_info()[1])
logger.debug('Failed to check/download scan file from previous execution. Reason:', reason)
else:
logger.debug('Even not checking whether scan file exists on remote machine or not.')
示例15: upgradeScannerExecutable
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