Changeset 1202


Ignore:
Timestamp:
12/13/06 16:25:01 (6 years ago)
Author:
mglb1
Message:

Check network templates for service state in the same way that host templates
are checked and ignore templates relating to disabled or unknown services.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccsd/trunk/crcnetd/_utils/ccsd_cfengine.py

    r1199 r1202  
    4848from crcnetd._utils.ccsd_server import registerResource, exportViaXMLRPC, \ 
    4949        initThread, registerRecurring, suggestThreadpoolSize 
     50from crcnetd._utils.ccsd_service import getServiceInstance, ccs_service_error 
    5051 
    5152DEFAULT_MAX_THREADS = 10 
     
    293294    stats["planned"] = {} 
    294295    stats["generated"] = {} 
     296    stats["skipped"] = {} 
    295297    stats["initiated"] = time.time() 
    296298    stats["setupprogress"] = 10 
     
    314316    stats["planned"]["hosts"] = hosts 
    315317    stats["generated"]["hosts"] = {} 
    316      
     318    stats["skipped"]["hosts"] = {} 
     319 
    317320    # Work out how many host templates we're going to be generating 
    318321    total = 0 
     
    331334    stats["planned"]["total"] += len(stats["planned"]["network"]) 
    332335    stats["generated"]["network"] = {} 
    333          
     336    stats["skipped"]["network"] = {} 
     337 
    334338    # Aquire the lock to deal with statistics 
    335339    statsKey = token = createPassword(8) 
     
    499503            try: 
    500504                generated = _templateStats[statsKey]["generated"]["network"] 
     505                skipped = _templateStats[statsKey]["skipped"]["network"] 
    501506                for template in network: 
    502                     if not template in generated.keys(): 
    503                         continue 
    504                     # Check for errors 
    505                     if generated[template]["error"] != "": 
    506                         hasTemplateError = True 
     507                    if template in generated.keys(): 
     508                        # Check for errors 
     509                        if generated[template]["error"] != "": 
     510                            hasTemplateError = True 
     511                    else: 
     512                        if template not in skipped.keys(): 
     513                            continue 
    507514                    # Remove from the list 
    508515                    network.remove(template) 
     
    666673        template = _networkTemplates[template_id] 
    667674        t = eval("template.%s()" % template.templateName) 
     675        # Is it enabled? 
     676        if not t.enabledOnNetwork(networkData["session_id"]): 
     677            _statsLock.acquire() 
     678            try: 
     679                skipped = _templateStats[statsKey]["skipped"]["network"] 
     680                skipped[template_id] = True 
     681            finally: 
     682                _statsLock.release() 
     683            _threadLimit.release() 
     684            return 
    668685        # Set up the variables we want to substitute in 
    669686        t._searchList = [networkData] 
     
    789806        return host.hasServiceEnabledByName(serviceName) 
    790807 
     808    def enabledOnNetwork(self, session_id): 
     809        """Returns true if the template is able to be processed 
     810 
     811        By default this method looks to see if the template has defined a  
     812        serviceName parameter. If it has then the function checks to see if 
     813        that service is enabled. If it is not the function returns False.  
     814         
     815        This function may be overriden by other classes/templates if you want 
     816        to implement more logic than the default implementation provides. 
     817        """ 
     818        serviceName = getattr(self, "serviceName", None) 
     819        if serviceName is None: 
     820            return True 
     821 
     822        try: 
     823            service = getServiceInstance(session_id, serviceName) 
     824        except ccs_service_error: 
     825            # Named service not known 
     826            return False 
     827        return service.getState() 
     828 
    791829    def getTemplateVariables(self): 
    792830        """Returns a dictionary of variables that can be used by the template 
     
    913951        session.begin("Moved SSH keys due to host rename from %s => %s" %  
    914952                (old_name, host["host_name"])) 
    915         print "started revision" 
    916953        commit = 1 
    917954 
     
    940977    # Commit changeset if necessary 
    941978    if commit==1: 
    942         print "committing revision" 
    943979        session.commit() 
    944980         
     
    12591295    # PHP sends in an associative array we want the values only 
    12601296    hosts = hosts.values() 
    1261     print hosts 
    12621297 
    12631298    # Loop through the specified hosts and mark them as pending 
Note: See TracChangeset for help on using the changeset viewer.