Move command processing into shared function
Change-Id: I4e40607a9aa5e03a7b3f5b68e4261828209a5813changes/74/11974/2
parent
2cc29b5ef7
commit
f7255fa7cf
|
@ -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
|
||||
|
|
|
@ -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 = ''
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue