9d742b5d18b643083c7dc9ea8c362749149df210
[bootmanager.git] / source / steps / InstallUninitHardware.py
1 #!/usr/bin/python
2 #
3 # $Id$
4 # $URL$
5 #
6 # Copyright (c) 2003 Intel Corporation
7 # All rights reserved.
8 #
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
11 # expected /proc/partitions format
12
13 import os
14
15 from Exceptions import *
16 import utils
17
18
19
20 def Run( vars, log ):
21     """
22     Unitializes hardware:
23     - unmount everything mounted during install, except the
24     /dev/planetlab/root and /dev/planetlab/vservers. This includes
25     calling swapoff for /dev/planetlab/swap.
26
27     Except the following variables from the store:
28     TEMP_PATH         the path to download and store temp files to
29     SYSIMG_PATH       the path where the system image will be mounted
30                       (always starts with TEMP_PATH)
31     PARTITIONS        dictionary of generic part. types (root/swap)
32                       and their associated devices.
33
34     Sets the following variables:
35     None
36     
37     """
38
39     log.write( "\n\nStep: Install: Shutting down installer.\n" )
40
41     # make sure we have the variables we need
42     try:
43         TEMP_PATH= vars["TEMP_PATH"]
44         if TEMP_PATH == "":
45             raise ValueError, "TEMP_PATH"
46
47         SYSIMG_PATH= vars["SYSIMG_PATH"]
48         if SYSIMG_PATH == "":
49             raise ValueError, "SYSIMG_PATH"
50
51         PARTITIONS= vars["PARTITIONS"]
52         if PARTITIONS == None:
53             raise ValueError, "PARTITIONS"
54
55     except KeyError, var:
56         raise BootManagerException, "Missing variable in vars: %s\n" % var
57     except ValueError, var:
58         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
59
60
61     try:
62         # make sure the required partitions exist
63         val= PARTITIONS["root"]
64         val= PARTITIONS["swap"]
65         val= PARTITIONS["vservers"]
66     except KeyError, part:
67         raise BootManagerException, "Missing partition in PARTITIONS: %s\n" % part
68
69     try:
70         # backwards compat, though, we should never hit this case post PL 3.2
71         os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
72         utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
73     except OSError, e:
74         pass
75             
76     log.write( "Shutting down swap\n" )
77     utils.sysexec( "swapoff %s" % PARTITIONS["swap"], log )
78
79     return 1