summaryrefslogtreecommitdiffstats
path: root/fuel/deploy/configure_settings.py
blob: cdeea4923d79a40c7572b2c12d9db8cef76838ea (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import common
import os
import yaml
import io
import re

N = common.N
E = common.E
R = common.R
RO = common.RO
exec_cmd = common.exec_cmd
parse = common.parse
err = common.err

class ConfigureSettings(object):

    def __init__(self, yaml_config_dir, env_id):
        self.yaml_config_dir = yaml_config_dir
        self.env_id = env_id

    def download_settings(self):
        exec_cmd('fuel --env %s settings --download' % self.env_id)

    def upload_settings(self):
        exec_cmd('fuel --env %s settings --upload' % self.env_id)


    def config_settings(self):
        self.download_settings()
        self.modify_settings()
        self.upload_settings()

    # Fix console speed
    def fix_console_speed(data):
        # First remove all console= from the kernel cmdline
        cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
        pat = re.compile(r"console=[\w,]+\s+")
        repl = 1
        while repl != 0:
            cmdline, repl = pat.subn("", cmdline)

        # Then add the console info we want
        cmdline = re.sub(r"^", "console=tty0 console=ttyS0,115200 ", cmdline)
        data["editable"]["kernel_params"]["kernel"]["value"] = cmdline

    # Initialize kernel audit
    def initialize_kernel_audit(data):
        cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
        cmdline = "audit=1 " + cmdline
        data["editable"]["kernel_params"]["kernel"]["value"] = cmdline

    # Add crashkernel parameter to boot parameters. W/o this we can't
    # make crash dumps after initial deploy. Standard grub setup will add
    # crashkernel= options - with bad values but that is another issue - but
    # that only enables crash dumps after first reboot
    def add_crashkernel_support(data):
        cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
        cmdline += " crashkernel=256M"
        data["editable"]["kernel_params"]["kernel"]["value"] = cmdline


    def modify_settings(self):

        filename = "%s/settings_%d.yaml" % (self.yaml_config_dir, self.env_id)
        if not os.path.isfile(filename):
            err("Failed to find %s\n" % filename)

        with io.open(filename) as stream:
            data = yaml.load(stream)

        self.fix_console_speed(data)

        self.initialize_kernel_audit(data)

        self.add_crashkernel_support(data)

        # Make sure we have the correct libvirt type
        data["editable"]["common"]["libvirt_type"]["value"] = "kvm"


        # Save the settings into the file from which we loaded them
        with io.open(filename, "w") as stream:
            yaml.dump(data, stream, default_flow_style=False)