def perform_full_import(self, dirname): self.set_main_path(dirname) dbdata = self.parse_main_xml() self.start_schema() self.import_apt_sources(dbdata.aptsources) self.report_total_suites(len(dbdata.suites)) for suite in dbdata.suites: self.make_suite(suite) suitedir = self.main_path / suite.name self._import_traits(suite.name, dbdata.get_traits(suite.name), suitedir) self.report_suite_imported(suite.name) self.import_all_families() self.import_all_profiles() self.import_all_diskconfigs() machinedb = self.main_path / 'machine_database.xml' if machinedb.isfile(): mh = MachineHandler(self.conn) mh.import_machine_database(self.main_path) default_environment_basename = 'default-environment' filename = self.main_path / default_environment_basename if filename.isfile(): # similar code exists in kde/environ.py defenv = DefaultEnvironment(self.conn) newcfg = RawConfigParser() newcfg.read(filename) defenv.update(newcfg) self.import_all_aptkeys()
def perform_full_import(self, dirname): self.set_main_path(dirname) dbdata = self.parse_main_xml() self.start_schema() self.import_apt_sources(dbdata.aptsources) self.report_total_suites(len(dbdata.suites)) for suite in dbdata.suites: self.make_suite(suite) suitedir = self.main_path / suite.name self._import_traits(suite.name, dbdata.get_traits(suite.name), suitedir) self.report_suite_imported(suite.name) self.import_all_families() self.import_all_profiles() self.import_all_diskconfigs() machinedb = self.main_path / 'machine_database.xml' if machinedb.isfile(): mh = MachineHandler(self.conn) mh.import_machine_database(self.main_path) default_environment_basename = 'default-environment' filename = self.main_path / default_environment_basename if filename.isfile(): # similar code exists in kde/environ.py defenv = DefaultEnvironment(self.conn) newcfg = RawConfigParser() newcfg.read(filename) defenv.update(newcfg)
def __init__(self, conn): object.__init__(self) self.conn = conn self.target = None self.defenv = DefaultEnvironment(self.conn) #check for default environment rows = self.defenv.cursor.select() if not len(rows): raise InstallSetupError, 'There is no data in the default_environment table'
def __init__(self, conn): CommandBoxWindow.__init__(self) self.conn = conn self.defenv = DefaultEnvironment(self.conn) self.add_menu(['load', 'edit', 'save'], 'main', self.main_menu_selected) self.cursor = StatementCursor(self.conn) self.cursor.set_table('default_environment') self.view = ScrollCList() self.vbox.add(self.view) self.reset_rows()
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list( self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) #self.installer = TraitInstaller(self.conn, self.suite) self.installer = ProfileInstaller(self.conn) self.installer.set_logfile() self.installer.set_profile(self.profile) self.installer.set_target(self.target) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = path(os.environ['PAELLA_TARGET']) self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.db = ToolkitDatabase(self.conn) self.db.set_profile(self.profile) self.traits = self.db.profile.make_traitlist() profile_families = self.db.profile.get_families() self.families = list( self.db.family.get_related_families(profile_families)) self.default = DefaultEnvironment(self.conn) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] self.db.set_machine(self.machine) # we need to make an installer to do # some of the installer functions. self.installer = None if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
def __init__(self, conn, cfg): object.__init__(self) self.conn = conn self.cfg = cfg self.defenv = DefaultEnvironment(self.conn) self.machine = MachineHandler(self.conn) self.cursor = StatementCursor(self.conn) self.target = None self.installer = None self._mounted = None self._bootstrapped = None self.debmirror = self.cfg.get('debrepos', 'http_mirror') self._raid_setup = False self._raid_drives = {} self._enable_bad_hacks = False if self.cfg.is_it_true('installer', 'enable_bad_hacks'): self._enable_bad_hacks = True
def make_sources_list_common(conn, target, suite, installer=False): defenv = DefaultEnvironment(conn) suitecursor = SuiteCursor(conn) apt_rows = suitecursor.get_apt_rows(suite) if installer: # while installing use sources from local mirror uri = defenv.get('installer', 'http_mirror') else: # otherwise use official sources list uri = None apt_lines = make_sources_list_lines(apt_rows, uri=uri, installer=installer) aptdir = os.path.join(target, 'etc', 'apt') makepaths(aptdir) sources_list = file(os.path.join(aptdir, 'sources.list'), 'w') for line in apt_lines: sources_list.write('%s\n' % line) sources_list.write('\n') sources_list.close()
class DefEnvEditor(CommandBoxWindow): def __init__(self, conn): CommandBoxWindow.__init__(self) self.conn = conn self.defenv = DefaultEnvironment(self.conn) self.add_menu(['load', 'edit', 'save'], 'main', self.main_menu_selected) self.cursor = StatementCursor(self.conn) self.cursor.set_table('default_environment') self.view = ScrollCList() self.vbox.add(self.view) self.reset_rows() def reset_rows(self): self.view.set_rows(self.cursor.select(order=['section', 'option'])) def main_menu_selected(self, menuitem, name): if name == 'edit': newcfg = self.defenv.edit() self._update_dfenv(newcfg) elif name in ['load', 'save']: filesel = FileSelection(title='%s Default Environment' % name) filesel.cancel_button.connect('clicked', lambda x: filesel.destroy()) filesel.show() filesel.ok_button.connect('clicked', self.ok_filesel, filesel) filesel.set_data('action', name) def ok_filesel(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if action == 'save': self.defenv.write(file(path, 'w')) elif action == 'load': newcfg = RawConfigParser() newcfg.read(path) self._update_dfenv(newcfg) def _update_dfenv(self, newcfg): self.defenv.update(newcfg) self.defenv = DefaultEnvironment(self.conn) self.reset_rows()
def __init__(self, conn, cfg=None): object.__init__(self) self.conn = conn self.target = None self.cfg = cfg self.defenv = DefaultEnvironment(self.conn) #check for default environment rows = self.defenv.cursor.select() if not len(rows): raise Error, 'There is no data in the default_environment table' self.set_logfile('_unused_')
class InstallerManager(object): def __init__(self, conn): self.conn = conn self.defenv = DefaultEnvironment(conn) def get_known_machines(self): machines = [] macs = self.defenv.options('machines') for mac in macs: machine = self.defenv.get('machines', mac) if machine not in machines: machines.append(machine) return machines def approve_machine(self, machine): env = self.get_current_environment(machine) def get_current_environment(self, machine): env = CurrentEnvironment(self.conn) env.change(machine) return env
def __init__(self, conn): BaseProcessor.__init__(self) self.conn = conn self.target = None self.suite = None self.base_suite = None self.defenv = DefaultEnvironment(self.conn) # an attribute for the child installer self.installer = None # check for default environment rows = self.defenv.cursor.select() if not len(rows): raise DefaultEnvironmentError, 'There is no data in the default_environment table'
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = InstallerConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = path(os.environ['PAELLA_TARGET']) self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) # we add this here as a convenience # we need to think about using check_call # instead of call for subprocess (just found # out about it) self.CmdLineError = CmdLineError # another convenience for using # pipes in subprocess calls self.PIPE = subprocess.PIPE self.db = ToolkitDatabase(self.conn) self.db.set_profile(self.profile) self.traits = self.db.profile.make_traitlist() # we need better family attributes # for both profile families and machine families profile_families = self.db.profile.get_families() self.profile_families = list( self.db.family.get_related_families(profile_families)) self.default = DefaultEnvironment(self.conn) # we should really use __getattr__ to raise a # warning when the families attribute is being # accessed so that we can be notified when there # are scripts that use it. self.families = self.profile_families if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] self.db.set_machine(self.machine) # we need to make an installer to do # some of the installer functions. self.installer = None if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
from useless.base.path import path from paella.base import PaellaConfig from paella.db import PaellaConnection from paella.db.trait import Trait from paella.db.family import Family from paella.db.profile import Profile from paella.db.machine import MachineHandler from paella.db.installer import InstallerManager from paella.db import DefaultEnvironment from paella.installer.toolkit import InstallerTools if __name__ == '__main__': cfg = PaellaConfig() conn = PaellaConnection() suite = 'bootstrap' t = Trait(conn, suite) f = Family(conn) p = Profile(conn) m = MachineHandler(conn) de = DefaultEnvironment(conn) im = InstallerManager(conn) #os.environ['PAELLA_MACHINE'] = 'testmachine' os.environ['PAELLA_PROFILE'] = 'default' os.environ['PAELLA_TARGET'] = path('/foo/bar') it = InstallerTools()
def __init__(self, conn): self.conn = conn self.defenv = DefaultEnvironment(conn)
class Installer(object): def __init__(self, conn): object.__init__(self) self.conn = conn self.target = None self.defenv = DefaultEnvironment(self.conn) #check for default environment rows = self.defenv.cursor.select() if not len(rows): raise InstallSetupError, 'There is no data in the default_environment table' def set_logfile(self, logfile=None): env = os.environ if logfile is None: if env.has_key('PAELLA_LOGFILE'): self.logfile = env['PAELLA_LOGFILE'] elif env.has_key('LOGFILE'): self.logfile = env['LOGFILE'] elif self.defenv.has_option('installer', 'default_logfile'): self.logfile = self.defenv.get('installer', 'default_logfile') else: raise InstallSetupError, 'There is no log file defined, giving up.' else: self.logfile = logfile logdir = os.path.dirname(self.logfile) if logdir: makepaths(os.path.dirname(self.logfile)) format = '%(name)s - %(asctime)s - %(levelname)s: %(message)s' self.log = Log('paella-installer', self.logfile, format) bkup = '%s.bkup' % self.logfile if not os.path.exists(bkup): os.link(self.logfile, bkup) def set_target(self, target): self.target = target self.paelladir = os.path.join(target, 'root/paella') os.environ['PAELLA_TARGET'] = target def command(self, command, args='', chroot=True): cmd = '%s %s' % (command, args) if chroot: return 'chroot %s %s' % (self.target, cmd) else: return cmd def with_proc(self, command, args=''): mount = 'mount -t proc proc /proc;\n' umount = 'umount /proc;\n' cmd = '%s %s\n' % (command, args) return self.command("bash -c '%s'" % ''.join([mount, cmd, umount])) def run(self, name, command, args='', proc=False, destroylog=False, chroot=True, keeprunning=False): if not chroot and proc: raise InstallError, 'bad options, cannot mount proc with no_chroot' if proc: cmd = self.with_proc(command, args=args) else: cmd = self.command(command, args=args, chroot=chroot) runvalue = runlog(cmd, destroylog=destroylog, keeprunning=keeprunning) return runvalue
class BaseInstaller(BaseProcessor): def __init__(self, conn): BaseProcessor.__init__(self) self.conn = conn self.target = None self.defenv = DefaultEnvironment(self.conn) # check for default environment rows = self.defenv.cursor.select() if not len(rows): raise DefaultEnvironmentError, 'There is no data in the default_environment table' def set_target(self, target): self.target = path(target) self.paelladir = self.target / 'root/paella' os.environ['PAELLA_TARGET'] = self.target def create_target_directory(self): if not self.target.isdir(): makepaths(self.target) if not self.target.isdir(): raise InstallError, 'unable to create target directory %s' % self.target def set_logfile(self, logfile): self.logfile = path(logfile) format = '%(name)s - %(asctime)s - %(levelname)s: %(message)s' logdir = self.logfile.dirname() if not logdir.isdir(): makepaths(logdir) self.log = Log('paella-installer', self.logfile, format) # the mailserver trait used to somehow erase the logfile # so a bkup is generated here. bkup = self.logfile + '.bkup' if not bkup.exists(): self.logfile.link(bkup) @requires_target_exists def _bootstrap_with_tarball(self, suite): suite_path = path(self.defenv.get('installer', 'suite_storage')) filename = '%s.tar.gz' % suite basefile = suite_path / filename taropts = '-xzf' if not basefile.exists(): filename = '%s.tar' % suite basefile = suite_path / filename taropts = '-xf' cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile) retval = subprocess.call(cmd, shell=True) if retval: raise InstallError, 'extracting tarball failed %d' % retval else: self._bootstrapped = True @requires_target_exists def _bootstrap_with_debootstrap(self, suite): mirror = self.defenv.get('installer', 'http_mirror') cmd = debootstrap(suite, self.target, mirror) retval = subprocess.call(cmd, shell=True) if not retval: raise InstallError, 'debootstrap of target failed %d' % retval # common method for mounting /proc and /sys # here fs is either 'proc' or 'sys' def _mount_target_virtfs(self, fs): fstype = dict(proc='proc', sys='sysfs') cmd = 'mount -t %s none %s' % (fstype[fs], self.target / fs) retval = subprocess.call(cmd, shell=True) if retval: raise InstallError, 'mount of /%s returned error %d' % (fs, retval) def _umount_target_virtfs(self, fs): cmd = 'umount %s' % (self.target / fs) retval = subprocess.call(cmd, shell=True) if retval: raise InstallError, 'umount of target /%s returned error %d' % (fs, retval) @requires_bootstrap def _mount_target_proc(self): self._mount_target_virtfs('proc') @requires_bootstrap def _mount_target_sys(self): self._mount_target_virtfs('sys') @requires_target_proc_mounted def _umount_target_proc(self): self._umount_target_virtfs('proc') @requires_target_sys_mounted def _umount_target_sys(self): self._umount_target_virtfs('sys') def _target_proc_mounted(self): testfile = self.target / 'proc/version' return testfile.isfile() def _target_sys_mounted(self): testdir = self.target / 'sys/kernel' return testdir.isdir()
class NewInstaller(object): def __init__(self, conn, cfg): object.__init__(self) self.conn = conn self.cfg = cfg self.defenv = DefaultEnvironment(self.conn) self.machine = MachineHandler(self.conn) self.cursor = StatementCursor(self.conn) self.target = None self.installer = None self._mounted = None self._bootstrapped = None self.debmirror = self.cfg.get('debrepos', 'http_mirror') self._raid_setup = False self._raid_drives = {} self._enable_bad_hacks = False if self.cfg.is_it_true('installer', 'enable_bad_hacks'): self._enable_bad_hacks = True def set_logfile(self, logfile): env = os.environ if logfile is None: if env.has_key('PAELLA_LOGFILE'): self.logfile = env['PAELLA_LOGFILE'] elif env.has_key('LOGFILE'): self.logfile = env['LOGFILE'] elif self.defenv.has_option('installer', 'default_logfile'): self.logfile = self.defenv.get('installer', 'default_logfile') else: raise InstallSetupError, 'There is no log file defined, giving up.' else: self.logfile = logfile logdir = os.path.dirname(self.logfile) if logdir: makepaths(os.path.dirname(self.logfile)) format = '%(name)s - %(asctime)s - %(levelname)s: %(message)s' self.log = Log('paella-installer', self.logfile, format) def _check_target(self): if not self.target: raise Error, 'no target specified' def _check_installer(self): if not self.installer: raise Error, 'no installer available' def _check_mounted(self): self._check_target() if not self._mounted: raise InstallError, 'target not mounted' def _check_bootstrap(self): self._check_mounted() if not self._bootstrapped: raise Error, 'target not bootstrapped' def set_machine(self, machine): self.machine.set_machine(machine) try: logfile = os.environ['LOGFILE'] except KeyError: logfile = '/paellalog/paella-install-%s.log' % machine os.environ['LOGFILE'] = logfile os.environ['PAELLA_MACHINE'] = machine disklogpath = join(dirname(logfile), 'disklog') if not os.path.isdir(disklogpath): makepaths(disklogpath) self.disklogpath = disklogpath self.curenv = CurrentEnvironment(self.conn, self.machine.current.machine) self.set_logfile(logfile) def check_if_mounted(self, device): mounts = file('/proc/mounts') for line in file: if line.startswith(device): return True return False def unmount_device(self, device): mounted = os.system('umount %s' % device) def make_filesystems(self): device = self.machine.array_hack(self.machine.current.machine_type) mddev = False if device == '/dev/md': mdnum = 0 mddev = True all_fsmounts = self.machine.get_installable_fsmounts() env = CurrentEnvironment(self.conn, self.machine.current.machine) for row in all_fsmounts: if mddev: pdev = '/dev/md%d' % mdnum mdnum += 1 else: pdev = device + str(row.partition) if row.mnt_name in env.keys(): print '%s held' % row.mnt_name elif row.fstype == 'swap': runlog('echo making swap on %s' % pdev) runlog('mkswap %s' % pdev) else: print 'making filesystem for', row.mnt_name make_filesystem(pdev, row.fstype) def set_target(self, target): self.target = target def _pdev(self, device, partition): return device + str(partition) def _mount_target_proc(self): self._check_bootstrap() tproc = join(self.target, 'proc') cmd = 'mount --bind /proc %s' % tproc runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem mounting target /proc at %s' % tproc else: self._proc_mounted = True def _umount_target_proc(self): tproc = join(self.target, 'proc') cmd = 'umount %s' % tproc runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem unmounting target /proc at %s' % tproc else: self._proc_mounted = False def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq('filesystem', self.machine.current.filesystem) clause &= Gt('partition', '0') table = 'filesystem_mounts natural join mounts' mounts = self.cursor.select(table=table, clause=clause, order='mnt_point') if mounts[0].mnt_point != '/': raise Error, 'bad set of mounts', mounts mddev = False mdnum = 0 if device == '/dev/md': mddev = True pdev = '/dev/md0' mdnum += 1 else: pdev = self._pdev(device, mounts[0].partition) runlog('echo mounting target %s to %s ' % (pdev, self.target)) clause &= Neq('mnt_point', '/') mounts = self.cursor.select(table=table, clause=clause, order='ord') mountable = [mount for mount in mounts if mount.fstype != 'swap'] runlog('mount %s %s' % (pdev, self.target)) for mnt in mountable: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) if mddev: pdev = '/dev/md%d' % mdnum else: pdev = self._pdev(device, mnt.partition) mdnum += 1 runlog('mount %s %s' % (pdev, tpath)) self._mounted = True def setup_installer(self): profile = self.machine.current.profile self.installer = ProfileInstaller(self.conn) self.installer.log = self.log self.installer.set_profile(profile) self.suite = self.installer.suite def organize_disks(self): return self.machine.check_machine_disks( self.machine.current.machine_type) def _setup_disks(self, diskname, disks=None): if disks is None: disks = self.organize_disks() devices = disks[diskname] def setup_disks(self): disks = self.organize_disks() disknames = disks.keys() if not len(disknames): self._setup_disk_fai('default', '/dev/hda') else: if len(disknames) > 1: #this isn't really handled yet self.partition_disks() self.make_filesystems() else: devices = disks[disknames[0]] if len(devices) > 1: #this is a raid setup self.partition_disks() self.make_filesystems() elif len(devices) == 1: self._setup_disk_fai(self.machine.current.filesystem, devices[0]) else: self._setup_disk_fai('default', '/dev/hda') def _setup_disk_fai(self, filesystem, device): disk_config = self.machine.make_disk_config_info(device) fileid, disk_config_path = tempfile.mkstemp('paella', 'diskinfo') disk_config_file = file(disk_config_path, 'w') disk_config_file.write(disk_config) disk_config_file.close() script = '/usr/lib/paella/scripts/setup_harddisks_fai' options = '-X -f %s' % disk_config_path env = 'env LOGDIR=%s diskvar=%s' % (self.disklogpath, join(self.disklogpath, 'diskvar')) command = '%s %s %s' % (env, script, options) runlog(command) def _setup_raid_drives(self, diskname, devices): self._raid_setup = True self._raid_drives[diskname] = devices for device in devices: self._partition_disk(diskname, device) ndev = len(devices) print 'doing raid setup on %s' % diskname fs = self.machine.current.filesystem print fs pnums = [ r.partition for r in self.machine.get_installable_fsmounts(fs) ] mdnum = 0 for p in pnums: mdadm = 'mdadm --create /dev/md%d' % mdnum mdadm = '%s --force -l1 -n%d ' % (mdadm, ndev) devices = ['%s%s' % (d, p) for d in devices] command = mdadm + ' '.join(devices) print command yesman = 'bash -c "yes | %s"' % command print yesman os.system(yesman) mdnum += 1 print 'doing raid setup on %s' % str(devices) mdstat = file('/proc/mdstat').read() while mdstat.find('resync') > -1: sleep(10) mdstat = file('/proc/mdstat').read() def partition_disks(self): disks = self.organize_disks() for diskname in disks: for device in disks[diskname]: self._partition_disk(diskname, device) if len(disks[diskname]) > 1: self._raid_setup = True self._raid_drives[diskname] = disks[diskname] ndev = len(disks[diskname]) print 'doing raid setup on %s' % diskname fs = self.machine.current.filesystem print fs pnums = [ r.partition for r in self.machine.get_installable_fsmounts(fs) ] mdnum = 0 for p in pnums: mdadm = 'mdadm --create /dev/md%d' % mdnum mdadm = '%s --force -l1 -n%d ' % (mdadm, ndev) devices = ['%s%s' % (d, p) for d in disks[diskname]] command = mdadm + ' '.join(devices) print command yesman = 'bash -c "yes | %s"' % command print yesman os.system(yesman) mdnum += 1 print 'doing raid setup on %s' % str(disks[diskname]) mdstat = file('/proc/mdstat').read() while mdstat.find('resync') > -1: sleep(10) mdstat = file('/proc/mdstat').read() def _partition_disk(self, diskname, device): print 'partitioning', diskname, device dump = self.machine.make_partition_dump(diskname, device) i, o = os.popen2('sfdisk %s' % device) i.write(dump) i.close() def extract_basebootstrap(self): self._check_mounted() self._check_installer() runlog('echo extracting premade base tarball') suite_path = self.cfg.get('installer', 'suite_storage') basefile = join(suite_path, '%s.tar' % self.suite) runvalue = runlog('tar -C %s -xf %s' % (self.target, basefile)) if runvalue: raise Error, 'problems extracting %s' % basefile self._bootstrapped = True def bootstrap_target(self): self._check_mounted() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True def _make_generic_devices(self, devices): here = os.getcwd() os.chdir(join(self.target, 'dev')) for dev in devices: runlog('echo making device %s with MAKEDEV' % dev) runlog('./MAKEDEV %s' % dev) os.chdir(here) def _extract_devices_tarball(self): dtball = self.cfg.get('installer', 'devices_tarball') devpath = join(self.target, 'dev') cmd = 'tar -C %s -xf %s' % (devpath, dtball) runvalue = runlog(cmd) if runvalue: raise Error, 'problem extracting devices tarball' def make_disk_devices(self): devices = map(basename, self.machine.get_disk_devices()) self._make_generic_devices(devices) def make_tty_devices(self): self._make_generic_devices(['console']) def make_input_devices(self): self._make_generic_devices(['input']) def make_generic_devices(self): #devices = ['std', 'console', 'pty', 'tap', 'sg', 'input', 'audio'] self._make_generic_devices(['generic']) def ready_base_for_install(self): self._check_bootstrap() self._check_installer() fstab = self.machine.make_fstab() ready_base_for_install(self.target, self.cfg, self.suite, fstab) if self.cfg.is_it_true('installer', 'use_devices_tarball'): runlog('echo extracting devices tarball') self._extract_devices_tarball() else: runlog('echo using MAKEDEV to make devices') self.make_generic_devices() self.make_disk_devices() if self._raid_setup: mdpath = join(self.target, 'etc/mdadm') makepaths(mdpath) mdconfname = join(mdpath, 'mdadm.conf') mdconf = file(mdconfname, 'w') for diskname in self._raid_drives: devices = ['%s*' % d for d in self._raid_drives[diskname]] line = 'DEVICE %s' % ' '.join(devices) mdconf.write(line + '\n') mdconf.close() mdconf = file(mdconfname, 'a') arrdata = commands.getoutput('mdadm -E --config=%s -s' % mdconfname) mdconf.write(arrdata + '\n') mdconf.write('\n') mdconf.close() self._mount_target_proc() def install_to_target(self): os.environ['DEBIAN_FRONTEND'] = 'noninteractive' self._check_target() self._check_installer() self.installer.set_target(self.target) self.installer.process() def post_install(self): print 'post_install' modules = self.machine.get_modules() print 'installing modules', modules setup_modules(self.target, modules) print 'modules installed' kernel = self.machine.current.kernel print 'installing kernel', kernel install_kernel(kernel, self.target) print 'kernel installed' def install(self, machine, target): self.set_machine(machine) if self._enable_bad_hacks: self.setup_disks() else: self.partition_disks() self.make_filesystems() self.setup_installer() self.set_target(target) self.ready_target() if self.cfg.is_it_true('installer', 'bootstrap_target'): self.bootstrap_target() else: self.extract_basebootstrap() self.ready_base_for_install() self.install_to_target() self.post_install()
def _update_dfenv(self, newcfg): self.defenv.update(newcfg) self.defenv = DefaultEnvironment(self.conn) self.reset_rows()
class NewInstaller(object): def __init__(self, conn, cfg): object.__init__(self) self.conn = conn self.cfg = cfg self.defenv = DefaultEnvironment(self.conn) self.machine = MachineHandler(self.conn) self.cursor = StatementCursor(self.conn) self.target = None self.installer = None self._mounted = None self._bootstrapped = None self.debmirror = self.cfg.get('debrepos', 'http_mirror') self._raid_setup = False self._raid_drives = {} self._enable_bad_hacks = False if self.cfg.is_it_true('installer', 'enable_bad_hacks'): self._enable_bad_hacks = True def set_logfile(self, logfile): env = os.environ if logfile is None: if env.has_key('PAELLA_LOGFILE'): self.logfile = env['PAELLA_LOGFILE'] elif env.has_key('LOGFILE'): self.logfile = env['LOGFILE'] elif self.defenv.has_option('installer', 'default_logfile'): self.logfile = self.defenv.get('installer', 'default_logfile') else: raise InstallSetupError, 'There is no log file defined, giving up.' else: self.logfile = logfile logdir = os.path.dirname(self.logfile) if logdir: makepaths(os.path.dirname(self.logfile)) format = '%(name)s - %(asctime)s - %(levelname)s: %(message)s' self.log = Log('paella-installer', self.logfile, format) def _check_target(self): if not self.target: raise Error, 'no target specified' def _check_installer(self): if not self.installer: raise Error, 'no installer available' def _check_mounted(self): self._check_target() if not self._mounted: raise InstallError, 'target not mounted' def _check_bootstrap(self): self._check_mounted() if not self._bootstrapped: raise Error, 'target not bootstrapped' def set_machine(self, machine): self.machine.set_machine(machine) try: logfile = os.environ['LOGFILE'] except KeyError: logfile = '/paellalog/paella-install-%s.log' % machine os.environ['LOGFILE'] = logfile os.environ['PAELLA_MACHINE'] = machine disklogpath = join(dirname(logfile), 'disklog') if not os.path.isdir(disklogpath): makepaths(disklogpath) self.disklogpath = disklogpath self.curenv = CurrentEnvironment(self.conn, self.machine.current.machine) self.set_logfile(logfile) def check_if_mounted(self, device): mounts = file('/proc/mounts') for line in file: if line.startswith(device): return True return False def unmount_device(self, device): mounted = os.system('umount %s' % device) def make_filesystems(self): device = self.machine.array_hack(self.machine.current.machine_type) mddev = False if device == '/dev/md': mdnum = 0 mddev = True all_fsmounts = self.machine.get_installable_fsmounts() env = CurrentEnvironment(self.conn, self.machine.current.machine) for row in all_fsmounts: if mddev: pdev = '/dev/md%d' % mdnum mdnum += 1 else: pdev = device + str(row.partition) if row.mnt_name in env.keys(): print '%s held' % row.mnt_name elif row.fstype == 'swap': runlog('echo making swap on %s' % pdev) runlog('mkswap %s' % pdev) else: print 'making filesystem for', row.mnt_name make_filesystem(pdev, row.fstype) def set_target(self, target): self.target = target def _pdev(self, device, partition): return device + str(partition) def _mount_target_proc(self): self._check_bootstrap() tproc = join(self.target, 'proc') cmd = 'mount --bind /proc %s' % tproc runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem mounting target /proc at %s' % tproc else: self._proc_mounted = True def _umount_target_proc(self): tproc = join(self.target, 'proc') cmd = 'umount %s' % tproc runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem unmounting target /proc at %s' % tproc else: self._proc_mounted = False def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq('filesystem', self.machine.current.filesystem) clause &= Gt('partition', '0') table = 'filesystem_mounts natural join mounts' mounts = self.cursor.select(table=table, clause=clause, order='mnt_point') if mounts[0].mnt_point != '/': raise Error, 'bad set of mounts', mounts mddev = False mdnum = 0 if device == '/dev/md': mddev = True pdev = '/dev/md0' mdnum += 1 else: pdev = self._pdev(device, mounts[0].partition) runlog('echo mounting target %s to %s ' % (pdev, self.target)) clause &= Neq('mnt_point', '/') mounts = self.cursor.select(table=table, clause=clause, order='ord') mountable = [mount for mount in mounts if mount.fstype != 'swap'] runlog('mount %s %s' % (pdev, self.target)) for mnt in mountable: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) if mddev: pdev = '/dev/md%d' % mdnum else: pdev = self._pdev(device, mnt.partition) mdnum += 1 runlog('mount %s %s' % (pdev, tpath)) self._mounted = True def setup_installer(self): profile = self.machine.current.profile self.installer = ProfileInstaller(self.conn) self.installer.log = self.log self.installer.set_profile(profile) self.suite = self.installer.suite def organize_disks(self): return self.machine.check_machine_disks(self.machine.current.machine_type) def _setup_disks(self, diskname, disks=None): if disks is None: disks = self.organize_disks() devices = disks[diskname] def setup_disks(self): disks = self.organize_disks() disknames = disks.keys() if not len(disknames): self._setup_disk_fai('default', '/dev/hda') else: if len(disknames) > 1: #this isn't really handled yet self.partition_disks() self.make_filesystems() else: devices = disks[disknames[0]] if len(devices) > 1: #this is a raid setup self.partition_disks() self.make_filesystems() elif len(devices) == 1: self._setup_disk_fai(self.machine.current.filesystem, devices[0]) else: self._setup_disk_fai('default', '/dev/hda') def _setup_disk_fai(self, filesystem, device): disk_config = self.machine.make_disk_config_info(device) fileid, disk_config_path = tempfile.mkstemp('paella', 'diskinfo') disk_config_file = file(disk_config_path, 'w') disk_config_file.write(disk_config) disk_config_file.close() script = '/usr/lib/paella/scripts/setup_harddisks_fai' options = '-X -f %s' % disk_config_path env = 'env LOGDIR=%s diskvar=%s' % (self.disklogpath, join(self.disklogpath, 'diskvar')) command = '%s %s %s' % (env, script, options) runlog(command) def _setup_raid_drives(self, diskname, devices): self._raid_setup = True self._raid_drives[diskname] = devices for device in devices: self._partition_disk(diskname, device) ndev = len(devices) print 'doing raid setup on %s' % diskname fs = self.machine.current.filesystem print fs pnums = [r.partition for r in self.machine.get_installable_fsmounts(fs)] mdnum = 0 for p in pnums: mdadm = 'mdadm --create /dev/md%d' % mdnum mdadm = '%s --force -l1 -n%d ' % (mdadm, ndev) devices = ['%s%s' % (d, p) for d in devices] command = mdadm + ' '.join(devices) print command yesman = 'bash -c "yes | %s"' % command print yesman os.system(yesman) mdnum += 1 print 'doing raid setup on %s' % str(devices) mdstat = file('/proc/mdstat').read() while mdstat.find('resync') > -1: sleep(10) mdstat = file('/proc/mdstat').read() def partition_disks(self): disks = self.organize_disks() for diskname in disks: for device in disks[diskname]: self._partition_disk(diskname, device) if len(disks[diskname]) > 1: self._raid_setup = True self._raid_drives[diskname] = disks[diskname] ndev = len(disks[diskname]) print 'doing raid setup on %s' % diskname fs = self.machine.current.filesystem print fs pnums = [r.partition for r in self.machine.get_installable_fsmounts(fs)] mdnum = 0 for p in pnums: mdadm = 'mdadm --create /dev/md%d' % mdnum mdadm = '%s --force -l1 -n%d ' % (mdadm, ndev) devices = ['%s%s' % (d, p) for d in disks[diskname]] command = mdadm + ' '.join(devices) print command yesman = 'bash -c "yes | %s"' % command print yesman os.system(yesman) mdnum += 1 print 'doing raid setup on %s' % str(disks[diskname]) mdstat = file('/proc/mdstat').read() while mdstat.find('resync') > -1: sleep(10) mdstat = file('/proc/mdstat').read() def _partition_disk(self, diskname, device): print 'partitioning', diskname, device dump = self.machine.make_partition_dump(diskname, device) i, o = os.popen2('sfdisk %s' % device) i.write(dump) i.close() def extract_basebootstrap(self): self._check_mounted() self._check_installer() runlog('echo extracting premade base tarball') suite_path = self.cfg.get('installer', 'suite_storage') basefile = join(suite_path, '%s.tar' % self.suite) runvalue = runlog('tar -C %s -xf %s' % (self.target, basefile)) if runvalue: raise Error, 'problems extracting %s' % basefile self._bootstrapped = True def bootstrap_target(self): self._check_mounted() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True def _make_generic_devices(self, devices): here = os.getcwd() os.chdir(join(self.target, 'dev')) for dev in devices: runlog('echo making device %s with MAKEDEV' % dev) runlog('./MAKEDEV %s' % dev) os.chdir(here) def _extract_devices_tarball(self): dtball = self.cfg.get('installer', 'devices_tarball') devpath = join(self.target, 'dev') cmd = 'tar -C %s -xf %s' % (devpath, dtball) runvalue = runlog(cmd) if runvalue: raise Error, 'problem extracting devices tarball' def make_disk_devices(self): devices = map(basename, self.machine.get_disk_devices()) self._make_generic_devices(devices) def make_tty_devices(self): self._make_generic_devices(['console']) def make_input_devices(self): self._make_generic_devices(['input']) def make_generic_devices(self): #devices = ['std', 'console', 'pty', 'tap', 'sg', 'input', 'audio'] self._make_generic_devices(['generic']) def ready_base_for_install(self): self._check_bootstrap() self._check_installer() fstab = self.machine.make_fstab() ready_base_for_install(self.target, self.cfg, self.suite, fstab) if self.cfg.is_it_true('installer', 'use_devices_tarball'): runlog('echo extracting devices tarball') self._extract_devices_tarball() else: runlog('echo using MAKEDEV to make devices') self.make_generic_devices() self.make_disk_devices() if self._raid_setup: mdpath = join(self.target, 'etc/mdadm') makepaths(mdpath) mdconfname = join(mdpath, 'mdadm.conf') mdconf = file(mdconfname, 'w') for diskname in self._raid_drives: devices = ['%s*' % d for d in self._raid_drives[diskname]] line = 'DEVICE %s' % ' '.join(devices) mdconf.write(line + '\n') mdconf.close() mdconf = file(mdconfname, 'a') arrdata = commands.getoutput('mdadm -E --config=%s -s' % mdconfname) mdconf.write(arrdata + '\n') mdconf.write('\n') mdconf.close() self._mount_target_proc() def install_to_target(self): os.environ['DEBIAN_FRONTEND'] = 'noninteractive' self._check_target() self._check_installer() self.installer.set_target(self.target) self.installer.process() def post_install(self): print 'post_install' modules = self.machine.get_modules() print 'installing modules', modules setup_modules(self.target, modules) print 'modules installed' kernel = self.machine.current.kernel print 'installing kernel', kernel install_kernel(kernel, self.target) print 'kernel installed' def install(self, machine, target): self.set_machine(machine) if self._enable_bad_hacks: self.setup_disks() else: self.partition_disks() self.make_filesystems() self.setup_installer() self.set_target(target) self.ready_target() if self.cfg.is_it_true('installer', 'bootstrap_target'): self.bootstrap_target() else: self.extract_basebootstrap() self.ready_base_for_install() self.install_to_target() self.post_install()