Home | History | Annotate | Download | only in hosts
      1 #
      2 # Copyright 2007 Google Inc. Released under the GPL v2
      3 
      4 """
      5 This module defines the base classes for the server Host hierarchy.
      6 
      7 Implementation details:
      8 You should import the "hosts" package instead of importing each type of host.
      9 
     10         Host: a machine on which you can run programs
     11         RemoteHost: a remote machine on which you can run programs
     12 """
     13 
     14 __author__ = """
     15 mbligh (at] google.com (Martin J. Bligh),
     16 poirier (at] google.com (Benjamin Poirier),
     17 stutsman (at] google.com (Ryan Stutsman)
     18 """
     19 
     20 from autotest_lib.client.common_lib import hosts
     21 from autotest_lib.server import utils
     22 
     23 
     24 class Host(hosts.Host):
     25     """
     26     This class represents a machine on which you can run programs.
     27 
     28     It may be a local machine, the one autoserv is running on, a remote
     29     machine or a virtual machine.
     30 
     31     Implementation details:
     32     This is an abstract class, leaf subclasses must implement the methods
     33     listed here. You must not instantiate this class but should
     34     instantiate one of those leaf subclasses.
     35 
     36     When overriding methods that raise NotImplementedError, the leaf class
     37     is fully responsible for the implementation and should not chain calls
     38     to super. When overriding methods that are a NOP in Host, the subclass
     39     should chain calls to super(). The criteria for fitting a new method into
     40     one category or the other should be:
     41         1. If two separate generic implementations could reasonably be
     42            concatenated, then the abstract implementation should pass and
     43            subclasses should chain calls to super.
     44         2. If only one class could reasonably perform the stated function
     45            (e.g. two separate run() implementations cannot both be executed)
     46            then the method should raise NotImplementedError in Host, and
     47            the implementor should NOT chain calls to super, to ensure that
     48            only one implementation ever gets executed.
     49     """
     50 
     51     bootloader = None
     52     support_devserver_provision = False
     53 
     54 
     55     def __init__(self, *args, **dargs):
     56         super(Host, self).__init__(*args, **dargs)
     57 
     58         self.start_loggers()
     59         if self.job:
     60             self.job.hosts.add(self)
     61 
     62 
     63     def _initialize(self, *args, **dargs):
     64         super(Host, self)._initialize(*args, **dargs)
     65 
     66         self.serverdir = utils.get_server_dir()
     67         self.env = {}
     68 
     69 
     70     def close(self):
     71         super(Host, self).close()
     72 
     73         if self.job:
     74             self.job.hosts.discard(self)
     75