From cb30f3a566b73c78c3ea666acfcd3f288098684a Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Thu, 5 Mar 2020 13:12:27 +0100 Subject: Refactoring the sdc-BE-init python scripts Deeper refactoring of python script: - create the python package with init script - support for python 3.x - reuse code - new design - support for .json conf file - update the docker chef script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron Change-Id: I02169eb7d0e3e90851ba1811536d1712c3b4145f --- .../scripts/import/tosca/importAnnotationTypes.py | 35 ---- .../scripts/import/tosca/importCategoryTypes.py | 75 ------- .../resources/scripts/import/tosca/importCommon.py | 90 --------- .../scripts/import/tosca/importDataTypes.py | 76 ------- .../scripts/import/tosca/importGroupTypes.py | 75 ------- .../scripts/import/tosca/importHeatTypes.py | 137 ------------- .../scripts/import/tosca/importNfvTypes.py | 115 ----------- .../scripts/import/tosca/importNodeType.py | 170 ---------------- .../scripts/import/tosca/importNormativeAll.py | 145 -------------- .../import/tosca/importNormativeCapabilities.py | 78 ------- .../import/tosca/importNormativeElements.py | 108 ---------- .../importNormativeInterfaceLifecycleTypes.py | 77 ------- .../importNormativeNoHeatAndNormativeTypes.py | 136 ------------- .../import/tosca/importNormativeRelationships.py | 82 -------- .../scripts/import/tosca/importNormativeTypes.py | 177 ---------------- .../scripts/import/tosca/importONAPNormativeAll.py | 160 --------------- .../scripts/import/tosca/importOnapTypes.py | 92 --------- .../scripts/import/tosca/importPolicyTypes.py | 76 ------- .../scripts/import/tosca/importSolTypes.py | 92 --------- .../scripts/import/tosca/importUsersFromYaml.py | 223 --------------------- .../scripts/import/tosca/onapTypesToUpgrade.json | 9 - .../scripts/import/tosca/typesToUpgrade.json | 4 - .../import/tosca/upgradeHeatAndNormativeTypes.py | 108 ---------- .../scripts/import/tosca/upgradeHeatTypes1707.py | 111 ---------- .../scripts/import/tosca/upgradeNfvTypes.py | 101 ---------- .../scripts/import/tosca/upgradeNormative.py | 130 ------------ .../import/tosca/upgradeNormativeVersion.py | 108 ---------- .../import/tosca/upgradeNormativeVersionAll.py | 102 ---------- .../tosca/upgradeNormativeVersionProd1702_3537.py | 134 ------------- .../scripts/import/tosca/upgradeONAPNormative.py | 146 -------------- .../scripts/import/tosca/upgradeONAPTypes.py | 101 ---------- .../scripts/import/tosca/upgradeSolTypes.py | 100 --------- 32 files changed, 3373 deletions(-) delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importCommon.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py delete mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py (limited to 'catalog-be/src/main/resources/scripts/import') diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py deleted file mode 100644 index 5f0d4ad421..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py +++ /dev/null @@ -1,35 +0,0 @@ -import sys - -from importCommon import parse_cmd_line_params -from importNormativeElements import import_element - -IMPORT_ANNOTATION_URL = "/sdc2/rest/v1/catalog/uploadType/annotationtypes" -ANNOTATION_FILE_PATH = "../../../import/tosca/annotation-types/" -ANNOTATION_ZIP_FILE = "annotationTypesZip" -ANNOTATION_ELEMENT_NAME = "annotationTypes" - -##################################################################################################################################################################################### -# # -# Import tosca data types # -# # -# activation : # -# python importAnnotaionTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importAnnotaionTypes.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################### - - -def import_annotation_types(scheme, be_host, be_port, admin_user, exit_on_success): - import_element(scheme, be_host, be_port, admin_user, exit_on_success, ANNOTATION_FILE_PATH, IMPORT_ANNOTATION_URL, - ANNOTATION_ELEMENT_NAME, ANNOTATION_ZIP_FILE) - - -def main(argv): - scheme, be_host, be_port, admin_user = parse_cmd_line_params(argv) - import_annotation_types(scheme, be_host, be_port, admin_user, True) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py deleted file mode 100644 index cb361c6fd5..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py +++ /dev/null @@ -1,75 +0,0 @@ -from importCommon import * -from importNormativeElements import createNormativeElement - - -######################################################################################################################################################################################### -# # -# Import categoriy types # -# # -# activation : # -# python importCategoryTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importCategoryTypes.py [-f | --ifile= ] # -# # -######################################################################################################################################################################################### - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importCategories(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/categories", "categoryTypes", "categoriesZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success is True: - error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importCategories(scheme, be_host, be_port, admin_user, 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 deleted file mode 100644 index 6f976d013f..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py +++ /dev/null @@ -1,90 +0,0 @@ -import getopt -import sys - -############################################################################################################### -# -# -############################################################################################################### - -debugFlag = True - - -def join_strings(lst): - concat = "" - for string in lst: - if string is not None: - if type(string) == int: - string = str(string) - concat += (string + " ") - return concat - - -def debug(desc, *args): - if debugFlag: - print desc, join_strings(args) - - -def is_debug(): - return debugFlag - - -def log(desc, arg=None): - print desc, arg - - -def error_and_exit(error_code, error_desc): - if error_code > 0: - print "status={0}. {1}".format(error_code, '' if error_desc is None else error_desc) - else: - print "status={0}".format(error_code) - sys.exit(error_code) - - -def print_name_and_return_code(name, code): - print "{0:30} | {1:6}".format(name, code) - - -def print_frame_line(): - print "----------------------------------------" - - -def parse_cmd_line_params(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - return scheme, be_host, be_port, admin_user - - -def usage(): - print sys.argv[ - 0], '[optional -s | --scheme=, default http ] [-i | --ip=] [-p ' \ - '| --port= ] [-u | --user= ] ' diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py deleted file mode 100644 index c37fc87d0f..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py +++ /dev/null @@ -1,76 +0,0 @@ -from importCommon import * -from importNormativeElements import createNormativeElement - - -##################################################################################################################################################################################### -# # -# Import tosca data types # -# # -# activation : # -# python importDataTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importDataTypes.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################### - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http ] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importDataTypes(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, "/sdc2/rest/v1/catalog/uploadType/datatypes", "dataTypes", "dataTypesZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success is True: - error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - #print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importDataTypes(scheme, be_host, be_port, admin_user, 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 deleted file mode 100644 index 7db60331aa..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py +++ /dev/null @@ -1,75 +0,0 @@ -from importCommon import * -from importNormativeElements import createNormativeElement - - -##################################################################################################################################################################################### -# # -# Import tosca data types # -# # -# activation : # -# python importGroupTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importGroupTypes.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################### - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http ] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importGroupTypes(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/grouptypes", "groupTypes", "groupTypesZip", True) - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success: - error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importGroupTypes(scheme, be_host, be_port, admin_user, 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 deleted file mode 100644 index 92b8634437..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py +++ /dev/null @@ -1,137 +0,0 @@ -from importNormativeTypes import * - - -##################################################################################################################################################################################### -# # -# Import heat types # -# # -# activation : # -# python importHeatTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importHeatTypes.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################### - -def importHeatTypes(scheme, be_host, be_port, admin_user, file_dir, update_version): - heat_types = ["globalNetwork", - "globalPort", - "globalCompute", - "volume", - "cinderVolume", - "contrailVirtualNetwork", - "neutronNet", - "neutronPort", - "novaServer", - "extVl", - "internalVl", - "extCp", - "vl", - "eline", - "abstractSubstitute", - "Generic_VFC", - "Generic_VF", - "Generic_CR", - "Generic_PNF", - "Generic_Service", - "contrailNetworkRules", - "contrailPort", - "portMirroring", - "serviceProxy", - "contrailV2NetworkRules", - "contrailV2VirtualNetwork", - "securityRules", - "contrailAbstractSubstitute", - "contrailCompute", - "contrailV2VirtualMachineInterface", - "subInterface", - "contrailV2VLANSubInterface", - "multiFlavorVFC", - "vnfConfiguration", - "extCp2", - "extNeutronCP", - "extContrailCP", - "portMirroringByPolicy", - "forwardingPath", - "configuration", - "VRFObject", - "extVirtualMachineInterfaceCP", - "VLANNetworkReceptor", - "VRFEntry", - "subInterfaceV2", - "contrailV2VLANSubInterfaceV2", - "fabricConfiguration"] - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for heat_type in heat_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, heat_type, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + heat_type + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = importHeatTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/heat-types/", update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py deleted file mode 100644 index ed68695475..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py +++ /dev/null @@ -1,115 +0,0 @@ -from importNormativeTypes import * - - -##################################################################################################################################################################################################### -# # -# Import Nfv Types from a given file # -# # -# activation : # -# python importNfvTypes.py [optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsers.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################################### - -def importNfvTypes(scheme, be_host, be_port, admin_user, file_dir, update_version): - nfv_types = ["underlayVpn", - "overlayTunnel", - "genericNeutronNet", - "allottedResource", - "extImageFile", - "extLocalStorage", - "extZteCP", - "extZteVDU", - "extZteVL", - "NSD", - "VDU", - "vduCompute", - "Cp", - "vduVirtualStorage", - "vduVirtualBlockStorage", - "vduVirtualFileStorage", - "vduVirtualObjectStorage", - "vduVirtualStorage", - "vnfVirtualLink", - "vnfExtCp", - "vduCp", - "VNF", - "PonUni", - "OltNni", - "OntNni"] - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for nfv_type in nfv_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, nfv_type, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + nfv_type + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = importNfvTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/nfv-types/", update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(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 deleted file mode 100644 index 55521997f5..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py +++ /dev/null @@ -1,170 +0,0 @@ -import json -import os -import zipfile -from StringIO import StringIO - -import pycurl - -import importCommon -from importCommon import * - - -################################################################################################################################################ -# # -################################################################################################################################################ - - -def createZipFromYml(ymlFile, zipFile): - zip = zipfile.ZipFile(zipFile, 'w', zipfile.ZIP_DEFLATED) - - zip.write(ymlFile, os.path.basename(ymlFile)) - zip.close() - - -def createUserNormativeType(scheme, be_host, be_port, admin_user, file_dir, element_name): - try: - log("in create normative type ", element_name) - debug("userId", admin_user) - debug("fileDir", file_dir) - - _buffer = StringIO() - c = pycurl.Curl() - - url = scheme + '://' + be_host + ':' + be_port + '/sdc2/rest/v1/catalog/upload/multipart' - c.setopt(c.URL, url) - c.setopt(c.POST, 1) - - admin_header = 'USER_ID: ' + admin_user - # c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) - c.setopt(pycurl.HTTPHEADER, [admin_header]) - - ymlFile = file_dir + element_name + "/normative-types-new-" + element_name + ".yml" - zipFile = file_dir + element_name + "/normative-types-new-" + element_name + ".zip" - debug(ymlFile) - debug(zipFile) - path = zipFile - debug("path=" + path) - current_json_file = file_dir + element_name + "/" + element_name + ".json" - debug(current_json_file) - json_file = open(current_json_file) - - debug("before load json") - json_data = json.load(json_file, strict=False) - debug(json_data) - - json_as_str = json.dumps(json_data) - debug(path) - send = [('resourceMetadata', json_as_str), ('resourceZip', (pycurl.FORM_FILE, path))] - debug(send) - c.setopt(pycurl.HTTPPOST, send) - - c.setopt(c.WRITEFUNCTION, _buffer.write) - if scheme == 'https': - c.setopt(pycurl.SSL_VERIFYPEER, 0) - c.setopt(pycurl.SSL_VERIFYHOST, 0) - - c.perform() - - # print("Before get response code") - http_res = c.getinfo(c.RESPONSE_CODE) - if http_res is not None: - debug("http response=", http_res) - # print('Status: ' + str(responseCode)) - debug(_buffer.getvalue()) - c.close() - - return element_name, http_res, _buffer.getvalue() - - except Exception as inst: - print("ERROR=" + str(inst)) - return element_name, None, None - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-l | --location=] [-e | --element=]' - 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.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - location = None - element = None - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:l:e:h:s:", - ["ip=", "port=", "user=", "location=", "element=", "debug=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-l", "--location"): - location = arg - elif opt in ("-e", "--element"): - element = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if location is None: - print 'Missing file location' - usage() - sys.exit(3) - - if element is 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(scheme, be_host, be_port, admin_user, location, element) - # result = createUserNormativeType(beHost, bePort, adminUser, fileDir, normativeType) - print "---------------------------------------" - print "{0:30} | {1:6}".format(result[0], result[1]) - print "---------------------------------------" - - if result[1] is None or result[1] not in [200, 201]: - print "Failed creating normative type " + element + ". " + str(result[1]) - error_and_exit(1, None) - - error_and_exit(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 deleted file mode 100644 index c61b8bcc03..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py +++ /dev/null @@ -1,145 +0,0 @@ -import os -import time - -import importCommon -from importAnnotationTypes import import_annotation_types -from importCategoryTypes import importCategories -from importCommon import * -from importDataTypes import importDataTypes -from importGroupTypes import importGroupTypes -from importHeatTypes import importHeatTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importNormativeRelationships import importNormativeRelationships -from importNormativeTypes import importNormativeTypes -from importPolicyTypes import importPolicyTypes - - -################################################################################################################################################################################################################################# -# # -# Import all users from a given file # -# # -# activation : # -# python importNormativeAll.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# [-v | --updateversion=] # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python importNormativeAll.py # -# # -################################################################################################################################################################################################################################# - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] [-v | --updateversion=]' - - -def handleResults(results, update_version): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:", - ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - elif opt in ("-v", "--updateversion"): - print arg - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - - file_location = base_file_location + "data-types/" - importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - - print 'sleep until data type cache is updated' - time.sleep(70) - - file_location = base_file_location + "capability-types/" - importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "relationship-types/" - importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "categories/" - importCategories(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "normative-types/" - results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handleResults(results, update_version) - - file_location = base_file_location + "heat-types/" - results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handleResults(results_heat, update_version) - - file_location = base_file_location + "group-types/" - importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "policy-types/" - importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - - import_annotation_types(scheme, be_host, be_port, admin_user, False) - - error_and_exit(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 deleted file mode 100644 index 989233d380..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py +++ /dev/null @@ -1,78 +0,0 @@ -import importCommon -from importCommon import * -from importNormativeElements import createNormativeElement - - -################################################################################################################################################################################################# -# # -# Import normative capabilities # -# # -# activation : # -# python importNormativeCapabilities.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importNormativeCapabilities.py [-f | --ifile= ] # -# # -################################################################################################################################################################################################# - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importNormativeCapabilities(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", - "capabilityTypeZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - importCommon.error_and_exit(1, None) - else: - if exit_on_success is True: - importCommon.error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - importCommon.error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importNormativeCapabilities(scheme, be_host, be_port, admin_user, 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 deleted file mode 100644 index 47ed633b06..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py +++ /dev/null @@ -1,108 +0,0 @@ -import pycurl -import zipfile -from StringIO import StringIO -import json -import copy -from importCommon import * - - -################################################################################################################################################################################# -# # -# Import all users from a given file # -# # -# activation : # -# python importUsers.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsers.py [-f | --ifile= ] # -# # -################################################################################################################################################################################# -def import_element(scheme, be_host, be_port, admin_user, exit_on_success, file_dir, url_suffix, element_name, element_form_name, - with_metadata=False): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name, with_metadata) - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success: - error_and_exit(0, None) - - - -def createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name, - with_metadata=False): - try: - log("in create normative element ", element_name) - buffer = StringIO() - c = pycurl.Curl() - - url = scheme + '://' + be_host + ':' + be_port + url_suffix - c.setopt(c.URL, url) - c.setopt(c.POST, 1) - - admin_header = 'USER_ID: ' + admin_user - c.setopt(pycurl.HTTPHEADER, [admin_header]) - - type_file_name = file_dir + "/" + element_name - - multi_part_form_data = create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name) - - c.setopt(pycurl.HTTPPOST, multi_part_form_data) - c.setopt(c.WRITEFUNCTION, buffer.write) - - if scheme == 'https': - c.setopt(pycurl.SSL_VERIFYPEER, 0) - c.setopt(pycurl.SSL_VERIFYHOST, 0) - - c.perform() - - http_res = c.getinfo(c.RESPONSE_CODE) - if http_res is not None: - debug("http response=", http_res) - debug("response buffer", buffer.getvalue()) - c.close() - return (element_name, http_res, buffer.getvalue()) - - except Exception as inst: - print("ERROR=" + str(inst)) - return (element_name, None, None) - - -def create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name): - tosca_type_zip_part = create_zip_file_multi_part(element_form_name, type_file_name, element_name) - multi_part_form_data = [tosca_type_zip_part] - if with_metadata: - metadata_type_part = create_metadata_multipart(type_file_name) - multi_part_form_data.append(metadata_type_part) - debug(multi_part_form_data) - return multi_part_form_data - - -def create_metadata_multipart(type_file_name): - metadata = create_json_metadata_str(type_file_name) - return ("toscaTypeMetadata", metadata) - - -def create_zip_file_multi_part(element_form_name, type_file_name, element_name): - zf = zipfile.ZipFile(type_file_name + ".zip", "w") - zf.write(type_file_name + '.yml', element_name + '.yml') - zf.close() - - tosca_type_zip_path = type_file_name + ".zip" - tosca_type_zip_part = (element_form_name, (pycurl.FORM_FILE, tosca_type_zip_path)) - return tosca_type_zip_part - - -def create_json_metadata_str(file_name): - type_metadata_json_file = file_name + ".json" - debug(type_metadata_json_file) - json_file = open(type_metadata_json_file) - - debug("before load json") - json_data = json.load(json_file, strict=False) - debug(json_data) - - return json.dumps(json_data) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py deleted file mode 100644 index 1e6b9ca44f..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py +++ /dev/null @@ -1,77 +0,0 @@ -from importCommon import * -from importNormativeElements import createNormativeElement - - -############################################################################################################################################################################################################# -# # -# Import all users from a given file # -# # -# activation : # -# python importNormativeInterfaceLifecycleTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importNormativeInterfaceLifecycleTypes.py [-f | --ifile= ] # -# # -############################################################################################################################################################################################################# - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", "interfaceLifecycleTypes", - "interfaceLifecycleTypeZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success is True: - error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, True, - "../../../import/tosca/interface-lifecycle-types//") - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py deleted file mode 100644 index b06959ae40..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py +++ /dev/null @@ -1,136 +0,0 @@ -import os -import time - -import importCommon -from importCommon import * -from importDataTypes import importDataTypes -from importGroupTypes import importGroupTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importPolicyTypes import importPolicyTypes - - -##################################################################################################################################################################################################################################################### -# # -# Import all users from a given file # -# # -# activation : # -# python importNormativeNoHeatAndNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# [-v | --updateversion=] # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python importNormativeNoHeatAndNormativeTypes.py # -# # -##################################################################################################################################################################################################################################################### - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] [-v | --updateversion=]' - - -def handleResults(results, update_version): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:", - ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - elif opt in ("-v", "--updateversion"): - print arg - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - - file_location = base_file_location + "data-types/" - importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - - print 'sleep until data type cache is updated' - time.sleep(70) - - file_location = base_file_location + "capability-types/" - importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - - # 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) - - file_location = base_file_location + "group-types/" - importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "policy-types/" - importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py deleted file mode 100644 index a6040d0215..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py +++ /dev/null @@ -1,82 +0,0 @@ -import importCommon -from importCommon import * -from importNormativeElements import createNormativeElement - - -################################################################################################################################################################################################# -# # -# Import normative relationships -# # -# # -# activation : # -# python importNormativeRelationships.py [-s | --scheme= ] [-i | --ip=] [-p -# | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importNormativeRelationships.py [-f | --ifile= ] -# # -# # -################################################################################################################################################################################################# - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importNormativeRelationships(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/relationship", "relationshipTypes", - "relationshipTypeZip") - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - importCommon.error_and_exit(1, None) - else: - if exit_on_success is True: - importCommon.error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - importCommon.error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importNormativeRelationships(scheme, be_host, be_port, admin_user, True, - "../../../import/tosca/relationship-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 deleted file mode 100644 index 889ea05b66..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py +++ /dev/null @@ -1,177 +0,0 @@ -import json -import zipfile -from StringIO import StringIO - -import pycurl - -from importCommon import * - - -######################################################################################################################################################################################### -# # -# Import all users from a given file # -# # -# activation : # -# python importNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# [-v | --updateversion=] # -# shortest activation (be host = localhost, be port = 8080): # -# python importNormativeTypes.py [-f | --ifile= ] # -# # -######################################################################################################################################################################################### - -def createNormativeType(scheme, be_host, be_port, admin_user, file_dir, element_name, update_version): - try: - log("in create normative type ", element_name) - debug("userId", admin_user) - debug("fileDir", file_dir) - - buffer = StringIO() - c = pycurl.Curl() - if is_debug(): - c.setopt(pycurl.VERBOSE, 1) - - url = scheme + '://' + be_host + ':' + be_port + '/sdc2/rest/v1/catalog/upload/multipart' - if update_version is not None: - url += '?createNewVersion=' + update_version - c.setopt(c.URL, url) - c.setopt(c.POST, 1) - - admin_header = 'USER_ID: ' + admin_user - # c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) - c.setopt(pycurl.HTTPHEADER, [admin_header]) - - yml_path = file_dir + element_name + "/" + element_name + ".yml" - path = file_dir + element_name + "/" + element_name + ".zip" - - zf = zipfile.ZipFile(path, "w") - zf.write(yml_path, element_name + '.yml') - zf.close() - - debug(path) - current_json_file = file_dir + element_name + "/" + element_name + ".json" - # sed -i 's/"userId": ".*",/"userId": "'${USER_ID}'",/' ${current_json_file} - - jsonFile = open(current_json_file) - - debug("before load json") - json_data = json.load(jsonFile, strict=False) - debug(json_data) - - json_as_str = json.dumps(json_data) - - send = [('resourceMetadata', json_as_str), ('resourceZip', (pycurl.FORM_FILE, path))] - debug(send) - c.setopt(pycurl.HTTPPOST, send) - - # data = json.dumps(user) - # c.setopt(c.POSTFIELDS, data) - - if scheme == 'https': - c.setopt(pycurl.SSL_VERIFYPEER, 0) - c.setopt(pycurl.SSL_VERIFYHOST, 0) - - # c.setopt(c.WRITEFUNCTION, lambda x: None) - c.setopt(c.WRITEFUNCTION, buffer.write) - - # print("before perform") - c.perform() - - # print("Before get response code") - http_res = c.getinfo(c.RESPONSE_CODE) - if http_res is not None: - debug("http response=", http_res) - # print('Status: ' + str(responseCode)) - debug(buffer.getvalue()) - c.close() - - return (element_name, http_res, buffer.getvalue()) - - except Exception as inst: - print("ERROR=" + str(inst)) - return (element_name, None, None) - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-v | --updateversion=]' - - -def importNormativeTypes(scheme, be_host, be_port, admin_user, file_dir, update_version): - normative_types = ["root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database", - "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer", - "port", "network"] - # normative_types = [ "root" ] - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for normative_type in normative_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, normative_type, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating normative type " + normative_type + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', updateversion =', update_version - - if be_host is None: - usage() - sys.exit(3) - - results = importNormativeTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/normative-types/", - update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py deleted file mode 100644 index de67cd7e57..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py +++ /dev/null @@ -1,160 +0,0 @@ -import os -import time - -import importCommon -from importCategoryTypes import importCategories -from importCommon import * -from importDataTypes import importDataTypes -from importGroupTypes import importGroupTypes -from importHeatTypes import importHeatTypes -from importNfvTypes import importNfvTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importNormativeRelationships import importNormativeRelationships -# from importNormativeElements import createNormativeElement -from importNormativeTypes import importNormativeTypes -from importOnapTypes import importOnapTypes -from importPolicyTypes import importPolicyTypes -from importSolTypes import importSolTypes - - -################################################################################################################################################################################################# -# # -# Import all users from a given file # -# # -# activation : # -# python importNormativeAll.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# [-v | --updateversion=] # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # # -# python importNormativeAll.py # -# # -################################################################################################################################################################################################# - -def usage(): - print sys.argv[0], \ - '[-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] [-v | --updateversion=]' - - -def handle_results(results, update_version): - if results is not None: - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debugf = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - opts = [] - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:", - ["ip=", "port=", "user=", "debug=", "update_version=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debugf = bool(arg.lower() == "true" or arg.lower() == "yes") - elif opt in ("-v", "--update_version"): - print arg - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debugf, ', update_version =', update_version - - if debugf is not None: - print 'set debug mode to ' + str(debugf) - importCommon.debugFlag = debugf - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + pathdir) - - base_file_location = pathdir + "/../../../import/tosca/" - - file_location = base_file_location + "data-types/" - importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - - print 'sleep until data type cache is updated' - time.sleep(70) - - file_location = base_file_location + "capability-types/" - importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "relationship-types/" - importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "categories/" - importCategories(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "normative-types/" - results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handle_results(results, update_version) - - file_location = base_file_location + "heat-types/" - results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handle_results(results_heat, update_version) - - file_location = base_file_location + "nfv-types/" - results_heat = importNfvTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handle_results(results_heat, update_version) - - file_location = base_file_location + "onap-types/" - results_heat = importOnapTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handle_results(results_heat, update_version) - - file_location = base_file_location + "sol-types/" - results_heat = importSolTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handle_results(results_heat, update_version) - - file_location = base_file_location + "group-types/" - importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "policy-types/" - importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py deleted file mode 100644 index f6e4749b57..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py +++ /dev/null @@ -1,92 +0,0 @@ -from importNormativeTypes import * - - -##################################################################################################################################################################################################### -# # -# Import all users from a given file # -# # -# activation : # -# python importUsers.py [optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsers.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################################### - -def importOnapTypes(scheme, be_host, be_port, admin_user, file_dir, update_version): - # Add desired type names to the list - onap_types = [] - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for onap_type in onap_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, onap_type, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + onap_type + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "update_version="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--update_version"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = importOnapTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/onap-types/", update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(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 deleted file mode 100644 index 47f783d0a6..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py +++ /dev/null @@ -1,76 +0,0 @@ -from importCommon import * -from importNormativeElements import createNormativeElement - - -##################################################################################################################################################################################### -# # -# Import tosca data types # -# # -# activation : # -# python importPolicyTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importPolicyTypes.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################### - -def usage(): - print sys.argv[ - 0], '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ]' - - -def importPolicyTypes(scheme, be_host, be_port, admin_user, exit_on_success, file_dir): - result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, - "/sdc2/rest/v1/catalog/uploadType/policytypes", "policyTypes", "policyTypesZip", - True) - - print_frame_line() - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - if result[1] is None or result[1] not in [200, 201, 409]: - error_and_exit(1, None) - else: - if exit_on_success: - error_and_exit(0, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - importPolicyTypes(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/policy-types/") - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py deleted file mode 100644 index 5a8d2aaf70..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py +++ /dev/null @@ -1,92 +0,0 @@ -from importNormativeTypes import * - - -##################################################################################################################################################################################################### -# # -# Import Sol Types from a given file # -# # -# activation : # -# python importSolTypes.py [optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsers.py [-f | --ifile= ] # -# # -##################################################################################################################################################################################################### - -def importSolTypes(scheme, be_host, be_port, admin_user, file_dir, update_version): - # Add desired type names to the list - sol_types = [] - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for onap_type in sol_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, onap_type, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + onap_type + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = importSolTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/sol-types/", update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -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 deleted file mode 100644 index 8cc8926ac5..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py +++ /dev/null @@ -1,223 +0,0 @@ -import getopt -import json -import sys - -import pycurl -import yaml - - -######################################################################################################################################################################################### -# # -# Import all users from a given YAML file # -# # -# activation : # -# python importUsersFromYaml.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsersFromYaml.py [-f | --ifile= ] # -# # -# PyYAML module shall be added to python. # -# pip install PyYAML>=3.1.0 --proxy=http://one.proxy.att.com:8080 # -######################################################################################################################################################################################### - - -def importUsers(scheme, be_host, be_port, users, admin_user): - result = [] - - for user in users: - # print("Going to add user " + user['userId']) - get_res = getUser(scheme, be_host, be_port, user) - user_id = get_res[0] - error = get_res[1] - # print error - if error is not None and error == 404: - res = createUser(scheme, be_host, be_port, user, admin_user) - result.append(res) - else: - if error == 200: - cur_result = user_id, 409 - result.append(cur_result) - else: - result.append(get_res) - - return result - - -def getUser(scheme, be_host, be_port, user): - if user.get('userId') is None: - print "Ignoring record", user - return 'NotExist', 200 - user_id = user['userId'] - try: - c = pycurl.Curl() - - # print type(userId) - url = scheme + '://' + be_host + ':' + be_port + '/sdc2/rest/v1/user/' + str(user_id) - c.setopt(c.URL, url) - - if scheme == 'https': - c.setopt(pycurl.SSL_VERIFYPEER, 0) - c.setopt(pycurl.SSL_VERIFYHOST, 0) - - # 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") - http_res = c.getinfo(c.RESPONSE_CODE) - # print("After get response code") - # response_code = c.getinfo(c.RESPONSE_CODE) - # print('Status: ' + str(response_code)) - - c.close() - - return user_id, http_res - - except Exception as inst: - print(inst) - return user_id, None - - -def createUser(scheme, be_host, be_port, user, admin_user): - if user.get('userId') is None: - print "Ignoring record", user - return 'NotExist', 200 - - user_id = user['userId'] - try: - c = pycurl.Curl() - - url = scheme + '://' + be_host + ':' + be_port + '/sdc2/rest/v1/user' - c.setopt(c.URL, url) - c.setopt(c.POST, 1) - - admin_header = 'USER_ID: ' + admin_user - c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', admin_header]) - - data = json.dumps(user) - c.setopt(c.POSTFIELDS, data) - - if scheme == 'https': - c.setopt(pycurl.SSL_VERIFYPEER, 0) - c.setopt(pycurl.SSL_VERIFYHOST, 0) - - c.setopt(c.WRITEFUNCTION, lambda x: None) - # print("before perform") - c.perform() - - # print("Before get response code") - http_res = c.getinfo(c.RESPONSE_CODE) - # print("After get response code") - # responseCode = c.getinfo(c.RESPONSE_CODE) - # print('Status: ' + str(responseCode)) - - c.close() - - return user_id, http_res - - except Exception as inst: - print(inst) - return user_id, None - - -def error_and_exit(error_code, error_desc): - if error_code > 0: - print("status=" + str(error_code) + ". " + error_desc) - else: - print("status=" + str(error_code)) - sys.exit(error_code) - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-f | --ifile= ]' - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - input_file = None - - admin_user = 'jh0003' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:f:h:s:", ["ip=", "port=", "ifile=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-f", "--ifile"): - input_file = arg - elif opt in ("-s", "--scheme"): - scheme = arg - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', users file =', input_file - - if input_file is None: - usage() - sys.exit(3) - - print 'Input file is ', input_file - - users_as_yaml_file = open(input_file, 'r') - users_doc = yaml.load(users_as_yaml_file) - print users_doc - - clone_users = [] - for users in users_doc.values(): - for x, y in users.items(): - copied_user = y - copied_user['userId'] = x - # print copiedUser - clone_users.append(copied_user) - - print clone_users - - users_as_yaml_file.close() - - # activeUsers = filter(lambda x: x.get('status') == None or x['status'] == 'ACTIVE', cloneUsers) - - result_table = importUsers(scheme, be_host, be_port, clone_users, admin_user) - - g = lambda x: x[1] != 201 and x[1] != 409 - - result = filter(g, result_table) - - if len(result) > 0: - # print("ERROR: Failed to load the users " + ', '.join(map(lambda x: x[0],result))) - error_and_exit(3, "Failed to load the users " + ', '.join(map(lambda x: x[0], result))) - - g = lambda x: x[1] == 409 - result = filter(g, result_table) - - print("-------------------------------------------") - print("Existing users: " + ', '.join(map(lambda x: x[0], result))) - - result = filter(lambda x: x[1] == 201, result_table) - if len(list(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("-------------------------------------------") - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json deleted file mode 100644 index cbe581acd2..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "nfv": [ - "allottedResource" - ], - "onap": [ - ], - "sol":[ - ] -} \ No newline at end of file diff --git a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json deleted file mode 100644 index 4d59e0248d..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "heat": [], - "normative": [] -} diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py deleted file mode 100644 index 7ba925038f..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py +++ /dev/null @@ -1,108 +0,0 @@ -from importNormativeTypes import * - - -################################################################################################################################################################################################ -# # -# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # -# # -# activation # -# python upgradeHeatAndNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python upgradeHeatAndNormativeTypes.py [-f | --ifile= ] # -# # -################################################################################################################################################################################################ - - -def upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version): - response_codes = [200, 201] - if update_version == 'false': - response_codes = [200, 201, 409] - with open("typesToUpgrade.json", 'r') as stream: - try: - types = json.load(stream) - heat_types = types["heat"] - debug(heat_types) - normative_types = types["normative"] - debug(normative_types) - heat_file_dir = base_dir + "heat-types/" - debug(heat_file_dir) - normative_file_dir = base_dir + "normative-types/" - debug(normative_file_dir) - results = [] - for heat_type in heat_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, heat_file_dir, - heat_type.encode('ascii', 'ignore'), update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + heat_type + ". " + str(result[1]) - for normativeType in normative_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, normative_file_dir, - normativeType.encode('ascii', 'ignore'), update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating normative type " + normativeType + ". " + str(result[1]) - return results - except Exception as exc: - print(exc) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/", update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py deleted file mode 100644 index 5394864fdb..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py +++ /dev/null @@ -1,111 +0,0 @@ -from importNormativeTypes import * - - -################################################################################################################################################################################# -# # -# Import all users from a given file # -# # -# activation : # -# python importUsers.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python importUsers.py [-f | --ifile= ] # -# # -################################################################################################################################################################################# - - -def upgradeHeatTypes1707(scheme, be_host, be_port, admin_user, file_dir, update_version): - heat_types = ["volume", - "cinderVolume", - "extVl", - "extCp", - "Generic_VFC", - "Generic_VF", - "Generic_PNF", - "Generic_Service", - "globalPort", - "globalNetwork", - "contrailV2VirtualMachineInterface", - "contrailV2VLANSubInterface", - "contrailPort", - "contrailV2VirtualNetwork", - "contrailVirtualNetwork", - "neutronNet", - "neutronPort", - "multiFlavorVFC", - "vnfConfiguration"] - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - results = [] - for heatType in heat_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, heatType, update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating heat type " + heatType + ". " + str(result[1]) - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = upgradeHeatTypes1707(scheme, be_host, be_port, admin_user, "../../../import/tosca/heat-types/", - update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py deleted file mode 100644 index ce939878ae..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py +++ /dev/null @@ -1,101 +0,0 @@ -from importNormativeTypes import * - - -################################################################################################################################################################################################ -# # -# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # -# # -# activation # -# python upgradeHeatAndNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python upgradeHeatAndNormativeTypes.py [-f | --ifile= ] # -# # -################################################################################################################################################################################################ - - -def upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version): - response_codes = [200, 201] - results = [] - - if update_version == 'false': - response_codes = [200, 201, 409] - with open("onapTypesToUpgrade.json", 'r') as stream: - try: - types = json.load(stream) - nfv_types = types["nfv"] - debug(nfv_types) - nfv_file_dir = base_dir + "nfv-types/" - debug(nfv_file_dir) - for nfvType in nfv_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, nfv_file_dir, - nfvType.encode('ascii', 'ignore'), update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating nfv type " + nfvType + ". " + str(result[1]) - except Exception as exc: - print(exc) - - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/", - update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(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 deleted file mode 100644 index c8f5ecf9e6..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py +++ /dev/null @@ -1,130 +0,0 @@ -import os -import time - -import importCommon -from importAnnotationTypes import import_annotation_types -from importCategoryTypes import importCategories -from importCommon import * -from importDataTypes import importDataTypes -from importGroupTypes import importGroupTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importNormativeRelationships import importNormativeRelationships -from importPolicyTypes import importPolicyTypes -from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile - - -################################################################################################################################################################################################################################# -# # -# Upgrades the normative types # -# # -# activation : # -# python upgradeNormative.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python upgradeNormative.py # -# # -################################################################################################################################################################################################################################# - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=]' - - -def handleResults(results): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - - file_location = base_file_location + "categories/" - importCategories(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "relationship-types/" - importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "data-types/" - importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "policy-types/" - importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "capability-types/" - importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "group-types/" - importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - - import_annotation_types(scheme, be_host, be_port, admin_user, False) - - print 'sleep until data type cache is updated' - time.sleep(70) - - results_heat = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, update_version) - handleResults(results_heat) - - error_and_exit(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 deleted file mode 100644 index b5ba42f971..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py +++ /dev/null @@ -1,108 +0,0 @@ -import os - -import importCommon -from importCommon import * -from importNormativeTypes import createNormativeType - - -################################################################################################################################################################################################################################# -# # -# Upgrades the normative types # -# # -# activation : # -# python upgradeNormative.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python upgradeNormative.py # -# # -################################################################################################################################################################################################################################# - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=]' - - -def handleResults(results): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - results = [] - - ########################################################################## - # ---------------------------------for release 1702---------------------- # - ########################################################################## - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, - "contrailV2VirtualMachineInterface", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version) - results.append(result) - - handleResults(results) - - error_and_exit(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 deleted file mode 100644 index a5e2ebae67..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py +++ /dev/null @@ -1,102 +0,0 @@ -import os - -import importCommon -from importCommon import * -from importHeatTypes import importHeatTypes -from importNormativeTypes import importNormativeTypes -from importOnapTypes import importOnapTypes - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] [-v | --updateversion=]' - - -def handleResults(results, update_version): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:", - ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - elif opt in ("-v", "--updateversion"): - print arg - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - - file_location = base_file_location + "normative-types/" - results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handleResults(results, update_version) - - file_location = base_file_location + "heat-types/" - results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handleResults(results_heat, update_version) - - file_location = base_file_location + "onap-types/" - results_onap = importOnapTypes(scheme, be_host, be_port, admin_user, file_location, update_version) - handleResults(results_onap, update_version) - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py deleted file mode 100644 index cc2325f9fb..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py +++ /dev/null @@ -1,134 +0,0 @@ -import os - -import importCommon -from importCommon import * -from importNormativeTypes import createNormativeType - - -################################################################################################################################################################################################################################# -# # -# Upgrades the normative types # -# # -# activation : # -# python upgradeNormative.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python upgradeNormative.py # -# # -################################################################################################################################################################################################################################# - - -def usage(): - print sys.argv[0], \ - '[optional -s | --scheme=, default http] [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=]' - - -def handleResults(results): - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - print_frame_line() - - failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results) - if len(list(failed_results)) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - debug_f = None - update_version = 'true' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f - - if debug_f is not None: - print 'set debug mode to ' + str(debug_f) - importCommon.debugFlag = debug_f - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + path_dir) - - base_file_location = path_dir + "/../../../import/tosca/" - results = [] - - ########################################################################## - # ---------------------------------for release 1702---------------------- # - ########################################################################## - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailPort", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, - "contrailV2VirtualMachineInterface", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailCompute", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "novaServer", update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailV2VirtualNetwork", - update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailVirtualNetwork", - update_version) - results.append(result) - - file_location = base_file_location + "heat-types/" - result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronNet", update_version) - results.append(result) - - handleResults(results) - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py deleted file mode 100644 index 59fece9376..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py +++ /dev/null @@ -1,146 +0,0 @@ -import os -import time -from importCategoryTypes import importCategories -from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile -from importDataTypes import importDataTypes -from importPolicyTypes import importPolicyTypes -from importGroupTypes import importGroupTypes -from importNormativeCapabilities import importNormativeCapabilities -from importNormativeRelationships import importNormativeRelationships -from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from upgradeNfvTypes import upgradeNfvTypesPerConfigFile -from upgradeONAPTypes import upgradeOnapTypesPerConfigFile -from upgradeSolTypes import upgradeSolTypesPerConfigFile - -from importCommon import * -import importCommon - - -################################################################################################################################################################################################# -# # -# Upgrades the normative types # -# # -# activation : # -# python upgradeNormative.py [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # -# # -# # -# shortest activation (be host = localhost, be port = 8080, user = jh0003): # -# python upgradeNormative.py # -# # -################################################################################################################################################################################################# - -def usage(): - print sys.argv[ - 0], '[-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] ' - - -def handle_results(results): - if results is not None: - print_frame_line() - for result in results: - print_name_and_return_code(result[0], result[1]) - - print_frame_line() - - failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results) - if len(failed_results) > 0: - error_and_exit(1, None) - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - is_debug = None - update_version = 'true' - update_onap_version = 'false' - importCommon.debugFlag = False - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s", - ["scheme=", "ip=", "port=", "user=", "debug=", "updateversion="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-d", "--debug"): - print arg - is_debug = bool(arg.lower() == "true" or arg.lower() == "yes") - - print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', is_debug - - if is_debug is not None: - print 'set debug mode to ' + str(is_debug) - importCommon.debugFlag = is_debug - - if be_host is None: - usage() - sys.exit(3) - - print sys.argv[0] - pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + pathdir) - - base_file_location = pathdir + "/../../../import/tosca/" - - file_location = base_file_location + "categories/" - importCategories(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "relationship-types/" - importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "data-types/" - importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "policy-types/" - importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "group-types/" - importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "capability-types/" - importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - - file_location = base_file_location + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - - print 'sleep until data type cache is updated' - time.sleep(70) - - results_heat = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, update_version) - handle_results(results_heat) - - results_heat = upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, - update_onap_version) - handle_results(results_heat) - - results_heat = upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, - update_onap_version) - handle_results(results_heat) - - results_heat = upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, - update_onap_version) - handle_results(results_heat) - - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py deleted file mode 100644 index bb26659621..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py +++ /dev/null @@ -1,101 +0,0 @@ -from importNormativeTypes import * - - -################################################################################################################################################################################################ -# # -# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # -# # -# activation # -# python upgradeHeatAndNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python upgradeHeatAndNormativeTypes.py [-f | --ifile= ] # -# # -################################################################################################################################################################################################ - - -def upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version): - response_codes = [200, 201] - results = [] - - if update_version == 'false': - response_codes = [200, 201, 409] - with open("onapTypesToUpgrade.json", 'r') as stream: - try: - types = json.load(stream) - onap_types = types["onap"] - debug(onap_types) - onap_file_dir = base_dir + "onap-types/" - debug(onap_file_dir) - for onap_type in onap_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, onap_file_dir, - onap_type.encode('ascii', 'ignore'), update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating onap type " + onap_type + ". " + str(result[1]) - except Exception as exc: - print(exc) - - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/", - update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py deleted file mode 100644 index aa60e4d49d..0000000000 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py +++ /dev/null @@ -1,100 +0,0 @@ -from importNormativeTypes import * - - -################################################################################################################################################################################################ -# # -# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # -# # -# activation # -# python upgradeHeatAndNormativeTypes.py [-s | --scheme= ] [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # -# # -# shortest activation (be host = localhost, be port = 8080): # -# python upgradeHeatAndNormativeTypes.py [-f | --ifile= ] # -# # -################################################################################################################################################################################################ - - -def upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version): - response_codes = [200, 201] - results = [] - if update_version == 'false': - response_codes = [200, 201, 409] - with open("onapTypesToUpgrade.json", 'r') as stream: - try: - types = json.load(stream) - sol_types = types["sol"] - debug(sol_types) - sol_file_dir = base_dir + "sol-types/" - debug(sol_file_dir) - for solType in sol_types: - result = createNormativeType(scheme, be_host, be_port, admin_user, sol_file_dir, - solType.encode('ascii', 'ignore'), update_version) - results.append(result) - if result[1] is None or result[1] not in response_codes: - print "Failed creating sol type " + solType + ". " + str(result[1]) - except Exception as exc: - print(exc) - - return results - - -def main(argv): - print 'Number of arguments:', len(sys.argv), 'arguments.' - - be_host = 'localhost' - be_port = '8080' - admin_user = 'jh0003' - update_version = 'true' - scheme = 'http' - - try: - opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="]) - except getopt.GetoptError: - usage() - error_and_exit(2, 'Invalid input') - - for opt, arg in opts: - # print opt, arg - if opt == '-h': - usage() - sys.exit(3) - elif opt in ("-i", "--ip"): - be_host = arg - elif opt in ("-p", "--port"): - be_port = arg - elif opt in ("-u", "--user"): - admin_user = arg - elif opt in ("-s", "--scheme"): - scheme = arg - elif opt in ("-v", "--updateversion"): - if arg.lower() == "false" or arg.lower() == "no": - update_version = 'false' - - print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user - - if be_host is None: - usage() - sys.exit(3) - - results = upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/", - update_version) - - print "-----------------------------" - for result in results: - print "{0:20} | {1:6}".format(result[0], result[1]) - print "-----------------------------" - - response_codes = [200, 201] - - if update_version == 'false': - response_codes = [200, 201, 409] - - failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results) - if len(list(failed_normatives)) > 0: - error_and_exit(1, None) - else: - error_and_exit(0, None) - - -if __name__ == "__main__": - main(sys.argv[1:]) -- cgit 1.2.3-korg