aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/adapters/cobbler/triggers/sync/post/migrate_ks.py
blob: 5eec46d65c493c03d6249f68ca77248ae241e93b (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
##############################################################################
# Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

"""script to migrate rendered kickstart files from cobbler to outside."""
import logging

from cobbler import api


def main():
    """main entry"""
    cobbler_api = api.BootAPI()
    for system in cobbler_api.systems():
        cobbler_api.kickgen.generate_kickstart_for_system(system.name)
        try:
            with open(
                '/var/www/cblr_ks/%s' % system.name, 'w'
            ) as kickstart_file:
                logging.info("Migrating kickstart for %s", system.name)
                data = cobbler_api.kickgen.generate_kickstart_for_system(
                    system.name)
                kickstart_file.write(data)
        except Exception as error:
            logging.error("Directory /var/www/cblr_ks/ does not exist.")
            logging.exception(error)
            raise error


if __name__ == '__main__':
    logging.info("Running kickstart migration")
    main()