From d821b57f7ce05f7da6d2893303ef4a1e93112685 Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 6 Jan 2022 16:11:21 +0100 Subject: [PATCH] Introduce high level OMMClient2 interface --- mitel_ommclient2/__init__.py | 8 ++++++ mitel_ommclient2/client.py | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 mitel_ommclient2/__init__.py create mode 100644 mitel_ommclient2/client.py diff --git a/mitel_ommclient2/__init__.py b/mitel_ommclient2/__init__.py new file mode 100644 index 0000000..463a3ec --- /dev/null +++ b/mitel_ommclient2/__init__.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +from . import client +from . import connection +from . import messages +from . import session + +from .client import OMMClient2 diff --git a/mitel_ommclient2/client.py b/mitel_ommclient2/client.py new file mode 100644 index 0000000..b598336 --- /dev/null +++ b/mitel_ommclient2/client.py @@ -0,0 +1,50 @@ +#!/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 + + 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