Exemplo n.º 1
0
 def _make_traitlist(self, traits, log=None):
     tp = TraitParent(self.conn, self.current.suite)
     listed = traits
     all = list(tp.get_traitset(listed))
     setfun = tp.set_trait
     parfun = tp.parents
     return make_deplist(listed, all, setfun, parfun, log)
Exemplo n.º 2
0
 def _make_traitlist(self, traits, log=None):
     tp = TraitParent(self.conn, self.current.suite)
     listed = traits
     all = list(tp.get_traitset(listed))
     setfun = tp.set_trait
     parfun = tp.parents
     return make_deplist(listed, all, setfun, parfun, log)
Exemplo n.º 3
0
 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.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'])
Exemplo n.º 4
0
 def set_profile(self, profile):
     self.profile = profile
     self._profile.set_profile(profile)
     os.environ['PAELLA_PROFILE'] = profile
     self.profiletrait.set_profile(profile)
     self._init_attributes()
     self._setup_installer(self.suite)
     self.traitparent = TraitParent(self.conn, self.suite)
     self.log.info('profile set to %s' % profile)
     traitlist = self.make_traitlist()
     self._setup_trait_processes(traitlist)
Exemplo n.º 5
0
class _ProfileEnvironment(Environment):
    def __init__(self, conn, profile):
        self.suite = get_suite(conn, profile)
        self.profile = profile
        Environment.__init__(self, conn, 'profile_variables', 'trait')
        self.traitparent = TraitParent(self.conn, self.suite)

    def set_trait(self, trait):
        self.set_main(trait)
        self.traitparent.set_trait(trait)

    def _single_clause_(self):
        return Eq('profile', self.profile) & Eq('trait', self.__main_value__)

    def __setitem__(self, key, value):
        try:
            self.cursor.insert(
                data={
                    'profile': self.profile,
                    'trait': self.__main_value__,
                    self.__key_field__: key,
                    self.__value_field__: value
                })
        except OperationalError:
            self.cursor.update(data={self.__value_field__: value},
                               clause=self._double_clause_(key))

    def _make_superdict__orig_(self):
        clause = Eq('profile', self.profile)
        superdict = {}
        traits = [
            row.trait
            for row in self.cursor.select(fields=['trait'], clause=clause)
        ]
        for trait in traits:
            self.set_trait(trait)
            items = [(trait + '_' + key, value) for key, value in self.items()]
            superdict.update(dict(items))
        return superdict

    def _make_superdict_(self):
        clause = Eq('profile', self.profile)
        return Environment._make_superdict_(self, clause)

    def _get_defaults_(self, trait):
        return self.traitparent.get_environment([trait])

    def _update_defaults_(self, trait):
        for trait, data in self._get_defaults_(trait):
            self.set_trait(trait)
            self.update(data)
Exemplo n.º 6
0
def install_packages_uml(conn, suite, profile, target):
    traits = get_traits(conn, profile)
    tp = TraitParent(conn, suite)
    pp = TraitPackage(conn, suite)
    packages = ' '.join([p.package for p in pp.all_packages(traits, tp)])
    os.system('chroot %s apt-get update' % target)
    os.system('chroot %s apt-get -y install %s' % (target, packages))
Exemplo n.º 7
0
 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.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"])
Exemplo n.º 8
0
class _ProfileEnvironment(Environment):
    def __init__(self, conn, profile):
        self.suite = get_suite(conn, profile)
        self.profile = profile
        Environment.__init__(self, conn, 'profile_variables', 'trait')
        self.traitparent = TraitParent(self.conn, self.suite)
        
    def set_trait(self, trait):
        self.set_main(trait)
        self.traitparent.set_trait(trait)
        
    def _single_clause_(self):
        return Eq('profile', self.profile) & Eq('trait', self.__main_value__)
    
    def __setitem__(self, key, value):
        try:
            self.cursor.insert(data={'profile' : self.profile,
                                     'trait' : self.__main_value__,
                                     self.__key_field__ : key,
                                     self.__value_field__ : value})
        except OperationalError:
            self.cursor.update(data={self.__value_field__ : value},
                               clause=self._double_clause_(key))
            
        
    def _make_superdict__orig_(self):
        clause = Eq('profile', self.profile)
        superdict = {}
        traits = [row.trait for row in self.cursor.select(fields=['trait'], clause=clause)]
        for trait in traits:
            self.set_trait(trait)
            items = [(trait + '_' + key, value) for key, value in self.items()]
            superdict.update(dict(items))
        return superdict

    def _make_superdict_(self):
        clause = Eq('profile', self.profile)
        return Environment._make_superdict_(self, clause)
    
    def _get_defaults_(self, trait):
        return self.traitparent.get_environment([trait])

    def _update_defaults_(self, trait):
        for trait, data in self._get_defaults_(trait):
            self.set_trait(trait)
            self.update(data)
Exemplo n.º 9
0
 def set_profile(self, profile):
     self.profile = profile
     self._profile.set_profile(profile)
     os.environ['PAELLA_PROFILE'] = profile
     self.profiletrait.set_profile(profile)
     self.traits = self.profiletrait.trait_rows()
     self.env = ProfileEnvironment(self.conn, self.profile)
     self.familydata = self._profile.get_family_data()
     self.profiledata = self._profile.get_profile_data()
     self.suite = get_suite(self.conn, profile)
     self.installer = TraitInstaller(self.conn, self.suite)
     self.installer.log = self.log
     self.installer.familydata = self.familydata
     self.installer.profiledata = self.profiledata
     self.installer.mtypedata = self.mtypedata
     self.traitparent = TraitParent(self.conn, self.suite)
     self.log.info('profile set to %s' % profile)
     traitlist = self.make_traitlist()
     self.setup_initial_paellainfo_env(traitlist)
Exemplo n.º 10
0
 def set_profile(self, profile):
     self.profile = profile
     self._profile.set_profile(profile)
     os.environ['PAELLA_PROFILE'] = profile
     self.profiletrait.set_profile(profile)
     self._init_attributes()
     self._setup_installer(self.suite)
     self.traitparent = TraitParent(self.conn, self.suite)
     self.log.info('profile set to %s' % profile)
     traitlist = self.make_traitlist()
     self._setup_trait_processes(traitlist)
Exemplo n.º 11
0
class _ProfileEnvironment(Environment):
    def __init__(self, conn, profile):
        self.suite = get_suite(conn, profile)
        self.profile = profile
        Environment.__init__(self, conn, 'profile_variables', 'trait')
        self.traitparent = TraitParent(self.conn, self.suite)
        
    def set_trait(self, trait):
        self.set_main(trait)
        self.traitparent.set_trait(trait)
        
    def _single_clause_(self):
        return Eq('profile', self.profile) & Eq('trait', self.__main_value__)
    
    def __setitem__(self, key, value):
        try:
            self.cursor.insert(data={'profile' : self.profile,
                                     'trait' : self.__main_value__,
                                     self.__key_field__ : key,
                                     self.__value_field__ : value})
        except OperationalError:
            self.cursor.update(data={self.__value_field__ : value},
                               clause=self._double_clause_(key))
            
        
    def make_superdict(self, sep='_'):
        clause = Eq('profile', self.profile)
        return Environment.make_superdict(self, clause, sep=sep)
    
    def _get_defaults_(self, trait):
        return self.traitparent.get_environment([trait])

    def _update_defaults_(self, trait):
        for trait, data in self._get_defaults_(trait):
            self.set_trait(trait)
            self.update(data)
Exemplo n.º 12
0
 def set_profile(self, profile):
     self.profile = profile
     self._profile.set_profile(profile)
     os.environ['PAELLA_PROFILE'] = profile
     self.profiletrait.set_profile(profile)
     self.traits = self.profiletrait.trait_rows()
     self.env = ProfileEnvironment(self.conn, self.profile)
     self.familydata = self._profile.get_family_data()
     self.profiledata = self._profile.get_profile_data()
     self.suite = get_suite(self.conn, profile)
     self.installer = TraitInstaller(self.conn, self.suite)
     self.installer.log = self.log
     self.installer.familydata = self.familydata
     self.installer.profiledata = self.profiledata
     self.installer.mtypedata = self.mtypedata
     self.traitparent = TraitParent(self.conn, self.suite)
     self.log.info('profile set to %s' % profile)
     traitlist = self.make_traitlist()
     self.setup_initial_paellainfo_env(traitlist)
Exemplo n.º 13
0
class InstallerTools(object):
    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.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"])

    # this needs updating for machine type data
    def env(self):
        env = TemplatedEnvironment(self.tp.Environment())
        env.update(self.pr.get_family_data())
        env.update(self.pr.get_profile_data())
        return env

    def set_trait(self, trait):
        self.trait = trait
        self.tp.set_trait(trait)
        self.tr.set_trait(trait)
        self.parents = self.tr.parents()
        self._envv = self.env()
        tinstaller = self.installer.installer
        tinstaller.set_trait(trait)
        self.packages = tinstaller.traitpackage.packages()
        self.templates = tinstaller.traittemplate.templates()

    def get(self, key):
        if self._envv is None:
            raise Error, "need to set trait first"
        return self._envv.dereference(key)

    def lget(self, key):
        key = "_".join([self.trait, key])
        return self.get(key)

    def install_modules(self, name):
        modules = str2list(self.get(name))
        print "installing modules", modules, "to %s/etc/modules" % self.target
        setup_modules(self.target, modules)

    def remove_packages(self, packages=None):
        if packages is None:
            packages = self.packages
        if len(packages):
            if hasattr(packages[0], "package"):
                packages = [p.package for p in packages]
        package_list = " ".join(packages)
        command = "apt-get -y remove %s" % package_list
        self.installer.run("remove", command, proc=True)

    def chroot_command(self, cmd):
        return "chroot %s %s" % (self.target, cmd)
Exemplo n.º 14
0
class ProfileInstaller(BaseInstaller):
    # here parent is the chroot installer
    # The target needs to be set in the parent before
    # this class is initialized.
    def __init__(self, parent):
        BaseInstaller.__init__(self, parent.conn)
        self._parent = parent
        self.target = parent.target
        # we need this paelladir attribute for now
        # but may replace/redo this later
        self.paelladir = self.target / 'root/paella'
        self.profile = None
        self.suite = None
        self.profiletrait = ProfileTrait(self.conn)
        self._profile = Profile(self.conn)
        if hasattr(parent, 'mainlog'):
            self.mainlog = parent.mainlog
            name = self.__class__.__name__
            self.mainlog.add_logger(name)
            self.log = self.mainlog.loggers[name]

        # make empty data dicts
        self.machine_data = {}
        self.familydata = {}
        self.profiledata = {}

    # this method is called within set_profile
    def _init_attributes(self):
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, self.profile)

    # this method is called within set_profile
    # here is where the trait installer is setup
    # the data attributes need to be filled before this is called
    # this method needs to be fixed to use the new trait installer
    def _setup_installer(self, suite):
        self.installer = TraitInstaller(self)
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.installer.machine_data = self.machine_data

    # here is where the processes are setup
    # every process is a trait and it maps to the same
    # function.  a "current_index" attribute keeps track
    # of which trait is being processed.
    def _setup_trait_processes(self, traitlist):
        self.setup_initial_paellainfo_env(traitlist)
        self._processes = traitlist
        self._process_map = {}.fromkeys(traitlist, self.process_trait)

    # setting the profile involves a lot of work
    # there are helper methods defined to help split
    # the code up into more manageable pieces.
    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ['PAELLA_PROFILE'] = profile
        self.profiletrait.set_profile(profile)
        self._init_attributes()
        self._setup_installer(self.suite)
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info('profile set to %s' % profile)
        traitlist = self.make_traitlist()
        self._setup_trait_processes(traitlist)

    # currently there is no script functionality
    # but there may be in the future.
    def make_script(self, procname):
        return None

    # this method needs to be checked
    def make_traitlist(self):
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        log = None
        return self._profile.make_traitlist_with_traits(listed, log=log)

    def get_profile_data(self):
        return self.env.ProfileData()

    # this method needs to be checked
    # self.paelladir needs to be defined
    def setup_initial_paellainfo_files(self, traits):
        makepaths(self.paelladir)
        traitlist = file(join(self.paelladir, 'traitlist'), 'w')
        for trait in traits:
            traitlist.write('%s\n' % trait)
        traitlist.close()
        itraits = file(join(self.paelladir, 'installed_traits'), 'w')
        itraits.write('Installed Traits:\n')
        itraits.close()

    # initialize data in current_environment,
    # if PAELLA_MACHINE is set
    def setup_initial_paellainfo_env(self, traits):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            curenv['current_profile'] = self.profile
            curenv['traitlist'] = ', '.join(traits)
            curenv['installed_traits'] = ''

    # this method has been rewritten to use
    # self.current_index
    # the UnbornError should never be raised
    def process_trait(self):
        trait = self._processes[self.current_index]
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info('processing trait %s' % trait)
        self.installer.run_all_processes()
        self.processed.append(trait)
        self.current_index += 1
        self.log.info('processed:  %s' % ', '.join(self.processed))
        self.append_installed_traits(trait)

    # this used to be called process
    def run_all_processes(self):
        traits = self.make_traitlist()
        self.setup_initial_paellainfo_files(traits)
        self.setup_initial_paellainfo_env(traits)
        self.processed = []
        self.current_index = 0
        BaseInstaller.run_all_processes(self)
        self.log.info('all traits processed for profile %s' % self.profile)
        self.log.info('------------------------------------')

    # this method needs to be checked
    def set_template_path(self, tpath):
        self.installer.set_template_path(tpath)

    # this method needs to be checked
    # target should be set upon init.
    # need to remove apt-get update command
    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command('apt-get update'))

    # this method needs to be checked
    # this method doesn't belong in the profile installer
    # this is a machine installer method
    def install_kernel(self, package):
        os.system(self.command('touch /boot/vmlinuz-fake'))
        os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz'))
        os.system(self.command('apt-get -y install %s' % package))
        print 'kernel %s installed' % package

    # This helps reporting when when a trait is processed
    def append_installed_traits(self, trait):
        self._append_installed_traits_file(trait)
        self._append_installed_traits_db(trait)

    # this method needs to be checked
    # self.paelladir needs to be defined
    def _append_installed_traits_file(self, trait):
        itraits = file(join(self.paelladir, 'installed_traits'), 'a')
        itraits.write(trait + '\n')
        itraits.close()

    # this method needs to be checked
    def _append_installed_traits_db(self, trait):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            line = curenv['installed_traits']
            traits = [t.strip() for t in line.split(',')]
            traits.append(trait)
            curenv['installed_traits'] = ', '.join(traits)
Exemplo n.º 15
0
def get_profile_packages(conn, suite, profile):
    traits = get_traits(conn, profile)
    tp = TraitParent(conn, suite)
    pp = TraitPackage(conn, suite)
    packages = [p.package for p in pp.all_packages(traits, tp)]
    return packages
Exemplo n.º 16
0
class ProfileInstaller(BaseInstaller):
    # here parent is the chroot installer
    # The target needs to be set in the parent before
    # this class is initialized.
    def __init__(self, parent):
        BaseInstaller.__init__(self, parent.conn)
        self._parent = parent
        self.target = parent.target
        # we need this paelladir attribute for now
        # but may replace/redo this later
        self.paelladir = self.target / 'root/paella'
        self.profile = None
        self.suite = None
        self.profiletrait = ProfileTrait(self.conn)
        self._profile = Profile(self.conn)
        if False:
            # setup logfile
            if hasattr(parent, 'log'):
                self.log = parent.log
                self.log.info('profile installer initialized')
            else:
                raise RuntimeError, 'No logfile for parent defined'
        if hasattr(parent, 'mainlog'):
            self.mainlog = parent.mainlog
            name = self.__class__.__name__
            self.mainlog.add_logger(name)
            self.log = self.mainlog.loggers[name]
            
        # make empty data dicts
        self.mtypedata = {}
        self.familydata = {}
        self.profiledata = {}
        

    # this method is called within set_profile
    def _init_attributes(self):
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, self.profile)

    # this method is called within set_profile
    # here is where the trait installer is setup
    # the data attributes need to be filled before this is called
    # this method needs to be fixed to use the new trait installer
    def _setup_installer(self, suite):
        self.installer = TraitInstaller(self)
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.installer.mtypedata = self.mtypedata

    # here is where the processes are setup
    # every process is a trait and it maps to the same
    # function.  a "current_index" attribute keeps track
    # of which trait is being processed.
    def _setup_trait_processes(self, traitlist):
        self.setup_initial_paellainfo_env(traitlist)
        self._processes = traitlist
        self._process_map = {}.fromkeys(traitlist, self.process_trait)

    # setting the profile involves a lot of work
    # there are helper methods defined to help split
    # the code up into more manageable pieces.
    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ['PAELLA_PROFILE'] = profile
        self.profiletrait.set_profile(profile)
        self._init_attributes()
        self._setup_installer(self.suite)
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info('profile set to %s' % profile)
        traitlist = self.make_traitlist()
        self._setup_trait_processes(traitlist)

    # currently there is no script functionality
    # but there may be in the future.
    def make_script(self, procname):
        return None
     
    # this method needs to be checked
    def make_traitlist(self):
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        log = None
        return self._profile.make_traitlist_with_traits(listed, log=log)

    def get_profile_data(self):
        return self.env.ProfileData()
    
    # this method needs to be checked
    # self.paelladir needs to be defined
    def setup_initial_paellainfo_files(self, traits):
        makepaths(self.paelladir)
        traitlist = file(join(self.paelladir, 'traitlist'), 'w')
        for trait in traits:
            traitlist.write('%s\n' % trait)
        traitlist.close()
        itraits = file(join(self.paelladir, 'installed_traits'), 'w')
        itraits.write('Installed Traits:\n')
        itraits.close()

    # initialize data in current_environment,
    # if PAELLA_MACHINE is set
    def setup_initial_paellainfo_env(self, traits):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            curenv['current_profile'] = self.profile
            curenv['traitlist'] = ', '.join(traits)
            curenv['installed_traits'] = ''

            
    # this method has been rewritten to use
    # self.current_index
    # the UnbornError should never be raised
    def process_trait(self):
        trait = self._processes[self.current_index]
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info('processing trait %s' % trait)
        self.installer.run_all_processes()
        self.processed.append(trait)
        self.current_index += 1
        self.log.info('processed:  %s' % ', '.join(self.processed))
        self.append_installed_traits(trait)
        
    # this used to be called process
    def run_all_processes(self):
        traits = self.make_traitlist()
        self.setup_initial_paellainfo_files(traits)
        self.setup_initial_paellainfo_env(traits)
        self.processed = []
        self.current_index = 0
        BaseInstaller.run_all_processes(self)
        self.log.info('all traits processed for profile %s' % self.profile)
        self.log.info('------------------------------------')

    # this method needs to be checked
    def set_template_path(self, tpath):
        self.installer.set_template_path(tpath)

    # this method needs to be checked
    # target should be set upon init.
    # need to remove apt-get update command
    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command('apt-get update'))

    # this method needs to be checked
    # this method doesn't belong in the profile installer
    # this is a machine installer method
    def install_kernel(self, package):
        os.system(self.command('touch /boot/vmlinuz-fake'))
        os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz'))
        os.system(self.command('apt-get -y install %s' % package))
        print 'kernel %s installed' % package

    # This helps reporting when when a trait is processed
    def append_installed_traits(self, trait):
        self._append_installed_traits_file(trait)
        self._append_installed_traits_db(trait)
        
    # this method needs to be checked
    # self.paelladir needs to be defined
    def _append_installed_traits_file(self, trait):
        itraits = file(join(self.paelladir, 'installed_traits'), 'a')
        itraits.write(trait + '\n')
        itraits.close()

    # this method needs to be checked
    def _append_installed_traits_db(self, trait):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            line = curenv['installed_traits']
            traits = [t.strip() for t in line.split(',')]
            traits.append(trait)
            curenv['installed_traits'] = ', '.join(traits)
Exemplo n.º 17
0
 def __init__(self, conn, profile):
     self.suite = get_suite(conn, profile)
     self.profile = profile
     Environment.__init__(self, conn, 'profile_variables', 'trait')
     self.traitparent = TraitParent(self.conn, self.suite)
Exemplo n.º 18
0
class InstallerTools(object):
    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.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'])

    # this needs updating for machine type data
    def env(self):
        env = TemplatedEnvironment(self.tp.Environment())
        env.update(self.pr.get_family_data())
        env.update(self.pr.get_profile_data())
        return env

    def set_trait(self, trait):
        self.trait = trait
        self.tp.set_trait(trait)
        self.tr.set_trait(trait)
        self.parents = self.tr.parents()
        self._envv = self.env()
        tinstaller = self.installer.installer
        tinstaller.set_trait(trait)
        self.packages = tinstaller.traitpackage.packages()
        self.templates = tinstaller.traittemplate.templates()

    def get(self, key):
        if self._envv is None:
            raise Error, 'need to set trait first'
        return self._envv.dereference(key)

    def lget(self, key):
        key = '_'.join([self.trait, key])
        return self.get(key)

    def install_modules(self, name):
        modules = str2list(self.get(name))
        print 'installing modules', modules, 'to %s/etc/modules' % self.target
        setup_modules(self.target, modules)

    def remove_packages(self, packages=None):
        if packages is None:
            packages = self.packages
        if len(packages):
            if hasattr(packages[0], 'package'):
                packages = [p.package for p in packages]
        package_list = ' '.join(packages)
        command = 'apt-get -y remove %s' % package_list
        self.installer.run('remove', command, proc=True)

    def chroot_command(self, cmd):
        return 'chroot %s %s' % (self.target, cmd)
Exemplo n.º 19
0
class ProfileInstaller(Installer):
    def __init__(self, conn):
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
        Installer.__init__(self, conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.profile = None
        self.installer = None
        self._profile = Profile(self.conn)
        if hasattr(self, 'log'):
            self.log.info('profile installer initialized')
        else:
            self.set_logfile()
            self.log.info('profile installer initialized')
        self.mtypedata = {}
        
        
    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ['PAELLA_PROFILE'] = profile
        self.profiletrait.set_profile(profile)
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, profile)
        self.installer = TraitInstaller(self.conn, self.suite)
        self.installer.log = self.log
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.installer.mtypedata = self.mtypedata
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info('profile set to %s' % profile)
        traitlist = self.make_traitlist()
        self.setup_initial_paellainfo_env(traitlist)
        
    def get_profile_data(self):
        return self.env.ProfileData()
    
    def set_logpath(self, logpath):
        Installer.set_logpath(self, logpath)
        if hasattr(self, 'installer'):
            self.installer.set_logpath(logpath)
        
    def make_traitlist(self):
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        #log = self.log
        log = None
        return self._profile.make_traitlist_with_traits(listed, log=log)

    def setup_initial_paellainfo_files(self, traits):
        makepaths(self.paelladir)
        traitlist = file(join(self.paelladir, 'traitlist'), 'w')
        for trait in traits:
            traitlist.write('%s\n' % trait)
        traitlist.close()
        itraits = file(join(self.paelladir, 'installed_traits'), 'w')
        itraits.write('Installed Traits:\n')
        itraits.close()

    def setup_initial_paellainfo_env(self, traits):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            curenv['current_profile'] = self.profile
            curenv['traitlist'] = ', '.join(traits)
            curenv['installed_traits'] = ''
            
    def process(self):
        traits = self.make_traitlist()
        self.setup_initial_paellainfo_files(traits)
        self.setup_initial_paellainfo_env(traits)
        self.processed = []
        for trait in traits:
            self.process_trait(trait)
            self.log.info('currently processed %s' % ','.join(self.processed))
        self.log.info('all traits processed for profile %s' % self.profile)
        self.log.info('------------------------------------')
        
    def _append_installed_traits_file(self, trait):
        itraits = file(join(self.paelladir, 'installed_traits'), 'a')
        itraits.write(trait + '\n')
        itraits.close()

    def _append_installed_traits_db(self, trait):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            line = curenv['installed_traits']
            traits = [t.strip() for t in line.split(',')]
            traits.append(trait)
            curenv['installed_traits'] = ', '.join(traits)
            
            
        
    def process_trait(self, trait):
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info('processing trait %s' % trait)
        self.installer.process()
        self.processed.append(trait)
        self.log.info('processed:  %s' % ', '.join(self.processed))
        self.append_installed_traits(trait)

    def set_template_path(self, path):
        self.installer.set_template_path(path)

    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command('apt-get update'))

    def install_kernel(self, package):
        os.system(self.command('touch /boot/vmlinuz-fake'))
        os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz'))
        os.system(self.command('apt-get -y install %s' % package))
        print 'kernel %s installed' % package

    def append_installed_traits(self, trait):
        self._append_installed_traits_file(trait)
        self._append_installed_traits_db(trait)
Exemplo n.º 20
0
class ProfileInstaller(Installer):
    def __init__(self, conn):
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
        Installer.__init__(self, conn)
        self.profiletrait = ProfileTrait(self.conn)
        self.profile = None
        self.installer = None
        self._profile = Profile(self.conn)
        if hasattr(self, 'log'):
            self.log.info('profile installer initialized')
        else:
            self.set_logfile()
            self.log.info('profile installer initialized')
        self.mtypedata = {}

    def set_profile(self, profile):
        self.profile = profile
        self._profile.set_profile(profile)
        os.environ['PAELLA_PROFILE'] = profile
        self.profiletrait.set_profile(profile)
        self.traits = self.profiletrait.trait_rows()
        self.env = ProfileEnvironment(self.conn, self.profile)
        self.familydata = self._profile.get_family_data()
        self.profiledata = self._profile.get_profile_data()
        self.suite = get_suite(self.conn, profile)
        self.installer = TraitInstaller(self.conn, self.suite)
        self.installer.log = self.log
        self.installer.familydata = self.familydata
        self.installer.profiledata = self.profiledata
        self.installer.mtypedata = self.mtypedata
        self.traitparent = TraitParent(self.conn, self.suite)
        self.log.info('profile set to %s' % profile)
        traitlist = self.make_traitlist()
        self.setup_initial_paellainfo_env(traitlist)

    def get_profile_data(self):
        return self.env.ProfileData()

    def set_logpath(self, logpath):
        Installer.set_logpath(self, logpath)
        if hasattr(self, 'installer'):
            self.installer.set_logpath(logpath)

    def make_traitlist(self):
        listed = [x.trait for x in self.profiletrait.trait_rows()]
        #log = self.log
        log = None
        return self._profile.make_traitlist_with_traits(listed, log=log)

    def setup_initial_paellainfo_files(self, traits):
        makepaths(self.paelladir)
        traitlist = file(join(self.paelladir, 'traitlist'), 'w')
        for trait in traits:
            traitlist.write('%s\n' % trait)
        traitlist.close()
        itraits = file(join(self.paelladir, 'installed_traits'), 'w')
        itraits.write('Installed Traits:\n')
        itraits.close()

    def setup_initial_paellainfo_env(self, traits):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            curenv['current_profile'] = self.profile
            curenv['traitlist'] = ', '.join(traits)
            curenv['installed_traits'] = ''

    def process(self):
        traits = self.make_traitlist()
        self.setup_initial_paellainfo_files(traits)
        self.setup_initial_paellainfo_env(traits)
        self.processed = []
        for trait in traits:
            self.process_trait(trait)
            self.log.info('currently processed %s' % ','.join(self.processed))
        self.log.info('all traits processed for profile %s' % self.profile)
        self.log.info('------------------------------------')

    def _append_installed_traits_file(self, trait):
        itraits = file(join(self.paelladir, 'installed_traits'), 'a')
        itraits.write(trait + '\n')
        itraits.close()

    def _append_installed_traits_db(self, trait):
        if os.environ.has_key('PAELLA_MACHINE'):
            machine = os.environ['PAELLA_MACHINE']
            curenv = CurrentEnvironment(self.conn, machine)
            line = curenv['installed_traits']
            traits = [t.strip() for t in line.split(',')]
            traits.append(trait)
            curenv['installed_traits'] = ', '.join(traits)

    def process_trait(self, trait):
        self.traitparent.set_trait(trait)
        self.installer.set_trait(trait)
        parents = [r.parent for r in self.traitparent.parents()]
        for p in parents:
            if p not in self.processed:
                raise UnbornError
        self.log.info('processing trait %s' % trait)
        self.installer.process()
        self.processed.append(trait)
        self.log.info('processed:  %s' % ', '.join(self.processed))
        self.append_installed_traits(trait)

    def set_template_path(self, path):
        self.installer.set_template_path(path)

    def set_target(self, target, update=False):
        Installer.set_target(self, target)
        self.installer.set_target(target)
        if update:
            os.system(self.command('apt-get update'))

    def install_kernel(self, package):
        os.system(self.command('touch /boot/vmlinuz-fake'))
        os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz'))
        os.system(self.command('apt-get -y install %s' % package))
        print 'kernel %s installed' % package

    def append_installed_traits(self, trait):
        self._append_installed_traits_file(trait)
        self._append_installed_traits_db(trait)
Exemplo n.º 21
0
 def __init__(self, conn, profile):
     self.suite = get_suite(conn, profile)
     self.profile = profile
     Environment.__init__(self, conn, 'profile_variables', 'trait')
     self.traitparent = TraitParent(self.conn, self.suite)