コード例 #1
0
    def _load_sources(self, force_update):
        """ Load sources from the config """
        self.sentinels = set()
        cachefiles = set()

        for collection in list(Collection.collections.values()):
            cachefiles.update(collection.cachefiles)
            if not self.disableMetaData:
                collection.setup_data(force_update)
            self.sentinels.update(collection.basegroups)

        Collection.clear_cache()

        for source in self.sources:
            cachefiles.add(source.cachefile)
            if not self.disableMetaData:
                source.setup_data(force_update)

        for cfile in glob.glob(os.path.join(self.cachepath, "cache-*")):
            if cfile not in cachefiles:
                try:
                    if os.path.isdir(cfile):
                        shutil.rmtree(cfile)
                    else:
                        os.unlink(cfile)
                except OSError:
                    err = sys.exc_info()[1]
                    logger.error("Packages: Could not remove cache file %s: %s"
                                 % (cfile, err))
コード例 #2
0
ファイル: __init__.py プロジェクト: amplify-education/bcfg2
    def _load_sources(self, force_update):
        """ Load sources from the config """
        self.sentinels = set()
        cachefiles = set()

        for collection in list(Collection.collections.values()):
            cachefiles.update(collection.cachefiles)
            if not self.disableMetaData:
                collection.setup_data(force_update)
            self.sentinels.update(collection.basegroups)

        Collection.clear_cache()

        for source in self.sources:
            cachefiles.add(source.cachefile)
            if not self.disableMetaData:
                source.setup_data(force_update)

        for cfile in glob.glob(os.path.join(self.cachepath, "cache-*")):
            if cfile not in cachefiles:
                try:
                    if os.path.isdir(cfile):
                        shutil.rmtree(cfile)
                    else:
                        os.unlink(cfile)
                except OSError:
                    err = sys.exc_info()[1]
                    self.logger.error("Packages: Could not remove cache file "
                                      "%s: %s" % (cfile, err))
コード例 #3
0
ファイル: __init__.py プロジェクト: solj/bcfg2-old
    def create_config(self, entry, metadata):
        """ create yum/apt config for the specified host """
        attrib = {"encoding": "ascii", "owner": "root", "group": "root", "type": "file", "perms": "0644"}

        collection = Collection.factory(metadata, self.sources, self.data)
        entry.text = collection.get_config()
        for (key, value) in list(attrib.items()):
            entry.attrib.__setitem__(key, value)
コード例 #4
0
ファイル: __init__.py プロジェクト: mkdfh/bcfg2-dev
    def _build_packages(self,
                        metadata,
                        independent,
                        structures,
                        collection=None):
        """ build list of packages that need to be included in the
        specification by validate_structures() """
        if self.disableResolver:
            # Config requests no resolver
            return

        if collection is None:
            collection = Collection.factory(metadata, self.sources, self.data)
        # initial is the set of packages that are explicitly specified
        # in the configuration
        initial = set()
        # base is the set of initial packages with groups expanded
        base = set()
        to_remove = []
        for struct in structures:
            for pkg in struct.xpath('//Package | //BoundPackage'):
                if pkg.get("name"):
                    initial.add(pkg.get("name"))
                elif pkg.get("group"):
                    try:
                        if pkg.get("type"):
                            gpkgs = collection.get_group(pkg.get("group"),
                                                         ptype=pkg.get("type"))
                        else:
                            gpkgs = collection.get_group(pkg.get("group"))
                        base.update(gpkgs)
                    except TypeError:
                        raise
                        self.logger.error("Could not resolve group %s" %
                                          pkg.get("group"))
                    to_remove.append(pkg)
                else:
                    self.logger.error("Packages: Malformed Package: %s" %
                                      lxml.etree.tostring(pkg))
        base.update(initial)
        for el in to_remove:
            el.getparent().remove(el)

        packages, unknown = collection.complete(base)
        if unknown:
            self.logger.info("Packages: Got %d unknown entries" % len(unknown))
            self.logger.info("Packages: %s" % list(unknown))
        newpkgs = list(packages.difference(initial))
        self.logger.debug("Packages: %d initial, %d complete, %d new" %
                          (len(initial), len(packages), len(newpkgs)))
        newpkgs.sort()
        for pkg in newpkgs:
            lxml.etree.SubElement(independent,
                                  'BoundPackage',
                                  name=pkg,
                                  version='auto',
                                  type=collection.ptype,
                                  origin='Packages')
コード例 #5
0
ファイル: __init__.py プロジェクト: solj/bcfg2-old
    def validate_structures(self, metadata, structures):
        """Ensure client configurations include all needed prerequisites

        Arguments:
        metadata - client metadata instance
        structures - a list of structure-stage entry combinations
        """
        collection = Collection.factory(metadata, self.sources, self.data)
        indep = lxml.etree.Element("Independent")
        self._build_packages(metadata, indep, structures, collection=collection)
        collection.build_extra_structures(indep)
        structures.append(indep)
コード例 #6
0
    def create_config(self, entry, metadata):
        """ create yum/apt config for the specified host """
        attrib = {'encoding': 'ascii',
                  'owner': 'root',
                  'group': 'root',
                  'type': 'file',
                  'perms': '0644'}

        collection = Collection.factory(metadata, self.sources, self.data)
        entry.text = collection.get_config()
        for (key, value) in list(attrib.items()):
            entry.attrib.__setitem__(key, value)
コード例 #7
0
ファイル: __init__.py プロジェクト: jjneely/bcfg2-solj
    def create_config(self, entry, metadata):
        """ create yum/apt config for the specified host """
        attrib = {'encoding': 'ascii',
                  'owner': 'root',
                  'group': 'root',
                  'type': 'file',
                  'perms': '0644'}

        collection = Collection.factory(metadata, self.sources, self.data)
        entry.text = collection.get_config()
        for (key, value) in list(attrib.items()):
            entry.attrib.__setitem__(key, value)
コード例 #8
0
ファイル: __init__.py プロジェクト: jjneely/bcfg2-solj
    def _build_packages(self, metadata, independent, structures,
                        collection=None):
        """ build list of packages that need to be included in the
        specification by validate_structures() """
        if self.disableResolver:
            # Config requests no resolver
            return

        if collection is None:
            collection = Collection.factory(metadata, self.sources, self.data)
        # initial is the set of packages that are explicitly specified
        # in the configuration
        initial = set()
        # base is the set of initial packages with groups expanded
        base = set()
        to_remove = []
        for struct in structures:
            for pkg in struct.xpath('//Package | //BoundPackage'):
                if pkg.get("name"):
                    initial.add(pkg.get("name"))
                elif pkg.get("group"):
                    try:
                        if pkg.get("type"):
                            gpkgs = collection.get_group(pkg.get("group"),
                                                         ptype=pkg.get("type"))
                        else:
                            gpkgs = collection.get_group(pkg.get("group"))
                        base.update(gpkgs)
                    except TypeError:
                        raise
                        self.logger.error("Could not resolve group %s" %
                                          pkg.get("group"))
                    to_remove.append(pkg)
                else:
                    self.logger.error("Packages: Malformed Package: %s" %
                                      lxml.etree.tostring(pkg))
        base.update(initial)
        for el in to_remove:
            el.getparent().remove(el)

        packages, unknown = collection.complete(base)
        if unknown:
            self.logger.info("Packages: Got %d unknown entries" % len(unknown))
            self.logger.info("Packages: %s" % list(unknown))
        newpkgs = list(packages.difference(initial))
        self.logger.debug("Packages: %d initial, %d complete, %d new" %
                          (len(initial), len(packages), len(newpkgs)))
        newpkgs.sort()
        for pkg in newpkgs:
            lxml.etree.SubElement(independent, 'BoundPackage', name=pkg,
                                  version='auto', type=collection.ptype,
                                  origin='Packages')
コード例 #9
0
    def validate_structures(self, metadata, structures):
        '''Ensure client configurations include all needed prerequisites

        Arguments:
        metadata - client metadata instance
        structures - a list of structure-stage entry combinations
        '''
        collection = Collection.factory(metadata, self.sources, self.data)
        indep = lxml.etree.Element('Independent')
        self._build_packages(metadata, indep, structures,
                             collection=collection)
        collection.build_extra_structures(indep)
        structures.append(indep)
コード例 #10
0
ファイル: __init__.py プロジェクト: mkdfh/bcfg2-dev
 def HandleEntry(self, entry, metadata):
     if entry.tag == 'Package':
         collection = Collection.factory(metadata, self.sources, self.data)
         entry.set('version', 'auto')
         entry.set('type', collection.ptype)
     elif entry.tag == 'Path':
         if (self.config.has_section("global") and
             ((self.config.has_option("global", "yum_config") and
               entry.get("name") == self.config.get("global", "yum_config"))
              or (self.config.has_option("global", "apt_config")
                  and entry.get("name") == self.config.get(
                      "global", "apt_config")))):
             self.create_config(entry, metadata)
コード例 #11
0
 def HandlesEntry(self, entry, metadata):
     if entry.tag == 'Package':
         collection = Collection.factory(metadata, self.sources, self.data)
         if collection.magic_groups_match():
             return True
     elif entry.tag == 'Path':
         # managed entries for yum/apt configs
         if ((self.config.has_option("global", "yum_config") and
              entry.get("name") == self.config.get("global",
                                                   "yum_config")) or
             (self.config.has_option("global", "apt_config") and 
              entry.get("name") == self.config.get("global", "apt_config"))):
             return True
     return False
コード例 #12
0
ファイル: __init__.py プロジェクト: jjneely/bcfg2-solj
 def HandleEntry(self, entry, metadata):
     if entry.tag == 'Package':
         collection = Collection.factory(metadata, self.sources, self.data)
         entry.set('version', 'auto')
         entry.set('type', collection.ptype)
     elif entry.tag == 'Path':
         if (self.config.has_section("global") and
             ((self.config.has_option("global", "yum_config") and
               entry.get("name") == self.config.get("global",
                                                    "yum_config")) or
              (self.config.has_option("global", "apt_config") and 
               entry.get("name") == self.config.get("global",
                                                    "apt_config")))):
             self.create_config(entry, metadata)
コード例 #13
0
ファイル: __init__.py プロジェクト: jjneely/bcfg2-solj
 def HandlesEntry(self, entry, metadata):
     if entry.tag == 'Package':
         collection = Collection.factory(metadata, self.sources, self.data)
         if collection.magic_groups_match():
             return True
     elif entry.tag == 'Path':
         # managed entries for yum/apt configs
         if ((self.config.has_option("global", "yum_config") and
              entry.get("name") == self.config.get("global",
                                                   "yum_config")) or
             (self.config.has_option("global", "apt_config") and 
              entry.get("name") == self.config.get("global", "apt_config"))):
             return True
     return False
コード例 #14
0
ファイル: __init__.py プロジェクト: solj/bcfg2-old
 def HandleEntry(self, entry, metadata):
     if entry.tag == "Package":
         collection = Collection.factory(metadata, self.sources, self.data)
         entry.set("version", "auto")
         entry.set("type", collection.ptype)
     elif entry.tag == "Path":
         if self.config.has_section("global") and (
             (
                 self.config.has_option("global", "yum_config")
                 and entry.get("name") == self.config.get("global", "yum_config")
             )
             or (
                 self.config.has_option("global", "apt_config")
                 and entry.get("name") == self.config.get("global", "apt_config")
             )
         ):
             self.create_config(entry, metadata)
コード例 #15
0
 def get_additional_data(self, metadata):
     collection = Collection.factory(metadata, self.sources, self.data)
     return dict(sources=collection.get_additional_data())
コード例 #16
0
ファイル: __init__.py プロジェクト: solj/bcfg2-old
 def get_additional_data(self, metadata):
     collection = Collection.factory(metadata, self.sources, self.data)
     return dict(sources=collection.get_additional_data())
コード例 #17
0
ファイル: __init__.py プロジェクト: amplify-education/bcfg2
 def _get_collection(self, metadata):
     return Collection.factory(metadata, self.sources, self.data,
                               debug=self.debug_flag)
コード例 #18
0
 def _get_collection(self, metadata):
     return Collection.factory(metadata,
                               self.sources,
                               self.data,
                               debug=self.debug_flag)