3 from StringIO import StringIO
7 from importCategoryTypes import importCategories
8 from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
9 from importDataTypes import importDataTypes
10 from importPolicyTypes import importPolicyTypes
11 from importGroupTypes import importGroupTypes
12 from importNormativeCapabilities import importNormativeCapabilities
13 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
14 from importOnapTypes import importOnapTypes
17 from importCommon import *
20 #################################################################################################################################################################################################################################
22 # Upgrades the normative types #
25 # python upgradeNormative.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>] #
28 # shortest activation (be host = localhost, be port = 8080, user = jh0003): #
29 # python upgradeNormative.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>]'
36 def handleResults(results, updateversion):
38 for result in results:
39 printNameAndReturnCode(result[0], result[1])
42 failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
43 if (len(failedResults) > 0):
47 print 'Number of arguments:', len(sys.argv), 'arguments.'
53 updateversion = 'true'
54 importCommon.debugFlag = False
58 opts, args = getopt.getopt(argv,"i:p:u:d:h:s:",["ip=","port=","user=","debug=","scheme="])
59 except getopt.GetoptError:
61 errorAndExit(2, 'Invalid input')
68 elif opt in ("-i", "--ip"):
70 elif opt in ("-p", "--port"):
72 elif opt in ("-u", "--user"):
74 elif opt in ("-s", "--scheme"):
76 elif opt in ("-d", "--debug"):
78 debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
80 print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
83 print 'set debug mode to ' + str(debugf)
84 importCommon.debugFlag = debugf
86 if ( beHost == None ):
91 pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
92 debug("path dir =" + pathdir)
94 baseFileLocation = pathdir + "/../../../import/tosca/"
96 fileLocation = baseFileLocation + "categories/"
97 importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
99 fileLocation = baseFileLocation + "data-types/"
100 importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
102 fileLocation = baseFileLocation + "policy-types/"
103 importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
105 fileLocation = baseFileLocation + "capability-types/"
106 importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
108 fileLocation = baseFileLocation + "group-types/"
109 importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
111 fileLocation = baseFileLocation + "interface-lifecycle-types/"
112 importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
114 print 'sleep until data type cache is updated'
117 resultsHeat = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateversion)
118 handleResults(resultsHeat, 'false')
120 errorAndExit(0, None)
122 if __name__ == "__main__":