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 | |
| 5 | """This module defines the Guest class in the Host hierarchy. |
| 6 | |
| 7 | Implementation details: |
| 8 | You 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__ = """mbligh@google.com (Martin J. Bligh), |
| 14 | poirier@google.com (Benjamin Poirier), |
| 15 | stutsman@google.com (Ryan Stutsman)""" |
| 16 | |
| 17 | |
| 18 | import ssh_host |
| 19 | |
| 20 | |
| 21 | class Guest(ssh_host.SSHHost): |
| 22 | """This class represents a virtual machine on which you can run |
| 23 | programs. |
| 24 | |
| 25 | It is not the machine autoserv is running on. |
| 26 | |
| 27 | Implementation details: |
| 28 | This is an abstract class, leaf subclasses must implement the methods |
| 29 | listed here and in parent classes which have no implementation. They |
| 30 | may reimplement methods which already have an implementation. You |
| 31 | must not instantiate this class but should instantiate one of those |
| 32 | leaf subclasses.""" |
| 33 | |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 34 | controlling_hypervisor = None |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 35 | |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 36 | def __init__(self, controlling_hypervisor): |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 37 | """Construct a Guest object |
| 38 | |
| 39 | Args: |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 40 | controlling_hypervisor: Hypervisor object that is |
| 41 | responsible for the creation and management of |
| 42 | this guest |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 43 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 44 | hostname= controlling_hypervisor.new_guest() |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 45 | super(Guest, self).__init__(hostname) |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 46 | self.controlling_hypervisor= controlling_hypervisor |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 47 | |
| 48 | def __del__(self): |
| 49 | """Destroy a Guest object |
| 50 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 51 | self.controlling_hypervisor.delete_guest(self.hostname) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 52 | |
| 53 | def hardreset(self): |
| 54 | """Perform a "hardreset" of the guest. |
| 55 | |
| 56 | It is restarted through the hypervisor. That will restart it |
| 57 | even if the guest otherwise innaccessible through ssh. |
| 58 | """ |
mbligh | 34169c2 | 2007-07-23 16:38:51 +0000 | [diff] [blame^] | 59 | return self.controlling_hypervisor.reset_guest(self.hostname) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 60 | |