Skip to content

Commit

Permalink
Merge pull request #146 from zoufou/v0.6-beta
Browse files Browse the repository at this point in the history
0.6b10
  • Loading branch information
farirat committed May 10, 2015
2 parents 00e5c77 + 612fe1c commit b4786d3
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
# Command to install dependencies
install:
- python setup.py sdist
- sudo pip install dist/jasmin-0.6b9.tar.gz
- sudo pip install dist/jasmin-0.6b10.tar.gz
# Commands to run tests:
script:
# Add jasmind to system autostartup:
Expand Down
2 changes: 1 addition & 1 deletion jasmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MAJOR = 0
MINOR = 6
PATCH = 9
PATCH = 10
META = 'b'

def get_version():
Expand Down
2 changes: 2 additions & 0 deletions jasmin/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def _get(self, section, option, default=None):
return default
if self.config.has_option(section, option) == False:
return default
if self.config.get(section, option) == 'None':
return None

return self.config.get(section, option)

Expand Down
2 changes: 1 addition & 1 deletion jasmin/protocols/cli/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, config_file = None):
self.bind = self._get('jcli', 'bind', '127.0.0.1')
self.port = self._getint('jcli', 'port', 8990)

self.authentication = self._getint('jcli', 'authentication', True)
self.authentication = self._getbool('jcli', 'authentication', True)
self.admin_username = self._get('jcli', 'admin_username', 'jcliadmin')
self.admin_password = self._get('jcli', 'admin_password', '79e9b0aa3f3e7c53e916f7ac47439bcb').decode('hex')

Expand Down
6 changes: 3 additions & 3 deletions jasmin/protocols/cli/filtersm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pickle
import time
from dateutil import parser
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.routing.jasminApi import *
from jasmin.routing.Filters import (TransparentFilter, UserFilter, GroupFilter,
ConnectorFilter, SourceAddrFilter, DestinationAddrFilter,
Expand Down Expand Up @@ -209,14 +209,14 @@ def exist_filter_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown Filter: %s' % fid)
return exist_filter_and_call

class FiltersManager(Manager):
class FiltersManager(PersistableManager):
'''FiltersManager does not have a PB like other managers (router, users, groups ...), it is
used to simplify route adding syntax by creating reusable filters, these filters are saved in
self.filters'''
managerName = 'filter'

def __init__(self, protocol):
Manager.__init__(self, protocol, None)
PersistableManager.__init__(self, protocol, None)

self.filters = {}

Expand Down
4 changes: 2 additions & 2 deletions jasmin/protocols/cli/groupsm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pickle
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.routing.jasminApi import Group

# A config map between console-configuration keys and Group keys.
Expand Down Expand Up @@ -56,7 +56,7 @@ def exist_group_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown Group: %s' % gid)
return exist_group_and_call

class GroupsManager(Manager):
class GroupsManager(PersistableManager):
managerName = 'group'

def persist(self, arg, opts):
Expand Down
6 changes: 3 additions & 3 deletions jasmin/protocols/cli/httpccm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pickle
import time
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.routing.jasminApi import HttpConnector

# A config map between console-configuration keys and Httpcc keys.
Expand Down Expand Up @@ -63,14 +63,14 @@ def exist_httpcc_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown Httpcc: %s' % cid)
return exist_httpcc_and_call

class HttpccManager(Manager):
class HttpccManager(PersistableManager):
'''HttpccManager does not have a PB like other managers (router, users, groups ...), it is
used to simplify route adding syntax by creating reusable httpccs, these httpccs are saved in
self.httpccs'''
managerName = 'httpcc'

def __init__(self, protocol):
Manager.__init__(self, protocol, None)
PersistableManager.__init__(self, protocol, None)

self.httpccs = {}

Expand Down
70 changes: 63 additions & 7 deletions jasmin/protocols/cli/jcli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from hashlib import md5
from optparse import make_option
from jasmin.protocols.cli.managers import PersistableManager
from jasmin.protocols.cli.options import options
from jasmin.protocols.cli.protocol import CmdProtocol
from jasmin.protocols.cli.smppccm import SmppCCManager
Expand All @@ -9,6 +10,7 @@
from jasmin.protocols.cli.mtrouterm import MtRouterManager
from jasmin.protocols.cli.filtersm import FiltersManager
from jasmin.protocols.cli.httpccm import HttpccManager
from jasmin.protocols.cli.statsm import StatsManager

class JCliProtocol(CmdProtocol):
motd = 'Welcome to Jasmin console\nType help or ? to list commands.\n'
Expand Down Expand Up @@ -39,6 +41,8 @@ def __init__(self, log_category = 'jcli'):
self.commands.append('smppccm')
if 'httpccm' not in self.commands:
self.commands.append('httpccm')
if 'stats' not in self.commands:
self.commands.append('stats')

def connectionMade(self):
# Provision security
Expand All @@ -56,10 +60,15 @@ def connectionMade(self):
self.terminal.write('Authentication required.\n\n')

# Provision managers
self.managers = {'user': UsersManager(self, self.factory.pb), 'group': GroupsManager(self, self.factory.pb),
'morouter': MoRouterManager(self, self.factory.pb), 'mtrouter': MtRouterManager(self, self.factory.pb),
'smppccm': SmppCCManager(self, self.factory.pb), 'filter': FiltersManager(self),
'httpccm': HttpccManager(self)}
self.managers = {'user': UsersManager(self, self.factory.pb),
'group': GroupsManager(self, self.factory.pb),
'morouter': MoRouterManager(self, self.factory.pb),
'mtrouter': MtRouterManager(self, self.factory.pb),
'smppccm': SmppCCManager(self, self.factory.pb),
'filter': FiltersManager(self),
'httpccm': HttpccManager(self),
'stats': StatsManager(self, self.factory.pb),
}

def lineReceived(self, line):
"Go to CmdProtocol.lineReceived when authenticated only"
Expand Down Expand Up @@ -320,7 +329,7 @@ def do_persist(self, arg, opts):
'Persist current configuration profile to disk in PROFILE'

for _, manager in self.managers.iteritems():
if manager is not None:
if manager is not None and isinstance(manager, PersistableManager):
manager.persist(arg, opts)
self.sendData()

Expand All @@ -331,6 +340,53 @@ def do_load(self, arg, opts):
'Load configuration PROFILE profile from disk'

for _, manager in self.managers.iteritems():
if manager is not None:
if manager is not None and isinstance(manager, PersistableManager):
manager.load(arg, opts)
self.sendData()
self.sendData()

@options([make_option(None, '--user', type="string", metavar="UID",
help = "Show user stats"),
make_option(None, '--users', action="store_true",
help = "Show all users stats"),
make_option(None, '--smppc', type="string", metavar="CID",
help = "Show smpp connector stats"),
make_option(None, '--smppcs', action="store_true",
help = "Show all smpp connectors stats"),
make_option(None, '--moroute', type="string", metavar="ORDER",
help = "Show MO Route stats"),
make_option(None, '--moroutes', action="store_true",
help = "Show all MO Routes stats"),
make_option(None, '--mtroute', type="string", metavar="ORDER",
help = "Show MT Route stats"),
make_option(None, '--mtroutes', action="store_true",
help = "Show all MT Routes stats"),
make_option(None, '--httpapi', action="store_true",
help = "Show HTTP API stats"),
make_option(None, '--smppsapi', action="store_true",
help = "Show SMPP Server API stats"),
], '')
def do_stats(self, arg, opts = None):
'Stats management'

if opts.user:
self.managers['stats'].user(arg, opts)
elif opts.users:
self.managers['stats'].users(arg, opts)
elif opts.smppc:
self.managers['stats'].smppc(arg, opts)
elif opts.smppcs:
self.managers['stats'].smppcs(arg, opts)
elif opts.moroute:
self.managers['stats'].moroute(arg, opts)
elif opts.moroutes:
self.managers['stats'].moroutes(arg, opts)
elif opts.mtroute:
self.managers['stats'].mtroute(arg, opts)
elif opts.mtroutes:
self.managers['stats'].mtroutes(arg, opts)
elif opts.httpapi:
self.managers['stats'].httpapi(arg, opts)
elif opts.smppsapi:
self.managers['stats'].smppsapi(arg, opts)
else:
return self.sendData('Missing required option')
11 changes: 6 additions & 5 deletions jasmin/protocols/cli/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ def handle_TAB(self):
'Tab completition is disabled inside a session'
self.lineBuffer = ''

def __init__(self, protocol, pb):
self.protocol = protocol
self.pb = pb

class PersistableManager(Manager):
def persist(self, arg, opts):
'Must be implemeted by manager to persist current configuration to disk'
raise NotImplementedError

def load(self, arg, opts):
'Must be implemeted by manager to reload current configuration to disk'
raise NotImplementedError

def __init__(self, protocol, pb):
self.protocol = protocol
self.pb = pb
raise NotImplementedError
4 changes: 2 additions & 2 deletions jasmin/protocols/cli/morouterm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import inspect
import pickle
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.protocols.cli.filtersm import MOFILTERS
from jasmin.routing.jasminApi import SmppServerSystemIdConnector
from jasmin.routing.Routes import (DefaultRoute, StaticMORoute, RandomRoundrobinMORoute)
Expand Down Expand Up @@ -207,7 +207,7 @@ def exist_moroute_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown MO Route: %s' % order)
return exist_moroute_and_call

class MoRouterManager(Manager):
class MoRouterManager(PersistableManager):
managerName = 'morouter'

def persist(self, arg, opts):
Expand Down
4 changes: 2 additions & 2 deletions jasmin/protocols/cli/mtrouterm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import inspect
import pickle
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.protocols.cli.filtersm import MTFILTERS
from jasmin.routing.jasminApi import SmppClientConnector
from jasmin.routing.Routes import (DefaultRoute, StaticMTRoute, RandomRoundrobinMTRoute)
Expand Down Expand Up @@ -204,7 +204,7 @@ def exist_mtroute_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown MT Route: %s' % order)
return exist_mtroute_and_call

class MtRouterManager(Manager):
class MtRouterManager(PersistableManager):
managerName = 'mtrouter'

def persist(self, arg, opts):
Expand Down
4 changes: 2 additions & 2 deletions jasmin/protocols/cli/smppccm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from twisted.internet import defer, reactor
from jasmin.protocols.smpp.configs import SMPPClientConfig, UnknownValue
from jasmin.protocols.cli.managers import Manager, Session
from jasmin.protocols.cli.managers import PersistableManager, Session
from jasmin.vendor.smpp.pdu.constants import addr_ton_name_map, addr_ton_value_map
from jasmin.vendor.smpp.pdu.constants import addr_npi_name_map, addr_npi_value_map
from jasmin.vendor.smpp.pdu.constants import replace_if_present_flap_name_map, replace_if_present_flap_value_map
Expand Down Expand Up @@ -189,7 +189,7 @@ def exist_connector_and_call(self, *args, **kwargs):
return self.protocol.sendData('Unknown connector: %s' % cid)
return exist_connector_and_call

class SmppCCManager(Manager):
class SmppCCManager(PersistableManager):
managerName = 'smppcc'

def persist(self, arg, opts):
Expand Down
34 changes: 34 additions & 0 deletions jasmin/protocols/cli/statsm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from jasmin.protocols.cli.managers import Manager

class StatsManager(Manager):
managerName = 'stats'

def user(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def users(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def smppc(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def smppcs(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def moroute(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def moroutes(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def mtroute(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def mtroutes(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def httpapi(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

def smppsapi(self, arg, opts):
return self.protocol.sendData('Not implemented yet.')

0 comments on commit b4786d3

Please sign in to comment.