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


Python utils.LocalCommandRunner类代码示例

本文整理汇总了Python中cloudify.utils.LocalCommandRunner的典型用法代码示例。如果您正苦于以下问题:Python LocalCommandRunner类的具体用法?Python LocalCommandRunner怎么用?Python LocalCommandRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: install_blueprint_plugins

def install_blueprint_plugins(blueprint_path):

    requirements = create_requirements(
        blueprint_path=blueprint_path
    )

    if requirements:
        # validate we are inside a virtual env
        if not utils.is_virtual_env():
            raise exceptions.CloudifyCliError(
                'You must be running inside a '
                'virtualenv to install blueprint plugins')

        runner = LocalCommandRunner(get_logger())
        # dump the requirements to a file
        # and let pip install it.
        # this will utilize pip's mechanism
        # of cleanup in case an installation fails.
        tmp_path = tempfile.mkstemp(suffix='.txt', prefix='requirements_')[1]
        utils.dump_to_file(collection=requirements, file_path=tmp_path)
        command_parts = [sys.executable, '-m', 'pip', 'install', '-r',
                         tmp_path]
        runner.run(command=' '.join(command_parts), stdout_pipe=False)
    else:
        get_logger().debug('There are no plugins to install')
开发者ID:funkyHat,项目名称:cloudify-cli,代码行数:25,代码来源:common.py

示例2: FileServer

class FileServer(object):
    def __init__(self, root_path=None, port=5555):
        self.port = port
        self.root_path = root_path or os.path.dirname(resources.__file__)
        self.process = None
        self.logger = setup_logger("cloudify_agent.tests.utils.FileServer", logger_level=logging.DEBUG)
        self.runner = LocalCommandRunner(self.logger)

    def start(self, timeout=5):
        if os.name == "nt":
            serve_path = os.path.join(VIRTUALENV, "Scripts", "serve")
        else:
            serve_path = os.path.join(VIRTUALENV, "bin", "serve")

        self.process = subprocess.Popen(
            [serve_path, "-p", str(self.port), self.root_path], stdin=open(os.devnull, "w"), stdout=None, stderr=None
        )

        end_time = time.time() + timeout

        while end_time > time.time():
            if self.is_alive():
                logger.info("File server is up and serving from {0} ({1})".format(self.root_path, self.process.pid))
                return
            logger.info("File server is not responding. waiting 10ms")
            time.sleep(0.1)
        raise RuntimeError("FileServer failed to start")

    def stop(self, timeout=15):
        if self.process is None:
            return

        end_time = time.time() + timeout

        if os.name == "nt":
            self.runner.run(
                "taskkill /F /T /PID {0}".format(self.process.pid),
                stdout_pipe=False,
                stderr_pipe=False,
                exit_on_failure=False,
            )
        else:
            self.runner.run("kill -9 {0}".format(self.process.pid))

        while end_time > time.time():
            if not self.is_alive():
                logger.info("File server has shutdown")
                return
            logger.info("File server is still running. waiting 10ms")
            time.sleep(0.1)
        raise RuntimeError("FileServer failed to stop")

    def is_alive(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.connect(("localhost", self.port))
            s.close()
            return True
        except socket.error:
            return False
开发者ID:konradxyz,项目名称:cloudify-agent,代码行数:60,代码来源:utils.py

示例3: extract_plugin_name

def extract_plugin_name(plugin_url):
    previous_cwd = os.getcwd()
    fetch_plugin_from_pip_by_url = not os.path.isdir(plugin_url)
    plugin_dir = plugin_url
    try:
        if fetch_plugin_from_pip_by_url:
            plugin_dir = tempfile.mkdtemp()
            req_set = pip.req.RequirementSet(build_dir=None,
                                             src_dir=None,
                                             download_dir=None)
            req_set.unpack_url(link=pip.index.Link(plugin_url),
                               location=plugin_dir,
                               download_dir=None,
                               only_download=False)
        runner = LocalCommandRunner()
        os.chdir(plugin_dir)
        plugin_name = runner.run(
            '{0} {1} {2}'.format(_python(),
                                 path.join(
                                     path.dirname(__file__),
                                     'extract_package_name.py'),
                                 plugin_dir)).std_out
        runner.run('{0} install --no-deps {1}'.format(_pip(), plugin_dir))
        return plugin_name
    finally:
        os.chdir(previous_cwd)
        if fetch_plugin_from_pip_by_url:
            shutil.rmtree(plugin_dir)
开发者ID:zengxianhui,项目名称:cloudify-manager,代码行数:28,代码来源:tasks.py

示例4: extract_package_to_dir

def extract_package_to_dir(package_url):
    """
    Using a subprocess to extract a pip package to a temporary directory.
    :param: package_url: the URL of the package source.
    :return: the directory the package was extracted to.

    """
    plugin_dir = None
    archive_dir = tempfile.mkdtemp()
    runner = LocalCommandRunner()

    try:
        # We run `pip download` command in a subprocess to support
        # multi-threaded scenario (i.e snapshot restore).
        # We don't use `curl` because pip can handle different kinds of files,
        # including .git.
        command = [get_pip_path(), 'download', '-d',
                   archive_dir, '--no-deps', package_url]
        runner.run(command=command)
        archive = _get_archive(archive_dir, package_url)
        plugin_dir_parent = extract_archive(archive)
        plugin_dir = _get_plugin_path(plugin_dir_parent, package_url)

    except NonRecoverableError as e:
        if plugin_dir and os.path.exists(plugin_dir):
            shutil.rmtree(plugin_dir)
        raise e

    finally:
        if os.path.exists(archive_dir):
            shutil.rmtree(archive_dir)

    return plugin_dir
开发者ID:cloudify-cosmo,项目名称:cloudify-agent,代码行数:33,代码来源:installer.py

示例5: install_blueprint_plugins

def install_blueprint_plugins(blueprint_path):

    requirements = create_requirements(
        blueprint_path=blueprint_path
    )

    if requirements:
        # validate we are inside a virtual env
        if not utils.is_virtual_env():
            raise exceptions.CloudifyCliError(
                'You must be running inside a '
                'virtualenv to install blueprint plugins')

        runner = LocalCommandRunner(get_logger())
        # dump the requirements to a file
        # and let pip install it.
        # this will utilize pip's mechanism
        # of cleanup in case an installation fails.
        output = tempfile.NamedTemporaryFile(mode='w',
                                             delete=True,
                                             suffix='.txt',
                                             prefix='requirements_')
        utils.dump_to_file(collection=requirements,
                           file_path=output.name)
        runner.run(command='pip install -r {0}'.format(output.name),
                   stdout_pipe=False)
    else:
        get_logger().debug('There are no plugins to install..')
开发者ID:geokala,项目名称:cloudify-cli,代码行数:28,代码来源:common.py

示例6: _list_plugin_files

    def _list_plugin_files(self, plugin_name):

        """
        Retrieves python files related to the plugin.
        __init__ file are filtered out.

        :param plugin_name: The plugin name.

        :return: A list of file paths.
        :rtype: list of str
        """

        module_paths = []
        runner = LocalCommandRunner(self._logger)

        files = runner.run(
            '{0} show -f {1}'
            .format(utils.get_pip_path(), plugin_name)
        ).std_out.splitlines()
        for module in files:
            if self._is_valid_module(module):
                # the file paths are relative to the
                # package __init__.py file.
                prefix = '../' if os.name == 'posix' else '..\\'
                module_paths.append(
                    module.replace(prefix, '')
                    .replace(os.sep, '.').replace('.py', '').strip())
        return module_paths
开发者ID:codilime,项目名称:cloudify-agent,代码行数:28,代码来源:base.py

示例7: _assert_plugin_installed

 def _assert_plugin_installed(self, package_name,
                              plugin, dependencies=None):
     if not dependencies:
         dependencies = []
     runner = LocalCommandRunner()
     out = runner.run(
         '{0}/bin/pip list | grep {1}'
         .format(self.temp_folder, plugin['name'])).std_out
     self.assertIn(package_name, out)
     for dependency in dependencies:
         self.assertIn(dependency, out)
开发者ID:zengxianhui,项目名称:cloudify-manager,代码行数:11,代码来源:test_installer.py

示例8: _fix_virtualenv

def _fix_virtualenv():

    """
    This method is used for auto-configuration of the virtualenv.
    It is needed in case the environment was created using different paths
    than the one that is used at runtime.

    """

    from cloudify_agent.shell.main import get_logger
    logger = get_logger()

    bin_dir = '{0}/bin'.format(VIRTUALENV)

    logger.debug('Searching for executable files in {0}'.format(bin_dir))
    for executable in os.listdir(bin_dir):
        path = os.path.join(bin_dir, executable)
        logger.debug('Checking {0}...'.format(path))
        if not os.path.isfile(path):
            logger.debug('{0} is not a file. Skipping...'.format(path))
            continue
        if os.path.islink(path):
            logger.debug('{0} is a link. Skipping...'.format(path))
            continue
        basename = os.path.basename(path)
        if basename in ['python', 'python2.7', 'python2.6']:
            logger.debug('{0} is the python executable. Skipping...'
                         .format(path))
            continue
        with open(path) as f:
            lines = f.read().split(os.linesep)
            if lines[0].endswith('/bin/python'):
                new_line = '#!{0}/python'.format(bin_dir)
                logger.debug('Replacing {0} with {1}'
                             .format(lines[0], new_line))
                lines[0] = new_line
        with open(path, 'w') as f:
            f.write(os.linesep.join(lines))

    runner = LocalCommandRunner(logger)

    logger.debug('Searching for links in {0}'.format(VIRTUALENV))
    for link in ['archives', 'bin', 'include', 'lib']:
        link_path = '{0}/local/{1}'.format(VIRTUALENV, link)
        logger.debug('Checking {0}...'.format(link_path))
        try:
            runner.run('unlink {0}'.format(link_path))
            runner.run('ln -s {0}/{1} {2}'
                       .format(VIRTUALENV, link, link_path))
        except CommandExecutionException:
            pass
开发者ID:pkdevboxy,项目名称:cloudify-agent,代码行数:51,代码来源:configure.py

示例9: InstallerTestBase

class InstallerTestBase(unittest.TestCase):

    def setUp(self):
        self.logger = setup_logger('InstallerTest')
        config_path = os.environ.get('CONFIG_PATH')
        self.logger.info('Config: {0}'.format(config_path))
        with open(config_path) as config_file:
            self.config = yaml.load(config_file)
        self.logger.info(str(self.config))
        current_ctx.set(MockCloudifyContext())
        self.runner = LocalCommandRunner(self.logger)
        self.base_dir = tempfile.mkdtemp()
        self.logger.info('Base dir: {0}'.format(self.base_dir))
        _, self.script_path = tempfile.mkstemp(dir=self.base_dir,
                                               suffix='.py')
        install_utils.prepare_script({}, self.script_path)

    def tearDown(self):
        shutil.rmtree(self.base_dir)

    def get_agent(self):
        result = {
            'local': True,
            'package_url': self.config['agent_url'],
            'user': self.config['agent_user'],
            'basedir': self.base_dir,
            'manager_ip': '127.0.0.1',
            'name': 'agent_{0}'.format(uuid.uuid4())
        }
        agent_config.prepare_connection(result)
        # We specify base_dir and user directly, so runner is not needed.
        agent_config.prepare_agent(result, None)
        _, agent_file_path = tempfile.mkstemp(dir=self.base_dir)
        with open(agent_file_path, 'a') as agent_file:
            agent_file.write(json.dumps(result))
        result['agent_file'] = agent_file_path
        return result

    def cleanup_agent(self, agent):
        os.remove(agent['agent_file'])

    def call(self, operation, agent):
        agent_config_path = agent['agent_file']
        command = '{0} {1} --operation={2} --config={3}'.format(
            self.config['python_path'],
            self.script_path,
            operation,
            agent_config_path)
        self.logger.info('Calling: "{0}"'.format(command))
        self.runner.run(command)
开发者ID:konradxyz,项目名称:cloudify-install-agents,代码行数:50,代码来源:test_install_agent.py

示例10: extract_plugin_name

def extract_plugin_name(plugin_dir):
    previous_cwd = os.getcwd()

    try:
        os.chdir(plugin_dir)
        runner = LocalCommandRunner(host=utils.get_local_ip())
        plugin_name = runner.run(
            '{0} {1} {2}'.format(_python(),
                                 path.join(
                                     path.dirname(__file__),
                                     'extract_package_name.py'),
                                 plugin_dir)).std_out
        return plugin_name
    finally:
        os.chdir(previous_cwd)
开发者ID:arcivanov,项目名称:cloudify-manager,代码行数:15,代码来源:tasks.py

示例11: __init__

 def __init__(self, root_path=None, port=5555):
     self.port = port
     self.root_path = root_path or os.path.dirname(resources.__file__)
     self.process = None
     self.logger = setup_logger('cloudify_agent.tests.utils.FileServer',
                                logger_level=logging.DEBUG)
     self.runner = LocalCommandRunner(self.logger)
开发者ID:gvsurenderreddy,项目名称:cloudify-agent,代码行数:7,代码来源:utils.py

示例12: setUp

 def setUp(self):
     super(BaseDaemonLiveTestCase, self).setUp()
     self.celery = Celery(broker='amqp://',
                          backend='amqp://')
     self.celery.conf.update(
         CELERY_TASK_RESULT_EXPIRES=defaults.CELERY_TASK_RESULT_EXPIRES)
     self.runner = LocalCommandRunner(logger=self.logger)
     self.daemons = []
开发者ID:geokala,项目名称:cloudify-agent,代码行数:8,代码来源:__init__.py

示例13: _disable_requiretty

def _disable_requiretty():

    """
    Disables the requiretty directive in the /etc/sudoers file. This
    will enable operations that require sudo permissions to work properly.

    This is needed because operations are executed
    from within the worker process, which is not a tty process.

    """

    from cloudify_agent.shell.main import get_logger
    runner = LocalCommandRunner(get_logger())

    disable_requiretty_script_path = utils.resource_to_tempfile(
        resource_path='disable-requiretty.sh'
    )
    runner.run('chmod +x {0}'.format(disable_requiretty_script_path))
    runner.run('{0}'.format(disable_requiretty_script_path))
开发者ID:konradxyz,项目名称:cloudify-agent,代码行数:19,代码来源:configure.py

示例14: extract_package_name

def extract_package_name(package_dir):
    """
    Detects the package name of the package located at 'package_dir' as
    specified in the package setup.py file.

    :param package_dir: the directory the package was extracted to.

    :return: the package name
    """
    runner = LocalCommandRunner()
    plugin_name = runner.run(
        '{0} {1} {2}'.format(
            sys.executable,
            os.path.join(os.path.dirname(plugins.__file__),
                         'extract_package_name.py'),
            package_dir),
        cwd=package_dir
    ).std_out
    return plugin_name
开发者ID:pkdevboxy,项目名称:cloudify-agent,代码行数:19,代码来源:installer.py

示例15: _test_agent_installation

    def _test_agent_installation(self, agent_config, _):
        new_ctx = mock_context()
        current_ctx.set(new_ctx)

        self.assert_daemon_dead(agent_config['name'])
        create_agent(agent_config=agent_config)
        self.wait_for_daemon_alive(agent_config['name'])

        new_agent = ctx.instance.runtime_properties['cloudify_agent']

        agent_ssl_cert.verify_remote_cert(new_agent['agent_dir'])

        command_format = 'cfy-agent daemons {0} --name {1}'.format(
            '{0}',
            new_agent['name'])
        runner = LocalCommandRunner()
        runner.run(command_format.format('stop'))
        runner.run(command_format.format('delete'))

        self.assert_daemon_dead(agent_config['name'])
        return new_agent
开发者ID:cloudify-cosmo,项目名称:cloudify-agent,代码行数:21,代码来源:test_install_local.py


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