/[gli]/trunk/src/GLIClientConfiguration.py
Gentoo

Contents of /trunk/src/GLIClientConfiguration.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (show annotations) (download) (as text)
Wed Jun 1 00:17:24 2005 UTC (13 years, 4 months ago) by agaffney
File MIME type: text/x-python
File size: 17451 byte(s)
Changed 'data' to 'self.data' in a few
  places in GLIClientConfiguration.

1 """
2 Gentoo Linux Installer
3
4 $Id: GLIClientConfiguration.py,v 1.30 2005/06/01 00:17:24 agaffney Exp $
5 Copyright 2004 Gentoo Technologies Inc.
6
7 The GLIClientConfiguration module contains the ClientConfiguration class
8 which is a singleton class that represents configuration data that is
9 used by the installer client during installation. Data that is part of
10 the actual install is contained in GLIInstallProfile.
11
12 Usage:
13 from GLIClientConfiguration import ClientConfiguration
14
15 PROCEDURE TO ADD NEW VARIABLES:
16 1. Add a handler to the list. If the variable has children make sure you do it right.
17 Look at the existing structure to get an idea.
18 2. Create a section for the two or three functions.
19 3. Create the get_variable_name and set_variable_name functions.
20 Ensure the set function has correct error checking.
21 4. If a simple value, add to the list in the general serialize() function.
22 If more complex add a serialize_variable_name to the list of special cases.
23 Then add the serialize_variable_name function to the section for the variable.
24 """
25
26 import string, re, GLIUtility, SimpleXMLParser
27 import xml.dom.minidom
28 from GLIException import *
29
30 class ClientConfiguration:
31
32 # SHARED_CLIENT_CONFIGURATION = None
33
34 # ##
35 # # FIXME: what does this do?
36 # # @param cls Parameter description
37 # def shared_client_configuration(cls):
38 # if GLIClientConfiguration.SHARED_CLIENT_CONFIGURATION == None:
39 # GLIClientConfiguration.SHARED_CLIENT_CONFIGURATION = cls()
40 #
41 # return GLIClientConfiguration.SHARED_CLIENT_CONFIGURATION
42 # ###############################################################
43 # #####################WHAT IS THIS DOING HERE????###############
44 # shared_client_configuration = classmethod(shared_client_configuration)
45 # ###############################################################
46
47 ##
48 # Initializes the ClientConfiguration.
49 def __init__(self):
50 self._architecture_template = None
51 self._profile_uri = ""
52
53 # This is the full path to the logfile
54 self._log_file = "/var/log/installer.log"
55
56 # This is the root mount point
57 self._root_mount_point = "/mnt/gentoo"
58
59 # Initialize some variables so we never reference a variable that never exists.
60 self._dns_servers = ()
61 self._network_type = None
62 self._network_interface = ""
63 self._network_ip = ""
64 self._network_broadcast = ""
65 self._network_netmask = ""
66 self._network_gateway = ""
67 self._enable_ssh = False
68 self._root_passwd = ""
69 self._interactive = True
70 self._kernel_modules = ()
71 self._ftp_proxy = ""
72 self._http_proxy = ""
73 self._rsync_proxy = ""
74 self._verbose = True
75 self.data = "" # used for serialization
76
77 _parser = SimpleXMLParser.SimpleXMLParser()
78
79 _parser.addHandler('client-configuration/architecture-template', self.set_architecture_template)
80 _parser.addHandler('client-configuration/dns-servers', self.set_dns_servers)
81 _parser.addHandler('client-configuration/enable-ssh', self.set_enable_ssh)
82 _parser.addHandler('client-configuration/ftp-proxy', self.set_ftp_proxy)
83 _parser.addHandler('client-configuration/http-proxy', self.set_http_proxy)
84 _parser.addHandler('client-configuration/interactive', self.set_interactive)
85 _parser.addHandler('client-configuration/kernel-modules', self.set_kernel_modules)
86 _parser.addHandler('client-configuration/log-file', self.set_log_file)
87 _parser.addHandler('client-configuration/network-interface', self.set_network_interface)
88 _parser.addHandler('client-configuration/network-ip', self.set_network_ip)
89 _parser.addHandler('client-configuration/network-broadcast', self.set_network_broadcast)
90 _parser.addHandler('client-configuration/network-netmask', self.set_network_netmask)
91 _parser.addHandler('client-configuration/network-gateway', self.set_network_gateway)
92 _parser.addHandler('client-configuration/network-type', self.set_network_type)
93 _parser.addHandler('client-configuration/profile-uri', self.set_profile_uri)
94 _parser.addHandler('client-configuration/root-mount-point', self.set_root_mount_point)
95 _parser.addHandler('client-configuration/root-passwd', self.set_root_passwd)
96 _parser.addHandler('client-configuration/rsync-proxy', self.set_rsync_proxy)
97
98 ##
99 # Parses the given filename populating the client_configuration.
100 # @param filename the file to be parsed. This should be a URI actually.
101 def parse(self, filename):
102 self._parser.parse(filename)
103
104 ##
105 # Serializes the Client Configuration into an XML format that is returned.
106 def serialize(self):
107 fntable ={ 'architecture-template': self.get_architecture_template,
108 'dns-servers': self.get_dns_servers,
109 'enable-ssh': self.get_enable_ssh,
110 'ftp-proxy': self.get_ftp_proxy,
111 'http-proxy': self.get_http_proxy,
112 'interactive': self.get_interactive,
113 'log-file': self.get_log_file,
114 'network-broadcast': self.get_network_broadcast,
115 'network-gateway': self.get_network_gateway,
116 'network-interface': self.get_network_interface,
117 'network-ip': self.get_network_ip,
118 'network-netmask': self.get_network_netmask,
119 'network-type': self.get_network_type,
120 'profile-uri': self.get_profile_uri,
121 'root-mount-point': self.get_root_mount_point,
122 'root-passwd': self.get_root_passwd,
123 'rsync-proxy': self.get_rsync_proxy,
124 }
125 self.data = "<client-configuration>"
126
127 for key in fntable.keys():
128 self.data += "<%s>%s</%s>" % (key, fntable[key](), key)
129
130 # Serialize the special cases.
131 self.serialize_kernel_modules()
132
133 #Finish by putting it all in nice XML.
134 dom = xml.dom.minidom.parseString(self.data)
135 return dom.toprettyxml()
136
137 ############################################################################
138 #### Architecture Template
139
140 ##
141 # Sets the architecture to be used for the install.
142 # @param xml_path not used here.
143 # @param architecture_template the architecture to be installed
144 # @param xml_attr not used here.
145 def set_architecture_template(self, xml_path, architecture_template, xml_attr):
146 self._architecture_template = architecture_template
147 # FIXME!!!! SHOULD CHECK IF A CORRECT ARCH HERE
148
149 ##
150 # Returns the architecture_template
151 def get_architecture_template(self):
152 return self._architecture_template
153
154 # This variable has a simple serialize function.
155
156 ############################################################################
157 #### DNS Servers List
158
159 ##
160 # Sets the dns servers
161 # @param xml_path not used here.
162 # @param nameservers space-separated list of nameservers
163 # @param xml_attr not used here.
164 def set_dns_servers(self, xml_path, nameservers, xml_attr):
165 if type(nameservers) == str:
166 nameservers = nameservers.split(" ")
167 dns = []
168 for server in nameservers:
169 dns.append(server)
170 self._dns_servers = tuple(dns)
171
172 ##
173 # Returns the list of dns servers
174 # @param self Parameter description
175 def get_dns_servers(self):
176 return self._dns_servers
177
178 # This variable has a simple serialize function.
179
180 ############################################################################
181 #### Enable SSH Decision for livecd environment
182
183 ##
184 # Choose whether or not to enable SSH.
185 # @param xml_path not used here.
186 # @param enable_ssh a True/False bool value here or a string
187 # @param xml_attr not used here.
188 def set_enable_ssh(self, xml_path, enable_ssh, xml_attr):
189 if type(enable_ssh) == str:
190 enable_ssh = GLIUtility.strtobool(enable_ssh)
191 self._enable_ssh = enable_ssh
192
193 ##
194 # Returns the choice of whether or not to enable SSH (True/False)
195 # @param self Parameter description
196 def get_enable_ssh(self):
197 return self._enable_ssh
198
199 # This variable has a simple serialize function.
200
201 ############################################################################
202 #### FTP Proxy Address Information for livecd environment
203
204 ##
205 # Sets the FTP proxy URI
206 # @param xml_path not used here.
207 # @param proxy a URI
208 # @param xml_attr not used here.
209 def set_ftp_proxy(self, xml_path, proxy, xml_attr):
210 self._ftp_proxy = proxy
211
212 ##
213 # Returns the FTP proxy.
214 # @param self Parameter description
215 def get_ftp_proxy(self):
216 return self._ftp_proxy
217
218 # This variable has a simple serialize function.
219
220 ############################################################################
221 #### HTTP Proxy Address Information for livecd environment
222
223 ##
224 # Sets the HTTP proxy URI
225 # @param xml_path not used here.
226 # @param proxy a URI
227 # @param xml_attr not used here.
228 def set_http_proxy(self, xml_path, proxy, xml_attr):
229 self._http_proxy = proxy
230
231 ##
232 # Returns the HTTP proxy
233 def get_http_proxy(self):
234 return self._http_proxy
235
236 # This variable has a simple serialize function.
237
238 ############################################################################
239 #### Interactive Install
240
241 ##
242 # Sets whether or not to be an interactive install. (boolean)
243 # @param xml_path not used here.
244 # @param interactive True/False bool value or a string.
245 # @param xml_attr not used here.
246 def set_interactive(self, xml_path, interactive, xml_attr):
247 if type(interactive) != bool:
248 interactive = GLIUtility.strtobool(interactive)
249 self._interactive = interactive
250
251 ##
252 # Returns bool value on interactive install choice.
253 # @param self Parameter description
254 def get_interactive(self):
255 return self._interactive
256
257 # This variable has a simple serialize function.
258
259 ############################################################################
260 #### Set Kernel Modules to be loaded for the livecd environment
261
262 ##
263 # Sets a list of modules to load on the livecd environment.
264 # @param xml_path not used here.
265 # @param modules string of modules
266 # @param xml_attr not used here.
267 def set_kernel_modules(self, xml_path, modules, xml_attr):
268 self._kernel_modules = tuple(string.split(modules))
269
270 ##
271 # Returns the list of kernel modules to load on the livecd environment.
272 def get_kernel_modules(self):
273 return self._kernel_modules
274
275 ##
276 # Serialization for the kernel module list. joins together the modules.
277 def serialize_kernel_modules(self):
278 # Special Case the kernel modules
279 self.data += "<kernel-modules>%s</kernel-modules>" % string.join(self.get_kernel_modules())
280 self.data += "</client-configuration>"
281
282 ############################################################################
283 #### Log File Location
284
285 ##
286 # Sets the log filename.
287 # @param xml_path not used here.
288 # @param log_file the name of the logfile for the CC to use.
289 # @param xml_attr not used here.
290 def set_log_file(self, xml_path, log_file, xml_attr):
291 self._log_file = log_file
292
293 ##
294 # Returns the log filename
295 def get_log_file(self):
296 return self._log_file
297
298 # This variable has a simple serialize function.
299
300 ############################################################################
301 #### Network Broadcast Address for livecd environment
302
303 ##
304 # Sets the network broadcast address for the livecd environment
305 # @param xml_path not used here.
306 # @param broadcast the network broadcast address
307 # @param xml_attr= None
308 def set_network_broadcast(self, xml_path, broadcast, xml_attr=None):
309 if not GLIUtility.is_ip(broadcast):
310 raise GLIException("IPAddressError", 'fatal','set_network_broadcast', 'The specified broadcast is not a valid IP Address!')
311 else:
312 # FIXME: Need to guess the broadcast... just in case (probably need the gateway..)
313 pass
314 self._network_broadcast = broadcast
315
316 ##
317 # Returns the network broadcast address
318 def get_network_broadcast(self):
319 return self._network_broadcast
320
321 # This variable has a simple serialize function.
322
323 ############################################################################
324 #### Network Gateway Address for livecd environment
325
326 ##
327 # Sets the network gateway for the livecd environment
328 # @param xml_path not used here.
329 # @param gateway the network gateway
330 # @param xml_attr= None
331 def set_network_gateway(self, xml_path, gateway, xml_attr=None):
332 if not GLIUtility.is_ip(gateway):
333 raise GLIException("IPAddressError", 'fatal', 'set_network_gateway', "The gateway IP provided is not a valid gateway!!")
334 self._network_gateway = gateway
335
336 ##
337 # Returns the network gateway
338 def get_network_gateway(self):
339 return self._network_gateway
340
341 # This variable has a simple serialize function.
342
343 ############################################################################
344 #### Network Interface Information for livecd environment
345
346 ##
347 # Sets the network interface configuration info for the livecd environment
348 # @param xml_path not used here.
349 # @param interface the interface to talk over
350 # @param xml_attr= None
351 def set_network_interface(self, xml_path, interface, xml_attr=None):
352 if not GLIUtility.is_eth_device(interface):
353 raise GLIException("InterfaceError", 'fatal', 'set_network_interface', "Interface " + interface + " must be a valid device!")
354 self._network_interface = interface
355
356 ##
357 # Returns the network interface
358 def get_network_interface(self):
359 return self._network_interface
360
361 # This variable has a simple serialize function.
362
363 ############################################################################
364 #### Network IP Address for livecd environment
365
366 ##
367 # Sets the network ip address for the livecd environment
368 # @param xml_path not used here.
369 # @param ip the ip address
370 # @param xml_attr= None
371 def set_network_ip(self, xml_path, ip, xml_attr=None):
372 if not GLIUtility.is_ip(ip):
373 raise GLIException("IPAddressError", 'fatal', 'set_network_ip', 'The specified IP ' + ip + ' is not a valid IP Address!')
374 self._network_ip = ip
375
376 ##
377 # Returns the network ip address
378 def get_network_ip(self):
379 return self._network_ip
380
381 # This variable has a simple serialize function.
382
383 ############################################################################
384 #### Network Netmask Address for livecd environment
385
386 ##
387 # Sets the network netmask for the livecd environment
388 # @param xml_path not used here.
389 # @param netmask the network netmask
390 # @param xml_attr= None
391 def set_network_netmask(self, xml_path, netmask, xml_attr=None):
392 if not GLIUtility.is_ip(netmask):
393 raise GLIException("IPAddressError", 'fatal','set_network_netmask', 'The specified netmask is not a valid IP Address!')
394 else:
395 # Need to guess the netmask... just in case (probably need the gateway..)
396 pass
397
398 self._network_netmask = netmask
399
400 ##
401 # Returns the network netmask
402 def get_network_netmask(self):
403 return self._network_netmask
404
405 # This variable has a simple serialize function.
406
407
408 ############################################################################
409 #### Network Type Information for livecd environment (static or dhcp)
410
411 ##
412 # Sets the network configuration info for the livecd environment
413 # @param xml_path not used here.
414 # @param network_type the network type, either static or dhcp
415 # @param xml_attr=None
416 def set_network_type(self, xml_path, network_type, xml_attr):
417
418 if not (network_type == 'static' or network_type == 'dhcp'):
419 raise GLIException("NoSuchTypeError", 'fatal','set_network_type',"You can only have a static or dhcp network!")
420
421 self._network_type = network_type
422
423 ##
424 # Returns the network type
425 def get_network_type(self):
426 return self._network_type
427
428 # This variable has a simple serialize function.
429
430 ############################################################################
431 #### Install Profile URI
432
433 ##
434 # Sets the profile_uri for use in non-interactive installs
435 # @param xml_path not used here.
436 # @param profile_uri location of the profile
437 # @param xml_attr not used here.
438 def set_profile_uri(self, xml_path, profile_uri, xml_attr):
439 if profile_uri != None and not GLIUtility.is_uri(profile_uri):
440 raise GLIException("URIError", 'fatal', 'set_profile_uri',"The URI specified is not valid!")
441 self._profile_uri = profile_uri
442
443 ##
444 # Returns the profile_uri
445 def get_profile_uri(self):
446 return self._profile_uri
447
448 # This variable has a simple serialize function.
449
450 ############################################################################
451 #### Root Mount Point For New System
452
453 ##
454 # Sets the root_mount_point for the new system to be installed to
455 # @param xml_path not used here.
456 # @param root_mount_point new location for the root mount point
457 # @param xml_attr not used here.
458 def set_root_mount_point(self, xml_path, root_mount_point, xml_attr):
459 self._root_mount_point = root_mount_point
460
461 ##
462 # Returns the root_mount_point
463 def get_root_mount_point(self):
464 return self._root_mount_point
465
466 # This variable has a simple serialize function.
467
468 ############################################################################
469 #### Root Password Selection for livecd environment
470
471 ##
472 # Sets the root password on the livecd. This is supposed to be given a hash.
473 # @param xml_path not used here.
474 # @param passwd a hashed password to be set on the livecd environment.
475 # @param xml_attr not used here.
476 def set_root_passwd(self, xml_path, passwd, xml_attr):
477 self._root_passwd = passwd
478
479 ##
480 # Returns the hash of the root password for the livecd environment
481 def get_root_passwd(self):
482 return self._root_passwd
483
484 # This variable has a simple serialize function.
485
486 ############################################################################
487 #### RSYNC Proxy Address Information for livecd environment
488
489 ##
490 # Sets the RSYNC proxy URI
491 # @param xml_path not used here.
492 # @param proxy a URI
493 # @param xml_attr not used here.
494 def set_rsync_proxy(self, xml_path, proxy, xml_attr):
495 self._rsync_proxy = proxy
496
497 ##
498 # Returns the RSYNC proxy
499 def get_rsync_proxy(self):
500 return self._rsync_proxy

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20