blob: 0d8270c7356f885c8295d603263d02db04b748f6 [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
11 Guest: a virtual machine on which you can run programs
12"""
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
21import ssh_host
22
23
24class Guest(ssh_host.SSHHost):
mbligh7d2bde82007-08-02 16:26:10 +000025 """
26 This class represents a virtual machine on which you can run
mblighdcd57a82007-07-11 23:06:47 +000027 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
mbligh7d2bde82007-08-02 16:26:10 +000036 leaf subclasses.
37 """
mblighdcd57a82007-07-11 23:06:47 +000038
mbligh34169c22007-07-23 16:38:51 +000039 controlling_hypervisor = None
mbligh7d2bde82007-08-02 16:26:10 +000040
mblighdcd57a82007-07-11 23:06:47 +000041
mbligh34169c22007-07-23 16:38:51 +000042 def __init__(self, controlling_hypervisor):
mbligh7d2bde82007-08-02 16:26:10 +000043 """
44 Construct a Guest object
mblighdcd57a82007-07-11 23:06:47 +000045
46 Args:
mbligh34169c22007-07-23 16:38:51 +000047 controlling_hypervisor: Hypervisor object that is
48 responsible for the creation and management of
49 this guest
mblighdcd57a82007-07-11 23:06:47 +000050 """
mbligh34169c22007-07-23 16:38:51 +000051 hostname= controlling_hypervisor.new_guest()
mblighdcd57a82007-07-11 23:06:47 +000052 super(Guest, self).__init__(hostname)
mbligh34169c22007-07-23 16:38:51 +000053 self.controlling_hypervisor= controlling_hypervisor
mbligh7d2bde82007-08-02 16:26:10 +000054
mblighdcd57a82007-07-11 23:06:47 +000055
56 def __del__(self):
mbligh7d2bde82007-08-02 16:26:10 +000057 """
58 Destroy a Guest object
mblighdcd57a82007-07-11 23:06:47 +000059 """
mbligh34169c22007-07-23 16:38:51 +000060 self.controlling_hypervisor.delete_guest(self.hostname)
mbligh7d2bde82007-08-02 16:26:10 +000061
mblighdcd57a82007-07-11 23:06:47 +000062
mbligh3409ee72007-10-16 23:58:33 +000063 def hardreset(self, timeout=600, wait=True):
mbligh7d2bde82007-08-02 16:26:10 +000064 """
65 Perform a "hardreset" of the guest.
mblighdcd57a82007-07-11 23:06:47 +000066
67 It is restarted through the hypervisor. That will restart it
68 even if the guest otherwise innaccessible through ssh.
69 """
mbligh34169c22007-07-23 16:38:51 +000070 return self.controlling_hypervisor.reset_guest(self.hostname)