def startwork(config=None, logger=None): """Main start """ fullURL = getFullUrl(config) agents = getDataFromSiteFE({}, fullURL, "/sitefe/json/frontend/ips") if agents[2] != 'OK': print 'Received a failure getting information from Site Frontend %s' % str( agents) return workDir = config.get('frontend', 'privatedir') + "/forwardingService/" createDirs(workDir) copy2("/etc/httpd/conf.d/sitefe-httpd.conf", str(workDir + "httpd-copy.conf")) httpdCopy = readFile(str(workDir + "httpd-copy.conf")) try: newDict = evaldict(agents[0]) except FailedToParseError as ex: print 'Server returned not a json loadable object. Raising error. Output %s. Errors: %s' % ( str(agents), ex) return if not newDict: print 'Seems server returned empty dictionary. Exiting.' return newOut, changed = prepareNewHTTPDConfig(newDict, httpdCopy) if changed: writeNewConfig(newOut, workDir) copy2(str(workDir + "httpd-new.conf"), "/etc/httpd/conf.d/sitefe-httpd.conf") stdout = externalCommand("service httpd restart") print stdout # Restart apache... return
def __init__(self, config, logger): self.config = config if config else getConfig() self.logger = logger if logger else getLogger( "%s/%s/" % (self.config.get('general', 'logDir'), COMPONENT), self.config.get('general', 'logLevel')) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== Debugger Start Work. Hostname: %s", self.hostname)
def __init__(self, config, logger): # You can call and use the DTNRM Libraries for getting configuration # or site frontend URL from configuration file, so that any information # is available at the plugin level self.config, self.logger = getDefaultConfigAgent(COMPONENT, config, logger) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/DTNRMPrint/" createDirs(self.workDir) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== DTNRMPrint Start Work at __init__. Hostname: %s", self.hostname) self.debug = self.config.getboolean('general', "debug")
def startwork(self): """Start Provisioning Service main worker.""" fullURL = getFullUrl(self.config, sitename=self.sitename) jOut = self.getData(fullURL, "/sitefe/json/frontend/getdata") workDir = self.config.get('general', 'privatedir') + "/ProvisioningService/" createDirs(workDir) if not jOut: self.logger.info( 'Seems server returned empty dictionary. Exiting.') return # Get switch information... switchPlugin = self.config.get(self.sitename, 'plugin') self.logger.info('Will load %s switch plugin' % switchPlugin) method = importlib.import_module( "SiteFE.ProvisioningService.Plugins.%s" % switchPlugin.lower()) switchruler = method.mainCaller() topology = method.topology() switches = topology.getTopology() alliases = self.getAllAliases(switches) outputDict = {} allDeltas = self.getData(fullURL, "/sitefe/v1/deltas?oldview=true") for switchName in list(list(switches['switches'].keys()) + alliases): newDeltas = self.checkdeltas(switchName, allDeltas) for newDelta in newDeltas: outputDict.setdefault(newDelta['ID']) for actionKey in ['reduction', 'addition']: try: newvlan = self.getnewvlan(newDelta, newDelta['ID'], switchName, actionKey) if actionKey == 'reduction' and newDelta[ 'ParsedDelta'][actionKey]: self.deltaRemoval(newDelta, newDelta['ID'], newvlan, switchName, switchruler, fullURL) elif actionKey == 'addition' and newDelta[ 'ParsedDelta'][actionKey]: if newDelta['State'] in ['cancel']: newDelta['ReductionID'] = newDelta['ID'] self.deltaRemoval(newDelta, newDelta['ID'], newvlan, switchName, switchruler, fullURL) else: self.deltaCommit(newDelta, newDelta['ID'], newvlan, switchName, switchruler, fullURL) else: self.logger.warning('Unknown delta state') pretty = pprint.PrettyPrinter(indent=4) pretty.pprint(evaldict(newDelta)) except IOError as ex: print(ex) raise Exception('Received IOError')
def __init__(self, config, logger): self.config = config if config else getConfig() self.logger = logger if logger else getLogger( "%s/%s/" % (self.config.get('general', 'logDir'), COMPONENT), self.config.get('general', 'logLevel')) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/RulerAgent/" createDirs(self.workDir) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.noRules = self.config.getboolean('agent', 'norules') self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== Ruler Start Work. Hostname: %s", self.hostname) self.vInterface = VInterfaces(self.config, self.logger)
def __init__(self, config, logger): self.config, self.logger = getDefaultConfigAgent(COMPONENT, config, logger) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/RulerAgent/" createDirs(self.workDir) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.noRules = False if self.config.has_option('agent', 'norules'): self.noRules = self.config.getboolean('agent', 'norules') self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== Ruler Start Work. Hostname: %s", self.hostname) self.debug = self.config.getboolean('general', "debug") self.pretty = pprint.PrettyPrinter(indent=4) self.agentdb = contentDB(logger=self.logger, config=self.config) self.vInterface = VInterfaces(self.config, self.logger) self.qosruler = QOS(self.config, self.logger)
def startWork(config=None, logger=None): """ Execute main script for DTN-RM Agent output preparation """ workDir = config.get('general', 'private_dir') + "/DTNRM/" createDirs(workDir) dic = prepareJsonOut(config, logger) fullUrl = getFullUrl(config) dic = appendConfig(config, dic) if config.getboolean('general', "debug"): pretty = pprint.PrettyPrinter(indent=4) logger.debug(pretty.pformat(dic)) agent = contentDB(logger=logger, config=config) agent.dumpFileContentAsJson(workDir + "/latest-out.json", dic) logger.info('Will try to publish information to SiteFE') fullUrl += '/sitefe' outVals = publishToSiteFE(dic, fullUrl, '/json/frontend/updatehost') if outVals[2] != 'OK' or outVals[1] != 200: if outVals[3]: publishToSiteFE(dic, fullUrl, '/json/frontend/addhost')