5 from importCommon import *
6 from importDataTypes import importDataTypes
7 from importGroupTypes import importGroupTypes
8 from importNormativeCapabilities import importNormativeCapabilities
9 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
10 from importPolicyTypes import importPolicyTypes
13 #####################################################################################################################################################################################################################################################
15 # Import all users from a given file #
18 # python importNormativeNoHeatAndNormativeTypes.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>] #
19 # [-v <true|false> | --updateversion=<true|false>] #
21 # shortest activation (be host = localhost, be port = 8080, user = jh0003): #
22 # python importNormativeNoHeatAndNormativeTypes.py #
24 #####################################################################################################################################################################################################################################################
29 '[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>]'
32 def handleResults(results, update_version):
34 for result in results:
35 print_name_and_return_code(result[0], result[1])
38 response_codes = [200, 201]
40 if update_version == 'false':
41 response_codes = [200, 201, 409]
43 failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
44 if len(list(failed_results)) > 0:
45 error_and_exit(1, None)
49 print 'Number of arguments:', len(sys.argv), 'arguments.'
55 update_version = 'true'
56 importCommon.debugFlag = False
60 opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
61 ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
62 except getopt.GetoptError:
64 error_and_exit(2, 'Invalid input')
71 elif opt in ("-i", "--ip"):
73 elif opt in ("-p", "--port"):
75 elif opt in ("-u", "--user"):
77 elif opt in ("-s", "--scheme"):
79 elif opt in ("-d", "--debug"):
81 debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
82 elif opt in ("-v", "--updateversion"):
84 if arg.lower() == "false" or arg.lower() == "no":
85 update_version = 'false'
87 print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
89 if debug_f is not None:
90 print 'set debug mode to ' + str(debug_f)
91 importCommon.debugFlag = debug_f
98 path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
99 debug("path dir =" + path_dir)
101 base_file_location = path_dir + "/../../../import/tosca/"
103 file_location = base_file_location + "data-types/"
104 importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
106 print 'sleep until data type cache is updated'
109 file_location = base_file_location + "capability-types/"
110 importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
112 file_location = base_file_location + "interface-lifecycle-types/"
113 importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
115 # fileLocation = baseFileLocation + "categories/"
116 # importCategories(beHost, bePort, adminUser, False, fileLocation)
118 # fileLocation = baseFileLocation + "normative-types/"
119 # results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
120 # handleResults(results, updateversion)
122 # fileLocation = baseFileLocation + "heat-types/"
123 # resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
124 # handleResults(resultsHeat, updateversion)
126 file_location = base_file_location + "group-types/"
127 importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
129 file_location = base_file_location + "policy-types/"
130 importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
132 error_and_exit(0, None)
135 if __name__ == "__main__":