Pull the host factory method out of server/hosts/__init__.py and into
a separate module, and add in a hook for site-specific code.

Risk: Low
Visibility: Most just a refactoring.

Signed-off-by: John Admanski <jadmanski@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2111 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/__init__.py b/server/hosts/__init__.py
index e8291b0..03f49fc 100644
--- a/server/hosts/__init__.py
+++ b/server/hosts/__init__.py
@@ -27,38 +27,5 @@
 # bootloader classes
 from bootloader import Bootloader
 
-
-# generic host factory
-def create_host(hostname, **args):
-    from autotest_lib.client.common_lib import utils, error
-    from autotest_lib.server import utils as server_utils
-
-    # by default assume we're using SSH support
-    hosts = [SSHHost]
-
-    # use serial console support if it's available
-    conmux_args = {}
-    for key in ("conmux_server", "conmux_attach"):
-        if key in args:
-            conmux_args[key] = args[key]
-    if SerialHost.host_is_supported(hostname, **conmux_args):
-        hosts.append(SerialHost)
-    else:
-        # no serial host available, try netconsole logging if available
-        def run_func(cmd):
-            base_cmd = SSHHost.ssh_base_command(connect_timeout=3)
-            full_cmd = '%s %s "%s"' % (base_cmd, hostname,
-                                       server_utils.sh_escape(cmd))
-            try:
-                utils.run(full_cmd)
-            except error.CmdError:
-                pass
-
-        if NetconsoleHost.host_is_supported(run_func):
-            hosts.append(NetconsoleHost)
-        else:
-            hosts.append(DmesgHost)  # nothing available, fall back to dmesg
-
-    # create a custom host class for this machine and make an instance of it
-    host_class = type("%s_host" % hostname, tuple(hosts), {})
-    return host_class(hostname, **args)
+# factory function
+from factory import create_host