Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 166 lines (146 sloc) 5.383 kb
6949598 Use /usr/bin/env python instead of /usr/bin/python
Chris Lalancette authored
1 #!/usr/bin/env python
4df1f62 Initial commit.
Chris Lalancette authored
2
a01f2b9 Do some import cleanup, along with copyright fixes.
Chris Lalancette authored
3 # Copyright (C) 2010,2011 Chris Lalancette <clalance@redhat.com>
f039d66 Make sure we have proper copyright on every file.
Chris Lalancette authored
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
a01f2b9 Do some import cleanup, along with copyright fixes.
Chris Lalancette authored
24 import ConfigParser
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
25
4d3545c Rename IDL to TDL.
Chris Lalancette authored
26 import oz.TDL
976f2ce Use a factory to select among the guest OSs.
Chris Lalancette authored
27 import oz.GuestFactory
4df1f62 Initial commit.
Chris Lalancette authored
28
29 def usage():
976f2ce Use a factory to select among the guest OSs.
Chris Lalancette authored
30 print "Usage: oz-install [OPTIONS] <tdl>"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
31 print " OPTIONS:"
cdb5741 Allow custom kickstarts/autoattend.
Chris Lalancette authored
32 print " -a <auto>\tUse the guest configuration tool from <auto> instead"
33 print "\t\tof using the hard-coded one. This is useful if you want to pass"
34 print "\t\ta custom kickstart for installation"
6c223c2 Update the oz-install help output.
Chris Lalancette authored
35 print " -c <config>\tGet config from <config> (default is /etc/oz/oz.cfg)"
c7b11e1 @sdake Add -x option to write libxml file data to a specified file
sdake authored
36 print " -x <xmlfile>\tWrite libvirt XML to the specified file"
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
37 print " -d <level>\tTurn up logging level. The levels are:"
38 print "\t\t\t0 - errors only (this is the default)"
39 print "\t\t\t1 - errors and warnings"
40 print "\t\t\t2 - errors, warnings, and information"
41 print "\t\t\t3 - all messages"
42 print "\t\t\t4 - all messages, prepended with the level and classname"
976f2ce Use a factory to select among the guest OSs.
Chris Lalancette authored
43 print " -f\t\tForce download of installation media even if already cached"
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
44 print " -g\t\tGenerate the ICICLE after installation"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
45 print " -h\t\tPrint this help message"
73b6e14 Add a new oz-install option -p.
Chris Lalancette authored
46 print " -p\t\tCleanup old guests with the same name before installation"
aa20c6a Add user-configurable timeout.
Chris Lalancette authored
47 print " -t <timeout>\tUse a timeout of <timeout> for installation, rather than the default"
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
48 print " -u\t\tAfter installation, do the customization"
4df1f62 Initial commit.
Chris Lalancette authored
49 print " Currently supported architectures are:"
d45b71c Updates for RHL 6.X series.
Chris Lalancette authored
50 print " i386, x86_64"
4df1f62 Initial commit.
Chris Lalancette authored
51 print " Currently supported distros are:"
976f2ce Use a factory to select among the guest OSs.
Chris Lalancette authored
52 oz.GuestFactory.distrolist()
4df1f62 Initial commit.
Chris Lalancette authored
53 sys.exit(1)
54
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
55 try:
92370be Sort the oz-install command-line parsing.
Chris Lalancette authored
56 opts, args = getopt.gnu_getopt(sys.argv[1:], 'a:c:d:fghpt:ux:',
57 ['auto', 'config', 'debug', 'force-download',
73b6e14 Add a new oz-install option -p.
Chris Lalancette authored
58 'generate-icicle', 'help', 'cleanup',
92370be Sort the oz-install command-line parsing.
Chris Lalancette authored
59 'timeout', 'customize', 'xmlfile'])
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
60 except getopt.GetoptError, err:
61 print str(err)
62 usage()
63
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
64 loglevel = logging.ERROR
65 logformat = "%(message)s"
5568e88 Fixes for the config file feature.
Chris Lalancette authored
66 force_download = False
67 config_file = "/etc/oz/oz.cfg"
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
68 generate_icicle = False
c7b11e1 @sdake Add -x option to write libxml file data to a specified file
sdake authored
69 filename = None
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
70 customize = False
73b6e14 Add a new oz-install option -p.
Chris Lalancette authored
71 cleanup = False
cdb5741 Allow custom kickstarts/autoattend.
Chris Lalancette authored
72 auto = None
aa20c6a Add user-configurable timeout.
Chris Lalancette authored
73 timeout = None
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
74 for o, a in opts:
cdb5741 Allow custom kickstarts/autoattend.
Chris Lalancette authored
75 if o in ("-a", "--auto"):
76 auto = a
77 elif o in ("-c", "--config"):
73b6e14 Add a new oz-install option -p.
Chris Lalancette authored
78 config_file = a
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
79 elif o in ("-d", "--debug"):
349d575 Fix up the -d parsing.
Chris Lalancette authored
80 try:
81 d_int = int(a)
82 except ValueError:
83 usage()
84 if d_int == 0:
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
85 loglevel = logging.ERROR
349d575 Fix up the -d parsing.
Chris Lalancette authored
86 elif d_int == 1:
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
87 loglevel = logging.WARNING
349d575 Fix up the -d parsing.
Chris Lalancette authored
88 elif d_int == 2:
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
89 loglevel = logging.INFO
349d575 Fix up the -d parsing.
Chris Lalancette authored
90 elif d_int == 3:
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
91 loglevel = logging.DEBUG
349d575 Fix up the -d parsing.
Chris Lalancette authored
92 elif d_int >= 4:
9f15d74 Add in logging infrastructure.
Chris Lalancette authored
93 loglevel = logging.DEBUG
94 logformat = logging.BASIC_FORMAT
f41b1e3 Add an option to force the download of ISOs.
Chris Lalancette authored
95 elif o in ("-f", "--force-download"):
96 force_download = True
b829c70 Rename CDL to ICICLE all throughout the codebase.
Chris Lalancette authored
97 elif o in ("-g", "--generate-icicle"):
98 generate_icicle = True
73b6e14 Add a new oz-install option -p.
Chris Lalancette authored
99 elif o in ("-h", "--help"):
100 usage()
101 elif o in ("-p", "--cleanup"):
102 cleanup = True
aa20c6a Add user-configurable timeout.
Chris Lalancette authored
103 elif o in ("-t", "--timeout"):
104 timeout = int(a)
ef6c505 Add in a customize step to oz-install.
Chris Lalancette authored
105 elif o in ("-u", "--customize"):
106 customize = True
92370be Sort the oz-install command-line parsing.
Chris Lalancette authored
107 elif o in ("-x", "--xmlfile"):
108 filename = a
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
109 else:
90d519c Do some basic sanity checking on the URLs.
Chris Lalancette authored
110 assert False, "unhandled option"
bce7782 Add in Windows 2003 support.
Chris Lalancette authored
111
112 if os.geteuid() != 0:
113 print "%s must be run as root" % (sys.argv[0])
114 sys.exit(2)
115
2821a6c Make oz use IDL.
Chris Lalancette authored
116 if len(args) != 1:
1f0323a Some minor bugfixes.
Chris Lalancette authored
117 usage()
4df1f62 Initial commit.
Chris Lalancette authored
118
24d2fde Nicer error messages in oz-install, oz-customize, etc.
Chris Lalancette authored
119 try:
120 logging.basicConfig(level=loglevel, format=logformat)
121
122 tdl = oz.TDL.TDL(open(args[0], 'r').read())
123
124 config = ConfigParser.SafeConfigParser()
125 if os.access(config_file, os.F_OK):
126 config.read(config_file)
127
128 guest = oz.GuestFactory.guest_factory(tdl, config, auto)
129
130 if cleanup:
131 guest.cleanup_old_guest()
132 else:
133 guest.check_for_guest_conflict()
134
4e48d60 Make jeos caching invisible to the API user.
Chris Lalancette authored
135 try:
7d57014 Make sure to cleanup if generate_install_media fails somewhere.
Chris Lalancette authored
136 guest.generate_install_media(force_download)
24d2fde Nicer error messages in oz-install, oz-customize, etc.
Chris Lalancette authored
137 try:
4e48d60 Make jeos caching invisible to the API user.
Chris Lalancette authored
138 guest.generate_diskimage(force=force_download)
139 libvirt_xml = guest.install(timeout, force_download)
140 except:
141 guest.cleanup_old_guest()
142 raise
143 finally:
6fa6086 Remove a rogue semicolon from oz-install.
Chris Lalancette authored
144 guest.cleanup_install()
24d2fde Nicer error messages in oz-install, oz-customize, etc.
Chris Lalancette authored
145
146 if customize and generate_icicle:
147 print guest.customize_and_generate_icicle(libvirt_xml)
148 elif customize:
149 guest.customize(libvirt_xml)
150 elif generate_icicle:
151 print guest.generate_icicle(libvirt_xml)
152
c7b11e1 @sdake Add -x option to write libxml file data to a specified file
sdake authored
153 if filename is None:
154 filename = guest.name + time.strftime("%b_%d_%Y-%H:%M:%S")
24d2fde Nicer error messages in oz-install, oz-customize, etc.
Chris Lalancette authored
155 open(filename, 'w').write(libvirt_xml)
156 print "Libvirt XML was written to " + filename
bb02833 Fixes for compatibility with Python 2.4.
Chris Lalancette authored
157 except Exception, exc:
24d2fde Nicer error messages in oz-install, oz-customize, etc.
Chris Lalancette authored
158 if loglevel > logging.DEBUG:
159 print ""
160 print "ERROR: %s" % (str(exc))
161 print ""
162 print "(use -d3 to get the full backtrace)"
163 print ""
164 else:
165 raise
Something went wrong with that request. Please try again.