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 | |
| 11 | Guest: a virtual machine on which you can run programs |
| 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 | |
| 21 | import ssh_host |
| 22 | |
| 23 | |
| 24 | class Guest(ssh_host.SSHHost): |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 25 | """ |
| 26 | This class represents a virtual machine on which you can run |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 27 | programs. |
| 28 | |
| 29 | It is not the machine autoserv is running on. |
| 30 | |
| 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 |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 36 | leaf subclasses. |
| 37 | """ |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 38 | |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 39 | controlling_hypervisor = None |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 40 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 41 | |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 42 | def __init__(self, controlling_hypervisor): |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 43 | """ |
| 44 | Construct a Guest object |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 45 | |
| 46 | Args: |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 47 | controlling_hypervisor: Hypervisor object that is |
| 48 | responsible for the creation and management of |
| 49 | this guest |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 50 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 51 | hostname= controlling_hypervisor.new_guest() |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 52 | super(Guest, self).__init__(hostname) |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 53 | self.controlling_hypervisor= controlling_hypervisor |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 54 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 55 | |
| 56 | def __del__(self): |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 57 | """ |
| 58 | Destroy a Guest object |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 59 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 60 | self.controlling_hypervisor.delete_guest(self.hostname) |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 61 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 62 | |
mbligh | 3409ee7 | 2007-10-16 23:58:33 +0000 | [diff] [blame^] | 63 | def hardreset(self, timeout=600, wait=True): |
mbligh | 7d2bde8 | 2007-08-02 16:26:10 +0000 | [diff] [blame] | 64 | """ |
| 65 | Perform a "hardreset" of the guest. |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 66 | |
| 67 | It is restarted through the hypervisor. That will restart it |
| 68 | even if the guest otherwise innaccessible through ssh. |
| 69 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame] | 70 | return self.controlling_hypervisor.reset_guest(self.hostname) |