1 ##############################################################################
2 # Copyright (c) 2018 Nokia Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 def make_initial_config(service, dest):
14 for mk in ["", "/etc", "/%s" % service]:
17 src = "/etc/%s/%s.conf" % (service, service)
18 dest += "/%s.conf" % service
19 shutil.copyfile(src, dest)
22 def set_cpu_allocation_ratio():
23 docker_conf_base_dir = "/var/lib/config-data/puppet-generated"
24 if not os.path.isdir(docker_conf_base_dir):
27 nova_base = "%s/nova" % docker_conf_base_dir
28 if not os.path.isdir(nova_base):
29 # nova.conf to be used might not exist
30 make_initial_config("nova", nova_base)
31 nova_file = nova_base + '/etc/nova/nova.conf'
32 nova_file_bak = nova_base + '/etc/nova/nova.bak'
34 if not os.path.isfile(nova_file):
35 raise Exception("File doesn't exist: %s." % nova_file)
36 # TODO (tojuvone): Unfortunately ConfigParser did not produce working conf
37 fcheck = open(nova_file)
38 found_list = ([ca for ca in fcheck.readlines() if "cpu_allocation_ratio"
41 if found_list and len(found_list):
44 for car in found_list:
45 if car.startswith('#'):
47 if car.startswith('cpu_allocation_ratio'):
49 if "1.0" not in car.split('=')[1]:
51 if not found or change:
52 # need to add or change
53 shutil.copyfile(nova_file, nova_file_bak)
54 fin = open(nova_file_bak)
55 fout = open(nova_file, "wt")
57 if change and line.startswith("cpu_allocation_ratio"):
58 line = "cpu_allocation_ratio=1.0"
59 if not found and line.startswith("[DEFAULT]"):
60 line += "cpu_allocation_ratio=1.0\n"
65 set_cpu_allocation_ratio()