Пример #1
0
def enable():
    handler_utility.set_handler_status(Util.HandlerStatus('Installing'))
    pre_validation_checks()
    config = get_configuration_from_settings()
    if (config.get('IsPipelinesAgent') != None):
        enable_pipelines_agent(config)
        return

    compare_sequence_number()
    settings_are_same = test_extension_settings_are_same_as_disabled_version()
    if (settings_are_same):
        handler_utility.log("Skipping extension enable.")
        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus(
                'SkippingEnableSameSettingsAsDisabledVersion'))
    else:
        validate_inputs(config)
        ConfigureDeploymentAgent.set_logger(handler_utility.log)
        DownloadDeploymentAgent.set_logger(handler_utility.log)
        execute_agent_pre_check(config)
        remove_existing_agent_if_required(config)
        download_agent_if_required(config)
        configure_agent_if_required(config)
        handler_utility.set_handler_status(Util.HandlerStatus('Installed'))
        add_agent_tags(config)
        handler_utility.log('Extension is enabled.')

    handler_utility.set_handler_status(Util.HandlerStatus(
        'Enabled', 'success'))

    set_last_sequence_number()
    handler_utility.log('Removing disable markup file..')
    remove_extension_disabled_markup()
Пример #2
0
def uninstall():
    config = get_configuration_from_settings()

    if (config.get('IsPipelinesAgent') != None):
        return

    global configured_agent_exists
    configured_agent_exists = ConfigureDeploymentAgent.is_agent_configured(
        Constants.agent_working_folder)
    extension_update_file = '{0}/{1}'.format(Constants.agent_working_folder,
                                             Constants.update_file_name)
    is_udpate_scenario = os.path.isfile(extension_update_file)
    if (not (is_udpate_scenario)):
        if (configured_agent_exists == True):
            config = {
                'AgentWorkingFolder': Constants.agent_working_folder,
            }
            remove_existing_agent(config)
    else:
        handler_utility.log(
            'Extension update scenario. Deleting the file {0}/{1}'.format(
                Constants.agent_working_folder, Constants.update_file_name))
        os.remove(extension_update_file)

    handler_utility.set_handler_status(
        Util.HandlerStatus('Uninstalling', 'success'))
Пример #3
0
def disable():
    ConfigureDeploymentAgent.set_logger(handler_utility.log)
    config = get_configuration_from_settings()

    if (config.get('IsPipelinesAgent') != None):
        return

    handler_utility.log('Disable command is no-op for agent')
    handler_utility.log(
        'Disabling extension handler. Creating a markup file..')
    set_extension_disabled_markup()

    handler_utility.add_handler_sub_status(Util.HandlerSubStatus('Disabled'))

    handler_utility.set_handler_status(
        Util.HandlerStatus('Disabled', 'success'))
Пример #4
0
def enable_pipelines_agent(config):
    try:

        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('DownloadPipelinesAgent'))
        agentFolder = config["AgentFolder"]

        # download the agent tar file
        downloadUrl = config["AgentDownloadUrl"]
        agentFile = os.path.join(agentFolder, os.path.basename(downloadUrl))
        urllib.urlretrieve(downloadUrl, agentFile)

        # download the enable script
        downloadUrl = config["EnableScriptDownloadUrl"]
        enableFile = os.path.join(agentFolder, os.path.basename(downloadUrl))
        urllib.urlretrieve(downloadUrl, enableFile)

    except Exception as e:
        set_error_status_and_error_exit(
            e, RMExtensionStatus.rm_extension_status[
                'DownloadPipelinesAgentError']['operationName'],
            getattr(e, 'message'))

    try:
        # run the enable script
        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('EnablePipelinesAgent'))
        enableParameters = config["EnableScriptParameters"]
        enableProcess = subprocess.Popen(
            ['/bin/bash', '-c', enableFile, enableParameters])

        # wait for the script to complete
        installProcess.communicate()

    except Exception as e:
        set_error_status_and_error_exit(
            e,
            RMExtensionStatus.rm_extension_status['EnablePipelinesAgentError']
            ['operationName'], getattr(e, 'message'))

    handler_utility.add_handler_sub_status(
        Util.HandlerSubStatus('EnablePipelinesAgentSuccess'))
    handler_utility.set_handler_status(Util.HandlerStatus('Enabled'))
    handler_utility.log('Pipelines Agent is enabled.')
Пример #5
0
def compare_sequence_number():
    try:
        sequence_number = int(handler_utility._context._seq_no)
        last_sequence_number = get_last_sequence_number()
        if ((sequence_number == last_sequence_number)
                and not (test_extension_disabled_markup())):
            handler_utility.log(
                RMExtensionStatus.rm_extension_status['SkippedInstallation']
                ['Message'])
            handler_utility.log(
                'Skipping enable since seq numbers match. Seq number: {0}.'.
                format(sequence_number))
            handler_utility.add_handler_sub_status(
                Util.HandlerSubStatus('SkippedInstallation'))
            handler_utility.set_handler_status(
                Util.HandlerStatus('Enabled', 'success'))
            exit_with_code(0)

    except Exception as e:
        handler_utility.log('Sequence number check failed: {0}.'.format(
            getattr(e, 'message')))
Пример #6
0
def enable_pipelines_agent(config):
    try:
        handler_utility.log('Enable Pipelines Agent')

        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('DownloadPipelinesAgent'))
        agentFolder = config["AgentFolder"]
        handler_utility.log(agentFolder)

        if (not os.path.isdir(agentFolder)):
            handler_utility.log('Agent folder does not exist. Creating it.')
            os.makedirs(agentFolder, 0o777)

        # download the agent tar file
        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('DownloadPipelinesZip'))
        handler_utility.log('Download Pipelines Zip')
        downloadUrl = config["AgentDownloadUrl"]
        handler_utility.log(downloadUrl)
        filename = os.path.basename(downloadUrl)
        agentFile = os.path.join(agentFolder, filename)
        urllib.urlretrieve(downloadUrl, agentFile)

        # download the enable script
        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('DownloadPipelinesScript'))
        handler_utility.log('Download Pipelines Script')
        downloadUrl = config["EnableScriptDownloadUrl"]
        handler_utility.log(downloadUrl)
        filename = os.path.basename(downloadUrl)
        enableFile = os.path.join(agentFolder, filename)
        urllib.urlretrieve(downloadUrl, enableFile)

    except Exception as e:
        handler_utility.log(getattr(e, 'message'))
        handler_utility.log(e)
        set_error_status_and_error_exit(
            e, RMExtensionStatus.rm_extension_status[
                'DownloadPipelinesAgentError']['operationName'],
            getattr(e, 'message'))
        return

    try:
        # grant executable access to the script
        os.chmod(enableFile, 0o777)

        # run the enable script
        handler_utility.add_handler_sub_status(
            Util.HandlerSubStatus('EnablePipelinesAgent'))
        handler_utility.log('Run Pipelines Script')
        handler_utility.log(enableFile)
        enableParameters = config["EnableScriptParameters"]

        # run the script and wait for it to complete
        handler_utility.log("running script")
        argList = ['/bin/bash', enableFile] + shlex.split(enableParameters)
        enableProcess = subprocess.Popen(argList)
        enableProcess.communicate()

    except Exception as e:
        handler_utility.log(getattr(e, 'message'))
        handler_utility.log(e)
        set_error_status_and_error_exit(
            e,
            RMExtensionStatus.rm_extension_status['EnablePipelinesAgentError']
            ['operationName'], getattr(e, 'message'))
        return

    handler_utility.add_handler_sub_status(
        Util.HandlerSubStatus('EnablePipelinesAgentSuccess'))
    handler_utility.set_handler_status(Util.HandlerStatus(
        'Enabled', 'success'))
    handler_utility.log('Pipelines Agent is enabled.')