Refactoring the sdc-BE-init python scripts
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / tosca / upgrade / run.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5
6 from sdcBePy.common import logger
7 from sdcBePy.common.logger import error_and_exit
8 from sdcBePy.common.normative.main import process_element_list, process_type_list
9 from sdcBePy.common.sdcBeProxy import SdcBeProxy
10 from sdcBePy.tosca.main import get_args, usage
11 from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
12     get_normative_element_with_metadata_list
13 from sdcBePy.tosca.models.normativeToUpdateList import TypesToUpdate, get_heat_and_normative_to_update_list, \
14     get_nfv_onap_sol_to_update_list
15
16
17 def main():
18     scheme, be_host, be_port, admin_user, _, debug = get_args()
19
20     update_version = True
21     update_onap_version = False
22
23     if debug is False:
24         print('Disabling debug mode')
25         logger.debugFlag = debug
26
27     try:
28         sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
29     except AttributeError:
30         usage()
31         sys.exit(3)
32
33     # use to run script form this dir (not like the command)
34     # base_file_location = os.getcwd() + "/../../../../import/tosca/"
35     base_file_location = os.getcwd() + "/"
36     logger.debug("working directory =" + base_file_location)
37     process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
38     process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
39
40     all_types = get_all_types()
41
42     heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location)
43     process_type_list(heat_and_normative_list, sdc_be_proxy, update_version)
44
45     nfv_onap_sol_list = get_nfv_onap_sol_to_update_list(all_types, base_file_location)
46     process_type_list(nfv_onap_sol_list, sdc_be_proxy, update_onap_version)
47
48     logger.log("Updating end ->", "All normatives updated successfully!")
49     error_and_exit(0, None)
50
51
52 def get_all_types():
53     path = os.path.dirname(__file__)
54     return TypesToUpdate([path + "/../data/typesToUpgrade.json",
55                           path + "/../data/onapTypesToUpgrade.json"])
56
57
58 if __name__ == "__main__":
59     main()