Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def extract_tarball(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)
Ejemplo n.º 6
0
def extract_tarball(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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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
     pdev = self._pdev(device, mounts[0].partition)
     print 'mounting target', pdev, self.target
     runlog('mount %s %s' % (pdev, self.target))
     for mnt in mounts[1:]:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         pdev = self._pdev(device, mnt.partition)
         runlog('mount %s %s' % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
 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
     pdev = self._pdev(device, mounts[0].partition)
     print 'mounting target', pdev, self.target
     runlog('mount %s %s' % (pdev, self.target))
     for mnt in mounts[1:]:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         pdev = self._pdev(device, mnt.partition)
         runlog('mount %s %s' % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def bootstrap_target(self):
     self._check_mounted()
     self._check_installer()
     runlog(debootstrap(self.suite, self.target, self.debmirror))
     self._bootstrapped = True
Ejemplo n.º 14
0
def remove_debs(target):
    archives = 'var/cache/apt/archives'
    debs = os.path.join(target, archives, '*.deb')
    pdebs = os.path.join(target, archives, 'partial', '*.deb')
    runlog('rm %s %s -f' % (debs, pdebs))
Ejemplo n.º 15
0
def remove_debs(target):
    archives = 'var/cache/apt/archives'
    debs = os.path.join(target, archives, '*.deb')
    pdebs = os.path.join(target, archives, 'partial', '*.deb')
    runlog('rm %s %s -f' % (debs, pdebs))
Ejemplo n.º 16
0
 def bootstrap_target(self):
     self._check_mounted()
     self._check_installer()
     runlog(debootstrap(self.suite, self.target, self.debmirror))
     self._bootstrapped = True