forked from ungleich-public/cdist
		
	remove some old code, merge run into deploy_and_cleanup
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								72fef03184
							
						
					
				
			
			
				commit
				
					
						a9ffa86b74
					
				
			
		
					 1 changed files with 5 additions and 75 deletions
				
			
		| 
						 | 
					@ -57,30 +57,18 @@ class ConfigInstall(object):
 | 
				
			||||||
            shutil.rmtree(destination)
 | 
					            shutil.rmtree(destination)
 | 
				
			||||||
        shutil.move(self.context.local.out_path, destination)
 | 
					        shutil.move(self.context.local.out_path, destination)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def deploy_and_cleanup(self):
 | 
					    def run(self):
 | 
				
			||||||
        """Do what is most often done: deploy & cleanup"""
 | 
					        """Do what is most often done: deploy & cleanup"""
 | 
				
			||||||
        start_time = time.time()
 | 
					        start_time = time.time()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Old Code
 | 
					 | 
				
			||||||
        #self.deploy_to()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # New Code
 | 
					 | 
				
			||||||
        self.run()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.cleanup()
 | 
					 | 
				
			||||||
        self.log.info("Finished successful run in %s seconds",
 | 
					 | 
				
			||||||
            time.time() - start_time)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ###################################################################### 
 | 
					 | 
				
			||||||
    # New code for running on object priority (not stage priority)
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def run(self):
 | 
					 | 
				
			||||||
        """The main runner"""
 | 
					 | 
				
			||||||
        self.explorer.run_global_explorers(self.context.local.global_explorer_out_path)
 | 
					        self.explorer.run_global_explorers(self.context.local.global_explorer_out_path)
 | 
				
			||||||
        self.manifest.run_initial_manifest(self.context.initial_manifest)
 | 
					        self.manifest.run_initial_manifest(self.context.initial_manifest)
 | 
				
			||||||
        self.iterate_until_finished()
 | 
					        self.iterate_until_finished()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.cleanup()
 | 
				
			||||||
 | 
					        self.log.info("Finished successful run in %s seconds", time.time() - start_time)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def object_list(self):
 | 
					    def object_list(self):
 | 
				
			||||||
        """Short name for object list retrieval"""
 | 
					        """Short name for object list retrieval"""
 | 
				
			||||||
        for cdist_object in core.CdistObject.list_objects(self.context.local.object_path,
 | 
					        for cdist_object in core.CdistObject.list_objects(self.context.local.object_path,
 | 
				
			||||||
| 
						 | 
					@ -141,10 +129,6 @@ class ConfigInstall(object):
 | 
				
			||||||
            raise cdist.Error("The requirements of the following objects could not be resolved: %s" %
 | 
					            raise cdist.Error("The requirements of the following objects could not be resolved: %s" %
 | 
				
			||||||
                ("; ".join(info_string)))
 | 
					                ("; ".join(info_string)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ###################################################################### 
 | 
					 | 
				
			||||||
    # Code required by both methods (which will stay)
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def object_run(self, cdist_object, dry_run=False):
 | 
					    def object_run(self, cdist_object, dry_run=False):
 | 
				
			||||||
        """Run gencode and code for an object"""
 | 
					        """Run gencode and code for an object"""
 | 
				
			||||||
        self.log.debug("Trying to run object " + cdist_object.name)
 | 
					        self.log.debug("Trying to run object " + cdist_object.name)
 | 
				
			||||||
| 
						 | 
					@ -171,57 +155,3 @@ class ConfigInstall(object):
 | 
				
			||||||
        # Mark this object as done
 | 
					        # Mark this object as done
 | 
				
			||||||
        self.log.debug("Finishing run of " + cdist_object.name)
 | 
					        self.log.debug("Finishing run of " + cdist_object.name)
 | 
				
			||||||
        cdist_object.state = core.CdistObject.STATE_DONE
 | 
					        cdist_object.state = core.CdistObject.STATE_DONE
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ###################################################################### 
 | 
					 | 
				
			||||||
    # Stages based code
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def deploy_to(self):
 | 
					 | 
				
			||||||
        """Mimic the old deploy to: Deploy to one host"""
 | 
					 | 
				
			||||||
        self.stage_prepare()
 | 
					 | 
				
			||||||
        self.stage_run()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def stage_prepare(self):
 | 
					 | 
				
			||||||
        """Do everything for a deploy, minus the actual code stage"""
 | 
					 | 
				
			||||||
        self.explorer.run_global_explorers(self.context.local.global_explorer_out_path)
 | 
					 | 
				
			||||||
        self.manifest.run_initial_manifest(self.context.initial_manifest)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.log.info("Running object manifests and type explorers")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Continue process until no new objects are created anymore
 | 
					 | 
				
			||||||
        new_objects_created = True
 | 
					 | 
				
			||||||
        while new_objects_created:
 | 
					 | 
				
			||||||
            new_objects_created = False
 | 
					 | 
				
			||||||
            for cdist_object in core.CdistObject.list_objects(self.context.local.object_path,
 | 
					 | 
				
			||||||
                                                         self.context.local.type_path):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if cdist_object.state == core.CdistObject.STATE_PREPARED:
 | 
					 | 
				
			||||||
                    self.log.debug("Skipping re-prepare of object %s", cdist_object)
 | 
					 | 
				
			||||||
                    continue
 | 
					 | 
				
			||||||
                else:
 | 
					 | 
				
			||||||
                    self.object_prepare(cdist_object)
 | 
					 | 
				
			||||||
                    new_objects_created = True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def object_prepare(self, cdist_object):
 | 
					 | 
				
			||||||
        """Prepare object: Run type explorer + manifest"""
 | 
					 | 
				
			||||||
        self.log.info("Running manifest and explorers for " + cdist_object.name)
 | 
					 | 
				
			||||||
        self.explorer.run_type_explorers(cdist_object)
 | 
					 | 
				
			||||||
        self.manifest.run_type_manifest(cdist_object)
 | 
					 | 
				
			||||||
        cdist_object.state = core.CdistObject.STATE_PREPARED
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def stage_run(self):
 | 
					 | 
				
			||||||
        """The final (and real) step of deployment"""
 | 
					 | 
				
			||||||
        self.log.info("Generating and executing code")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        objects = core.CdistObject.list_objects(
 | 
					 | 
				
			||||||
            self.context.local.object_path,
 | 
					 | 
				
			||||||
            self.context.local.type_path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        dependency_resolver = resolver.DependencyResolver(objects)
 | 
					 | 
				
			||||||
        self.log.debug(pprint.pformat(dependency_resolver.dependencies))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for cdist_object in dependency_resolver:
 | 
					 | 
				
			||||||
            self.log.debug("Run object: %s", cdist_object)
 | 
					 | 
				
			||||||
            self.object_run(cdist_object)
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue