class UmlProfileInstaller(BaseUmlInstaller): @guest_mode def set_suite(self, suite): self.installer = ProfileInstaller(self.conn) self._suite = suite self.suitecursor = SuiteCursor(self.conn) @guest_mode def _set_profile_in_guest(self, profile): self.set_suite(get_suite(self.conn, profile)) self.installer.set_profile(profile) if hasattr(self, 'target'): self.installer.set_target(self.target) def set_profile(self, profile): if self.mode == 'host': self.options['paellaprofile'] = profile elif self.mode == 'guest': self._set_profile_in_guest(profile) else: raise ValueError, 'bad mode %s' % self.mode @guest_mode def set_template_path(self, path=None): self.installer.set_template_path(path) @host_mode def install_profile(self, profile, path): self.set_profile(profile) self.make_root_device(path) self.run_uml(popen=True) @host_mode def restore_profile(self, name, path): self.options['paella_action'] = 'restore' self.options['paellaprofile'] = name self.options['paellasuite'] = 'none' self.make_root_device(path) self.run_uml(popen=False) @guest_mode def extract_base_tarball(self): suite = self.suitecursor.get_base_suite(self._suite) fstype = self.cfg.get('umlmachines', 'backup_filesystem') if fstype == 'hostfs': #backup_path = path(self.cfg.get('umlmachines', 'hostfs_backup_path')).expand() backup_path = path(self.options['hostfs_backup_path'].value) else: backup_path = path('/mnt') basetarball = backup_path / path('%s.base.tar.gz' % suite) if not basetarball.isfile(): basetarball = backup_path / path('%s.base.tar' % suite) if basetarball.isfile(): extract_tarball(self.target, basetarball) else: raise RuntimeError, 'No base tarball found for suite %s' % suite @guest_mode def ready_base_for_install(self): cfg = self.installer.defenv ready_base_for_install(self.target, self.conn, self._suite) @guest_mode def perform_install(self, profile=None, backup_filesystem=None): machine = os.environ['PAELLA_MACHINE'] curenv = CurrentEnvironment(self.conn, machine) curenv['current_trait'] = 'None' curenv['current_trait_process'] = 'None' curenv['traitlist'] = '' mpkey = 'current_machine_process' if backup_filesystem is not None: curenv[mpkey] = 'mount_backup' self.mount_backup('/mnt', backup_filesystem) curenv[mpkey] = 'setup_target' self.setup_target() curenv[mpkey] = 'set_profile' self.set_profile(profile) curenv[mpkey] = 'extract_base_tarball' self.extract_base_tarball() curenv[mpkey] = 'ready_base_for_install' self.ready_base_for_install() curenv[mpkey] = 'set_template_path' self.set_template_path() curenv[mpkey] = 'process' self.process()
class UmlProfileInstaller(BaseUmlInstaller): @guest_mode def set_suite(self, suite): self.installer = ProfileInstaller(self.conn) self._suite = suite self.suitecursor = SuiteCursor(self.conn) @guest_mode def _set_profile_in_guest(self, profile): self.set_suite(get_suite(self.conn, profile)) self.installer.set_profile(profile) if hasattr(self, 'target'): self.installer.set_target(self.target) def set_profile(self, profile): if self.mode == 'host': self.options['paellaprofile'] = profile elif self.mode == 'guest': self._set_profile_in_guest(profile) else: raise ValueError, 'bad mode %s' % self.mode @guest_mode def set_template_path(self, path=None): self.installer.set_template_path(path) @host_mode def install_profile(self, profile, path): self.set_profile(profile) self.make_root_device(path) self.run_uml(popen=True) @host_mode def restore_profile(self, name, path): self.options['paella_action'] = 'restore' self.options['paellaprofile'] = name self.options['paellasuite'] = 'none' self.make_root_device(path) self.run_uml(popen=False) @guest_mode def extract_base_tarball(self): suite = self.suitecursor.get_base_suite(self._suite) fstype = self.cfg.get('umlmachines', 'backup_filesystem') if fstype == 'hostfs': #backup_path = path(self.cfg.get('umlmachines', 'hostfs_backup_path')).expand() backup_path = path(self.options['hostfs_backup_path'].value) else: backup_path = path('/mnt') basetarball = backup_path / path('%s.base.tar.gz' % suite) if not basetarball.isfile(): basetarball = backup_path / path('%s.base.tar' % suite) if basetarball.isfile(): extract_tarball(self.target, basetarball) else: raise RuntimeError, 'No base tarball found for suite %s' % suite @guest_mode def ready_base_for_install(self): cfg = self.installer.defenv ready_base_for_install(self.target, self.conn, self._suite) @guest_mode def perform_install(self, profile=None, backup_filesystem=None): machine = os.environ['PAELLA_MACHINE'] curenv = CurrentEnvironment(self.conn, machine) curenv['current_trait'] = 'None' curenv['current_trait_process'] = 'None' curenv['traitlist'] = '' mpkey = 'current_machine_process' if backup_filesystem is not None: curenv[mpkey] = 'mount_backup' self.mount_backup('/mnt', backup_filesystem) curenv[mpkey] = 'setup_target' self.setup_target() curenv[mpkey] = 'set_profile' self.set_profile(profile) curenv[mpkey] = 'extract_base_tarball' self.extract_base_tarball() curenv[mpkey] = 'ready_base_for_install' self.ready_base_for_install() curenv[mpkey] = 'set_template_path' self.set_template_path() curenv[mpkey] = 'process' self.process()
class BaseChrootInstaller(Installer): def __init__(self, conn, installer=None): Installer.__init__(self, conn) self._bootstrapped = False self.installer = installer self.debmirror = self.defenv.get('installer', 'http_mirror') self.suitecursor = SuiteCursor(self.conn) def _make_target_dir(self, target): makepaths(target) def _check_target(self): if self.target is None: raise InstallError, 'no target specified' def _check_target_exists(self): self._check_target() if not isdir(self.target): self._make_target_dir(self.target) if not isdir(self.target): raise InstallError, 'unable to create target directory %s' % self.target def _check_installer(self): if self.installer is None: raise InstallError, 'no installer available' def _check_bootstrap(self): self._check_target_exists() if not self._bootstrapped: raise InstallError, 'target not bootstrapped' def _check_target_proc(self): if not self._proc_mounted: raise InstallError, 'target /proc not mounted' def _extract_base_tarball(self, suite): self._check_target_exists() runlog('echo extracting premade base tarball') suite_path = self.defenv.get('installer', 'suite_storage') filename = '%s.tar.gz' % suite basefile = join(suite_path, filename) taropts = '-xzf' if not os.path.exists(basefile): filename = '%s.tar' % suite basefile = join(suite_path, filename) taropts = '-xf' runvalue = runlog('tar -C %s %s %s' % (self.target, taropts, basefile)) if runvalue: raise InstallError, 'problems extracting %s' % basefile else: self._bootstrapped = True def _bootstrap_target(self): self._check_installer() suite = self.suitecursor.get_base_suite(self.suite) if self.defenv.is_it_true('installer', 'bootstrap_target'): mirror = self.debmirror self._run_bootstrap(mirror, suite) else: self._extract_base_tarball(suite) 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): self._check_target_proc() 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_bootstrap(self, mirror, suite): self._check_target_exists() runvalue = runlog(debootstrap(suite, self.target, mirror)) if runvalue: print "runvalue returned from bootstrap", runvalue raise InstallError, 'bootstrapping %s on %s failed.' % (suite, self.target) else: self._bootstrapped = True