Decouple TXT Report file writing and formatting logic (6/6)
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / upgradeNormativeVersion.py
1 import os
2
3 import importCommon
4 from importCommon import *
5 from importNormativeTypes import createNormativeType
6
7
8 #################################################################################################################################################################################################################################
9 #                                                                                                                                                                                                                                                                                                                                                                                                                                                       #
10 # Upgrades the normative types                                                                                                                                                                                                                                                                                                                                                                                                  #
11 #                                                                                                                                                                                                                                                                                                                                                                                                                                                               #
12 # activation :                                                                                                                                                                                                                                                                                                                                                                                                                                  #
13 #       python upgradeNormative.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]    #
14 #                                                                                                                                                                                                                                                                                                                                                                                                                                                               #
15 #                                                                                                                                                                                                                                                                                                                                                                                                                                                               #
16 # shortest activation (be host = localhost, be port = 8080, user = jh0003):                                                                                                                                                                                                                                                                                                     #
17 #               python upgradeNormative.py                                                                                                                                                                                                                                                                                                                                                                                      #
18 #                                                                                                                                                                                                                                                                                                                                                                                                                                                       #
19 #################################################################################################################################################################################################################################
20
21
22 def usage():
23     print sys.argv[0], \
24         '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
25
26
27 def handleResults(results):
28     print_frame_line()
29     for result in results:
30         print_name_and_return_code(result[0], result[1])
31     print_frame_line()
32
33     failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results)
34     if len(list(failed_results)) > 0:
35         error_and_exit(1, None)
36
37
38 def main(argv):
39     print 'Number of arguments:', len(sys.argv), 'arguments.'
40
41     be_host = 'localhost'
42     be_port = '8080'
43     admin_user = 'jh0003'
44     debug_f = None
45     update_version = 'true'
46     importCommon.debugFlag = False
47     scheme = 'http'
48
49     try:
50         opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="])
51     except getopt.GetoptError:
52         usage()
53         error_and_exit(2, 'Invalid input')
54
55     for opt, arg in opts:
56         # print opt, arg
57         if opt == '-h':
58             usage()
59             sys.exit(3)
60         elif opt in ("-i", "--ip"):
61             be_host = arg
62         elif opt in ("-p", "--port"):
63             be_port = arg
64         elif opt in ("-u", "--user"):
65             admin_user = arg
66         elif opt in ("-s", "--scheme"):
67             scheme = arg
68         elif opt in ("-d", "--debug"):
69             print arg
70             debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
71
72     print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f
73
74     if debug_f is not None:
75         print 'set debug mode to ' + str(debug_f)
76         importCommon.debugFlag = debug_f
77
78     if be_host is None:
79         usage()
80         sys.exit(3)
81
82     print sys.argv[0]
83     path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
84     debug("path dir =" + path_dir)
85
86     base_file_location = path_dir + "/../../../import/tosca/"
87     results = []
88
89     ##########################################################################
90     # ---------------------------------for release 1702---------------------- #
91     ##########################################################################
92
93     file_location = base_file_location + "heat-types/"
94     result = createNormativeType(scheme, be_host, be_port, admin_user, file_location,
95                                  "contrailV2VirtualMachineInterface", update_version)
96     results.append(result)
97
98     file_location = base_file_location + "heat-types/"
99     result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version)
100     results.append(result)
101
102     handleResults(results)
103
104     error_and_exit(0, None)
105
106
107 if __name__ == "__main__":
108     main(sys.argv[1:])