'Prepare a namespace to be used when executing server control files.
This sets up the control file API by importing modules and making them
available under the appropriate names within namespace.
For use by _execute_code().
Args:
namespace: The namespace dictionary to fill in.
protect: Boolean.  If True (the default) any operation that would
clobber an existing entry in namespace will cause an error.
Raises:
error.AutoservError: When a name would be clobbered by import.'

def _fill_server_control_namespace(self, namespace, protect=True):

    def _import_names(module_name, names=()):
        '\n                                                Import    a    module    and    assign    named    attributes    into    namespace.\n\n                                                Args:\n                                                                module_name:    The    string    module    name.\n                                                                names:    A    limiting    list    of    names    to    import    from    module_name.        If\n                                                                                empty    (the    default),    all    names    are    imported    from    the    module\n                                                                                similar    to    a    "from    foo.bar    import    *"    statement.\n                                                Raises:\n                                                                error.AutoservError:    When    a    name    being    imported    would    clobber\n                                                                                a    name    already    in    namespace.\n                                                '
        module = __import__(module_name, {}, {}, names)
        if (not names):
            for submodule_name in module_name.split('.')[1:]:
                module = getattr(module, submodule_name)
            if hasattr(module, '__all__'):
                names = getattr(module, '__all__')
            else:
                names = dir(module)
        for name in names:
            if ((name in namespace) and protect):
                if (namespace[name] is not getattr(module, name)):
                    raise error.AutoservError(('importing    name    %s    from    %s    %r    would    override    %r' % (name, module_name, getattr(module, name), namespace[name])))
                else:
                    warnings.warn(('%s    (%r)    being    imported    from    %s    for    use    in    server    control    files    is    not    the    first    occurrence    of    that    import.' % (name, namespace[name], module_name)))
            namespace[name] = getattr(module, name)
    namespace.update(os=os, sys=sys, logging=logging)
    _import_names('autotest.server', ('hosts', 'autotest_remote', 'standalone_profiler', 'source_kernel', 'rpm_kernel', 'deb_kernel', 'git_kernel'))
    _import_names('autotest.server.subcommand', ('parallel', 'parallel_simple', 'subcommand'))
    _import_names('autotest.server.utils', ('run', 'get_tmp_dir', 'sh_escape', 'parse_machine'))
    _import_names('autotest.client.shared.error')
    _import_names('autotest.client.shared.barrier', ('barrier',))
    namespace['autotest_remote'].Autotest.job = self
    namespace['hosts'].Host.job = self
    namespace['hosts'].factory.ssh_user = self._ssh_user
    namespace['hosts'].factory.ssh_port = self._ssh_port
    namespace['hosts'].factory.ssh_pass = self._ssh_pass
