5 from importAnnotationTypes import import_annotation_types
6 from importCategoryTypes import importCategories
7 from importCommon import *
8 from importDataTypes import importDataTypes
9 from importGroupTypes import importGroupTypes
10 from importHeatTypes import importHeatTypes
11 from importNormativeCapabilities import importNormativeCapabilities
12 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
13 from importNormativeRelationships import importNormativeRelationships
14 from importNormativeTypes import importNormativeTypes
15 from importPolicyTypes import importPolicyTypes
18 #################################################################################################################################################################################################################################
20 # Import all users from a given file #
23 # 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>] #
24 # [-v <true|false> | --updateversion=<true|false>] #
26 # shortest activation (be host = localhost, be port = 8080, user = jh0003): #
27 # python importNormativeAll.py #
29 #################################################################################################################################################################################################################################
33 '[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>] [-v <true|false> | --updateversion=<true|false>]'
36 def handleResults(results, update_version):
38 for result in results:
39 print_name_and_return_code(result[0], result[1])
42 response_codes = [200, 201]
44 if update_version == 'false':
45 response_codes = [200, 201, 409]
47 failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
48 if len(list(failed_results)) > 0:
49 error_and_exit(1, None)
53 print 'Number of arguments:', len(sys.argv), 'arguments.'
59 update_version = 'true'
60 importCommon.debugFlag = False
64 opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
65 ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
66 except getopt.GetoptError:
68 error_and_exit(2, 'Invalid input')
75 elif opt in ("-i", "--ip"):
77 elif opt in ("-p", "--port"):
79 elif opt in ("-u", "--user"):
81 elif opt in ("-s", "--scheme"):
83 elif opt in ("-d", "--debug"):
85 debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
86 elif opt in ("-v", "--updateversion"):
88 if arg.lower() == "false" or arg.lower() == "no":
89 update_version = 'false'
91 print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
93 if debug_f is not None:
94 print 'set debug mode to ' + str(debug_f)
95 importCommon.debugFlag = debug_f
102 path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
103 debug("path dir =" + path_dir)
105 base_file_location = path_dir + "/../../../import/tosca/"
107 file_location = base_file_location + "data-types/"
108 importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
110 print 'sleep until data type cache is updated'
113 file_location = base_file_location + "capability-types/"
114 importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
116 file_location = base_file_location + "relationship-types/"
117 importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
119 file_location = base_file_location + "interface-lifecycle-types/"
120 importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
122 file_location = base_file_location + "categories/"
123 importCategories(scheme, be_host, be_port, admin_user, False, file_location)
125 file_location = base_file_location + "normative-types/"
126 results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
127 handleResults(results, update_version)
129 file_location = base_file_location + "heat-types/"
130 results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
131 handleResults(results_heat, update_version)
133 file_location = base_file_location + "group-types/"
134 importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
136 file_location = base_file_location + "policy-types/"
137 importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
139 import_annotation_types(scheme, be_host, be_port, admin_user, False)
141 error_and_exit(0, None)
144 if __name__ == "__main__":