blob: 812f673689fd848e77ca7f0903b354356659b6a8 [file] [log] [blame]
mblighdcd57a82007-07-11 23:06:47 +00001#!/usr/bin/python
2#
3# Copyright 2007 Google Inc. Released under the GPL v2
4
mbligh7d2bde82007-08-02 16:26:10 +00005"""
6This module defines the Guest class in the Host hierarchy.
mblighdcd57a82007-07-11 23:06:47 +00007
8Implementation details:
9You should import the "hosts" package instead of importing each type of host.
10
jadmanski0afbb632008-06-06 21:10:57 +000011 Guest: a virtual machine on which you can run programs
mblighdcd57a82007-07-11 23:06:47 +000012"""
13
mbligh7d2bde82007-08-02 16:26:10 +000014__author__ = """
15mbligh@google.com (Martin J. Bligh),
mblighdcd57a82007-07-11 23:06:47 +000016poirier@google.com (Benjamin Poirier),
mbligh7d2bde82007-08-02 16:26:10 +000017stutsman@google.com (Ryan Stutsman)
18"""
mblighdcd57a82007-07-11 23:06:47 +000019
20
jadmanski8d631c92008-08-18 21:12:40 +000021from autotest_lib.server.hosts import ssh_host
mblighdcd57a82007-07-11 23:06:47 +000022
23
24class Guest(ssh_host.SSHHost):
jadmanski0afbb632008-06-06 21:10:57 +000025 """
26 This class represents a virtual machine on which you can run
27 programs.
mbligh7d2bde82007-08-02 16:26:10 +000028
jadmanski0afbb632008-06-06 21:10:57 +000029 It is not the machine autoserv is running on.
mbligh7d2bde82007-08-02 16:26:10 +000030
jadmanski0afbb632008-06-06 21:10:57 +000031 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 """
mbligh7d2bde82007-08-02 16:26:10 +000038
jadmanski0afbb632008-06-06 21:10:57 +000039 controlling_hypervisor = None
40
41
jadmanski8d631c92008-08-18 21:12:40 +000042 def __init__(self, controlling_hypervisor, *args, **dargs):
jadmanski0afbb632008-06-06 21:10:57 +000043 """
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 """
jadmanski8d631c92008-08-18 21:12:40 +000051 hostname = controlling_hypervisor.new_guest()
52 super(Guest, self).__init__(hostname, *args, **dargs)
53 self.controlling_hypervisor = controlling_hypervisor
jadmanski0afbb632008-06-06 21:10:57 +000054
55
56 def __del__(self):
57 """
58 Destroy a Guest object
59 """
jadmanski8d631c92008-08-18 21:12:40 +000060 super(Guest, self).__del__()
jadmanski0afbb632008-06-06 21:10:57 +000061 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)