X-Git-Url: http://git.onelab.eu/?p=nodemanager.git;a=blobdiff_plain;f=plugins%2Fprivatebridge.py;h=9489f69cfdf004c5b32781757695017cfccefd9f;hp=8e77524a98e17632f1d26087f42933b3c680407d;hb=74d5761f260b5d887733e826b4ce6aed11f11487;hpb=6f1c653e7f3712cd67d5db796eeae5c35fdddf5f diff --git a/plugins/privatebridge.py b/plugins/privatebridge.py index 8e77524..9489f69 100644 --- a/plugins/privatebridge.py +++ b/plugins/privatebridge.py @@ -1,35 +1,31 @@ -#!/usr/bin/env python3 +""" +Private Bridge configurator. +""" -""" Private Bridge configurator. """ - -import http.client -import os import select -import shutil import subprocess import time import tools -from threading import Thread import logger -import tools priority = 9 class OvsException (Exception) : - def __init__ (self, message="no message"): - self.message=message - def __repr__ (self): return message + def __init__(self, message="no message"): + self.message = message + def __repr__(self): + return self.message def start(): logger.log('private bridge plugin starting up...') def log_call_read(command, timeout=logger.default_timeout_minutes*60, poll=1): - message=" ".join(command) + message = " ".join(command) logger.log("log_call: running command %s" % message) logger.verbose("log_call: timeout=%r s" % timeout) logger.verbose("log_call: poll=%r s" % poll) - trigger=time.time()+timeout + trigger = time.time()+timeout try: child = subprocess.Popen( command, bufsize=1, @@ -40,8 +36,9 @@ 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) - if r: stdout = stdout + child.stdout.read(1) + (r, w, x) = select.select([child.stdout], [], [], poll) + if r: + stdout = stdout + child.stdout.read(1) # is process over ? returncode=child.poll() # yes @@ -55,12 +52,14 @@ 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: @@ -109,8 +108,9 @@ def ovs_addport(name, portname, type, remoteip, key): if key: args = args + ["options:key=" + str(key)] - (returncode, stdout) = ovs_vsctl(args) - if (returncode != 0): raise OvsException("add-port") + returncode, stdout = ovs_vsctl(args) + if (returncode != 0): + raise OvsException("add-port") def ovs_delport(name, portname): (returncode, stdout) = ovs_vsctl(["del-port", name, portname]) @@ -182,7 +182,7 @@ def GetSlivers(data, conf = None, plc = None): sliver_name = sliver['name'] # build a dict of attributes, because it's more convenient - attributes={} + attributes = {} for attribute in sliver['attributes']: attributes[attribute['tagname']] = attribute['value']