From 8849b8488c155a56638e4dbb1dd3be9fd8cb6013 Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 16 Jun 2022 23:01:04 +0200 Subject: [PATCH] Introduce ability to attach users to devices --- mitel_ommclient2/client.py | 26 ++++++++++++++++++++++++++ mitel_ommclient2/messages/__init__.py | 1 + mitel_ommclient2/messages/setpp.py | 20 ++++++++++++++++++++ mitel_ommclient2/types/__init__.py | 21 ++++++++++++++++++++- ommcli | 5 +++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 mitel_ommclient2/messages/setpp.py diff --git a/mitel_ommclient2/client.py b/mitel_ommclient2/client.py index d71afc6..b0fc22c 100644 --- a/mitel_ommclient2/client.py +++ b/mitel_ommclient2/client.py @@ -53,6 +53,32 @@ class OMMClient2: r = self.connection.request(m) r.raise_on_error() + def attach_user_device(self, uid, ppn): + """ + Attach user to device + + :param uid: User id + :param ppn: Device id + + Requires ommsync=True + """ + t_u = types.PPUserType() + t_u.uid = uid + t_u.ppn = ppn + t_u.relType = types.PPRelTypeType("Dynamic") + t_d = types.PPDevType() + t_d.ppn = ppn + t_d.uid = uid + t_d.relType = types.PPRelTypeType("Dynamic") + m = messages.SetPP() + m.childs.user = [t_u] + m.childs.pp = [t_d] + r = self.connection.request(m) + r.raise_on_error() + if r.childs.user is None: + return None + return r.childs.user[0], r.childs.pp[0] + def create_user(self, num): """ Create PP user diff --git a/mitel_ommclient2/messages/__init__.py b/mitel_ommclient2/messages/__init__.py index 242f798..7bcd136 100644 --- a/mitel_ommclient2/messages/__init__.py +++ b/mitel_ommclient2/messages/__init__.py @@ -141,6 +141,7 @@ from .getppuser import GetPPUser, GetPPUserResp from .getpublickey import GetPublicKey, GetPublicKeyResp from .open import Open, OpenResp from .ping import Ping, PingResp +from .setpp import SetPP, SetPPResp from .setppuser import SetPPUser, SetPPUserResp def construct(request): diff --git a/mitel_ommclient2/messages/setpp.py b/mitel_ommclient2/messages/setpp.py new file mode 100644 index 0000000..a094876 --- /dev/null +++ b/mitel_ommclient2/messages/setpp.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +from . import Request, Response, request_type, response_type +from ..types import PPDevType, PPUserType + + +@request_type +class SetPP(Request): + CHILDS = { + "pp": PPDevType, + "user": PPUserType, + } + + +@response_type +class SetPPResp(Response): + CHILDS = { + "pp": PPDevType, + "user": PPUserType, + } diff --git a/mitel_ommclient2/types/__init__.py b/mitel_ommclient2/types/__init__.py index 29c03dc..b57d445 100644 --- a/mitel_ommclient2/types/__init__.py +++ b/mitel_ommclient2/types/__init__.py @@ -96,7 +96,11 @@ class MonitoringStateType(EnumType): class PPRelTypeType(EnumType): - VALUES = None + VALUES = [ + "Fixed", + "Dynamic", + "Unbound", + ] class AccountType(ChildType): @@ -134,6 +138,18 @@ class PPDevType(ChildType): "ppDefaultProfileLoaded": bool, "subscribeToPARIOnly": bool, # undocumented + "ommId": str, + "ommIdAck": str, + "timeStampAdmin": int, + "timeStampRelation": int, + "timeStampRoaming": int, + "timeStampSubscription": int, + "autoCreate": bool, + "roaming": None, # value: 'RoamingComplete' + "modicType": str, # value: '01' + "locationData": str, # value: '000001000000' + "dectIeFixedId": str, + "subscriptionId": str, "ppnSec": int, } @@ -213,4 +229,7 @@ class PPUserType(ChildType): "keyLockEnable": None, "keyLockPin": None, "keyLockTime": None, + "ppnOld": int, + "timeStampAdmin": int, + "timeStampRelation": int, } diff --git a/ommcli b/ommcli index 7113dff..838a805 100755 --- a/ommcli +++ b/ommcli @@ -70,6 +70,11 @@ if __name__ == "__main__": parser_exit = subparsers.add_parser("exit") parser_exit.set_defaults(func=exit) + parser_get_account = subparsers.add_parser("attach_user_device") + parser_get_account.add_argument("uid", type=int) + parser_get_account.add_argument("ppn", type=int) + parser_get_account.set_defaults(func=c.attach_user_device, format=format_list) + parser_get_account = subparsers.add_parser("create_user") parser_get_account.add_argument("num") parser_get_account.set_defaults(func=c.create_user, format=format_child_type)