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 upgradeONAPTypes import upgradeOnapTypesPerConfigFile
17 from importCommon import *
20 #################################################################################################################################################################################################
22 # Upgrades the normative types #
25 # python upgradeNormative.py [-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], '[-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):
37 if results is not None:
39 for result in results:
40 printNameAndReturnCode(result[0], result[1])
44 failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
45 if (len(failedResults) > 0):
49 print 'Number of arguments:', len(sys.argv), 'arguments.'
55 updateversion = 'true'
56 updateOnapVersion = 'false'
57 importCommon.debugFlag = False
61 opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="])
62 except getopt.GetoptError:
64 errorAndExit(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 debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
83 print 'scheme =',scheme,',be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
86 print 'set debug mode to ' + str(debugf)
87 importCommon.debugFlag = debugf
89 if ( beHost == None ):
94 pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
95 debug("path dir =" + pathdir)
97 baseFileLocation = pathdir + "/../../../import/tosca/"
99 fileLocation = baseFileLocation + "categories/"
100 importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
102 fileLocation = baseFileLocation + "data-types/"
103 importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
105 fileLocation = baseFileLocation + "policy-types/"
106 importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
108 fileLocation = baseFileLocation + "group-types/"
109 importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
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 print 'sleep until data type cache is updated'
120 resultsHeat = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateversion)
121 handleResults(resultsHeat)
123 resultsHeat = upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateOnapVersion)
124 handleResults(resultsHeat)
126 errorAndExit(0, None)
128 if __name__ == "__main__":