2022-01-06 16:11:21 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from .session import Session
|
|
|
|
from . import messages
|
|
|
|
|
|
|
|
class OMMClient2:
|
|
|
|
"""
|
|
|
|
High level wrapper for the OM Application XML Interface
|
|
|
|
|
|
|
|
This class tries to provide functions for often used methods without the
|
|
|
|
need of using the underlying messaging protocol
|
|
|
|
|
|
|
|
:param host: Hostname or IP address of the OMM
|
|
|
|
:param username: Username
|
|
|
|
:param password: Password
|
|
|
|
:param session: A :class:`mitel_ommclient2.session.Session` object
|
|
|
|
|
|
|
|
Usage::
|
|
|
|
|
|
|
|
>>> c = OMMClient2("omm.local", "admin", "admin")
|
|
|
|
>>> c.ping()
|
|
|
|
|
|
|
|
Use session for not implemented features::
|
|
|
|
|
|
|
|
>>> 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=None, username=None, password=None, session=None):
|
|
|
|
if session is None:
|
|
|
|
self.session = Session(host, username, password)
|
|
|
|
else:
|
|
|
|
self.session = session
|
|
|
|
|
2022-01-06 18:13:48 +01:00
|
|
|
def get_account(self, id):
|
|
|
|
"""
|
|
|
|
Get account
|
|
|
|
|
|
|
|
:param id: User id
|
|
|
|
"""
|
|
|
|
|
2022-01-06 23:58:59 +01:00
|
|
|
r = self.session.request(messages.GetAccount(id))
|
2022-01-06 18:13:48 +01:00
|
|
|
r.raise_on_error()
|
2022-01-06 23:58:59 +01:00
|
|
|
if r.account is None:
|
|
|
|
return None
|
2022-01-06 18:13:48 +01:00
|
|
|
return r.account[0]
|
|
|
|
|
2022-01-16 13:52:08 +01:00
|
|
|
def get_pp_dev(self, ppn):
|
|
|
|
"""
|
|
|
|
Get PP device
|
|
|
|
|
|
|
|
:param id: Device id
|
|
|
|
"""
|
|
|
|
r = self.session.request(messages.GetPPDev(ppn))
|
|
|
|
r.raise_on_error()
|
|
|
|
if r.pp is None:
|
|
|
|
return None
|
|
|
|
return r.pp[0]
|
|
|
|
|
2022-01-06 16:11:21 +01:00
|
|
|
def ping(self):
|
|
|
|
"""
|
|
|
|
Is OMM still there?
|
|
|
|
|
|
|
|
Returns `True` when response is received.
|
|
|
|
"""
|
|
|
|
|
|
|
|
r = self.session.request(messages.Ping())
|
|
|
|
if r.errCode is None:
|
|
|
|
return True
|
|
|
|
return False
|