- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprocessdb.py
More file actions
Latest commit
53 lines (44 loc) · 1.83 KB
/
Copy pathprocessdb.py
File metadata and controls
53 lines (44 loc) · 1.83 KB
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
"""
This module controls the process of yaml files to initialize database.
"""
importcommentjson
importjson
importos
importyaml
fromyamlimportCLoaderasLoader
fromnode_createimportnode_create
fromget_propertyimportget_home_directory
fromget_propertyimportget_policy_directory
defprocess_nodes():
withopen("{}/superloop_code/database/nodes.yaml".format(get_home_directory()), 'r') asyaml_file:
node_object=yaml.load(yaml_file,Loader=Loader)
returnnode_object
defprocess_templates():
withopen("{}/superloop_code/database/templates.yaml".format(get_home_directory()), 'r') asyaml_file:
template_object=yaml.load(yaml_file, yaml.UnsafeLoader)
returntemplate_object
defprocess_models():
withopen("{}/superloop_code/database/models.yaml".format(get_home_directory()), 'r') asyaml_file:
models_object=yaml.load(yaml_file, yaml.UnsafeLoader)
returnmodels_object
defprocess_policies():
withopen("{}/superloop_code/database/policies.yaml".format(get_home_directory()), 'r') asyaml_file:
policy_object=yaml.load(yaml_file, yaml.UnsafeLoader)
returnpolicy_object
defprocess_json(hardware_vendor,opersys,device_type,policy_file):
data= []
ifhardware_vendor=='cisco'andopersys=='asa'anddevice_type=='firewall':
try:
withopen("{}{}".format(get_policy_directory(hardware_vendor,opersys,device_type),policy_file), 'r') asjson_file:
data=commentjson.load(json_file)
exceptFileNotFoundErroraserror:
print('+ Cannot locate file.')
exit()
elifhardware_vendor=='juniper'andopersys=='junos'anddevice_type=='vfirewall':
try:
withopen("{}{}".format(get_policy_directory(hardware_vendor,opersys,device_type),policy_file), 'r') asjson_file:
data=commentjson.load(json_file)
exceptFileNotFoundErroraserror:
print('+ Cannot locate file.')
exit()
returndata