From 1d60043f37d2a54471d39b55cec6ae4fb76bf7d0 Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 16 Jun 2022 23:13:54 +0200 Subject: [PATCH] Add method for detaching device and user --- mitel_ommclient2/client.py | 52 ++++++++++++++++++++++++++++++++++++++ ommcli | 13 ++++++++++ 2 files changed, 65 insertions(+) diff --git a/mitel_ommclient2/client.py b/mitel_ommclient2/client.py index b0fc22c..14ddd70 100644 --- a/mitel_ommclient2/client.py +++ b/mitel_ommclient2/client.py @@ -95,6 +95,58 @@ class OMMClient2: return None return r.childs.user[0] + def detach_user_device(self, uid, ppn): + """ + Detach user from device + + :param uid: User id + :param ppn: Device id + + Requires ommsync=True + """ + t_u = types.PPUserType() + t_u.uid = uid + t_u.ppn = 0 + t_u.relType = types.PPRelTypeType("Unbound") + t_d = types.PPDevType() + t_d.ppn = ppn + t_d.uid = 0 + t_d.relType = types.PPRelTypeType("Unbound") + 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 detach_user_device_by_user(self, uid): + """ + Detach user from device + + This just requires the user id + + :param uid: User id + + Requires ommsync=True + """ + u = self.get_user(uid) + return self.detach_user_device(uid, u.ppn) + + def detach_user_device_by_device(self, ppn): + """ + Detach user from device + + This just requires the device id + + :param ppn: Device id + + Requires ommsync=True + """ + d = self.get_device(ppn) + return self.detach_user_device(d.uid, ppn) + def get_account(self, id): """ diff --git a/ommcli b/ommcli index 838a805..c85ea66 100755 --- a/ommcli +++ b/ommcli @@ -79,6 +79,19 @@ if __name__ == "__main__": parser_get_account.add_argument("num") parser_get_account.set_defaults(func=c.create_user, format=format_child_type) + parser_get_account = subparsers.add_parser("detach_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.detach_user_device, format=format_list) + + parser_get_account = subparsers.add_parser("detach_user_device_by_device") + parser_get_account.add_argument("ppn", type=int) + parser_get_account.set_defaults(func=c.detach_user_device_by_device, format=format_list) + + parser_get_account = subparsers.add_parser("detach_user_device_by_user") + parser_get_account.add_argument("uid", type=int) + parser_get_account.set_defaults(func=c.detach_user_device_by_user, format=format_list) + parser_get_account = subparsers.add_parser("get_account") parser_get_account.add_argument("id", type=int) parser_get_account.set_defaults(func=c.get_account, format=format_child_type)