aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2018-11-28 11:25:15 +0100
committerMax <msuraev@sysmocom.de>2018-11-28 12:52:48 +0000
commitf7255fa7cfb411716167e635877f4f1e19f91ab4 (patch)
treed15bc51047bf7e53506a3b2548c967802486d1d9
parent2cc29b5ef73250123bb0ff53581d0a5094042777 (diff)
Move command processing into shared function
-rw-r--r--osmopy/trap_helper.py12
-rwxr-xr-xscripts/ctrl2cgi.py10
-rwxr-xr-xscripts/soap.py12
3 files changed, 19 insertions, 15 deletions
diff --git a/osmopy/trap_helper.py b/osmopy/trap_helper.py
index 6f4b95d..d07ebd3 100644
--- a/osmopy/trap_helper.py
+++ b/osmopy/trap_helper.py
@@ -24,6 +24,7 @@
import sys, os, datetime, signal, logging, logging.handlers
from functools import partial
+from osmopy.osmo_ipa import Ctrl
from osmopy.twisted_ipa import CTRL
from twisted.internet import defer
@@ -56,6 +57,17 @@ def get_type(v):
loc = split_type(v)
return loc[-1]
+def comm_proc(comm, f, log):
+ """
+ Command processor: takes function f to run for each command
+ """
+ bsc_id = comm[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
+ log.debug("BSC %s commands: %r" % (bsc_id, comm))
+ for t in comm:
+ (_, m) = Ctrl().cmd(*t.split())
+ f(m)
+ return bsc_id
+
def make_params(bsc, data):
"""
Make parameters for request
diff --git a/scripts/ctrl2cgi.py b/scripts/ctrl2cgi.py
index c566a7c..6818b2a 100755
--- a/scripts/ctrl2cgi.py
+++ b/scripts/ctrl2cgi.py
@@ -22,14 +22,14 @@
*/
"""
-__version__ = "0.0.3" # bump this on every non-trivial change
+__version__ = "0.0.4" # bump this on every non-trivial change
from twisted.internet import defer, reactor
from osmopy.twisted_ipa import CTRL, IPAFactory, __version__ as twisted_ipa_version
from osmopy.osmo_ipa import Ctrl
from treq import post, collect
from functools import partial
-from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params
+from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params, comm_proc
from distutils.version import StrictVersion as V # FIXME: use NormalizedVersion from PEP-386 when available
import argparse, datetime, signal, sys, os, logging, logging.handlers
import hashlib
@@ -45,11 +45,7 @@ def handle_reply(f, log, resp):
Reply handler: process raw CGI server response, function f to run for each command
"""
decoded = json.loads(resp.decode('utf-8'))
- bsc_id = decoded.get('commands')[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
- log.debug("BSC %s commands: %r" % (bsc_id, decoded.get('commands')))
- for t in decoded.get('commands'): # Process commands format
- (_, m) = Ctrl().cmd(*t.split())
- f(m)
+ comm_proc(decoded.get('commands'), f, log)
def gen_hash(params, skey):
input = ''
diff --git a/scripts/soap.py b/scripts/soap.py
index 75acd89..6bf786c 100755
--- a/scripts/soap.py
+++ b/scripts/soap.py
@@ -22,7 +22,7 @@
*/
"""
-__version__ = "0.7.1" # bump this on every non-trivial change
+__version__ = "0.7.2" # bump this on every non-trivial change
from twisted.internet import defer, reactor
from osmopy.twisted_ipa import CTRL, IPAFactory, __version__ as twisted_ipa_version
@@ -30,7 +30,7 @@ from osmopy.osmo_ipa import Ctrl
from treq import post, collect
from suds.client import Client
from functools import partial
-from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params
+from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params, comm_proc
from distutils.version import StrictVersion as V # FIXME: use NormalizedVersion from PEP-386 when available
import argparse, datetime, signal, sys, os, logging, logging.handlers
@@ -40,15 +40,11 @@ assert V(twisted_ipa_version) > V('0.4')
def handle_reply(p, f, log, r):
"""
- Reply handler: takes function p to process raw SOAP server reply r, function f to run for each command and verbosity flag v
+ Reply handler: takes function p to process raw SOAP server reply r, function f to run for each command
"""
repl = p(r) # result is expected to have both commands[] array and error string (could be None)
- bsc_id = repl.commands[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
+ bsc_id = comm_proc(repl.commands, f, log)
log.info("Received SOAP response for BSC %s with %d commands, error status: %s" % (bsc_id, len(repl.commands), repl.error))
- log.debug("BSC %s commands: %s" % (bsc_id, repl.commands))
- for t in repl.commands: # Process OpenBscCommands format from .wsdl
- (_, m) = Ctrl().cmd(*t.split())
- f(m)
class Trap(CTRL):