From ac6786141feadccdc48b819ab21a825a54881ded Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 19 Jun 2015 17:10:16 +0200 Subject: [PATCH] spaces after comma --- bwmon.py | 6 ++-- conf_files.py | 10 +++--- config.py | 4 +-- coresched_lxc.py | 12 +++---- coresched_vs.py | 17 ++++----- curlwrapper.py | 8 ++--- database.py | 4 +-- initscript.py | 4 +-- logger.py | 30 ++++++++-------- net.py | 4 +-- nodemanager.py | 14 ++++---- plugins/codemux.py | 6 ++-- plugins/drl.py | 2 +- plugins/hostmap.py | 2 +- plugins/interfaces.py | 6 ++-- plugins/ipv6.py | 6 ++-- plugins/omf_resctl.py | 28 +++++++-------- plugins/privatebridge.py | 20 +++++------ plugins/rawdisk.py | 4 +-- plugins/reservation.py | 52 ++++++++++++++-------------- plugins/sliverauth.py | 18 +++++----- plugins/specialaccounts.py | 12 +++---- plugins/syndicate.py | 2 +- plugins/update_ipv6addr_slivertag.py | 16 ++++----- plugins/vsys.py | 19 +++++----- plugins/vsys_privs.py | 36 +++++++++---------- plugins/vsys_sysctl.py | 8 ++--- slivermanager.py | 7 ++-- 28 files changed, 179 insertions(+), 178 deletions(-) diff --git a/bwmon.py b/bwmon.py index f4c0133..476ef6d 100644 --- a/bwmon.py +++ b/bwmon.py @@ -482,8 +482,8 @@ def sync(nmdbcopy): period, \ default_MaxRate, \ default_Maxi2Rate, \ - default_MaxKByte,\ - default_Maxi2KByte,\ + default_MaxKByte, \ + default_Maxi2KByte, \ default_Share, \ dev_default @@ -656,7 +656,7 @@ def sync(nmdbcopy): # Update byte counts slice.update(kernelhtbs[xid], live[xid]['_rspec']) - logger.verbose("bwmon: Saving %s slices in %s" % (slices.keys().__len__(),DB_FILE)) + logger.verbose("bwmon: Saving %s slices in %s" % (slices.keys().__len__(), DB_FILE)) f = open(DB_FILE, "w") pickle.dump((version, slices, deaddb), f) f.close() diff --git a/conf_files.py b/conf_files.py index fcc3b7d..a5b2cb2 100644 --- a/conf_files.py +++ b/conf_files.py @@ -45,12 +45,12 @@ class conf_files: try: uid = pwd.getpwnam(cf_rec['file_owner'])[2] except: - logger.log('conf_files: cannot find user %s -- %s not updated'%(cf_rec['file_owner'],dest)) + logger.log('conf_files: cannot find user %s -- %s not updated'%(cf_rec['file_owner'], dest)) return try: gid = grp.getgrnam(cf_rec['file_group'])[2] except: - logger.log('conf_files: cannot find group %s -- %s not updated'%(cf_rec['file_group'],dest)) + logger.log('conf_files: cannot find group %s -- %s not updated'%(cf_rec['file_group'], dest)) return url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source']) # set node_id at the end of the request - hacky @@ -63,7 +63,7 @@ class conf_files: try: logger.verbose("conf_files: retrieving URL=%s"%url) contents = curlwrapper.retrieve(url, self.config.cacert) - except xmlrpclib.ProtocolError,e: + except xmlrpclib.ProtocolError as e: logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url)) return if not cf_rec['always_update'] and sha(contents).digest() == self.checksum(dest): @@ -74,7 +74,7 @@ class conf_files: logger.log('conf_files: installing file %s from %s' % (dest, url)) try: os.makedirs(os.path.dirname(dest)) except OSError: pass - tools.write_file(dest, lambda f: f.write(contents), mode=mode, uidgid=(uid,gid)) + tools.write_file(dest, lambda f: f.write(contents), mode=mode, uidgid=(uid, gid)) if self.system(cf_rec['postinstall_cmd']): self.system(err_cmd) def run_once(self, data): @@ -83,7 +83,7 @@ class conf_files: try: self.update_conf_file(f) except: logger.log_exc("conf_files: failed to update conf_file") else: - logger.log_missing_data("conf_files.run_once",'conf_files') + logger.log_missing_data("conf_files.run_once", 'conf_files') def start(): pass diff --git a/config.py b/config.py index cfc35f8..98bb224 100644 --- a/config.py +++ b/config.py @@ -42,6 +42,6 @@ class Config: if __name__ == '__main__': from pprint import pprint - for (k,v) in Config().__dict__.iteritems(): + for (k, v) in Config().__dict__.iteritems(): if k not in ['__builtins__']: - pprint ( (k,v), ) + pprint ( (k, v), ) diff --git a/coresched_lxc.py b/coresched_lxc.py index a6aef79..aba6cb6 100644 --- a/coresched_lxc.py +++ b/coresched_lxc.py @@ -185,7 +185,7 @@ class CoreSched: lastCpu = cpu logger.log("CoreSched: allocating unit " + str(cpu) + " to slice " + name) - reservations[name] = reservations.get(name,[]) + [cpu] + reservations[name] = reservations.get(name, []) + [cpu] # now find a memory node to go with the cpu if memSchedule: @@ -193,7 +193,7 @@ class CoreSched: if mem != None: mems.remove(mem) logger.log("CoreSched: allocating memory node " + str(mem) + " to slice " + name) - mem_reservations[name] = mem_reservations.get(name,[]) + [mem] + mem_reservations[name] = mem_reservations.get(name, []) + [mem] else: logger.log("CoreSched: failed to find memory node for cpu" + str(cpu)) @@ -226,9 +226,9 @@ class CoreSched: # note that if a reservation is [], then we don't need to add # bestEffort cores to it, since it is bestEffort by default. - if reservations.get(name,[]) != []: + if reservations.get(name, []) != []: reservations[name] = reservations[name] + reservations["_default"] - mem_reservations[name] = mem_reservations.get(name,[]) + mem_reservations["_default"] + mem_reservations[name] = mem_reservations.get(name, []) + mem_reservations["_default"] logger.log("CoreSched: adding besteffort units to " + name + ". new units = " + str(reservations[name])) self.reserveUnits(self.cgroup_var_name, reservations) @@ -397,12 +397,12 @@ if __name__=="__main__": print "cpus:", x.listToRange(x.get_cpus()) print "sibling map:" for item in x.get_cpus(): - print " ", item, ",".join([str(y) for y in x.cpu_siblings.get(item,[])]) + print " ", item, ",".join([str(y) for y in x.cpu_siblings.get(item, [])]) print "mems:", x.listToRange(x.get_mems()) print "cpu to memory map:" for item in x.get_mems(): - print " ", item, ",".join([str(y) for y in x.mems_map.get(item,[])]) + print " ", item, ",".join([str(y) for y in x.mems_map.get(item, [])]) rspec_sl_test1 = {"cpu_cores": "1"} rec_sl_test1 = {"_rspec": rspec_sl_test1} diff --git a/coresched_vs.py b/coresched_vs.py index 774eb30..06aeb54 100644 --- a/coresched_vs.py +++ b/coresched_vs.py @@ -173,7 +173,7 @@ class CoreSched: lastCpu = cpu logger.log("CoreSched: allocating unit " + str(cpu) + " to slice " + name) - reservations[name] = reservations.get(name,[]) + [cpu] + reservations[name] = reservations.get(name, []) + [cpu] # now find a memory node to go with the cpu if memSchedule: @@ -181,7 +181,7 @@ class CoreSched: if mem != None: mems.remove(mem) logger.log("CoreSched: allocating memory node " + str(mem) + " to slice " + name) - mem_reservations[name] = mem_reservations.get(name,[]) + [mem] + mem_reservations[name] = mem_reservations.get(name, []) + [mem] else: logger.log("CoreSched: failed to find memory node for cpu" + str(cpu)) @@ -206,9 +206,9 @@ class CoreSched: # note that if a reservation is [], then we don't need to add # bestEffort cores to it, since it is bestEffort by default. - if reservations.get(name,[]) != []: + if reservations.get(name, []) != []: reservations[name] = reservations[name] + reservations["_default"] - mem_reservations[name] = mem_reservations.get(name,[]) + mem_reservations["_default"] + mem_reservations[name] = mem_reservations.get(name, []) + mem_reservations["_default"] logger.log("CoreSched: adding besteffort units to " + name + ". new units = " + str(reservations[name])) self.reserveUnits(self.cgroup_var_name, reservations) @@ -295,7 +295,7 @@ class CoreSched: if mems_map[self.mems[0]] == []: work = [] for item in reversed(self.mems): - if mems_map[item]!=[]: + if mems_map[item] != []: work = mems_map[item] else: # mems_map[item]==[] mems_map[item] = work @@ -332,7 +332,8 @@ class CoreSched: return [] siblings = [] - x = int(open(fn,"rt").readline().strip(),16) + with open(fn, "rt") as f: + x = int(f.readline().strip(), 16) cpuid = 0 while (x>0): if (x&1)!=0: @@ -354,12 +355,12 @@ if __name__=="__main__": print "cpus:", x.listToRange(x.get_cpus()) print "sibling map:" for item in x.get_cpus(): - print " ", item, ",".join([str(y) for y in x.cpu_siblings.get(item,[])]) + print " ", item, ",".join([str(y) for y in x.cpu_siblings.get(item, [])]) print "mems:", x.listToRange(x.get_mems()) print "cpu to memory map:" for item in x.get_mems(): - print " ", item, ",".join([str(y) for y in x.mems_map.get(item,[])]) + print " ", item, ",".join([str(y) for y in x.mems_map.get(item, [])]) rspec_sl_test1 = {"cpu_cores": "1"} rec_sl_test1 = {"_rspec": rspec_sl_test1} diff --git a/curlwrapper.py b/curlwrapper.py index 08223e3..4383a70 100644 --- a/curlwrapper.py +++ b/curlwrapper.py @@ -28,14 +28,14 @@ def retrieve(url, cacert=None, postdata=None, timeout=90): if timeout: command += ('--max-time', str(timeout)) command += ('--connect-timeout', str(timeout)) - command += (url,) + command += (url, ) if verbose: - print 'Invoking ',command - if postdata: print 'with postdata=',postdata + print 'Invoking ', command + if postdata: print 'with postdata=', postdata p = Sopen(command , stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) if postdata: p.stdin.write(postdata) p.stdin.close() - sout, sin, serr = select([p.stdout,p.stderr],[],[], timeout) + sout, sin, serr = select([p.stdout, p.stderr], [], [], timeout) if len(sout) == 0 and len(sin) == 0 and len(serr) == 0: logger.verbose("curlwrapper: timed out after %s" % timeout) p.kill(signal.SIGKILL) diff --git a/database.py b/database.py index 2c4dc49..0680b6c 100644 --- a/database.py +++ b/database.py @@ -143,7 +143,7 @@ It may be necessary in the future to do something smarter.""" # we still need the other ones to be handled try: sliver = account.get(name) - logger.verbose("database: sync : looping on %s (shell account class from pwd %s)" %(name,sliver._get_class())) + logger.verbose("database: sync : looping on %s (shell account class from pwd %s)" %(name, sliver._get_class())) # Make sure we refresh accounts that are running if rec['instantiation'] == 'plc-instantiated': logger.verbose ("database: sync : ensure_create'ing 'instantiation' sliver %s"%name) @@ -161,7 +161,7 @@ It may be necessary in the future to do something smarter.""" except SystemExit as e: sys.exit(e) except: - logger.log_exc("database: sync failed to handle sliver",name=name) + logger.log_exc("database: sync failed to handle sliver", name=name) # Wake up bwmom to update limits. bwmon.lock.set() diff --git a/initscript.py b/initscript.py index a25e06a..d02fad4 100644 --- a/initscript.py +++ b/initscript.py @@ -62,7 +62,7 @@ class Initscript: # create symlink for runlevel 3 if not os.path.islink(enable_link): try: - logger.log("Initscript: %s: creating runlevel3 symlink %s" % (self.name,enable_link)) + logger.log("Initscript: %s: creating runlevel3 symlink %s" % (self.name, enable_link)) os.symlink(enable_target, enable_link) except: logger.log_exc("Initscript failed to create runlevel3 symlink %s" % enable_link, name=self.name) @@ -105,4 +105,4 @@ class Initscript: logger.log("Initscript: %s: creating enabling symlink %s" % (self.name, enable_link)) os.symlink(enable_target, enable_link) except: - logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link,name=name) + logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link, name=name) diff --git a/logger.py b/logger.py index 767a04e..796064f 100644 --- a/logger.py +++ b/logger.py @@ -69,24 +69,24 @@ def log_trace(msg="", name=None): # for some reason the various modules are still triggered even when the # data from PLC cannot be reached # we show this message instead of the exception stack instead in this case -def log_missing_data(msg,key): - log("%s: could not find the %s key in data (PLC connection down?) - IGNORED"%(msg,key)) +def log_missing_data(msg, key): + log("%s: could not find the %s key in data (PLC connection down?) - IGNORED"%(msg, key)) -def log_data_in_file(data, file, message="",level=LOG_NODE): +def log_data_in_file(data, file, message="", level=LOG_NODE): if level > LOG_LEVEL: return import pprint, time try: - f=open(file,'w') - now=time.strftime("Last update: %Y.%m.%d at %H:%M:%S %Z", time.localtime()) - f.write(now+'\n') - if message: f.write('Message:'+message+'\n') - pp=pprint.PrettyPrinter(stream=f,indent=2) - pp.pprint(data) - f.close() - verbose("logger:.log_data_in_file Owerwrote %s"%file) + with open(file, 'w') as f: + now=time.strftime("Last update: %Y.%m.%d at %H:%M:%S %Z", time.localtime()) + f.write(now+'\n') + if message: f.write('Message:'+message+'\n') + pp=pprint.PrettyPrinter(stream=f, indent=2) + pp.pprint(data) + f.close() + verbose("logger:.log_data_in_file Owerwrote %s"%file) except: - log_exc('logger.log_data_in_file failed - file=%s - message=%r'%(file,message)) + log_exc('logger.log_data_in_file failed - file=%s - message=%r'%(file, message)) def log_slivers(data): log_data_in_file(data, LOG_SLIVERS, "raw GetSlivers") @@ -102,7 +102,7 @@ class Buffer: self.buffer = '' self.message = message - def add(self,c): + def add(self, c): self.buffer += c if c=='\n': self.flush() @@ -144,13 +144,13 @@ def log_call(command, timeout=default_timeout_minutes*60, poll=1): break # child has failed else: - log("log_call:end command (%s) returned with code %d" %(message,returncode)) + log("log_call:end command (%s) returned with code %d" %(message, returncode)) break # no : still within timeout ? if time.time() >= trigger: buffer.flush() child.terminate() - log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message,timeout)) + log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message, timeout)) break except: log_exc("failed to run command %s" % message) diff --git a/net.py b/net.py index b962864..23a13b6 100644 --- a/net.py +++ b/net.py @@ -30,10 +30,10 @@ def GetSlivers(data, config, plc): if not 'interfaces' in data: # added by caglar # band-aid for short period as old API returns networks instead of interfaces - # logger.log_missing_data('net.GetSlivers','interfaces') + # logger.log_missing_data('net.GetSlivers', 'interfaces') # return if not 'networks' in data: - logger.log_missing_data('net.GetSlivers','interfaces') + logger.log_missing_data('net.GetSlivers', 'interfaces') return else: KEY_NAME = "networks" diff --git a/nodemanager.py b/nodemanager.py index d397a4b..78a6d1a 100755 --- a/nodemanager.py +++ b/nodemanager.py @@ -77,7 +77,7 @@ class NodeManager: if os.path.exists(self.options.path): sys.path.append(self.options.path) plugins = [ os.path.split(os.path.splitext(x)[0])[1] - for x in glob.glob( os.path.join(self.options.path,'*.py') ) + for x in glob.glob( os.path.join(self.options.path, '*.py') ) if not x.endswith("/__init__.py") ] self.modules += plugins @@ -116,7 +116,7 @@ class NodeManager: try: callback = getattr(module, 'GetSlivers') module_data = data - if getattr(module,'persistent_data',False): + if getattr(module, 'persistent_data', False): module_data = last_data callback(data, config, plc) except SystemExit as e: @@ -157,7 +157,7 @@ class NodeManager: if att['tagname'] == 'vref': att['value'] = slicefamily continue - sliver['attributes'].append({ 'tagname':'vref','value':slicefamily}) + sliver['attributes'].append({ 'tagname':'vref', 'value':slicefamily}) except: logger.log_exc("nodemanager: Could not overwrite 'vref' attribute from 'GetSliceFamily'", name=sliver['name']) @@ -222,7 +222,7 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth # sort on priority (lower first) def module_priority (m): - return getattr(m,'priority',NodeManager.default_priority) + return getattr(m, 'priority', NodeManager.default_priority) self.loaded_modules.sort(key=module_priority) logger.log('ordered modules:') @@ -251,7 +251,7 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") - except Exception,e: + except Exception as e: logger.log("nodemanager: Retry Failed. ({}); Waiting..".format(e)) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") @@ -263,11 +263,11 @@ If this is not the case, please remove the pid file {}. -- exiting""".format(oth logger.log('nodemanager: mainloop - calling GetSlivers - period={} random={}' .format(iperiod, irandom)) self.GetSlivers(config, plc) - delay = iperiod + random.randrange(0,irandom) + delay = iperiod + random.randrange(0, irandom) work_end = time.time() work_duration = int(work_end-work_beg) logger.log('nodemanager: mainloop has worked for {} s - sleeping for {} s' - .format(work_duration,delay)) + .format(work_duration, delay)) time.sleep(delay) except SystemExit: pass diff --git a/plugins/codemux.py b/plugins/codemux.py index af7fb58..b25b703 100644 --- a/plugins/codemux.py +++ b/plugins/codemux.py @@ -62,7 +62,7 @@ def GetSlivers(data, config, plc = None): _writeconf = True # Add to dict of codemuxslices. Make list to support more than one # codemuxed host per slice. - codemuxslices.setdefault(sliver['name'],[]) + codemuxslices.setdefault(sliver['name'], []) codemuxslices[sliver['name']].append(params) except: logger.log("codemux: sliver %s not running yet. Deferring."\ @@ -153,9 +153,9 @@ def restartService(): if not os.path.exists("/etc/init.d/codemux"): return logger.log("codemux: Restarting codemux service") if isRunning(): - logger.log_call(["/etc/init.d/codemux","condrestart", ]) + logger.log_call(["/etc/init.d/codemux", "condrestart", ]) else: - logger.log_call(["/etc/init.d/codemux","restart", ]) + logger.log_call(["/etc/init.d/codemux", "restart", ]) def startService(): if not os.path.exists("/etc/init.d/codemux"): return diff --git a/plugins/drl.py b/plugins/drl.py index 0e33833..bfacd5b 100644 --- a/plugins/drl.py +++ b/plugins/drl.py @@ -67,7 +67,7 @@ def GetSlivers(data, conf = None, plc = None): node_id = tools.node_id() if 'slivers' not in data: - logger.log_missing_data("drl.GetSlivers",'slivers') + logger.log_missing_data("drl.GetSlivers", 'slivers') return for sliver in data['slivers']: diff --git a/plugins/hostmap.py b/plugins/hostmap.py index c6829cb..7f47afd 100644 --- a/plugins/hostmap.py +++ b/plugins/hostmap.py @@ -30,7 +30,7 @@ SUFFIX = "# ----- End -----" def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: - logger.log_missing_data("hostmap.GetSlivers",'slivers') + logger.log_missing_data("hostmap.GetSlivers", 'slivers') return if 'hostname' not in data: diff --git a/plugins/interfaces.py b/plugins/interfaces.py index 6927b23..bc24b4e 100644 --- a/plugins/interfaces.py +++ b/plugins/interfaces.py @@ -26,7 +26,7 @@ def start(): def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: - logger.log_missing_data("interfaces.GetSlivers",'slivers') + logger.log_missing_data("interfaces.GetSlivers", 'slivers') return for sliver in data['slivers']: @@ -43,7 +43,7 @@ def GetSlivers(data, config=None, plc=None): if tag['tagname'] == 'interface': interfaces = eval(tag['value']) - if not isinstance(interfaces, (list,tuple)): + if not isinstance(interfaces, (list, tuple)): # if interface is not a list, then make it into a singleton list interfaces = [interfaces] @@ -55,7 +55,7 @@ def GetSlivers(data, config=None, plc=None): url = mydict['url'] try: contents = curlwrapper.retrieve(url) - except xmlrpclib.ProtocolError,e: + except xmlrpclib.ProtocolError as e: logger.log('interfaces (%s): failed to retrieve %s' % (slicename, url)) continue else: diff --git a/plugins/ipv6.py b/plugins/ipv6.py index a4fb4c2..28e138f 100644 --- a/plugins/ipv6.py +++ b/plugins/ipv6.py @@ -193,7 +193,7 @@ interface virbr0 }; """ % locals() - with open(radvd_conf_file,'w') as f: + with open(radvd_conf_file, 'w') as f: f.write(configRadvd) kill_radvd() start_radvd() @@ -250,7 +250,7 @@ def GetSlivers(data, config, plc): valid_prefix = False else: valid_prefix = False - #logger.log("ipv6: '%s'=%s" % (sliversipv6prefixtag,ipv6addr) ) + #logger.log("ipv6: '%s'=%s" % (sliversipv6prefixtag, ipv6addr) ) valid_ipv6 = tools.is_valid_ipv6(ipv6addr) if not(valid_ipv6): logger.log("ipv6: the 'sliversipv6prefix' tag presented a non-valid IPv6 address!") @@ -277,7 +277,7 @@ def GetSlivers(data, config, plc): tools.reboot_slivers() else: logger.log("ipv6: starting to redefine the virtual network...") - #network_elem = buildLibvirtDefaultNetConfig(dom,ipv6addr,prefix) + #network_elem = buildLibvirtDefaultNetConfig(dom, ipv6addr, prefix) network_elem = add_ipv6(dom, ipv6addr, prefix) set_up(networkLibvirt, connLibvirt, network_elem, ipv6addr, prefix) logger.log("ipv6: trying to reboot the slivers...") diff --git a/plugins/omf_resctl.py b/plugins/omf_resctl.py index 4f6d5b1..d893687 100644 --- a/plugins/omf_resctl.py +++ b/plugins/omf_resctl.py @@ -54,20 +54,20 @@ omf_rc_trigger_log="/var/log/plc_trigger_omf_rc.log" # hopefully temporary: when trigger script is missing, fetch it at the url here omf_rc_trigger_url="http://git.mytestbed.net/?p=omf.git;a=blob_plain;f=omf_rc/bin/plc_trigger_omf_rc;hb=HEAD" def fetch_trigger_script_if_missing (slicename): - full_path="/vservers/%s/%s"%(slicename,omf_rc_trigger_script) + full_path="/vservers/%s/%s"%(slicename, omf_rc_trigger_script) if not os.path.isfile (full_path): - retcod=subprocess.call (['curl','--silent','-o',full_path,omf_rc_trigger_url]) + retcod=subprocess.call (['curl', '--silent', '-o', full_path, omf_rc_trigger_url]) if retcod!=0: logger.log("Could not fetch %s"%omf_rc_trigger_url) else: - subprocess.call(['chmod','+x',full_path]) + subprocess.call(['chmod', '+x', full_path]) logger.log("omf_resctl: fetched %s"%(full_path)) logger.log("omf_resctl: from %s"%(omf_rc_trigger_url)) def GetSlivers(data, conf = None, plc = None): logger.log("omf_resctl.GetSlivers") if 'accounts' not in data: - logger.log_missing_data("omf_resctl.GetSlivers",'accounts') + logger.log_missing_data("omf_resctl.GetSlivers", 'accounts') return try: @@ -93,18 +93,18 @@ def GetSlivers(data, conf = None, plc = None): expires=str(sliver['expires']) yaml_template = config_ple_template yaml_contents = yaml_template\ - .replace('_xmpp_server_',xmpp_server)\ - .replace('_slicename_',slicename)\ - .replace('_hostname_',hostname)\ - .replace('_expires_',expires) - yaml_full_path="/vservers/%s/%s"%(slicename,yaml_slice_path) + .replace('_xmpp_server_', xmpp_server)\ + .replace('_slicename_', slicename)\ + .replace('_hostname_', hostname)\ + .replace('_expires_', expires) + yaml_full_path="/vservers/%s/%s"%(slicename, yaml_slice_path) yaml_full_dir=os.path.dirname(yaml_full_path) if not os.path.isdir(yaml_full_dir): try: os.makedirs(yaml_full_dir) except OSError: pass - config_changes=tools.replace_file_with_string(yaml_full_path,yaml_contents) - logger.log("yaml_contents length=%d, config_changes=%r"%(len(yaml_contents),config_changes)) + config_changes=tools.replace_file_with_string(yaml_full_path, yaml_contents) + logger.log("yaml_contents length=%d, config_changes=%r"%(len(yaml_contents), config_changes)) # would make sense to also check for changes to authorized_keys # would require saving a copy of that some place for comparison # xxx todo @@ -118,12 +118,12 @@ def GetSlivers(data, conf = None, plc = None): # hence sudo -i slice_command = [ "sudo", "-i", omf_rc_trigger_script ] to_run = tools.command_in_slice (slicename, slice_command) - log_filename = "/vservers/%s/%s"%(slicename,omf_rc_trigger_log) + log_filename = "/vservers/%s/%s"%(slicename, omf_rc_trigger_log) logger.log("omf_resctl: starting %s"%to_run) logger.log("redirected into %s"%log_filename) logger.log("*not* waiting for completion..") - with open(log_filename,"a") as log_file: - subprocess.Popen(to_run, stdout=log_file,stderr=subprocess.STDOUT) + with open(log_filename, "a") as log_file: + subprocess.Popen(to_run, stdout=log_file, stderr=subprocess.STDOUT) # a first version tried to 'communicate' on that subprocess instance # but that tended to create deadlocks in some cases # causing nodemanager to stall... diff --git a/plugins/privatebridge.py b/plugins/privatebridge.py index 72bff53..5ec15b9 100644 --- a/plugins/privatebridge.py +++ b/plugins/privatebridge.py @@ -24,7 +24,7 @@ class OvsException (Exception) : def start(): logger.log('private bridge plugin starting up...') -def log_call_read(command,timeout=logger.default_timeout_minutes*60,poll=1): +def log_call_read(command, timeout=logger.default_timeout_minutes*60, poll=1): message=" ".join(command) logger.log("log_call: running command %s" % message) logger.verbose("log_call: timeout=%r s" % timeout) @@ -37,7 +37,7 @@ def log_call_read(command,timeout=logger.default_timeout_minutes*60,poll=1): stdout = "" while True: # see if anything can be read within the poll interval - (r,w,x)=select.select([child.stdout],[],[],poll) + (r, w, x)=select.select([child.stdout], [], [], poll) if r: stdout = stdout + child.stdout.read(1) # is process over ? returncode=child.poll() @@ -52,16 +52,16 @@ def log_call_read(command,timeout=logger.default_timeout_minutes*60,poll=1): return (returncode, stdout) # child has failed else: - log("log_call:end command (%s) returned with code %d" %(message,returncode)) + log("log_call:end command (%s) returned with code %d" %(message, returncode)) return (returncode, stdout) # no : still within timeout ? if time.time() >= trigger: child.terminate() - logger.log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message,timeout)) + logger.log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message, timeout)) return (-2, None) break except Exception as e: - logger.log_exc("failed to run command %s -> %s" % (message,e)) + logger.log_exc("failed to run command %s -> %s" % (message, e)) return (-1, None) @@ -87,7 +87,7 @@ def ovs_listbridge(): return stdout.split() def ovs_addbridge(name): - (returncode, stdout) = ovs_vsctl(["add-br",name]) + (returncode, stdout) = ovs_vsctl(["add-br", name]) if (returncode != 0): raise OvsException("add-br") def ovs_listports(name): @@ -96,7 +96,7 @@ def ovs_listports(name): return stdout.split() def ovs_delbridge(name): - (returncode, stdout) = ovs_vsctl(["del-br",name]) + (returncode, stdout) = ovs_vsctl(["del-br", name]) if (returncode != 0): raise OvsException("del-br") def ovs_addport(name, portname, type, remoteip, key): @@ -110,7 +110,7 @@ def ovs_addport(name, portname, type, remoteip, key): if (returncode != 0): raise OvsException("add-port") def ovs_delport(name, portname): - (returncode, stdout) = ovs_vsctl(["del-port",name,portname]) + (returncode, stdout) = ovs_vsctl(["del-port", name, portname]) if (returncode != 0): raise OvsException("del-port") def ensure_slicebridge_created(name, addr): @@ -171,7 +171,7 @@ def GetSlivers(data, conf = None, plc = None): node_id = tools.node_id() if 'slivers' not in data: - logger.log_missing_data("privatebridge.GetSlivers",'slivers') + logger.log_missing_data("privatebridge.GetSlivers", 'slivers') return valid_bridges = [] @@ -183,7 +183,7 @@ def GetSlivers(data, conf = None, plc = None): for attribute in sliver['attributes']: attributes[attribute['tagname']] = attribute['value'] - bridge_name = attributes.get('slice_bridge_name',None) + bridge_name = attributes.get('slice_bridge_name', None) if bridge_name: configure_slicebridge(sliver, attributes) valid_bridges.append(bridge_name) diff --git a/plugins/rawdisk.py b/plugins/rawdisk.py index 616d2c6..90f267a 100644 --- a/plugins/rawdisk.py +++ b/plugins/rawdisk.py @@ -51,13 +51,13 @@ def get_unused_devices(): def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: - logger.log_missing_data("rawdisk.GetSlivers",'slivers') + logger.log_missing_data("rawdisk.GetSlivers", 'slivers') return devices = get_unused_devices() for sliver in data['slivers']: for attribute in sliver['attributes']: - name = attribute.get('tagname',attribute.get('name','')) + name = attribute.get('tagname', attribute.get('name', '')) if name == 'rawdisk': for i in devices: st = os.stat(i) diff --git a/plugins/reservation.py b/plugins/reservation.py index a81cd04..b5728d9 100644 --- a/plugins/reservation.py +++ b/plugins/reservation.py @@ -25,9 +25,9 @@ persistent_data = True ############################## # rough implementation for a singleton class -def Singleton (klass,*args,**kwds): - if not hasattr(klass,'_instance'): - klass._instance=klass(*args,**kwds) +def Singleton (klass, *args, **kwds): + if not hasattr(klass, '_instance'): + klass._instance=klass(*args, **kwds) return klass._instance def start(): @@ -58,11 +58,11 @@ class reservation: # check we're using a compliant GetSlivers if 'reservation_policy' not in data: - logger.log_missing_data("reservation.GetSlivers",'reservation_policy') + logger.log_missing_data("reservation.GetSlivers", 'reservation_policy') return self.reservation_policy=data['reservation_policy'] if 'leases' not in data: - logger.log_missing_data("reservation.GetSlivers",'leases') + logger.log_missing_data("reservation.GetSlivers", 'leases') return # store data locally @@ -72,10 +72,10 @@ class reservation: # regular nodes are not affected if self.reservation_policy == 'none': return - elif self.reservation_policy not in ['lease_or_idle','lease_or_shared']: + elif self.reservation_policy not in ['lease_or_idle', 'lease_or_shared']: logger.log("reservation: ignoring -- unexpected value for reservation_policy %r"%self.reservation_policy) return - # at this point we have reservation_policy in ['lease_or_idle','lease_or_shared'] + # at this point we have reservation_policy in ['lease_or_idle', 'lease_or_shared'] # we make no difference for now logger.log("reservation.GetSlivers: reservable node -- policy=%s"%self.reservation_policy) self.sync_timers_from_leases() @@ -107,21 +107,21 @@ class reservation: def sync_timers_from_leases (self): self.clear_timers() for lease in self.data['leases']: - self.ensure_timer_from_until(lease['t_from'],lease['t_until']) + self.ensure_timer_from_until(lease['t_from'], lease['t_until']) # assuming t10: try: logger.log("update_ipv6addr_slivertag: slice name=%s" % (slice['name']) ) - slivertag_id=plc.AddSliceTag(slice['name'],tagname,value,node_id) + slivertag_id=plc.AddSliceTag(slice['name'], tagname, value, node_id) logger.log("update_ipv6addr_slivertag: slice tag added to slice %s" % \ (slice['name']) ) except: logger.log("update_ipv6addr_slivertag: could not set ipv6 addr tag to sliver. "+ - "slice=%s tag=%s node_id=%d" % (slice['name'],tagname,node_id) ) + "slice=%s tag=%s node_id=%d" % (slice['name'], tagname, node_id) ) # if the ipv6 addr set on the slice is different on the value provided, let's update it if (ipv6addr is not None) and (len(value)>0) and (ipv6addr!=value): - plc.UpdateSliceTag(slivertag_id,value) + plc.UpdateSliceTag(slivertag_id, value) # ipv6 entry on /etc/hosts of each slice result = tools.search_ipv6addr_hosts(slice['name'], value) if not result: diff --git a/plugins/vsys.py b/plugins/vsys.py index 17a7baf..4e0a661 100644 --- a/plugins/vsys.py +++ b/plugins/vsys.py @@ -19,7 +19,7 @@ def GetSlivers(data, config=None, plc=None): """ if 'slivers' not in data: - logger.log_missing_data("vsys.GetSlivers",'slivers') + logger.log_missing_data("vsys.GetSlivers", 'slivers') return # Touch ACLs and create dict of available @@ -30,7 +30,7 @@ def GetSlivers(data, config=None, plc=None): _restart = False # Parse attributes and update dict of scripts if 'slivers' not in data: - logger.log_missing_data("vsys.GetSlivers",'slivers') + logger.log_missing_data("vsys.GetSlivers", 'slivers') return for sliver in data['slivers']: for attribute in sliver['attributes']: @@ -127,12 +127,11 @@ def parseAcls(): for (root, dirs, files) in os.walk(VSYSBKEND): for file in files: if file.endswith(".acl") and not file.startswith("local_"): - f = open(root+"/"+file,"r+") - scriptname = file.replace(".acl", "") - scriptacls[scriptname] = [] - for slice in f.readlines(): - scriptacls[scriptname].append(slice.rstrip()) - f.close() + with open(root+"/"+file, "r+") as f: + scriptname = file.replace(".acl", "") + scriptacls[scriptname] = [] + for slice in f.readlines(): + scriptacls[scriptname].append(slice.rstrip()) # return what scripts are configured for which slices. return scriptacls @@ -145,7 +144,7 @@ def writeConf(slivers, oldslivers): if (len(slivers) != len(oldslivers)) or \ (len(set(oldslivers) - set(slivers)) != 0): logger.log("vsys: Updating %s" % VSYSCONF) - f = open(VSYSCONF,"w") + f = open(VSYSCONF, "w") for sliver in slivers: f.write("/vservers/%(name)s/vsys %(name)s\n" % {"name": sliver}) f.truncate() @@ -189,4 +188,4 @@ def trashVsysHandleInSliver (sliver): logger.log("vsys.trashVsysHandleInSliver: no action needed, %s not found"%slice_vsys_area) return retcod=subprocess.call([ 'rm', '-rf' , slice_vsys_area]) - logger.log ("vsys.trashVsysHandleInSliver: Removed %s (retcod=%s)"%(slice_vsys_area,retcod)) + logger.log ("vsys.trashVsysHandleInSliver: Removed %s (retcod=%s)"%(slice_vsys_area, retcod)) diff --git a/plugins/vsys_privs.py b/plugins/vsys_privs.py index bf3b1d1..b6e69e2 100755 --- a/plugins/vsys_privs.py +++ b/plugins/vsys_privs.py @@ -18,7 +18,7 @@ def start(): def GetSlivers(data, config=None, plc=None): if 'slivers' not in data: - logger.log_missing_data("vsys_privs.GetSlivers",'slivers') + logger.log_missing_data("vsys_privs.GetSlivers", 'slivers') return @@ -26,7 +26,7 @@ def GetSlivers(data, config=None, plc=None): # Parse attributes and update dict of scripts if 'slivers' not in data: - logger.log_missing_data("vsys_privs.GetSlivers",'slivers') + logger.log_missing_data("vsys_privs.GetSlivers", 'slivers') return for sliver in data['slivers']: slice = sliver['name'] @@ -52,19 +52,19 @@ def read_privs(): cur_privs={} priv_finder = os.walk(VSYS_PRIV_DIR) priv_find = [i for i in priv_finder] - (rootdir,slices,foo) = priv_find[0] + (rootdir, slices, foo) = priv_find[0] for slice in slices: cur_privs[slice]={} if (len(priv_find)>1): - for (slicedir,bar,tagnames) in priv_find[1:]: + for (slicedir, bar, tagnames) in priv_find[1:]: if (bar != []): # The depth of the vsys-privileges directory = 1 pass for tagname in tagnames: - tagfilename = os.path.join(slicedir,tagname) + tagfilename = os.path.join(slicedir, tagname) with open(tagfilename) as tagfile: values_n = tagfile.readlines() values = [ v.rstrip() for v in values_n ] @@ -73,10 +73,10 @@ def read_privs(): return cur_privs -def write_privs(cur_privs,privs): +def write_privs(cur_privs, privs): for slice in privs.keys(): variables = privs[slice] - slice_dir = os.path.join(VSYS_PRIV_DIR,slice) + slice_dir = os.path.join(VSYS_PRIV_DIR, slice) if (not os.path.exists(slice_dir)): os.mkdir(slice_dir) @@ -90,24 +90,24 @@ def write_privs(cur_privs,privs): pass else: v_file = os.path.join(slice_dir, k) - f = open(v_file,'w') + f = open(v_file, 'w') data = '\n'.join(v) f.write(data) f.close() - logger.log("vsys_privs: added vsys attribute %s for %s"%(k,slice)) + logger.log("vsys_privs: added vsys attribute %s for %s"%(k, slice)) # Remove files and directories # that are invalid for slice in cur_privs.keys(): variables = cur_privs[slice] - slice_dir = os.path.join(VSYS_PRIV_DIR,slice) + slice_dir = os.path.join(VSYS_PRIV_DIR, slice) # Add values that do not exist for k in variables.keys(): if (privs.has_key(slice) and cur_privs[slice].has_key(k)): # ok, spare this tag - print "Sparing %s, %s "%(slice,k) + print "Sparing %s, %s "%(slice, k) else: v_file = os.path.join(slice_dir, k) os.remove(v_file) @@ -118,14 +118,14 @@ def write_privs(cur_privs,privs): if __name__ == "__main__": test_slivers = {'slivers':[ - {'name':'foo','attributes':[ - {'tagname':'vsys_m','value':'2'}, - {'tagname':'vsys_m','value':'3'}, - {'tagname':'vsys_m','value':'4'} + {'name':'foo', 'attributes':[ + {'tagname':'vsys_m', 'value':'2'}, + {'tagname':'vsys_m', 'value':'3'}, + {'tagname':'vsys_m', 'value':'4'} ]}, - {'name':'bar','attributes':[ - #{'tagname':'vsys_x','value':'z'} + {'name':'bar', 'attributes':[ + #{'tagname':'vsys_x', 'value':'z'} ]} ]} - start(None,None) + start(None, None) GetSlivers(test_slivers) diff --git a/plugins/vsys_sysctl.py b/plugins/vsys_sysctl.py index abf3389..9be1400 100644 --- a/plugins/vsys_sysctl.py +++ b/plugins/vsys_sysctl.py @@ -13,7 +13,7 @@ def GetSlivers(data, config=None, plc=None): """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys.""" if 'slivers' not in data: - logger.log_missing_data("vsys.GetSlivers",'slivers') + logger.log_missing_data("vsys.GetSlivers", 'slivers') return slices = [] @@ -30,7 +30,7 @@ def GetSlivers(data, config=None, plc=None): except: logger.log("vsys_sysctl: failed to create dir %s" % dir) - (junk, key) = attribute['tagname'].split(".",1) + (junk, key) = attribute['tagname'].split(".", 1) value = str(attribute['value']) fn = os.path.join(dir, key) @@ -46,14 +46,14 @@ def GetSlivers(data, config=None, plc=None): # slice. This lets us know that we've done the sysctl. try: logger.log("vsys_sysctl: create file %s value %s" % (fn, value)) - with open(fn,"w") as f: + with open(fn, "w") as f: f.write(value+"\n") except: logger.log("vsys_sysctl: failed to create file %s" % fn) def test_value(fn, value): try: - slice_value = file(fn,"r").readline().strip() + slice_value = file(fn, "r").readline().strip() except: slice_value = None diff --git a/slivermanager.py b/slivermanager.py index 624853e..eb0a096 100644 --- a/slivermanager.py +++ b/slivermanager.py @@ -7,7 +7,8 @@ also to make inter-sliver resource loans. The sliver manager is also responsible for handling delegation accounts. """ -import string,re +import string +import re import time import logger @@ -149,7 +150,7 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True): # Take initscripts (global) returned by API, build a hash scriptname->code iscripts_hash = {} if 'initscripts' not in data: - logger.log_missing_data("slivermanager.GetSlivers",'initscripts') + logger.log_missing_data("slivermanager.GetSlivers", 'initscripts') return for initscript_rec in data['initscripts']: logger.verbose("slivermanager: initscript: %s" % initscript_rec['name']) @@ -183,7 +184,7 @@ def GetSlivers(data, config = None, plc=None, fullupdate=True): ### set initscripts; set empty rec['initscript'] if not # if tag 'initscript_code' is set, that's what we use - iscode = attributes.get('initscript_code','') + iscode = attributes.get('initscript_code', '') if iscode: rec['initscript']=iscode else: -- 2.43.0