5 from importCategoryTypes import importCategories
6 from importCommon import *
7 from importDataTypes import importDataTypes
8 from importGroupTypes import importGroupTypes
9 from importHeatTypes import importHeatTypes
10 from importNfvTypes import importNfvTypes
11 from importNormativeCapabilities import importNormativeCapabilities
12 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
13 from importNormativeRelationships import importNormativeRelationships
14 # from importNormativeElements import createNormativeElement
15 from importNormativeTypes import importNormativeTypes
16 from importOnapTypes import importOnapTypes
17 from importPolicyTypes import importPolicyTypes
18 from importSolTypes import importSolTypes
21 #################################################################################################################################################################################################
23 # Import all users from a given file #
26 # python importNormativeAll.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>] #
27 # [-v <true|false> | --updateversion=<true|false>] #
29 # shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
30 # python importNormativeAll.py #
32 #################################################################################################################################################################################################
36 '[-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>] [-v <true|false> | --updateversion=<true|false>]'
39 def handle_results(results, update_version):
40 if results is not None:
42 for result in results:
43 print_name_and_return_code(result[0], result[1])
46 response_codes = [200, 201]
48 if update_version == 'false':
49 response_codes = [200, 201, 409]
51 failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
52 if len(list(failed_results)) > 0:
53 error_and_exit(1, None)
57 print 'Number of arguments:', len(sys.argv), 'arguments.'
63 update_version = 'true'
64 importCommon.debugFlag = False
69 opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
70 ["ip=", "port=", "user=", "debug=", "update_version=", "scheme="])
71 except getopt.GetoptError:
73 error_and_exit(2, 'Invalid input')
80 elif opt in ("-i", "--ip"):
82 elif opt in ("-p", "--port"):
84 elif opt in ("-u", "--user"):
86 elif opt in ("-s", "--scheme"):
88 elif opt in ("-d", "--debug"):
90 debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
91 elif opt in ("-v", "--update_version"):
93 if arg.lower() == "false" or arg.lower() == "no":
94 update_version = 'false'
96 print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debugf, ', update_version =', update_version
98 if debugf is not None:
99 print 'set debug mode to ' + str(debugf)
100 importCommon.debugFlag = debugf
107 pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
108 debug("path dir =" + pathdir)
110 base_file_location = pathdir + "/../../../import/tosca/"
112 file_location = base_file_location + "data-types/"
113 importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
115 print 'sleep until data type cache is updated'
118 file_location = base_file_location + "capability-types/"
119 importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
121 file_location = base_file_location + "relationship-types/"
122 importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
124 file_location = base_file_location + "interface-lifecycle-types/"
125 importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
127 file_location = base_file_location + "categories/"
128 importCategories(scheme, be_host, be_port, admin_user, False, file_location)
130 file_location = base_file_location + "normative-types/"
131 results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
132 handle_results(results, update_version)
134 file_location = base_file_location + "heat-types/"
135 results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
136 handle_results(results_heat, update_version)
138 file_location = base_file_location + "nfv-types/"
139 results_heat = importNfvTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
140 handle_results(results_heat, update_version)
142 file_location = base_file_location + "onap-types/"
143 results_heat = importOnapTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
144 handle_results(results_heat, update_version)
146 file_location = base_file_location + "sol-types/"
147 results_heat = importSolTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
148 handle_results(results_heat, update_version)
150 file_location = base_file_location + "group-types/"
151 importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
153 file_location = base_file_location + "policy-types/"
154 importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
156 error_and_exit(0, None)
159 if __name__ == "__main__":