Example #1
0
    def object_run(self, cdist_object):
        """Run gencode and code for an object"""
        try:
            self.log.verbose("Running object " + cdist_object.name)
            if cdist_object.state == core.CdistObject.STATE_DONE:
                raise cdist.Error(("Attempting to run an already finished "
                                   "object: %s"), cdist_object)

            # Generate
            self.log.debug("Generating code for %s" % (cdist_object.name))
            cdist_object.code_local = self.code.run_gencode_local(cdist_object)
            cdist_object.code_remote = self.code.run_gencode_remote(
                cdist_object)
            if cdist_object.code_local or cdist_object.code_remote:
                cdist_object.changed = True

            # Execute
            if cdist_object.code_local or cdist_object.code_remote:
                self.log.info("Processing %s" % (cdist_object.name))
            if not self.dry_run:
                if cdist_object.code_local:
                    self.log.trace("Executing local code for %s" %
                                   (cdist_object.name))
                    self.code.run_code_local(cdist_object)
                if cdist_object.code_remote:
                    self.log.trace("Executing remote code for %s" %
                                   (cdist_object.name))
                    self.code.transfer_code_remote(cdist_object)
                    self.code.run_code_remote(cdist_object)

            # Mark this object as done
            self.log.trace("Finishing run of " + cdist_object.name)
            cdist_object.state = core.CdistObject.STATE_DONE
        except cdist.Error as e:
            raise cdist.CdistObjectError(cdist_object, e)
Example #2
0
    def resolve_object_dependencies(self, cdist_object, resolved, unresolved):
        """Resolve all dependencies for the given cdist_object and store them
        in the list which is passed as the 'resolved' arguments.

        e.g.
        resolved = []
        unresolved = []
        resolve_object_dependencies(some_object, resolved, unresolved)
        print("Dependencies for %s: %s" % (some_object, resolved))
        """
        self.log.debug('Resolving dependencies for: %s' % cdist_object.name)
        try:
            unresolved.append(cdist_object)
            for required_object in self.find_requirements_by_name(
                    cdist_object.requirements):
                self.log.debug("Object %s requires %s", cdist_object,
                               required_object)
                if required_object not in resolved:
                    if required_object in unresolved:
                        raise CircularReferenceError(cdist_object,
                                                     required_object)
                    self.resolve_object_dependencies(required_object, resolved,
                                                     unresolved)
            resolved.append(cdist_object)
            unresolved.remove(cdist_object)
        except RequirementNotFoundError as e:
            raise cdist.CdistObjectError(
                cdist_object, "requires non-existing " + e.requirement)
Example #3
0
    def _iterate_once_sequential(self):
        self.log.debug("Iteration in sequential mode")
        objects_changed = False

        for cdist_object in self.object_list():
            try:
                if cdist_object.requirements_unfinished(
                        cdist_object.requirements):
                    """We cannot do anything for this poor object"""
                    continue

                if cdist_object.state == core.CdistObject.STATE_UNDEF:
                    """Prepare the virgin object"""

                    self.object_prepare(cdist_object)
                    objects_changed = True

                if cdist_object.requirements_unfinished(
                        cdist_object.autorequire):
                    """The previous step created objects we depend on -
                       wait for them
                    """
                    continue

                if cdist_object.state == core.CdistObject.STATE_PREPARED:
                    self.object_run(cdist_object)
                    objects_changed = True
            except cdist.Error as e:
                raise cdist.CdistObjectError(cdist_object, e)

        return objects_changed
Example #4
0
 def object_prepare(self, cdist_object, transfer_type_explorers=True):
     """Prepare object: Run type explorer + manifest"""
     try:
         self.log.verbose("Preparing object {}".format(cdist_object.name))
         self.log.verbose("Running manifest and explorers for " +
                          cdist_object.name)
         self.explorer.run_type_explorers(cdist_object,
                                          transfer_type_explorers)
         self.manifest.run_type_manifest(cdist_object)
         cdist_object.state = core.CdistObject.STATE_PREPARED
     except cdist.Error as e:
         raise cdist.CdistObjectError(cdist_object, e)
Example #5
0
 def object_prepare(self, cdist_object, transfer_type_explorers=True):
     """Prepare object: Run type explorer + manifest"""
     self._handle_deprecation(cdist_object)
     self.log.verbose("Preparing object {}".format(cdist_object.name))
     self.log.verbose("Running manifest and explorers for " +
                      cdist_object.name)
     self.explorer.run_type_explorers(cdist_object, transfer_type_explorers)
     try:
         self.manifest.run_type_manifest(cdist_object)
         self.log.trace("[ORDER_DEP] Removing order dep files for %s",
                        cdist_object)
         cdist_object.cleanup()
         cdist_object.state = core.CdistObject.STATE_PREPARED
     except cdist.Error as e:
         raise cdist.CdistObjectError(cdist_object, e)