예제 #1
0
def _run(command, error_message):
    runner = utils.LocalCommandRunner(logger=ctx.logger)
    try:
        runner.run(command)
    except exceptions.CommandExecutionException as e:
        raise exceptions.NonRecoverableError('{0}: {1}'.format(
            error_message, e))
예제 #2
0
def run_install(commands,
                tmp_path,
                windows=False,
                extra_agent_params=None,
                cert=None):
    install_script = _get_install_script(cert,
                                         extra_agent_params=extra_agent_params)

    # Remove last line where main function is executed
    install_script = '\n'.join(install_script.split('\n')[:-1])

    if windows:
        install_script_path = os.path.abspath(
            os.path.join(str(tmp_path), 'install_script.ps1'))
    else:
        install_script_path = os.path.abspath(
            os.path.join(str(tmp_path), 'install_script.sh'))
    with open(install_script_path, 'w') as f:
        f.write(install_script)
        # Inject test commands
        f.write('\n{0}'.format('\n'.join(commands)))

    if windows:
        command_line = 'powershell {0}'.format(install_script_path)
    else:
        os.chmod(install_script_path, 0o755)
        command_line = install_script_path
    runner = cloudify_utils.LocalCommandRunner(logger)
    response = runner.run(command_line)
    return response.std_out
예제 #3
0
def _update_includes(module_paths):

    # Read current AppParameters
    app_parameters = read_app_parameters()

    new_app_parameters = add_module_paths_to_includes(module_paths,
                                                      app_parameters)
    utils.LocalCommandRunner().run(
        'cmd /c "{0} set CloudifyAgent AppParameters {1}"'.format(
            NSSM_PATH, new_app_parameters))

    # Write new AppParameters
    write_app_parameters(new_app_parameters)
예제 #4
0
def install_celery_plugin(plugin_url):

    """
    Installs celery tasks into the cloudify agent.

        1. Installs the plugin into the current python installation directory.
        2  Adds the python files into the agent includes directive.

    :param plugin_url: URL to an archive of the plugin.
    """

    command = 'cmd /c "{0}\Scripts\pip.exe install {1}"' \
        .format(sys.prefix, plugin_url)
    utils.LocalCommandRunner(
        logger=logger,
        host=utils.get_local_ip()
    ).run(command)
    plugin_name = plugin_utils.extract_plugin_name(plugin_url)
    module_paths = plugin_utils.extract_module_paths(plugin_name)
    _update_includes(module_paths)
예제 #5
0
 def _run(self, *commands):
     init_script = script.init_script(
         cloudify_agent=self.input_cloudify_agent)
     init_script = '\n'.join(init_script.split('\n')[:-1])
     if self.windows:
         init_script_path = os.path.abspath('init_script.ps1')
     else:
         init_script_path = os.path.abspath('init_script.sh')
     with open(init_script_path, 'w') as f:
         f.write(init_script)
         for command in commands:
             f.write('{0}\n'.format(command))
     if not self.windows:
         os.chmod(init_script_path, 0755)
     if self.windows:
         command_line = 'powershell {0}'.format(init_script_path)
     else:
         command_line = init_script_path
     runner = cloudify_utils.LocalCommandRunner(self.logger)
     response = runner.run(command_line)
     return response.std_out
예제 #6
0
    def _run(self, *commands):
        install_script = self._get_install_script()

        # Remove last line where main function is executed
        install_script = '\n'.join(install_script.split('\n')[:-1])

        if self.windows:
            install_script_path = os.path.abspath('install_script.ps1')
        else:
            install_script_path = os.path.abspath('install_script.sh')
        with open(install_script_path, 'w') as f:
            f.write(install_script)
            # Inject test commands
            f.write('\n{0}'.format('\n'.join(commands)))

        if not self.windows:
            os.chmod(install_script_path, 0o755)
        if self.windows:
            command_line = 'powershell {0}'.format(install_script_path)
        else:
            command_line = install_script_path
        runner = cloudify_utils.LocalCommandRunner(self.logger)
        response = runner.run(command_line)
        return response.std_out