Compare commits
No commits in common. "e6f93150a016e48fd9e4fd96e87f986cb0be4500" and "80fb8cd7cc328767a45cf87da39d1954662b2800" have entirely different histories.
e6f93150a0
...
80fb8cd7cc
@ -1,6 +1,6 @@
|
||||
# Mitel OMMClient2
|
||||
|
||||
Another attempt for a modern client library to the Mitel OM Application XML Interface.
|
||||
Another attempt for a client library to the Mitel OM Application XML Interface.
|
||||
|
||||
## Quicksart
|
||||
|
||||
@ -16,10 +16,10 @@ c = mitel_ommclient2.OMMClient2("omm.local", "admin", "admin")
|
||||
c.ping()
|
||||
|
||||
# Create custom messages
|
||||
r = c.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
|
||||
r = c.session.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
|
||||
|
||||
# Craft your own request, if it is not implemented yet
|
||||
r = c.request(mitel_ommclient2.messages.DictRequest("Ping", {"timeStamp": 2342}))
|
||||
r = c.session.request(mitel_ommclient2.messages.DictRequest("Ping", {"timeStamp": 2342}))
|
||||
```
|
||||
|
||||
Consult class documentation for more in depth examples and options.
|
||||
|
@ -4,22 +4,6 @@ mitel\_ommclient2.messages package
|
||||
Submodules
|
||||
----------
|
||||
|
||||
mitel\_ommclient2.messages.getaccount module
|
||||
--------------------------------------------
|
||||
|
||||
.. automodule:: mitel_ommclient2.messages.getaccount
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
mitel\_ommclient2.messages.getppdev module
|
||||
------------------------------------------
|
||||
|
||||
.. automodule:: mitel_ommclient2.messages.getppdev
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
mitel\_ommclient2.messages.open module
|
||||
--------------------------------------
|
||||
|
||||
|
@ -36,6 +36,14 @@ mitel\_ommclient2.exceptions module
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
mitel\_ommclient2.session module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: mitel_ommclient2.session
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
.. _api:
|
||||
|
||||
API Documentation
|
||||
=================
|
||||
mitel_ommclient2
|
||||
================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
|
@ -3,5 +3,6 @@
|
||||
from . import client
|
||||
from . import connection
|
||||
from . import messages
|
||||
from . import session
|
||||
|
||||
from .client import OMMClient2
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from .connection import Connection
|
||||
from .session import Session
|
||||
from . import messages
|
||||
|
||||
class OMMClient2:
|
||||
@ -13,53 +13,29 @@ class OMMClient2:
|
||||
:param host: Hostname or IP address of the OMM
|
||||
:param username: Username
|
||||
:param password: Password
|
||||
:param port: Port where to access the API, if None, use default value
|
||||
:param ommsync: If True login as OMM-Sync client. Some operations in OMM-Sync mode might lead to destroy DECT paring.
|
||||
:param session: A :class:`mitel_ommclient2.session.Session` object
|
||||
|
||||
Usage::
|
||||
|
||||
>>> c = OMMClient2("omm.local", "admin", "admin")
|
||||
>>> c.ping()
|
||||
|
||||
Use request to send custom messages::
|
||||
Use session for not implemented features::
|
||||
|
||||
>>> r = s.request(mitel_ommclient2.messages.Ping())
|
||||
>>> r = s.session.request(mitel_ommclient2.messages.Ping())
|
||||
|
||||
To get more contol over the connection handling, initialize
|
||||
:class:`mitel_ommclient2.session.Session` manually::
|
||||
|
||||
>>> s = mitel_ommclient2.session.Session("omm.local", "admin", "admin", port=12345)
|
||||
>>> c = OMMClient2(session=s)
|
||||
"""
|
||||
|
||||
def __init__(self, host, username, password, port=None, ommsync=False):
|
||||
self._host = host
|
||||
self._username = username
|
||||
self._password = password
|
||||
self._port = port
|
||||
self._ommsync = ommsync
|
||||
|
||||
# prepare connect arguments
|
||||
kwargs = {}
|
||||
if self._port is not None:
|
||||
kwargs["port"] = self._port
|
||||
|
||||
# Connect
|
||||
self._connection = Connection(self._host, **kwargs)
|
||||
self._connection.connect()
|
||||
|
||||
# Login
|
||||
r = self.request(messages.Open(self._username, self._password, UserDeviceSyncClient=self._ommsync))
|
||||
r.raise_on_error()
|
||||
|
||||
def request(self, request):
|
||||
"""
|
||||
Sends a request, waits for response and returns response
|
||||
|
||||
:param request: Request object
|
||||
|
||||
Usage::
|
||||
|
||||
>>> r = c.request(mitel_ommclient2.messages.Ping())
|
||||
>>> r.name
|
||||
'PingResp'
|
||||
"""
|
||||
|
||||
return self._connection.request(request)
|
||||
def __init__(self, host=None, username=None, password=None, session=None):
|
||||
if session is None:
|
||||
self.session = Session(host, username, password)
|
||||
else:
|
||||
self.session = session
|
||||
|
||||
def get_account(self, id):
|
||||
"""
|
||||
@ -68,7 +44,7 @@ class OMMClient2:
|
||||
:param id: User id
|
||||
"""
|
||||
|
||||
r = self.request(messages.GetAccount(id))
|
||||
r = self.session.request(messages.GetAccount(id))
|
||||
r.raise_on_error()
|
||||
if r.account is None:
|
||||
return None
|
||||
@ -80,7 +56,7 @@ class OMMClient2:
|
||||
|
||||
:param id: Device id
|
||||
"""
|
||||
r = self.request(messages.GetPPDev(ppn))
|
||||
r = self.session.request(messages.GetPPDev(ppn))
|
||||
r.raise_on_error()
|
||||
if r.pp is None:
|
||||
return None
|
||||
@ -93,7 +69,7 @@ class OMMClient2:
|
||||
Returns `True` when response is received.
|
||||
"""
|
||||
|
||||
r = self.request(messages.Ping())
|
||||
r = self.session.request(messages.Ping())
|
||||
if r.errCode is None:
|
||||
return True
|
||||
return False
|
||||
|
57
mitel_ommclient2/session.py
Normal file
57
mitel_ommclient2/session.py
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
|
||||
from . import connection
|
||||
from . import messages
|
||||
|
||||
class Session:
|
||||
"""
|
||||
Synchronous API session handler
|
||||
|
||||
:param host: Hostname or IP address of OMM
|
||||
:param username: Username
|
||||
:param password: Password
|
||||
:param port: Port
|
||||
:param ommsync: If True login as OMM-Sync client. Some operations in OMM-Sync mode might lead to destroy DECT paring.
|
||||
:param connection_class: One of :class:`mitel_ommclient2.connection.Connection` or :class:`mitel_ommclient2.connection.SSLConnection`
|
||||
|
||||
Usage::
|
||||
>>> s = Session("omm.local", "admin", "admin")
|
||||
>>> s.request(mitel_ommclient2.messages.Ping())
|
||||
"""
|
||||
|
||||
def __init__(self, host, username, password, port=None, ommsync=False, connection_class=None):
|
||||
self.host = host
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.port = port
|
||||
self.ommsync = ommsync
|
||||
self.connection_class = connection_class
|
||||
if self.connection_class is None:
|
||||
self.connection_class = connection.Connection
|
||||
|
||||
self._connection = None
|
||||
|
||||
self._ensure_connection()
|
||||
|
||||
def _ensure_connection(self):
|
||||
"""
|
||||
Make sure we are connected and logged in
|
||||
"""
|
||||
|
||||
if self._connection is None:
|
||||
kwargs = {}
|
||||
if self.port is not None:
|
||||
kwargs["port"] = self.port
|
||||
self._connection = self.connection_class(self.host, **kwargs)
|
||||
|
||||
self._connection.connect()
|
||||
|
||||
# Login
|
||||
r = self.request(messages.Open(self.username, self.password, UserDeviceSyncClient=self.ommsync))
|
||||
|
||||
r.raise_on_error()
|
||||
|
||||
def request(self, request):
|
||||
return self._connection.request(request)
|
Loading…
Reference in New Issue
Block a user