diff options
Diffstat (limited to 'catalog-be/src/main/resources/scripts')
16 files changed, 1690 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py new file mode 100644 index 0000000000..aca21754e8 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py @@ -0,0 +1,74 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement + +from importCommon import * +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importCategories(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/categories", "categoryTypes", "categoriesZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + errorAndExit(1, None) + else: + if (exitOnSuccess == True): + errorAndExit(0, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importCategories(beHost, bePort, adminUser, True, "../../../import/tosca/categories/") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py new file mode 100644 index 0000000000..acdb067849 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py @@ -0,0 +1,43 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy + +############################################################################################################### +# +# +############################################################################################################### + +debugFlag = True + +def join_strings(lst): + concat = "" + for string in lst: + if (string != None): + if (type(string) == int): + string = str(string) + concat += (string + " ") + return concat + +def debug(desc, *args): + 'print only if debug enabled' + if (debugFlag == True): + print desc, join_strings(args) + +def log(desc, arg=None): + 'print log info' + print desc, arg + +def errorAndExit(errorCode, errorDesc): + if ( errorCode > 0 ): + print "status={0}. {1}".format(errorCode, '' if errorDesc == None else errorDesc) + else: + print "status={0}".format(errorCode) + sys.exit(errorCode) + +def printNameAndReturnCode(name, code): + print "{0:30} | {1:6}".format(name, code) + +def printFrameLine(): + print "----------------------------------------" diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py new file mode 100644 index 0000000000..5d7f5b7576 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py @@ -0,0 +1,74 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement + +from importCommon import * +################################################################################################################################################ +# # +# Import tosca data types # +# # +# activation : # +# python importDataTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importDataTypes.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importDataTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/datatypes", "dataTypes", "dataTypesZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + errorAndExit(1, None) + else: + if (exitOnSuccess == True): + errorAndExit(0, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importDataTypes(beHost, bePort, adminUser, True, "../../../import/tosca/data-types/") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py new file mode 100644 index 0000000000..2b6a5db6f8 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py @@ -0,0 +1,74 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement + +from importCommon import * +################################################################################################################################################ +# # +# Import tosca data types # +# # +# activation : # +# python importGroupTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importGroupTypes.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importGroupTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/grouptypes", "groupTypes", "groupTypesZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + errorAndExit(1, None) + else: + if (exitOnSuccess == True): + errorAndExit(0, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importGroupTypes(beHost, bePort, adminUser, True, "../../../import/tosca/group-types/") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py new file mode 100644 index 0000000000..07eacf8d61 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py @@ -0,0 +1,113 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importCommon import * +from importNormativeTypes import * +import importCommon + +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def importHeatTypes(beHost, bePort, adminUser, fileDir, updateversion): + + heatTypes = [ "cinderVolume", +# "contrailVirtualNetwork", + "neutronNet", + "neutronPort", + "novaServer", + "vl", + "eline", + "abstractSubstitute", +# "contrailNetworkRules", +# "contrailPort", +# "contrailV2NetworkRules", +# "contrailV2VirtualNetwork", + "securityRules" +# "contrailAbstractSubstitute", +# "contrailCompute", +# "contrailV2VirtualMachineInterface" + ] + + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + results = [] + for heatType in heatTypes: + result = createNormativeType(beHost, bePort, adminUser, fileDir, heatType, updateversion) + results.append(result) + if ( result[1] == None or result[1] not in responseCodes) : + print "Failed creating heat type " + heatType + ". " + str(result[1]) + return results + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + updateversion = 'true' + + try: + opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-v", "--updateversion"): + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + results = importHeatTypes(beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion) + + print "-----------------------------" + for result in results: + print "{0:20} | {1:6}".format(result[0], result[1]) + print "-----------------------------" + + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedNormatives) > 0): + errorAndExit(1, None) + else: + errorAndExit(0, None) + + +if __name__ == "__main__": + main(sys.argv[1:]) + + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py new file mode 100644 index 0000000000..f35cc7bcee --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py @@ -0,0 +1,156 @@ +import pycurl +import sys, getopt, os +from StringIO import StringIO +import json +import copy +from importCommon import * +import importCommon +import zipfile +################################################################################################################################################ +# # +################################################################################################################################################ + +def createZipFromYml(ymlFile, zipFile): + zip = zipfile.ZipFile(zipFile, 'w', zipfile.ZIP_DEFLATED) + + zip.write(ymlFile, os.path.basename(ymlFile)) + zip.close() + +def createUserNormativeType(beHost, bePort, adminUser, fileDir, ELEMENT_NAME): + + try: + log("in create normative type ", ELEMENT_NAME) + debug("userId", adminUser) + debug("fileDir", fileDir) + + buffer = StringIO() + c = pycurl.Curl() + + url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart' + c.setopt(c.URL, url) + c.setopt(c.POST, 1) + + adminHeader = 'USER_ID: ' + adminUser + #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) + c.setopt(pycurl.HTTPHEADER, [adminHeader]) + + ymlFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".yml" + zipFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".zip" + debug(ymlFile) + debug(zipFile) + path = zipFile + debug("path=" + path) + CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json" + debug(CURRENT_JSON_FILE) + jsonFile = open(CURRENT_JSON_FILE) + + debug("before load json") + json_data = json.load(jsonFile, strict=False) + debug(json_data) + + jsonAsStr = json.dumps(json_data) + debug(path) + send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))] + debug(send) + c.setopt(pycurl.HTTPPOST, send) + + c.setopt(c.WRITEFUNCTION, buffer.write) + res = c.perform() + + #print("Before get response code") + httpRes = c.getinfo(c.RESPONSE_CODE) + if (httpRes != None): + debug("http response=", httpRes) + #print('Status: ' + str(responseCode)) + debug(buffer.getvalue()) + c.close() + + return (ELEMENT_NAME, httpRes, buffer.getvalue()) + + except Exception as inst: + print("ERROR=" + str(inst)) + return (ELEMENT_NAME, None, None) + + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-l <directory base location> | --location=<directory base location>] [-e <element name> | --element=<element name>]' + print "----------------- Example -------------------" + print "python importNodeType.py -d false -l /home/vagrant/catalog-be-1604.0.2.15.6-SNAPSHOT/scripts/import/tosca/../../../import/tosca/user-normative-types/ -e root1" + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + debugf = None + location = None + element = None + + try: + opts, args = getopt.getopt(argv,"i:p:u:d:l:e:h",["ip=","port=","user=","location=","element=", "debug="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-l", "--location"): + location = arg + elif opt in ("-e", "--element"): + element = arg + elif opt in ("-d", "--debug"): + print arg + debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + if (debugf != None): + print 'set debug mode to ' + str(debugf) + importCommon.debugFlag = debugf + + if (location == None): + print 'Missing file location' + usage() + sys.exit(3) + + if (element == None): + print 'Missing element name. E.g. root, compute, ...' + usage() + sys.exit(3) + + #pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + + #baseFileLocation = pathdir + "/../../../import/tosca/" + #fileDir = baseFileLocation + "user-normative-types/" + + #normativeType = "root1" + + result = createUserNormativeType(beHost, bePort, adminUser, location, element) + #result = createUserNormativeType(beHost, bePort, adminUser, fileDir, normativeType) + print "---------------------------------------" + print "{0:30} | {1:6}".format(result[0], result[1]) + print "---------------------------------------" + + if ( result[1] == None or result[1] not in [200, 201] ) : + print "Failed creating normative type " + element + ". " + str(result[1]) + errorAndExit(1, None) + + errorAndExit(0, None) + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py new file mode 100644 index 0000000000..ec9e93e6e4 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py @@ -0,0 +1,135 @@ +import pycurl +import sys, getopt, os +from StringIO import StringIO +import json +import copy +import time +#from importNormativeElements import createNormativeElement +from importNormativeElements import * +from importNormativeTypes import importNormativeTypes +from importHeatTypes import importHeatTypes +from importNormativeCapabilities import importNormativeCapabilities +from importCategoryTypes import importCategories +from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType +from importDataTypes import importDataTypes +from importGroupTypes import importGroupTypes +from importPolicyTypes import importPolicyTypes +from importCommon import * +import importCommon + +################################################################################################################################################################################################# +# # +# Import all users from a given file # +# # +# activation : # +# python importNormativeAll.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>] # +# [-v <true|false> | --updateversion=<true|false>] # +# # +# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # # +# python importNormativeAll.py # +# # +################################################################################################################################################################################################# + +def usage(): + 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>] [-v <true|false> | --updateversion=<true|false>]' + +def handleResults(results, updateversion): + printFrameLine() + for result in results: + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedResults) > 0): + errorAndExit(1, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + debugf = None + updateversion = 'true' + importCommon.debugFlag = False + + try: + opts, args = getopt.getopt(argv,"i:p:u:d:v:h",["ip=","port=","user=","debug=","updateversion="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-d", "--debug"): + print arg + debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + elif opt in ("-v", "--updateversion"): + print arg + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion + + if (debugf != None): + print 'set debug mode to ' + str(debugf) + importCommon.debugFlag = debugf + + if ( beHost == None ): + usage() + sys.exit(3) + + print sys.argv[0] + pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + pathdir) + + baseFileLocation = pathdir + "/../../../import/tosca/" + + fileLocation = baseFileLocation + "data-types/" + importDataTypes(beHost, bePort, adminUser, False, fileLocation) + + print 'sleep until data type cache is updated' + time.sleep( 70 ) + + fileLocation = baseFileLocation + "capability-types/" + importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "interface-lifecycle-types/" + importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "categories/" + importCategories(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "normative-types/" + results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion) + handleResults(results, updateversion) + + fileLocation = baseFileLocation + "heat-types/" + resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion) + handleResults(resultsHeat, updateversion) + + fileLocation = baseFileLocation + "group-types/" + importGroupTypes(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "policy-types/" + importPolicyTypes(beHost, bePort, adminUser, False, fileLocation) + + errorAndExit(0, None) + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py new file mode 100644 index 0000000000..bda02ddda9 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py @@ -0,0 +1,77 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement +from importCommon import * +import importCommon + +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importNormativeCapabilities(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", "capabilityTypeZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + importCommon.errorAndExit(1, None) + else: + if (exitOnSuccess == True): + importCommon.errorAndExit(0, None) + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + importCommon.errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importNormativeCapabilities(beHost, bePort, adminUser, True, "../../../import/tosca/capability-types/") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py new file mode 100644 index 0000000000..af643da4f4 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py @@ -0,0 +1,65 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importCommon import * +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def createNormativeElement(beHost, bePort, adminUser, fileDir, urlSuffix, ELEMENT_NAME, elementFormName): + + try: + log("in create normative element ", ELEMENT_NAME) + + buffer = StringIO() + c = pycurl.Curl() + + url = 'http://' + beHost + ':' + bePort + urlSuffix + c.setopt(c.URL, url) + c.setopt(c.POST, 1) + + adminHeader = 'USER_ID: ' + adminUser + #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) + c.setopt(pycurl.HTTPHEADER, [adminHeader]) + + + path = fileDir + "/" + ELEMENT_NAME + ".zip" + debug(path) + + send = [(elementFormName, (pycurl.FORM_FILE, path))] + debug(send) + c.setopt(pycurl.HTTPPOST, send) + + #data = json.dumps(user) + #c.setopt(c.POSTFIELDS, data) + + #c.setopt(c.WRITEFUNCTION, lambda x: None) + c.setopt(c.WRITEFUNCTION, buffer.write) + #print("before perform") + res = c.perform() + + #print("Before get response code") + httpRes = c.getinfo(c.RESPONSE_CODE) + if (httpRes != None): + debug("http response=", httpRes) + #print('Status: ' + str(responseCode)) + debug("response buffer", buffer.getvalue()) + c.close() + + return (ELEMENT_NAME, httpRes, buffer.getvalue()) + + except Exception as inst: + print("ERROR=" + str(inst)) + return (ELEMENT_NAME, None, None) + + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py new file mode 100644 index 0000000000..33f1cc42de --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py @@ -0,0 +1,75 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement +from importCommon import * + +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", "interfaceLifecycleTypes", "interfaceLifecycleTypeZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + errorAndExit(1, None) + else: + if (exitOnSuccess == True): + errorAndExit(0, None) + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, True, "../../../import/tosca/interface-lifecycle-types//") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py new file mode 100644 index 0000000000..76bae682c0 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py @@ -0,0 +1,159 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importCommon import * +import importCommon +################################################################################################################################################ +# # +# Import all users from a given file # +# # +# activation : # +# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# [-v <true|false> | --updateversion=<true|false>] # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsers.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def createNormativeType(beHost, bePort, adminUser, fileDir, ELEMENT_NAME, updateversion): + + try: + log("in create normative type ", ELEMENT_NAME) + debug("userId", adminUser) + debug("fileDir", fileDir) + + buffer = StringIO() + c = pycurl.Curl() + + url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart' + if updateversion != None: + url += '?createNewVersion=' + updateversion + c.setopt(c.URL, url) + c.setopt(c.POST, 1) + + adminHeader = 'USER_ID: ' + adminUser + #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) + c.setopt(pycurl.HTTPHEADER, [adminHeader]) + + + path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".zip" + debug(path) + CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json" + #sed -i 's/"userId": ".*",/"userId": "'${ATT_UID}'",/' ${CURRENT_JSON_FILE} + + jsonFile = open(CURRENT_JSON_FILE) + + debug("before load json") + json_data = json.load(jsonFile, strict=False) + debug(json_data) + + jsonAsStr = json.dumps(json_data) + + send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))] + debug(send) + c.setopt(pycurl.HTTPPOST, send) + + #data = json.dumps(user) + #c.setopt(c.POSTFIELDS, data) + + #c.setopt(c.WRITEFUNCTION, lambda x: None) + c.setopt(c.WRITEFUNCTION, buffer.write) + #print("before perform") + res = c.perform() + + #print("Before get response code") + httpRes = c.getinfo(c.RESPONSE_CODE) + if (httpRes != None): + debug("http response=", httpRes) + #print('Status: ' + str(responseCode)) + debug(buffer.getvalue()) + c.close() + + return (ELEMENT_NAME, httpRes, buffer.getvalue()) + + except Exception as inst: + print("ERROR=" + str(inst)) + return (ELEMENT_NAME, None, None) + + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-v <true|false> | --updateversion=<true|false>]' + + +def importNormativeTypes(beHost, bePort, adminUser, fileDir, updateversion): + + normativeTypes = [ "root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database", "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer", "port", "network"] + #normativeTypes = [ "root" ] + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + results = [] + for normativeType in normativeTypes: + result = createNormativeType(beHost, bePort, adminUser, fileDir, normativeType, updateversion) + results.append(result) + if ( result[1] == None or result[1] not in responseCodes ): + print "Failed creating normative type " + normativeType + ". " + str(result[1]) + return results + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + updateversion = 'true' + + try: + opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-v", "--updateversion"): + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', updateversion =', updateversion + + if ( beHost == None ): + usage() + sys.exit(3) + + results = importNormativeTypes(beHost, bePort, adminUser, "../../../import/tosca/normative-types/", updateversion) + + print "-----------------------------" + for result in results: + print "{0:20} | {1:6}".format(result[0], result[1]) + print "-----------------------------" + + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedNormatives) > 0): + errorAndExit(1, None) + else: + errorAndExit(0, None) + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py new file mode 100644 index 0000000000..c01e159264 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py @@ -0,0 +1,74 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importNormativeElements import createNormativeElement + +from importCommon import * +################################################################################################################################################ +# # +# Import tosca data types # +# # +# activation : # +# python importPolicyTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importPolicyTypes.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################ + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]' + + +def importPolicyTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir): + result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/policytypes", "policyTypes", "policyTypesZip") + + printFrameLine() + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + if ( result[1] == None or result[1] not in [200, 201, 409] ): + errorAndExit(1, None) + else: + if (exitOnSuccess == True): + errorAndExit(0, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser + + if ( beHost == None ): + usage() + sys.exit(3) + + importPolicyTypes(beHost, bePort, adminUser, True, "../../../import/tosca/policy-types/") + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py new file mode 100644 index 0000000000..8509855f38 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py @@ -0,0 +1,221 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +import yaml + +######################################################################################################################################################## +# # +# Import all users from a given YAML file # +# # +# activation : # +# python importUsersFromYaml.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # # +# python importUsersFromYaml.py [-f <input file> | --ifile=<input file> ] # +# # +# PyYAML module shall be added to python. # +# pip install PyYAML>=3.1.0 --proxy=http://one.proxy.att.com:8080 # +######################################################################################################################################################## + + +def importUsers(beHost, bePort, users, adminUser): + + result = [] + + for user in users: + + #print("Going to add user " + user['userId']) + + getRes = getUser(beHost, bePort, user) + userId = getRes[0] + error = getRes[1] + #print error + if ( error != None and error == 404 ): + res = createUser(beHost, bePort, user ,adminUser) + result.append(res) + else: + if ( error == 200 ): + curResult = (userId, 409) + result.append(curResult) + else: + result.append(getRes) + + return result + + +def getUser(beHost, bePort, user): + + if (user.get('userId') == None): + print "Ignoring record", user + return ('NotExist', 200) + userId = user['userId'] + try: + buffer = StringIO() + c = pycurl.Curl() + + #print type(userId) + url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user/' + str(userId) + c.setopt(c.URL, url) + + #adminHeader = 'USER_ID: ' + adminUser + c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json']) + c.setopt(c.WRITEFUNCTION, lambda x: None) + res = c.perform() + + #print("Before get response code") + httpRes = c.getinfo(c.RESPONSE_CODE) + #print("After get response code") + responseCode = c.getinfo(c.RESPONSE_CODE) + + #print('Status: ' + str(responseCode)) + + c.close() + + return (userId, httpRes) + + except Exception as inst: + print(inst) + return (userId, None) + + + +def createUser(beHost, bePort, user, adminUser): + + if (user.get('userId') == None): + print "Ignoring record", user + return ('NotExist', 200) + + userId = user['userId'] + try: + buffer = StringIO() + c = pycurl.Curl() + + url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user' + c.setopt(c.URL, url) + c.setopt(c.POST, 1) + + adminHeader = 'USER_ID: ' + adminUser + c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) + + data = json.dumps(user) + c.setopt(c.POSTFIELDS, data) + + c.setopt(c.WRITEFUNCTION, lambda x: None) + #print("before perform") + res = c.perform() + #print(res) + + #print("Before get response code") + httpRes = c.getinfo(c.RESPONSE_CODE) + #print("After get response code") + responseCode = c.getinfo(c.RESPONSE_CODE) + + #print('Status: ' + str(responseCode)) + + c.close() + + return (userId, httpRes) + + except Exception as inst: + print(inst) + return (userId, None) + + +def errorAndExit(errorCode, errorDesc): + if ( errorCode > 0 ): + print("status=" + str(errorCode) + ". " + errorDesc) + else: + print("status=" + str(errorCode)) + sys.exit(errorCode) + +def usage(): + print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]' + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + inputfile = None + + adminUser = 'jh0003' + + try: + opts, args = getopt.getopt(argv,"i:p:f:h:",["ip=","port=","ifile="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-f", "--ifile"): + inputfile = arg + + print 'be host =',beHost,', be port =', bePort,', users file =',inputfile + + if ( inputfile == None ): + usage() + sys.exit(3) + + print 'Input file is ', inputfile + + + usersAsYamlFile = open(inputfile, 'r') + usersDoc = yaml.load(usersAsYamlFile) + print usersDoc + + cloneUsers = [] + for users in usersDoc.values(): + for x,y in users.items(): + copiedUser = y + copiedUser['userId'] = x + #print copiedUser + cloneUsers.append(copiedUser) + + print cloneUsers + + usersAsYamlFile.close() + + #activeUsers = filter(lambda x: x.get('status') == None or x['status'] == 'ACTIVE', cloneUsers) + + resultTable = importUsers(beHost, bePort, cloneUsers, adminUser) + + g = lambda x: x[1] != 201 and x[1] != 409 + + result = filter(g, resultTable) + + if ( len(result) > 0 ): + #print("ERROR: Failed to load the users " + ', '.join(map(lambda x: x[0],result))) + errorAndExit(3, "Failed to load the users " + ', '.join(map(lambda x: x[0],result))) + + g = lambda x: x[1] == 409 + result = filter(g, resultTable) + + print("-------------------------------------------") + print("Existing users: " + ', '.join(map(lambda x: x[0],result))) + + result = filter(lambda x: x[1] == 201, resultTable) + if ( len(result) == 0 ): + print("-------------------------------------------") + print("No NEW user was loaded. All users are already exist") + print("-------------------------------------------") + else: + print("-------------------------------------------") + print("Loaded users: " + ', '.join(map(lambda x: x[0],result))) + print("-------------------------------------------") + + errorAndExit(0, None) + + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py new file mode 100644 index 0000000000..e6bb620692 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py @@ -0,0 +1,114 @@ +import pycurl +import sys, getopt, os +from StringIO import StringIO +import json +import copy +import time +from importCategoryTypes import importCategories +from importHeatTypes import importHeatTypes +from importNormativeCapabilities import importNormativeCapabilities +from importDataTypes import importDataTypes +from importGroupTypes import importGroupTypes +from importPolicyTypes import importPolicyTypes +from importCommon import * +import importCommon + +################################################################################################################################################################################################# +# # +# Upgrades the normative types # +# # +# activation : # +# 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>] # +# # +# # +# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # # +# python upgradeNormative.py # +# # +################################################################################################################################################################################################# + +def usage(): + 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>]' + +def handleResults(results, updateversion): + printFrameLine() + for result in results: + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) + if (len(failedResults) > 0): + errorAndExit(1, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + debugf = None + updateversion = 'false' + importCommon.debugFlag = False + + try: + opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-d", "--debug"): + print arg + debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf + + if (debugf != None): + print 'set debug mode to ' + str(debugf) + importCommon.debugFlag = debugf + + if ( beHost == None ): + usage() + sys.exit(3) + + print sys.argv[0] + pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + pathdir) + + baseFileLocation = pathdir + "/../../../import/tosca/" + + fileLocation = baseFileLocation + "categories/" + importCategories(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "data-types/" + importDataTypes(beHost, bePort, adminUser, False, fileLocation) + + print 'sleep until data type cache is updated' + time.sleep( 70 ) + fileLocation = baseFileLocation + "capability-types/" + importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "group-types/" + importGroupTypes(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "policy-types/" + importPolicyTypes(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "heat-types/" + resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion) + handleResults(resultsHeat, 'false') + + errorAndExit(0, None) + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py new file mode 100644 index 0000000000..0f70174173 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py @@ -0,0 +1,143 @@ +import pycurl +import sys, getopt, os +from StringIO import StringIO +import json +import copy +from importCommon import * +from importNormativeTypes import createNormativeType +import importCommon + +################################################################################################################################################################################################# +# # +# Upgrades the normative types # +# # +# activation : # +# 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>] # +# # +# # +# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # # +# python upgradeNormative.py # +# # +################################################################################################################################################################################################# + +def usage(): + 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>]' + +def handleResults(results, updateversion): + printFrameLine() + for result in results: + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) + if (len(failedResults) > 0): + errorAndExit(1, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + debugf = None + updateversion = 'true' + importCommon.debugFlag = False + + try: + opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-d", "--debug"): + print arg + debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf + + if (debugf != None): + print 'set debug mode to ' + str(debugf) + importCommon.debugFlag = debugf + + if ( beHost == None ): + usage() + sys.exit(3) + + print sys.argv[0] + pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + pathdir) + + baseFileLocation = pathdir + "/../../../import/tosca/" + results = [] + + + ########################################################################## + #---------------------------------for release 1610---------------------- # + ########################################################################## + + fileLocation = baseFileLocation + "normative-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "compute", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "normative-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "network", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "abstractSubstitute", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailAbstractSubstitute", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailNetworkRules", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "novaServer", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "neutronPort", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailVirtualNetwork", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "neutronNet", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "vl", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailV2VirtualNetwork", updateversion) + results.append(result) + + fileLocation = baseFileLocation + "heat-types/" + result = createNormativeType(beHost, bePort, adminUser, fileLocation, "securityRules", updateversion) + results.append(result) + + handleResults(results, 'false') + + errorAndExit(0, None) + +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py new file mode 100644 index 0000000000..72198ceab6 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py @@ -0,0 +1,93 @@ +import pycurl +import sys, getopt, os +from StringIO import StringIO +import json +import copy +import time +from importNormativeTypes import importNormativeTypes +from importHeatTypes import importHeatTypes +from importCommon import * +import importCommon + +def usage(): + 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>] [-v <true|false> | --updateversion=<true|false>]' + +def handleResults(results, updateversion): + printFrameLine() + for result in results: + printNameAndReturnCode(result[0], result[1]) + printFrameLine() + + responseCodes = [200, 201] + + if(updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedResults) > 0): + errorAndExit(1, None) + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + debugf = None + updateversion = 'true' + importCommon.debugFlag = False + + try: + opts, args = getopt.getopt(argv,"i:p:u:d:v:h",["ip=","port=","user=","debug=","updateversion="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + #print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-d", "--debug"): + print arg + debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + elif opt in ("-v", "--updateversion"): + print arg + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion + + if (debugf != None): + print 'set debug mode to ' + str(debugf) + importCommon.debugFlag = debugf + + if ( beHost == None ): + usage() + sys.exit(3) + + print sys.argv[0] + pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + pathdir) + + baseFileLocation = pathdir + "/../../../import/tosca/" + + fileLocation = baseFileLocation + "normative-types/" + results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion) + handleResults(results, updateversion) + + fileLocation = baseFileLocation + "heat-types/" + resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion) + handleResults(resultsHeat, updateversion) + + errorAndExit(0, None) + +if __name__ == "__main__": + main(sys.argv[1:]) + |