示例#1
0
def start_nodes(args, ports):
    log = logging.getLogger(__name__)

    log.info('Starting ConductR nodes..')
    for i in range(args.nr_of_containers):
        container_name = '{prefix}{nr}'.format(prefix=CONDUCTR_NAME_PREFIX,
                                               nr=i)
        container_id = terminal.docker_ps('name={}'.format(container_name))
        if not container_id:
            # Display the ports on the command line. Only if the user specifies a certain feature, then
            # the corresponding port will be displayed when running 'sandbox run' or 'sandbox debug'
            if ports:
                host_ip = sandbox_common.resolve_host_ip()
                ports_desc = ' exposing ' + ', '.join([
                    '{}:{}'.format(host_ip, map_port(i, port))
                    for port in sorted(ports)
                ])
            else:
                ports_desc = ''
            log.info('Starting container {container}{port_desc}..'.format(
                container=container_name, port_desc=ports_desc))
            cond0_ip = inspect_cond0_ip() if i > 0 else None
            conductr_container_roles = resolve_conductr_roles_by_container(
                args.conductr_roles, i)
            run_conductr_cmd(
                i, container_name, cond0_ip, args.envs,
                '{image}:{version}'.format(image=args.image,
                                           version=args.image_version),
                args.log_level, ports, args.bundle_http_port, args.features,
                conductr_container_roles)
        else:
            log.info(
                'ConductR node {} already exists, leaving it alone.'.format(
                    container_name))
示例#2
0
def start_nodes(args, ports):
    log = logging.getLogger(__name__)

    log.info('Starting ConductR nodes..')
    for i in range(args.nr_of_containers):
        container_name = '{prefix}{nr}'.format(prefix=CONDUCTR_NAME_PREFIX, nr=i)
        container_id = terminal.docker_ps('name={}'.format(container_name))
        if not container_id:
            # Display the ports on the command line. Only if the user specifies a certain feature, then
            # the corresponding port will be displayed when running 'sandbox run' or 'sandbox debug'
            if ports:
                host_ip = sandbox_common.resolve_host_ip()
                ports_desc = ' exposing ' + ', '.join(['{}:{}'.format(host_ip, map_port(i, port)) for port in sorted(ports)])
            else:
                ports_desc = ''
            log.info('Starting container {container}{port_desc}..'.format(container=container_name, port_desc=ports_desc))
            cond0_ip = inspect_cond0_ip() if i > 0 else None
            conductr_container_roles = resolve_conductr_roles_by_container(args.conductr_roles, i)
            run_conductr_cmd(
                i,
                container_name,
                cond0_ip,
                args.envs,
                '{image}:{version}'.format(image=args.image, version=args.image_version),
                args.log_level,
                ports,
                args.bundle_http_port,
                args.features,
                conductr_container_roles
            )
        else:
            log.info('ConductR node {} already exists, leaving it alone.'.format(container_name))
示例#3
0
 def handle_non_linux(*args, **kwargs):
     log.info('Docker could not connect to the docker VM.')
     log.info('It looks like the docker environment variables are not set. Let me try to set them..')
     [set_env(env[0], env[1]) for env in resolve_envs()]
     try:
         terminal.docker_ps()
         log.info('The Docker environment variables have been set for this command.')
         log.info('Continue processing..')
         log.warning('To set the environment variables for each terminal session '
                     'follow the instructions of the command:')
         log.warning('  docker-machine env {}'.format(vm_name))
         log.info('')
         return func(*args, **kwargs)
     except CalledProcessError:
         log.error('Docker could not be configured automatically.')
         log.error('Please set the docker environment variables.')
示例#4
0
def resolve_running_docker_containers():
    """Resolve running docker containers.
       Return the running container names (e.g. cond-0) in ascending order"""
    container_ids = terminal.docker_ps(
        ps_filter='name={}'.format(CONDUCTR_NAME_PREFIX))
    container_names = [
        terminal.docker_inspect(container_id, '{{.Name}}')[1:]
        for container_id in container_ids
    ]
    return sorted(container_names)
示例#5
0
 def handle_non_linux(*args, **kwargs):
     log.info('Docker could not connect to the docker VM.')
     log.info(
         'It looks like the docker environment variables are not set. Let me try to set them..'
     )
     [set_env(env[0], env[1]) for env in resolve_envs()]
     try:
         terminal.docker_ps()
         log.info(
             'The Docker environment variables have been set for this command.'
         )
         log.info('Continue processing..')
         log.warning(
             'To set the environment variables for each terminal session '
             'follow the instructions of the command:')
         log.warning('  docker-machine env {}'.format(vm_name))
         log.info('')
         return func(*args, **kwargs)
     except CalledProcessError:
         log.error('Docker could not be configured automatically.')
         log.error('Please set the docker environment variables.')
示例#6
0
    def test_docker_ps(self):
        ps_filter = 'name=cond-'
        image1 = 'image-id1'
        image2 = 'image-id2'

        check_output_mock = MagicMock(return_value='{}\n{}\n'.format(image1, image2))

        with patch('subprocess.check_output', check_output_mock):
            result = terminal.docker_ps(ps_filter)

        self.assertEqual(result, [image1, image2])
        check_output_mock.assert_called_with(['docker', 'ps', '--all', '--quiet', '--filter', ps_filter],
                                             universal_newlines=True, stderr=subprocess.DEVNULL)
示例#7
0
    def test_docker_ps(self):
        ps_filter = 'name=cond-'
        image1 = 'image-id1'
        image2 = 'image-id2'

        check_output_mock = MagicMock(
            return_value='{}\n{}\n'.format(image1, image2))

        with patch('subprocess.check_output', check_output_mock):
            result = terminal.docker_ps(ps_filter)

        self.assertEqual(result, [image1, image2])
        check_output_mock.assert_called_with(
            ['docker', 'ps', '--quiet', '--filter', ps_filter],
            universal_newlines=True)
def resolve_running_docker_containers():
    """Resolve running docker containers.
       Return the running container names (e.g. cond-0) in ascending order"""
    container_ids = terminal.docker_ps(ps_filter='name={}'.format(CONDUCTR_NAME_PREFIX))
    container_names = [terminal.docker_inspect(container_id, '{{.Name}}')[1:] for container_id in container_ids]
    return sorted(container_names)
示例#9
0
def get_running_haproxy():
    return terminal.docker_ps(
        ps_filter='name={}'.format(DEFAULT_SANDBOX_PROXY_CONTAINER_NAME))