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 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 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) print 'mounting target', pdev, self.target clause &= Neq('mnt_point', '/') mounts = self.cursor.select(table=table, clause=clause, order='ord') runlog('mount %s %s' % (pdev, self.target)) for mnt in mounts: 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 makedev(target, devices=['generic']): here = os.getcwd() os.chdir(join(target, 'dev')) for dev in devices: echo('making device %s with MAKEDEV' % dev) runlog('./MAKEDEV %s' % dev) os.chdir(here)
def make_device_entries(self): "this is a default process" if self.defenv.is_it_true('installer', 'use_devices_tarball'): runlog('echo extracting devices tarball') self._extract_devices_tarball() else: runlog('echo using MAKEDEV to make generic devices') self.make_generic_devices() self.make_disk_devices()
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 _extract_base_tarball(self, suite): self._check_target_exists() runlog('echo extracting premade base tarball') suite_path = self.defenv.get('installer', 'suite_storage') basefile = join(suite_path, '%s.tar' % suite) runvalue = runlog('tar -C %s -xf %s' % (self.target, basefile)) if runvalue: raise InstallError, 'problems extracting %s' % basefile else: self._bootstrapped = True
def make_filesystem(device, fstype): if fstype == 'reiserfs': cmd = 'mkreiserfs -f -q %s' % device elif fstype == 'ext3': cmd = 'mkfs.ext3 -F -q %s' % device elif fstype == 'ext2': cmd = 'mkfs.ext2 -F -q %s' % device else: raise Error, 'unhandled fstype %s ' % fstype echo(cmd) runlog(cmd, keeprunning=True)
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 extract_tarball_orig(target, tarball): here = os.getcwd() print 'extracting with tar' os.chdir(target) if tarball[-2:] == 'gz': opts = 'xzf' elif tarball[-3:] == 'bz2': opts = 'xjf' else: opts = 'xf' runlog('tar %s %s' % (opts, tarball)) os.chdir(here)
def mount_target(target, mounts, device): mounts = [m for m in mounts if int(m.partition)] 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 = '%s%d' % (device, mounts[0].partition) runlog('echo mounting target %s to %s' % (pdev, target)) runlog('mount %s %s' % (pdev, target)) mounts = mounts[1:] mountable = [m for m in mounts if m.fstype != 'swap'] for mnt in mountable: tpath = os.path.join(target, mnt.mnt_point[1:]) makepaths(tpath) if mddev: pdev = '/dev/md%d' % mdnum else: pdev = '%s%d' % (device, mnt.partition) mdnum += 1 runlog('echo mounting target %s to %s' % (pdev, tpath)) runlog('mount %s %s' % (pdev, tpath))
def create_raid_partition(devices, pnum, mdnum, raidlevel=1): opts = '--create /dev/md%d' % mdnum opts = '%s --force -l%d -n%d' % (opts, raidlevel, len(devices)) devices = ['%s%d' % (device, pnum) for device in devices] cmd = 'mdadm %s %s' % (opts, ' '.join(devices)) yes = 'bash -c "yes | %s"' % cmd return runlog(yes)
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 _run_bootstrap(self, mirror, suite): self._check_target_exists() runvalue = runlog(debootstrap(suite, self.target, mirror)) if runvalue: raise InstallError, 'bootstrapping %s on %s failed.' % (suite, self.target) else: self._bootstrapped = True
def _run_bootstrap(self, mirror, suite): self._check_target_exists() runvalue = runlog(debootstrap(suite, self.target, mirror)) if runvalue: raise InstallError, 'bootstrapping %s on %s failed.' % ( suite, self.target) else: self._bootstrapped = 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 run(self, name, command, args="", proc=False, destroylog=False, chroot=True, keeprunning=False): if not chroot and proc: raise Error, "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
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 extract_tarball(target, tarball): opts = '-xf' if tarball[-7:] == '.tar.gz' or tarball[-4:] == '.tgz': opts = '-xzf' elif tarball[-8:] == '.tar.bz2': opts = '-xjf' cmd = 'tar -C %s %s %s' % (target, opts, tarball) echo('extracting tarball with command %s' % cmd) return runlog(cmd)
def debootstrap_target(self): suite = self.installer.suite debmirror = self.installer.debmirror cmd = debootstrap(suite, self.target, debmirror) info = self.installer.log.info info('running debootstrap with cmd %s' % cmd) runvalue = runlog(debootstrap(self.installer.suite, self.target, self.installer.debmirror)) if runvalue: raise InstallError, 'problems bootstrapping with %s' % cmd
def setup_disk_fai(disk_config, logpath, script='/usr/lib/paella/scripts/setup_harddisks_fai'): 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() options = '-X -f %s' % disk_config_path env = 'env LOGDIR=%s diskvar=%s' % (logpath, join(logpath, 'diskvar')) command = '%s %s %s' % (env, script, options) return runlog(command)
def install_kernel(package, target): script = "#!/bin/bash\n" script += '#umount /proc\n' script += '#umount /proc\n' script += '#mount -t proc proc /proc\n' script += 'touch /boot/vmlinuz-fake\n' script += 'ln -s boot/vmlinuz-fake vmlinuz\n' script += 'apt-get -y install %s\n' % package script += 'echo "kernel %s installed"\n' % package script += '#umount /proc\n' script += '\n' sname = 'install_kernel.sh' full_path = os.path.join(target, sname) sfile = file(full_path, 'w') sfile.write(script) sfile.close() runlog('chmod a+x %s' % full_path) runlog('chroot %s ./%s' % (target, sname)) os.remove(full_path)
def debootstrap_target(self): suite = self.installer.suite debmirror = self.installer.debmirror cmd = debootstrap(suite, self.target, debmirror) info = self.installer.log.info info('running debootstrap with cmd %s' % cmd) runvalue = runlog( debootstrap(self.installer.suite, self.target, self.installer.debmirror)) if runvalue: raise InstallError, 'problems bootstrapping with %s' % cmd
def make_filesystems(device, fsmounts, env): mddev = False if device == '/dev/md': mdnum = 0 mddev = True for row in fsmounts: if mddev: pdev = '/dev/md%d' % mdnum mdnum += 1 else: pdev = device + str(row.partition) if row.mnt_name in env.keys(): echo('%s held' % row.mnt_name) elif row.fstype == 'swap': runlog('echo making swap on %s' % pdev) runvalue = runlog('mkswap %s' % pdev) if runvalue: raise Error, 'problem making swap on %s' % pdev else: echo('making filesystem for %s' % row.mnt_name) make_filesystem(pdev, row.fstype)
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 ready_base_for_install(self): self._check_bootstrap() fstab = '#unconfigured for chroot install\n' ready_base_for_install(self.target, self.defenv, self.suite, fstab) self._mount_target_proc() self._check_target_proc() cmd = self.command('apt-get', '-y update', chroot=True) runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem updating the apt lists.' if os.environ.has_key('FAKE_START_STOP_DAEMON'): make_fake_start_stop_daemon(self.target) self._base_ready = True
def run(self, name, command, args='', proc=False, destroylog=False, chroot=True, keeprunning=False): if not chroot and proc: raise Error, '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
def mount_target_proc(target, umount=False): tproc = join(target, 'proc') cmd = 'mount --bind /proc %s' % tproc if umount: cmd = 'umount -l %s' % tproc return runlog(cmd)
def bootstrap_target(self): self._check_target() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True
def remove_debs(target): archives = 'var/cache/apt/archives' debs = os.path.join(target, archives, '*.deb') pdebs = os.path.join(target, archives, 'partial', '*.deb') return runlog('rm %s %s -f' % (debs, pdebs))
def bootstrap_target(self): self._check_mounted() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True