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 set_cpu_allocation_ratio():
14 nova_file = '/etc/nova/nova.conf'
15 nova_file_bak = '/etc/nova/nova.bak'
17 if not os.path.isfile(nova_file):
18 raise Exception("File doesn't exist: %s." % nova_file)
19 # TODO (tojuvone): Unfortunately ConfigParser did not produce working conf
20 fcheck = open(nova_file)
21 found_list = ([ca for ca in fcheck.readlines() if "cpu_allocation_ratio"
24 if found_list and len(found_list):
27 for car in found_list:
28 if car.startswith('#'):
30 if car.startswith('cpu_allocation_ratio'):
32 if "1.0" not in car.split('=')[1]:
34 if not found or change:
35 # need to add or change
36 shutil.copyfile(nova_file, nova_file_bak)
37 fin = open(nova_file_bak)
38 fout = open(nova_file, "wt")
40 if change and line.startswith("cpu_allocation_ratio"):
41 line = "cpu_allocation_ratio=1.0"
42 if not found and line.startswith("[DEFAULT]"):
43 line += "cpu_allocation_ratio=1.0\n"
48 set_cpu_allocation_ratio()