3 from StringIO import StringIO
7 #from importNormativeElements import createNormativeElement
8 from importNormativeElements import *
9 from importNormativeTypes import importNormativeTypes
10 from importHeatTypes import importHeatTypes
11 from importNormativeCapabilities import importNormativeCapabilities
12 from importCategoryTypes import importCategories
13 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
14 from importDataTypes import importDataTypes
15 from importGroupTypes import importGroupTypes
16 from importPolicyTypes import importPolicyTypes
17 from importCommon import *
20 #####################################################################################################################################################################################################################################################
22 # Import all users from a given file #
25 # 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>] #
26 # [-v <true|false> | --updateversion=<true|false>] #
28 # shortest activation (be host = localhost, be port = 8080, user = jh0003): #
29 # python importNormativeNoHeatAndNormativeTypes.py #
31 #####################################################################################################################################################################################################################################################
34 print sys.argv[0], '[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, updateversion):
38 for result in results:
39 printNameAndReturnCode(result[0], result[1])
42 responseCodes = [200, 201]
44 if(updateversion == 'false'):
45 responseCodes = [200, 201, 409]
47 failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
48 if (len(failedResults) > 0):
52 print 'Number of arguments:', len(sys.argv), 'arguments.'
58 updateversion = 'true'
59 importCommon.debugFlag = False
63 opts, args = getopt.getopt(argv,"i:p:u:d:v:h:s:",["ip=","port=","user=","debug=","updateversion=", "scheme="])
64 except getopt.GetoptError:
66 errorAndExit(2, 'Invalid input')
73 elif opt in ("-i", "--ip"):
75 elif opt in ("-p", "--port"):
77 elif opt in ("-u", "--user"):
79 elif opt in ("-s", "--scheme"):
81 elif opt in ("-d", "--debug"):
83 debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
84 elif opt in ("-v", "--updateversion"):
86 if (arg.lower() == "false" or arg.lower() == "no"):
87 updateversion = 'false'
89 print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
92 print 'set debug mode to ' + str(debugf)
93 importCommon.debugFlag = debugf
95 if ( beHost == None ):
100 pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
101 debug("path dir =" + pathdir)
103 baseFileLocation = pathdir + "/../../../import/tosca/"
105 fileLocation = baseFileLocation + "data-types/"
106 importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
108 print 'sleep until data type cache is updated'
111 fileLocation = baseFileLocation + "capability-types/"
112 importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
114 fileLocation = baseFileLocation + "interface-lifecycle-types/"
115 importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
117 #fileLocation = baseFileLocation + "categories/"
118 #importCategories(beHost, bePort, adminUser, False, fileLocation)
120 #fileLocation = baseFileLocation + "normative-types/"
121 #results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
122 #handleResults(results, updateversion)
124 #fileLocation = baseFileLocation + "heat-types/"
125 #resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
126 #handleResults(resultsHeat, updateversion)
128 fileLocation = baseFileLocation + "group-types/"
129 importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
131 fileLocation = baseFileLocation + "policy-types/"
132 importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
134 errorAndExit(0, None)
136 if __name__ == "__main__":