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
|
# Copyright 2019 Orange and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
"""
Update policy files of an OpenStack platform
"""
import argparse
import logging
import os
COMPONENTS = [
"cinder",
"glance",
"keystone",
"neutron",
"nova",
]
logger = logging.getLogger(__name__)
def init():
"""
Initialize the application
:return: argument given in the command line
"""
global policy
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", '-v', action='store_true', help='verbose mode')
parser.add_argument("--debug", '-d', action='store_true', help='debug mode')
parser.add_argument("--dir",
help='directory containing policy files, defaults to /etc',
default="/etc")
parser.add_argument("--exclude", "-x",
help="Exclude some components "
"(example: \"nova,neutron\")",
default="")
parser.add_argument("--include", "-i",
help="Only include some components "
"(example: \"nova,neutron\")",
default="")
args = parser.parse_args()
logging_format = "%(levelname)s: %(message)s"
if args.verbose:
logging.basicConfig(level=logging.INFO, format=logging_format)
if args.debug:
logging.basicConfig(level=logging.DEBUG, format=logging_format)
else:
logging.basicConfig(format=logging_format)
return args
def update_component(component, args):
"""
:param component:
:return:
"""
filename = os.path.join(args.dir, component, "policy.json")
logger.info(f"Updating {component} ({filename})")
if not os.path.isfile(filename):
logger.error(f"Cannot find {filename}")
return
def main():
args = init()
if args.include:
for component in args.include.split(","):
update_component(component, args)
else:
excl_comp = args.exclude.split(",")
for component in COMPONENTS:
if component in excl_comp:
continue
update_component(component, args)
if __name__ == "__main__":
main()
|