Add method for detaching device and user

This commit is contained in:
clerie 2022-06-16 23:13:54 +02:00
parent 8849b8488c
commit 1d60043f37
2 changed files with 65 additions and 0 deletions

View File

@ -95,6 +95,58 @@ class OMMClient2:
return None return None
return r.childs.user[0] 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): def get_account(self, id):
""" """

13
ommcli
View File

@ -79,6 +79,19 @@ if __name__ == "__main__":
parser_get_account.add_argument("num") parser_get_account.add_argument("num")
parser_get_account.set_defaults(func=c.create_user, format=format_child_type) 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 = subparsers.add_parser("get_account")
parser_get_account.add_argument("id", type=int) parser_get_account.add_argument("id", type=int)
parser_get_account.set_defaults(func=c.get_account, format=format_child_type) parser_get_account.set_defaults(func=c.get_account, format=format_child_type)