1# 2# Copyright 2007 Google Inc. Released under the GPL v2 3 4""" 5This module defines the Guest class in the Host hierarchy. 6 7Implementation details: 8You should import the "hosts" package instead of importing each type of host. 9 10 Guest: a virtual machine on which you can run programs 11""" 12 13__author__ = """ 14mbligh@google.com (Martin J. Bligh), 15poirier@google.com (Benjamin Poirier), 16stutsman@google.com (Ryan Stutsman) 17""" 18 19 20from autotest_lib.server.hosts import ssh_host 21 22 23class Guest(ssh_host.SSHHost): 24 """ 25 This class represents a virtual machine on which you can run 26 programs. 27 28 It is not the machine autoserv is running on. 29 30 Implementation details: 31 This is an abstract class, leaf subclasses must implement the methods 32 listed here and in parent classes which have no implementation. They 33 may reimplement methods which already have an implementation. You 34 must not instantiate this class but should instantiate one of those 35 leaf subclasses. 36 """ 37 38 controlling_hypervisor = None 39 40 41 def _initialize(self, controlling_hypervisor, *args, **dargs): 42 """ 43 Construct a Guest object 44 45 Args: 46 controlling_hypervisor: Hypervisor object that is 47 responsible for the creation and management of 48 this guest 49 """ 50 hostname = controlling_hypervisor.new_guest() 51 super(Guest, self)._initialize(hostname, *args, **dargs) 52 self.controlling_hypervisor = controlling_hypervisor 53 54 55 def __del__(self): 56 """ 57 Destroy a Guest object 58 """ 59 super(Guest, self).__del__() 60 self.controlling_hypervisor.delete_guest(self.hostname) 61 62 63 def hardreset(self, timeout=600, wait=True): 64 """ 65 Perform a "hardreset" of the guest. 66 67 It is restarted through the hypervisor. That will restart it 68 even if the guest otherwise innaccessible through ssh. 69 """ 70 return self.controlling_hypervisor.reset_guest(self.hostname) 71