Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 170 lines (150 sloc) 5.39 kb
4df1f62 Initial commit.
Chris Lalancette authored
1 #!/usr/bin/python
2
f039d66 Make sure we have proper copyright on every file.
Chris Lalancette authored
3 # Copyright (C) 2010 Chris Lalancette <clalance@redhat.com>
4
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation;
8 # version 2.1 of the License.
9
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
4df1f62 Initial commit.
Chris Lalancette authored
19 import sys
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
20 import getopt
21 import os
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
22 import logging
8559fe2 Print the libvirt XML to a file instead of the screen.
Chris Lalancette authored
23 import time
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
24
4d3545c Rename IDL to TDL.
Chris Lalancette authored
25 import oz.TDL
f6a2ab4 Make a proper python RPM out of oz.
Chris Lalancette authored
26 import oz.Fedora
27 import oz.FedoraCore
28 import oz.RHEL_2_1
29 import oz.RHEL_3
30 import oz.RHEL_4
31 import oz.RHEL_5
e519c7a RHEL-6 support.
Chris Lalancette authored
32 import oz.RHEL_6
f6a2ab4 Make a proper python RPM out of oz.
Chris Lalancette authored
33 import oz.RHL
34 import oz.Ubuntu
35 import oz.Windows
bb100be Add OpenSUSE 11.3 as an install option.
Chris Lalancette authored
36 import oz.OpenSUSE
1b93acc Allow the user to configure where the output goes.
Chris Lalancette authored
37 import ConfigParser
4df1f62 Initial commit.
Chris Lalancette authored
38
39 def usage():
4d3545c Rename IDL to TDL.
Chris Lalancette authored
40 print "Usage: ozinstall [OPTIONS] <tdl>"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
41 print " OPTIONS:"
6c223c2 Update the oz-install help output.
Chris Lalancette authored
42 print " -c <config>\tGet config from <config> (default is /etc/oz/oz.cfg)"
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
43 print " -d <level>\tTurn up logging level. The levels are:"
44 print "\t\t\t0 - errors only (this is the default)"
45 print "\t\t\t1 - errors and warnings"
46 print "\t\t\t2 - errors, warnings, and information"
47 print "\t\t\t3 - all messages"
48 print "\t\t\t4 - all messages, prepended with the level and classname"
6c223c2 Update the oz-install help output.
Chris Lalancette authored
49 print " -f\t\tForce download of the installation media even if it is already cached"
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
50 print " -g\t\tGenerate the ICICLE after installation"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
51 print " -h\t\tPrint this help message"
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
52 print " -u\t\tAfter installation, do the customization"
4df1f62 Initial commit.
Chris Lalancette authored
53 print " Currently supported architectures are:"
d45b71c Updates for RHL 6.X series.
Chris Lalancette authored
54 print " i386, x86_64"
4df1f62 Initial commit.
Chris Lalancette authored
55 print " Currently supported distros are:"
02d48e0 Add support for Fedora 14.
Chris Lalancette authored
56 print " Fedora: 7, 8, 9, 10, 11, 12, 13, 14"
4df1f62 Initial commit.
Chris Lalancette authored
57 print " Fedora Core: 1, 2, 3, 4, 5, 6"
139efed Fix a few bugs in the RHEL-2.1 installation.
Chris Lalancette authored
58 print " RHEL 2.1: GOLD, U2, U3, U4, U5, U6"
4df1f62 Initial commit.
Chris Lalancette authored
59 print " RHEL 3: GOLD, U1, U2, U3, U4, U5, U6, U7, U8, U9"
60 print " RHEL 4: GOLD, U1, U2, U3, U4, U5, U6, U7, U8"
e6c00cb Add support for RHEL-5 U6.
Chris Lalancette authored
61 print " RHEL 5: GOLD, U1, U2, U3, U4, U5, U6"
e519c7a RHEL-6 support.
Chris Lalancette authored
62 print " RHEL 6: 0"
791e1c6 Add support for Ubuntu 9.10
Chris Lalancette authored
63 print " Ubuntu: 6.10, 7.04, 7.10, 8.04.[1,2,3,4], 8.10, 9.04, 9.10"
fda61f6 Add Windows 2000 support.
Chris Lalancette authored
64 print " Windows: 2000, XP, 2003"
bf31db8 Add support for RHL 8, 7.3, 7.2, 7.1, 7.0, 6.2, 6.3
Chris Lalancette authored
65 print " RHL: 7.0, 7.1, 7.2, 7.3, 8, 9"
0af9600 Add support for OpenSUSE 11.1.
Chris Lalancette authored
66 print " OpenSUSE: 11.1, 11.2, 11.3"
4df1f62 Initial commit.
Chris Lalancette authored
67 sys.exit(1)
68
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
69 try:
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
70 opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:d:fghu', ['config', 'debug', 'force-download', 'generate-icicle', 'help', 'customize'])
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
71 except getopt.GetoptError, err:
72 print str(err)
73 usage()
74
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
75 loglevel = logging.ERROR
76 logformat = "%(message)s"
5568e88 Fixes for the config file feature.
Chris Lalancette authored
77 force_download = False
78 config_file = "/etc/oz/oz.cfg"
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
79 generate_icicle = False
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
80 customize = False
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
81 for o, a in opts:
82 if o in ("-h", "--help"):
83 usage()
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
84 elif o in ("-d", "--debug"):
85 if int(a) == 0:
86 loglevel = logging.ERROR
87 elif int(a) == 1:
88 loglevel = logging.WARNING
89 elif int(a) == 2:
90 loglevel = logging.INFO
91 elif int(a) == 3:
92 loglevel = logging.DEBUG
93 elif int(a) >= 4:
94 loglevel = logging.DEBUG
95 logformat = logging.BASIC_FORMAT
96 else:
97 usage()
f41b1e3 Add an option to force the download of ISOs.
Chris Lalancette authored
98 elif o in ("-f", "--force-download"):
99 force_download = True
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
100 elif o in ("-g", "--generate-icicle"):
101 generate_icicle = True
5568e88 Fixes for the config file feature.
Chris Lalancette authored
102 elif o in ("-c", "--config"):
103 config_file = a
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
104 elif o in ("-u", "--customize"):
105 customize = True
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
106 else:
90d519c Do some basic sanity checking on the URLs.
Chris Lalancette authored
107 assert False, "unhandled option"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
108
109 if os.geteuid() != 0:
110 print "%s must be run as root" % (sys.argv[0])
111 sys.exit(2)
112
2821a6c Make oz use IDL.
Chris Lalancette authored
113 if len(args) != 1:
1f0323a Some minor bugfixes.
Chris Lalancette authored
114 usage()
4df1f62 Initial commit.
Chris Lalancette authored
115
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
116 logging.basicConfig(level=loglevel, format=logformat)
117
3bdb449 Make the TDL __init__ function take the xmlstring in.
Chris Lalancette authored
118 tdl = oz.TDL.TDL(open(args[0], 'r').read())
4df1f62 Initial commit.
Chris Lalancette authored
119
1b93acc Allow the user to configure where the output goes.
Chris Lalancette authored
120 config = ConfigParser.SafeConfigParser()
5568e88 Fixes for the config file feature.
Chris Lalancette authored
121 if os.access(config_file, os.F_OK):
122 config.read(config_file)
1b93acc Allow the user to configure where the output goes.
Chris Lalancette authored
123
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
124 if tdl.distro == "Fedora":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
125 guest = oz.Fedora.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
126 elif tdl.distro == "FedoraCore":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
127 guest = oz.FedoraCore.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
128 elif tdl.distro == "RHEL-2.1":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
129 guest = oz.RHEL_2_1.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
130 elif tdl.distro == "RHEL-3":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
131 guest = oz.RHEL_3.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
132 elif tdl.distro == "RHEL-4":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
133 guest = oz.RHEL_4.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
134 elif tdl.distro == "RHEL-5":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
135 guest = oz.RHEL_5.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
136 elif tdl.distro == "RHEL-6":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
137 guest = oz.RHEL_6.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
138 elif tdl.distro == "Ubuntu":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
139 guest = oz.Ubuntu.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
140 elif tdl.distro == "Windows":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
141 guest = oz.Windows.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
142 elif tdl.distro == "RHL":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
143 guest = oz.RHL.get_class(tdl, config)
c8fa25c Remove the useless TDL indirection from _var -> var()
Chris Lalancette authored
144 elif tdl.distro == "OpenSUSE":
4d3545c Rename IDL to TDL.
Chris Lalancette authored
145 guest = oz.OpenSUSE.get_class(tdl, config)
4df1f62 Initial commit.
Chris Lalancette authored
146 else:
147 usage()
148
149 guest.cleanup_old_guest()
f41b1e3 Add an option to force the download of ISOs.
Chris Lalancette authored
150 guest.generate_install_media(force_download)
cbb1d40 Make sure to cleanup after ourselves, even during failure.
Chris Lalancette authored
151 try:
152 guest.generate_diskimage()
153 try:
74b84e5 Allow ozinstall to do CDL generation.
Chris Lalancette authored
154 libvirt_xml = guest.install()
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
155
156 if customize:
157 guest.customize(libvirt_xml)
158
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
159 if generate_icicle:
160 print guest.generate_icicle(libvirt_xml)
161
8559fe2 Print the libvirt XML to a file instead of the screen.
Chris Lalancette authored
162 filename = guest.name + time.strftime("%b_%d_%Y-%H:%M:%S")
163 open(filename, 'w').write(libvirt_xml)
164 print "Libvirt XML was written to " + filename
d5478d0 Better exception reporting in ozinstall.
Chris Lalancette authored
165 except:
cbb1d40 Make sure to cleanup after ourselves, even during failure.
Chris Lalancette authored
166 guest.cleanup_old_guest()
d5478d0 Better exception reporting in ozinstall.
Chris Lalancette authored
167 raise
cbb1d40 Make sure to cleanup after ourselves, even during failure.
Chris Lalancette authored
168 finally:
169 guest.cleanup_install()
Something went wrong with that request. Please try again.