activate_ipa_host.py 872 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
   :Authors: Julian Gethmann
   :Contact: phd@gethmann.org
   :Date: 2017-11-27
   :Version: 0.1

   For more info see get_ipa_users.py

   Usage: activate_ipa_host.py $hostname
"""
from ipalib import api, cli

def bootstrap():
     """
     Bootstrap the script.
     I hope that all of this stuff is re-entrant.
     Also, api is defined in __init__.py.
     """
     api.bootstrap_with_global_options(context='cli')
     api.finalize()
     api.Backend.rpcclient.connect()

26
def main(host="las116.las.kit.edu"):
27
28
29
30
31
32
33
34
35
36
37
38
    bootstrap()
    result = api.Command.host_mod(host, random=True)
    print(result["result"]["randompassword"])


if __name__ == "__main__":
    import sys
    if len(sys.argv) != 2:
        print(__doc__)
        sys.exit(0)
    main(host=sys.argv[1])
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4