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