Compare commits
2 Commits
80fb8cd7cc
...
e6f93150a0
Author | SHA1 | Date | |
---|---|---|---|
e6f93150a0 | |||
8d2e94f5f3 |
@ -1,6 +1,6 @@
|
|||||||
# Mitel OMMClient2
|
# Mitel OMMClient2
|
||||||
|
|
||||||
Another attempt for a client library to the Mitel OM Application XML Interface.
|
Another attempt for a modern client library to the Mitel OM Application XML Interface.
|
||||||
|
|
||||||
## Quicksart
|
## Quicksart
|
||||||
|
|
||||||
@ -16,10 +16,10 @@ c = mitel_ommclient2.OMMClient2("omm.local", "admin", "admin")
|
|||||||
c.ping()
|
c.ping()
|
||||||
|
|
||||||
# Create custom messages
|
# Create custom messages
|
||||||
r = c.session.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
|
r = c.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
|
||||||
|
|
||||||
# Craft your own request, if it is not implemented yet
|
# Craft your own request, if it is not implemented yet
|
||||||
r = c.session.request(mitel_ommclient2.messages.DictRequest("Ping", {"timeStamp": 2342}))
|
r = c.request(mitel_ommclient2.messages.DictRequest("Ping", {"timeStamp": 2342}))
|
||||||
```
|
```
|
||||||
|
|
||||||
Consult class documentation for more in depth examples and options.
|
Consult class documentation for more in depth examples and options.
|
||||||
|
@ -4,6 +4,22 @@ mitel\_ommclient2.messages package
|
|||||||
Submodules
|
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
|
mitel\_ommclient2.messages.open module
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
|
@ -36,14 +36,6 @@ mitel\_ommclient2.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
mitel\_ommclient2.session module
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
.. automodule:: mitel_ommclient2.session
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
.. _api:
|
.. _api:
|
||||||
|
|
||||||
mitel_ommclient2
|
API Documentation
|
||||||
================
|
=================
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 4
|
:maxdepth: 4
|
||||||
|
@ -3,6 +3,5 @@
|
|||||||
from . import client
|
from . import client
|
||||||
from . import connection
|
from . import connection
|
||||||
from . import messages
|
from . import messages
|
||||||
from . import session
|
|
||||||
|
|
||||||
from .client import OMMClient2
|
from .client import OMMClient2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from .session import Session
|
from .connection import Connection
|
||||||
from . import messages
|
from . import messages
|
||||||
|
|
||||||
class OMMClient2:
|
class OMMClient2:
|
||||||
@ -13,29 +13,53 @@ class OMMClient2:
|
|||||||
:param host: Hostname or IP address of the OMM
|
:param host: Hostname or IP address of the OMM
|
||||||
:param username: Username
|
:param username: Username
|
||||||
:param password: Password
|
:param password: Password
|
||||||
:param session: A :class:`mitel_ommclient2.session.Session` object
|
: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.
|
||||||
|
|
||||||
Usage::
|
Usage::
|
||||||
|
|
||||||
>>> c = OMMClient2("omm.local", "admin", "admin")
|
>>> c = OMMClient2("omm.local", "admin", "admin")
|
||||||
>>> c.ping()
|
>>> c.ping()
|
||||||
|
|
||||||
Use session for not implemented features::
|
Use request to send custom messages::
|
||||||
|
|
||||||
>>> r = s.session.request(mitel_ommclient2.messages.Ping())
|
>>> r = s.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=None, username=None, password=None, session=None):
|
def __init__(self, host, username, password, port=None, ommsync=False):
|
||||||
if session is None:
|
self._host = host
|
||||||
self.session = Session(host, username, password)
|
self._username = username
|
||||||
else:
|
self._password = password
|
||||||
self.session = session
|
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 get_account(self, id):
|
def get_account(self, id):
|
||||||
"""
|
"""
|
||||||
@ -44,7 +68,7 @@ class OMMClient2:
|
|||||||
:param id: User id
|
:param id: User id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = self.session.request(messages.GetAccount(id))
|
r = self.request(messages.GetAccount(id))
|
||||||
r.raise_on_error()
|
r.raise_on_error()
|
||||||
if r.account is None:
|
if r.account is None:
|
||||||
return None
|
return None
|
||||||
@ -56,7 +80,7 @@ class OMMClient2:
|
|||||||
|
|
||||||
:param id: Device id
|
:param id: Device id
|
||||||
"""
|
"""
|
||||||
r = self.session.request(messages.GetPPDev(ppn))
|
r = self.request(messages.GetPPDev(ppn))
|
||||||
r.raise_on_error()
|
r.raise_on_error()
|
||||||
if r.pp is None:
|
if r.pp is None:
|
||||||
return None
|
return None
|
||||||
@ -69,7 +93,7 @@ class OMMClient2:
|
|||||||
Returns `True` when response is received.
|
Returns `True` when response is received.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = self.session.request(messages.Ping())
|
r = self.request(messages.Ping())
|
||||||
if r.errCode is None:
|
if r.errCode is None:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
#!/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