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 importOnapTypes import importOnapTypes
12 from importNormativeCapabilities import importNormativeCapabilities
13 from importCategoryTypes import importCategories
14 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
15 from importDataTypes import importDataTypes
16 from importGroupTypes import importGroupTypes
17 from importPolicyTypes import importPolicyTypes
18 from importCommon import *
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 #################################################################################################################################################################################################################################
35 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>]'
37 def handleResults(results, updateversion):
39 for result in results:
40 printNameAndReturnCode(result[0], result[1])
43 responseCodes = [200, 201]
45 if(updateversion == 'false'):
46 responseCodes = [200, 201, 409]
48 failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
49 if (len(failedResults) > 0):
53 print 'Number of arguments:', len(sys.argv), 'arguments.'
59 updateversion = 'true'
60 importCommon.debugFlag = False
64 opts, args = getopt.getopt(argv,"i:p:u:d:v:h:s:",["ip=","port=","user=","debug=","updateversion=","scheme="])
65 except getopt.GetoptError:
67 errorAndExit(2, 'Invalid input')
74 elif opt in ("-i", "--ip"):
76 elif opt in ("-p", "--port"):
78 elif opt in ("-u", "--user"):
80 elif opt in ("-s", "--scheme"):
82 elif opt in ("-d", "--debug"):
84 debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
85 elif opt in ("-v", "--updateversion"):
87 if (arg.lower() == "false" or arg.lower() == "no"):
88 updateversion = 'false'
90 print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
93 print 'set debug mode to ' + str(debugf)
94 importCommon.debugFlag = debugf
96 if ( beHost == None ):
101 pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
102 debug("path dir =" + pathdir)
104 baseFileLocation = pathdir + "/../../../import/tosca/"
106 fileLocation = baseFileLocation + "data-types/"
107 importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
109 print 'sleep until data type cache is updated'
112 fileLocation = baseFileLocation + "capability-types/"
113 importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
115 fileLocation = baseFileLocation + "interface-lifecycle-types/"
116 importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
118 fileLocation = baseFileLocation + "categories/"
119 importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
121 fileLocation = baseFileLocation + "normative-types/"
122 results = importNormativeTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
123 handleResults(results, updateversion)
125 fileLocation = baseFileLocation + "heat-types/"
126 resultsHeat = importHeatTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
127 handleResults(resultsHeat, updateversion)
129 fileLocation = baseFileLocation + "group-types/"
130 importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
132 fileLocation = baseFileLocation + "policy-types/"
133 importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
135 errorAndExit(0, None)
137 if __name__ == "__main__":