Exemple #1
0
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)
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
def StepMain(Framework):
    skipStepReason = Framework.getProperty(
        InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY)
    if skipStepReason is not None:
        logger.debug('Skipped by request to skip all steps, reason:',
                     skipStepReason)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        return
    skipStepReason = Framework.getProperty(
        InventoryUtils.generateSkipStep(
            Framework.getState().getCurrentStepName()))
    if skipStepReason is not None:
        logger.debug('Step skipped, reason:', skipStepReason)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        return

    if not Framework.getProperty(FIRST_TRY_CHECK_ERROR_CODE):
        # we don't want immediately check whether agent installation successful or not,
        # since for sure it is not. go to parking to let others to install
        logger.debug(
            'UD agent install command just run, will check result code after parking'
        )
        Framework.setProperty(FIRST_TRY_CHECK_ERROR_CODE,
                              FIRST_TRY_CHECK_ERROR_CODE)
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
        return
    else:
        logger.debug(
            'Going to check whether agent installation successful or not')
    InventoryUtils.executeStep(Framework, CheckInstallErrorCode,
                               InventoryUtils.STEP_REQUIRES_CONNECTION,
                               InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)
Exemple #6
0
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)
Exemple #7
0
def CheckAgentInstalledBeforeInstallation(Framework):
    try:
        logger.debug('Check if the UDA has already been installed...')
        agentInstalled = AgentUtils.isAgentInstalled(Framework)
        logger.debug('Agent installed result:%s' % agentInstalled)
        # Framework.setProperty('isAgentInstalled', agentInstalled)
        if agentInstalled:
            logger.debug('Check if the UDA can be connected...')
            agentConnected = isAgentConnected(Framework)
            logger.debug('Agent connecting result:%s' % agentConnected)
            # Framework.setProperty('isAgentConnected', agentConnected)
            if agentConnected:
                reason = 'The UDA has been already installed and can be connected successfully.'
                Framework.setProperty(InventoryUtils.generateSkipStep('Install Agent'), reason)
                Framework.setProperty(InventoryUtils.generateSkipStep('Check Agent Install Error Code'), reason)
                Framework.setProperty(InventoryUtils.generateSkipStep('Check Agent Installed'), reason)
            else:
                logger.debug('Agent installed but can not connect, reinstall it.')
                Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_UPGRADE, 'true')
    except:
        Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def StepMain(Framework):
    skipStepReason = Framework.getProperty(InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY)
    if skipStepReason is not None:
        logger.debug('Skipped by request to skip all steps, reason:', skipStepReason)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        return
    skipStepReason = Framework.getProperty(InventoryUtils.generateSkipStep(Framework.getState().getCurrentStepName()))
    if skipStepReason is not None:
        logger.debug('Step skipped, reason:', skipStepReason)
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        return

    if not Framework.getProperty(FIRST_TRY_CHECK_ERROR_CODE):
        # we don't want immediately check whether agent installation successful or not,
        # since for sure it is not. go to parking to let others to install
        logger.debug('UD agent install command just run, will check result code after parking')
        Framework.setProperty(FIRST_TRY_CHECK_ERROR_CODE, FIRST_TRY_CHECK_ERROR_CODE)
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
        return
    else:
        logger.debug('Going to check whether agent installation successful or not')
    InventoryUtils.executeStep(Framework, CheckInstallErrorCode,
                               InventoryUtils.STEP_REQUIRES_CONNECTION,
                               InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)