summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-02-28 14:26:07 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-03-23 09:48:56 +0000
commit5944b441468500fffa7111b5dea9181461ae1303 (patch)
tree9b358b2d25a309c1d6dfd86227ec75b52b2ccefa /catalog-be/src
parentec7da6aea30a1b73d1e0f5f75d2b6119ed8fa251 (diff)
Refactoring the sdc-BE-init python scripts
Adjust to the correct python syntax. Remove not used imports. Also fixed:  - the indents  - checking that all normative imported correctly logic Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: If7edc867f3cb591be157073fbc12b9842b200023
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py104
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCommon.py7
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py101
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py7
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py236
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py198
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py305
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py121
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py110
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py105
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py228
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py47
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py304
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py260
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py151
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py3
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py151
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py407
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py90
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py188
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py77
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py109
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py164
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py188
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py200
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py79
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py76
27 files changed, 1974 insertions, 2042 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
index 9ef8b4a200..cb361c6fd5 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
@@ -1,11 +1,7 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
+from importCommon import *
from importNormativeElements import createNormativeElement
-from importCommon import *
+
#########################################################################################################################################################################################
# #
# Import categoriy types #
@@ -19,59 +15,61 @@ from importCommon import *
#########################################################################################################################################################################################
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
-def importCategories(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/categories", "categoryTypes", "categoriesZip")
+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()
+ 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)
- if ( result[1] == None or result[1] not in [200, 201, 409] ):
- error_and_exit(1, None)
- else:
- if (exitOnSuccess == True):
- error_and_exit(0, None)
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- importCategories(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/categories/")
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ scheme = 'http'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index 74bdf806f0..6f976d013f 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
@@ -1,8 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
+import getopt
+import sys
###############################################################################################################
#
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
index bc68297383..c37fc87d0f 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
@@ -1,11 +1,7 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
+from importCommon import *
from importNormativeElements import createNormativeElement
-from importCommon import *
+
#####################################################################################################################################################################################
# #
# Import tosca data types #
@@ -18,58 +14,61 @@ from importCommon import *
# #
#####################################################################################################################################################################################
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+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")
-def importDataTypes(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/datatypes", "dataTypes", "dataTypesZip")
+ print_frame_line()
+ print_name_and_return_code(result[0], result[1])
+ print_frame_line()
- 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)
- if ( result[1] == None or result[1] not in [200, 201, 409] ):
- error_and_exit(1, None)
- else:
- if (exitOnSuccess == True):
- error_and_exit(0, None)
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- importDataTypes(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/data-types/")
+ 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__":
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
index 0a94bbef95..7db60331aa 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
@@ -1,6 +1,3 @@
-import getopt
-import sys
-
from importCommon import *
from importNormativeElements import createNormativeElement
@@ -18,8 +15,8 @@ from importNormativeElements import createNormativeElement
#####################################################################################################################################################################################
def usage():
- print sys.argv[
- 0], '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
def importGroupTypes(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
index 969c2f805f..92b8634437 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
@@ -1,11 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
from importNormativeTypes import *
-import importCommon
+
#####################################################################################################################################################################################
# #
@@ -19,129 +13,125 @@ import importCommon
# #
#####################################################################################################################################################################################
-def importHeatTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- heatTypes = [ "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",
+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",
+ "portMirroringByPolicy",
+ "forwardingPath",
+ "configuration",
+ "VRFObject",
+ "extVirtualMachineInterfaceCP",
+ "VLANNetworkReceptor",
+ "VRFEntry",
"subInterfaceV2",
"contrailV2VLANSubInterfaceV2",
- "fabricConfiguration"
- ]
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for heatType in heatTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, heatType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes) :
- print "Failed creating heat type " + heatType + ". " + str(result[1])
- return results
+ "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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = importHeatTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ update_version = 'true'
+ scheme = 'http'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index 667b8279c9..ed68695475 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py
@@ -1,11 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
from importNormativeTypes import *
-import importCommon
+
#####################################################################################################################################################################################################
# #
@@ -19,105 +13,103 @@ import importCommon
# #
#####################################################################################################################################################################################################
-def importNfvTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- nfvTypes = [ "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"
- ]
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for nfvType in nfvTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, nfvType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes) :
- print "Failed creating heat type " + nfvType + ". " + str(result[1])
- return results
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,',be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = importNfvTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/nfv-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ 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:])
+ 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
index 1418722dff..55521997f5 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
@@ -1,163 +1,170 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
import json
-import copy
-from importCommon import *
-import importCommon
+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, beHost, bePort, adminUser, fileDir, ELEMENT_NAME):
-
- try:
- log("in create normative type ", ELEMENT_NAME)
- debug("userId", adminUser)
- debug("fileDir", fileDir)
-
- buffer = StringIO()
- c = pycurl.Curl()
-
- url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
- c.setopt(c.URL, url)
- c.setopt(c.POST, 1)
-
- adminHeader = 'USER_ID: ' + adminUser
- #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
- c.setopt(pycurl.HTTPHEADER, [adminHeader])
-
- ymlFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".yml"
- zipFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".zip"
- debug(ymlFile)
- debug(zipFile)
- path = zipFile
- debug("path=" + path)
- CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json"
- debug(CURRENT_JSON_FILE)
- jsonFile = open(CURRENT_JSON_FILE)
-
- debug("before load json")
- json_data = json.load(jsonFile, strict=False)
- debug(json_data)
-
- jsonAsStr = json.dumps(json_data)
- debug(path)
- send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
- debug(send)
- c.setopt(pycurl.HTTPPOST, send)
-
- c.setopt(c.WRITEFUNCTION, buffer.write)
- if scheme == 'https':
- c.setopt(pycurl.SSL_VERIFYPEER, 0)
- c.setopt(pycurl.SSL_VERIFYHOST, 0)
-
- res = c.perform()
-
- #print("Before get response code")
- httpRes = c.getinfo(c.RESPONSE_CODE)
- if (httpRes != None):
- debug("http response=", httpRes)
- #print('Status: ' + str(responseCode))
- debug(buffer.getvalue())
- c.close()
-
- return (ELEMENT_NAME, httpRes, buffer.getvalue())
-
- except Exception as inst:
- print("ERROR=" + str(inst))
- return (ELEMENT_NAME, None, None)
+ 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> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-l <directory base location> | --location=<directory base location>] [-e <element name> | --element=<element name>]'
- print "----------------- Example -------------------"
- print "python importNodeType.py -d false -l /home/vagrant/catalog-be-1604.0.2.15.6-SNAPSHOT/scripts/import/tosca/../../../import/tosca/user-normative-types/ -e root1"
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-l <directory base location> | --location=<directory base location>] [-e <element name> | --element=<element name>]'
+ print "----------------- Example -------------------"
+ print "python importNodeType.py -d false -l /home/vagrant/catalog-be-1604.0.2.15.6-SNAPSHOT/scripts/import/tosca/../../../import/tosca/user-normative-types/ -e root1"
+
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- location = None
- element = None
- 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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-l", "--location"):
- location = arg
- elif opt in ("-e", "--element"):
- element = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if (location == None):
- print 'Missing file location'
- usage()
- sys.exit(3)
-
- if (element == None):
- print 'Missing element name. E.g. root, compute, ...'
- usage()
- sys.exit(3)
-
- #pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
-
- #baseFileLocation = pathdir + "/../../../import/tosca/"
- #fileDir = baseFileLocation + "user-normative-types/"
-
- #normativeType = "root1"
-
- result = createUserNormativeType(scheme, beHost, bePort, adminUser, location, element)
- #result = createUserNormativeType(beHost, bePort, adminUser, fileDir, normativeType)
- print "---------------------------------------"
- print "{0:30} | {1:6}".format(result[0], result[1])
- print "---------------------------------------"
-
- if ( result[1] == None or result[1] not in [200, 201] ) :
- print "Failed creating normative type " + element + ". " + str(result[1])
- error_and_exit(1, None)
-
- error_and_exit(0, None)
+ 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:])
+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
index e4f536ff85..c61b8bcc03 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
@@ -1,23 +1,18 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
import time
-# from importNormativeElements import createNormativeElement
-from importNormativeElements import *
-from importNormativeTypes import importNormativeTypes
-from importHeatTypes import importHeatTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeRelationships import importNormativeRelationships
+
+import importCommon
+from importAnnotationTypes import import_annotation_types
from importCategoryTypes import importCategories
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
+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
-from importAnnotationTypes import import_annotation_types
-from importCommon import *
-import importCommon
#################################################################################################################################################################################################################################
@@ -34,34 +29,34 @@ import importCommon
#################################################################################################################################################################################################################################
def usage():
- print sys.argv[
- 0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
-def handleResults(results, 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()
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ if update_version == 'false':
+ response_codes = [200, 201, 409]
- failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedResults) > 0):
+ 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.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = 'true'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ debug_f = None
+ update_version = 'true'
importCommon.debugFlag = False
scheme = 'http'
@@ -78,70 +73,70 @@ def main(argv):
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ 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")
+ 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"):
- updateversion = 'false'
+ if arg.lower() == "false" or arg.lower() == "no":
+ update_version = 'false'
- print 'scheme =', scheme, ', be host =', beHost, ', be port =', bePort, ', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
+ if debug_f is not None:
+ print 'set debug mode to ' + str(debug_f)
+ importCommon.debugFlag = debug_f
- if (beHost == None):
+ 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)
+ path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + path_dir)
- baseFileLocation = pathdir + "/../../../import/tosca/"
+ base_file_location = path_dir + "/../../../import/tosca/"
- fileLocation = baseFileLocation + "data-types/"
- importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ 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)
- fileLocation = baseFileLocation + "capability-types/"
- importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "capability-types/"
+ importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "relationship-types/"
- importNormativeRelationships(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "relationship-types/"
+ importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "interface-lifecycle-types/"
+ importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "categories/"
- importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "categories/"
+ importCategories(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "normative-types/"
- results = importNormativeTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(results, updateversion)
+ file_location = base_file_location + "normative-types/"
+ results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
+ handleResults(results, update_version)
- fileLocation = baseFileLocation + "heat-types/"
- resultsHeat = importHeatTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
+ 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)
- fileLocation = baseFileLocation + "group-types/"
- importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "group-types/"
+ importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "policy-types/"
- importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "policy-types/"
+ importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
- import_annotation_types(scheme, beHost, bePort, adminUser, False)
+ import_annotation_types(scheme, be_host, be_port, admin_user, False)
error_and_exit(0, None)
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
index e0f5c40ac9..989233d380 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
@@ -1,11 +1,7 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importNormativeElements import createNormativeElement
+import importCommon
from importCommon import *
-import importCommon
+from importNormativeElements import createNormativeElement
+
#################################################################################################################################################################################################
# #
@@ -19,62 +15,64 @@ import importCommon
# #
#################################################################################################################################################################################################
-
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+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")
-def importNormativeCapabilities(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", "capabilityTypeZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
+ print_frame_line()
+ print_name_and_return_code(result[0], result[1])
+ print_frame_line()
- if ( result[1] == None or result[1] not in [200, 201, 409] ):
- importCommon.error_and_exit(1, None)
- else:
- if (exitOnSuccess == True):
- importCommon.error_and_exit(0, None)
+ 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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- importNormativeCapabilities(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/capability-types/")
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ scheme = 'http'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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/importNormativeInterfaceLifecycleTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
index 89862f7df6..1e6b9ca44f 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
@@ -1,10 +1,6 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importNormativeElements import createNormativeElement
from importCommon import *
+from importNormativeElements import createNormativeElement
+
#############################################################################################################################################################################################################
# #
@@ -19,60 +15,63 @@ from importCommon import *
#############################################################################################################################################################################################################
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
-def importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", "interfaceLifecycleTypes", "interfaceLifecycleTypeZip")
+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()
+ print_frame_line()
+ print_name_and_return_code(result[0], result[1])
+ print_frame_line()
- if ( result[1] == None or result[1] not in [200, 201, 409] ):
- error_and_exit(1, None)
- else:
- if (exitOnSuccess == True):
- error_and_exit(0, None)
+ 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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/interface-lifecycle-types//")
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ scheme = 'http'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index c288d550f7..b06959ae40 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py
@@ -1,21 +1,14 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
import time
-#from importNormativeElements import createNormativeElement
-from importNormativeElements import *
-from importNormativeTypes import importNormativeTypes
-from importHeatTypes import importHeatTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importCategoryTypes import importCategories
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
+
+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
-from importCommon import *
-import importCommon
+
#####################################################################################################################################################################################################################################################
# #
@@ -30,109 +23,114 @@ import importCommon
# #
#####################################################################################################################################################################################################################################################
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
-
-def handleResults(results, updateversion):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedResults) > 0):
- error_and_exit(1, None)
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+
+
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = 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", "--updateversion"):
- print arg
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- baseFileLocation = pathdir + "/../../../import/tosca/"
-
- fileLocation = baseFileLocation + "data-types/"
- importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- print 'sleep until data type cache is updated'
- time.sleep( 70 )
-
- fileLocation = baseFileLocation + "capability-types/"
- importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- #fileLocation = baseFileLocation + "categories/"
- #importCategories(beHost, bePort, adminUser, False, fileLocation)
-
- #fileLocation = baseFileLocation + "normative-types/"
- #results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
- #handleResults(results, updateversion)
-
- #fileLocation = baseFileLocation + "heat-types/"
- #resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
- #handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "group-types/"
- importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "policy-types/"
- importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- error_and_exit(0, None)
+ 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:])
+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
index 7adcf333c7..a6040d0215 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
@@ -1,11 +1,7 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importNormativeElements import createNormativeElement
-from importCommon import *
import importCommon
+from importCommon import *
+from importNormativeElements import createNormativeElement
+
#################################################################################################################################################################################################
# #
@@ -24,60 +20,63 @@ import importCommon
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
-def importNormativeRelationships(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/relationship", "relationshipTypes", "relationshipTypeZip")
+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] == None or result[1] not in [200, 201, 409] ):
+ if result[1] is None or result[1] not in [200, 201, 409]:
importCommon.error_and_exit(1, None)
else:
- if (exitOnSuccess == True):
+ if exit_on_success is True:
importCommon.error_and_exit(0, None)
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
+ 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="])
+ 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
+ # print opt, arg
if opt == '-h':
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ admin_user = arg
elif opt in ("-s", "--scheme"):
scheme = arg
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
- if ( beHost == None ):
+ if be_host is None:
usage()
sys.exit(3)
- importNormativeRelationships(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/relationship-types/")
+ 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
index 0fcaf58ee6..889ea05b66 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
@@ -1,11 +1,12 @@
-import pycurl
-import sys, getopt
+import json
import zipfile
from StringIO import StringIO
-import json
-import copy
+
+import pycurl
+
from importCommon import *
-import importCommon
+
+
#########################################################################################################################################################################################
# #
# Import all users from a given file #
@@ -18,158 +19,159 @@ import importCommon
# #
#########################################################################################################################################################################################
-def createNormativeType(scheme, beHost, bePort, adminUser, fileDir, ELEMENT_NAME, updateversion):
-
- try:
- log("in create normative type ", ELEMENT_NAME)
- debug("userId", adminUser)
- debug("fileDir", fileDir)
-
- buffer = StringIO()
- c = pycurl.Curl()
- if is_debug():
- c.setopt(pycurl.VERBOSE, 1)
-
- url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
- if updateversion != None:
- url += '?createNewVersion=' + updateversion
- c.setopt(c.URL, url)
- c.setopt(c.POST, 1)
-
- adminHeader = 'USER_ID: ' + adminUser
- #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
- c.setopt(pycurl.HTTPHEADER, [adminHeader])
-
- yml_path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".yml"
- path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".zip"
-
- zf = zipfile.ZipFile(path, "w")
- zf.write(yml_path, ELEMENT_NAME + '.yml')
- zf.close()
-
- debug(path)
- CURRENT_JSON_FILE=fileDir + 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)
-
- jsonAsStr = json.dumps(json_data)
-
- send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
- debug(send)
- c.setopt(pycurl.HTTPPOST, send)
-
- #data = json.dumps(user)
- #c.setopt(c.POSTFIELDS, data)
-
- 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")
- res = c.perform()
-
- #print("Before get response code")
- httpRes = c.getinfo(c.RESPONSE_CODE)
- if (httpRes != None):
- debug("http response=", httpRes)
- #print('Status: ' + str(responseCode))
- debug(buffer.getvalue())
- c.close()
-
- return (ELEMENT_NAME, httpRes, buffer.getvalue())
-
- except Exception as inst:
- print("ERROR=" + str(inst))
- return (ELEMENT_NAME, None, None)
+def 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> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-v <true|false> | --updateversion=<true|false>]'
-
-
-def importNormativeTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- normativeTypes = [ "root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database", "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer", "port", "network"]
- #normativeTypes = [ "root" ]
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for normativeType in normativeTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, normativeType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes ):
- print "Failed creating normative type " + normativeType + ". " + str(result[1])
- return results
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-v <true|false> | --updateversion=<true|false>]'
+
+
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', updateversion =', updateversion
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = importNormativeTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/normative-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ 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:])
-
+ 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
index c573a448a4..de67cd7e57 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
@@ -1,25 +1,22 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
import time
-#from importNormativeElements import createNormativeElement
-from importNormativeElements import *
-from importNormativeTypes import importNormativeTypes
+
+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 importOnapTypes import importOnapTypes
-from importSolTypes import importSolTypes
from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeRelationships import importNormativeRelationships
-from importCategoryTypes import importCategories
from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from importDataTypes import importDataTypes
-from importGroupTypes import importGroupTypes
+from importNormativeRelationships import importNormativeRelationships
+# from importNormativeElements import createNormativeElement
+from importNormativeTypes import importNormativeTypes
+from importOnapTypes import importOnapTypes
from importPolicyTypes import importPolicyTypes
-from importCommon import *
-import importCommon
+from importSolTypes import importSolTypes
+
#################################################################################################################################################################################################
# #
@@ -35,126 +32,129 @@ import importCommon
#################################################################################################################################################################################################
def usage():
- print sys.argv[0], '[-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+ print sys.argv[0], \
+ '[-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+
-def handleResults(results, 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()
+ print_frame_line()
+ for result in results:
+ print_name_and_return_code(result[0], result[1])
+ print_frame_line()
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ 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)
- failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedResults) > 0):
- error_and_exit(1, None)
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
- opts = []
-
- 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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = 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", "--updateversion"):
- print arg
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,',be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- baseFileLocation = pathdir + "/../../../import/tosca/"
-
- fileLocation = baseFileLocation + "data-types/"
- importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- print 'sleep until data type cache is updated'
- time.sleep( 70 )
-
- fileLocation = baseFileLocation + "capability-types/"
- importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "relationship-types/"
- importNormativeRelationships(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "categories/"
- importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "normative-types/"
- results = importNormativeTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(results, updateversion)
-
- fileLocation = baseFileLocation + "heat-types/"
- resultsHeat = importHeatTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "nfv-types/"
- resultsHeat = importNfvTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "onap-types/"
- resultsHeat = importOnapTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "sol-types/"
- resultsHeat = importSolTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "group-types/"
- importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- fileLocation = baseFileLocation + "policy-types/"
- importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
-
- error_and_exit(0, None)
+ 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:])
+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
index 395b42d696..f6e4749b57 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py
@@ -1,11 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
from importNormativeTypes import *
-import importCommon
+
#####################################################################################################################################################################################################
# #
@@ -19,81 +13,80 @@ import importCommon
# #
#####################################################################################################################################################################################################
-def importOnapTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- #Add desired type names to the list
- onapTypes = []
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for onapType in onapTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, onapType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes) :
- print "Failed creating heat type " + onapType + ". " + str(result[1])
- return results
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,',be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = importOnapTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/onap-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ 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:])
+ 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
index 1bd6befbf7..47f783d0a6 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
@@ -1,6 +1,3 @@
-import getopt
-import sys
-
from importCommon import *
from importNormativeElements import createNormativeElement
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py
index 24479c4f6b..5a8d2aaf70 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py
@@ -1,11 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
from importNormativeTypes import *
-import importCommon
+
#####################################################################################################################################################################################################
# #
@@ -19,81 +13,80 @@ import importCommon
# #
#####################################################################################################################################################################################################
-def importSolTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- #Add desired type names to the list
- solTypes = []
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for onapType in solTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, onapType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes) :
- print "Failed creating heat type " + onapType + ". " + str(result[1])
- return results
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,',be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = importSolTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/sol-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ 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:])
+ 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
index 09fe726cec..8cc8926ac5 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
@@ -1,10 +1,11 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
+import getopt
import json
-import copy
+import sys
+
+import pycurl
import yaml
+
#########################################################################################################################################################################################
# #
# Import all users from a given YAML file #
@@ -20,213 +21,203 @@ import yaml
#########################################################################################################################################################################################
-def importUsers(scheme, beHost, bePort, users, adminUser):
-
- result = []
-
- for user in users:
-
- #print("Going to add user " + user['userId'])
-
- getRes = getUser(scheme, beHost, bePort, user)
- userId = getRes[0]
- error = getRes[1]
- #print error
- if ( error != None and error == 404 ):
- res = createUser(scheme, beHost, bePort, user ,adminUser)
- result.append(res)
- else:
- if ( error == 200 ):
- curResult = (userId, 409)
- result.append(curResult)
- else:
- result.append(getRes)
-
- return result
-
-
-def getUser(scheme, beHost, bePort, user):
-
- if (user.get('userId') == None):
- print "Ignoring record", user
- return ('NotExist', 200)
- userId = user['userId']
- try:
- buffer = StringIO()
- c = pycurl.Curl()
-
- #print type(userId)
- url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/user/' + str(userId)
- 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")
- httpRes = c.getinfo(c.RESPONSE_CODE)
- #print("After get response code")
- responseCode = c.getinfo(c.RESPONSE_CODE)
-
- #print('Status: ' + str(responseCode))
-
- c.close()
-
- return (userId, httpRes)
-
- except Exception as inst:
- print(inst)
- return (userId, None)
-
-
-
-def createUser(scheme, beHost, bePort, user, adminUser):
-
- if (user.get('userId') == None):
- print "Ignoring record", user
- return ('NotExist', 200)
-
- userId = user['userId']
- try:
- buffer = StringIO()
- c = pycurl.Curl()
-
- url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/user'
- c.setopt(c.URL, url)
- c.setopt(c.POST, 1)
-
- adminHeader = 'USER_ID: ' + adminUser
- c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
-
- data = json.dumps(user)
- c.setopt(c.POSTFIELDS, data)
-
- 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")
- res = c.perform()
- #print(res)
-
- #print("Before get response code")
- httpRes = c.getinfo(c.RESPONSE_CODE)
- #print("After get response code")
- responseCode = c.getinfo(c.RESPONSE_CODE)
-
- #print('Status: ' + str(responseCode))
-
- c.close()
-
- return (userId, httpRes)
-
- except Exception as inst:
- print(inst)
- return (userId, None)
-
-
-def error_and_exit(errorCode, errorDesc):
- if ( errorCode > 0 ):
- print("status=" + str(errorCode) + ". " + errorDesc)
- else:
- print("status=" + str(errorCode))
- sys.exit(errorCode)
-
+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> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]'
+
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- inputfile = None
-
- adminUser = 'jh0003'
- 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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-f", "--ifile"):
- inputfile = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', users file =',inputfile
-
- if ( inputfile == None ):
- usage()
- sys.exit(3)
-
- print 'Input file is ', inputfile
-
-
- usersAsYamlFile = open(inputfile, 'r')
- usersDoc = yaml.load(usersAsYamlFile)
- print usersDoc
-
- cloneUsers = []
- for users in usersDoc.values():
- for x,y in users.items():
- copiedUser = y
- copiedUser['userId'] = x
- #print copiedUser
- cloneUsers.append(copiedUser)
-
- print cloneUsers
-
- usersAsYamlFile.close()
-
- #activeUsers = filter(lambda x: x.get('status') == None or x['status'] == 'ACTIVE', cloneUsers)
-
- resultTable = importUsers(scheme, beHost, bePort, cloneUsers, adminUser)
-
- g = lambda x: x[1] != 201 and x[1] != 409
-
- result = filter(g, resultTable)
-
- if ( len(result) > 0 ):
- #print("ERROR: Failed to load the users " + ', '.join(map(lambda x: x[0],result)))
- 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, resultTable)
-
- print("-------------------------------------------")
- print("Existing users: " + ', '.join(map(lambda x: x[0],result)))
-
- result = filter(lambda x: x[1] == 201, resultTable)
- if ( len(result) == 0 ):
- print("-------------------------------------------")
- print("No NEW user was loaded. All users are already exist")
- print("-------------------------------------------")
- else:
- print("-------------------------------------------")
- print("Loaded users: " + ', '.join(map(lambda x: x[0],result)))
- print("-------------------------------------------")
-
- error_and_exit(0, None)
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ input_file = None
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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/upgradeHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
index 265bf33f9a..4bf1de37f1 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
@@ -1,12 +1,6 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
+import yaml
+
from importNormativeTypes import *
-import importCommon
-import json
################################################################################################################################################################################################
@@ -20,49 +14,52 @@ import json
# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
# #
################################################################################################################################################################################################
-def upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseDir, updateversion):
- responseCodes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+
+
+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)
- heatTypes = types["heat"]
- debug(heatTypes)
- normativeTypes = types["normative"]
- debug(normativeTypes)
- heatFileDir = baseDir + "heat-types/"
- debug(heatFileDir)
- normativeFileDir = baseDir + "normative-types/"
- debug(normativeFileDir)
+ 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 heatType in heatTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, heatFileDir, heatType.encode('ascii', 'ignore'), updateversion)
+ 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] == None or result[1] not in responseCodes):
- print "Failed creating heat type " + heatType + ". " + str(result[1])
- for normativeType in normativeTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, normativeFileDir, normativeType.encode('ascii', 'ignore'), updateversion)
+ 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] == None or result[1] not in responseCodes):
+ if result[1] is None or result[1] not in response_codes:
print "Failed creating normative type " + normativeType + ". " + str(result[1])
return results
except yaml.YAMLError as exc:
print(exc)
-
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = 'true'
+ 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="])
+ 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')
@@ -73,37 +70,37 @@ def main(argv):
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ admin_user = arg
elif opt in ("-s", "--scheme"):
scheme = arg
elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
+ if arg.lower() == "false" or arg.lower() == "no":
+ update_version = 'false'
- print 'scheme =',scheme,', be host =',beHost, ', be port =', bePort, ', user =', adminUser
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
- if (beHost == None):
+ if be_host is None:
usage()
sys.exit(3)
- results = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, "../../../import/tosca/", updateversion)
+ 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 "-----------------------------"
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ if update_version == 'false':
+ response_codes = [200, 201, 409]
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
+ 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)
@@ -111,4 +108,3 @@ def main(argv):
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
index 4f254f26fe..5394864fdb 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
@@ -1,11 +1,5 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
from importNormativeTypes import *
-import importCommon
+
#################################################################################################################################################################################
# #
@@ -19,101 +13,99 @@ import importCommon
# #
#################################################################################################################################################################################
-def upgradeHeatTypes1707(scheme, beHost, bePort, adminUser, fileDir, updateversion):
-
- heatTypes = [ "volume",
- "cinderVolume",
- "extVl",
- "extCp",
- "Generic_VFC",
- "Generic_VF",
- "Generic_PNF",
- "Generic_Service",
- "globalPort",
- "globalNetwork",
- "contrailV2VirtualMachineInterface",
- "contrailV2VLANSubInterface",
- "contrailPort",
- "contrailV2VirtualNetwork",
- "contrailVirtualNetwork",
- "neutronNet",
- "neutronPort",
- "multiFlavorVFC",
- "vnfConfiguration"
- ]
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for heatType in heatTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, heatType, updateversion)
- results.append(result)
- if ( result[1] == None or result[1] not in responseCodes) :
- print "Failed creating heat type " + heatType + ". " + str(result[1])
- return results
+
+def 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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- results = upgradeHeatTypes1707(scheme, beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+ be_host = 'localhost'
+ be_port = '8080'
+ admin_user = 'jh0003'
+ update_version = 'true'
+ scheme = 'http'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index cb7628e974..81ee843893 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py
@@ -1,12 +1,6 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
+import yaml
+
from importNormativeTypes import *
-import importCommon
-import json
################################################################################################################################################################################################
@@ -20,39 +14,44 @@ import json
# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
# #
################################################################################################################################################################################################
-def upgradeNfvTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseDir, updateversion):
- responseCodes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+
+
+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)
- nfvTypes = types["nfv"]
- debug(nfvTypes)
- nfvFileDir = baseDir + "nfv-types/"
- debug(nfvFileDir)
- results = []
- for nfvType in nfvTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, nfvFileDir, nfvType.encode('ascii', 'ignore'), updateversion)
+ 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] == None or result[1] not in responseCodes):
+ if result[1] is None or result[1] not in response_codes:
print "Failed creating nfv type " + nfvType + ". " + str(result[1])
except yaml.YAMLError as exc:
print(exc)
+ return results
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = 'true'
+ 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="])
+ 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')
@@ -63,37 +62,38 @@ def main(argv):
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ admin_user = arg
elif opt in ("-s", "--scheme"):
scheme = arg
elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
+ if arg.lower() == "false" or arg.lower() == "no":
+ update_version = 'false'
- print 'scheme =',scheme,', be host =',beHost, ', be port =', bePort, ', user =', adminUser
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
- if (beHost == None):
+ if be_host is None:
usage()
sys.exit(3)
- results = upgradeNfvTypesPerConfigFile(scheme, beHost, bePort, adminUser, "../../../import/tosca/", updateversion)
+ 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 "-----------------------------"
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ if update_version == 'false':
+ response_codes = [200, 201, 409]
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
+ 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)
@@ -101,4 +101,3 @@ def main(argv):
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
index 36a5d1181a..c8f5ecf9e6 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
@@ -1,22 +1,18 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
import time
+
+import importCommon
+from importAnnotationTypes import import_annotation_types
from importCategoryTypes import importCategories
-from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
+from importCommon import *
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 importAnnotationTypes import import_annotation_types
-
+from importNormativeRelationships import importNormativeRelationships
+from importPolicyTypes import importPolicyTypes
+from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
-from importCommon import *
-import importCommon
#################################################################################################################################################################################################################################
# #
@@ -31,99 +27,104 @@ import importCommon
# #
#################################################################################################################################################################################################################################
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
+
-def handleResults(results, updateversion):
+def handleResults(results):
print_frame_line()
for result in results:
print_name_and_return_code(result[0], result[1])
print_frame_line()
- failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
- if (len(failedResults) > 0):
+ 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.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = 'true'
+ 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="])
+ 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
+ # print opt, arg
if opt == '-h':
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ 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")
+ debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
+ if debug_f is not None:
+ print 'set debug mode to ' + str(debug_f)
+ importCommon.debugFlag = debug_f
- if ( beHost == None ):
+ 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)
+ path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + path_dir)
- baseFileLocation = pathdir + "/../../../import/tosca/"
+ base_file_location = path_dir + "/../../../import/tosca/"
- fileLocation = baseFileLocation + "categories/"
- importCategories(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "categories/"
+ importCategories(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "relationship-types/"
- importNormativeRelationships(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "relationship-types/"
+ importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "data-types/"
- importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "data-types/"
+ importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "policy-types/"
- importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "policy-types/"
+ importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "capability-types/"
- importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "capability-types/"
+ importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "group-types/"
- importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "group-types/"
+ importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
- fileLocation = baseFileLocation + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)
+ file_location = base_file_location + "interface-lifecycle-types/"
+ importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
- import_annotation_types(scheme, beHost, bePort, adminUser, False)
+ import_annotation_types(scheme, be_host, be_port, admin_user, False)
print 'sleep until data type cache is updated'
- time.sleep( 70 )
+ time.sleep(70)
- resultsHeat = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateversion)
- handleResults(resultsHeat, 'false')
+ 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:])
+ 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
index c6fa1c9cab..b5ba42f971 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
@@ -1,11 +1,9 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
+
+import importCommon
from importCommon import *
from importNormativeTypes import createNormativeType
-import importCommon
+
#################################################################################################################################################################################################################################
# #
@@ -20,91 +18,91 @@ import importCommon
# #
#################################################################################################################################################################################################################################
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
-
-def handleResults(results, updateversion):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
- if (len(failedResults) > 0):
- error_and_exit(1, None)
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- baseFileLocation = pathdir + "/../../../import/tosca/"
- results = []
-
-
- ##########################################################################
- #---------------------------------for release 1702---------------------- #
- ##########################################################################
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailV2VirtualMachineInterface", updateversion)
- results.append(result)
-
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "neutronPort", updateversion)
- results.append(result)
+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---------------------- #
+ ##########################################################################
- handleResults(results, 'false')
+ file_location = base_file_location + "heat-types/"
+ result = createNormativeType(scheme, be_host, be_port, admin_user, file_location,
+ "contrailV2VirtualMachineInterface", update_version)
+ results.append(result)
- error_and_exit(0, None)
+ file_location = base_file_location + "heat-types/"
+ result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version)
+ results.append(result)
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index 32045513b8..a5e2ebae67 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
@@ -1,100 +1,102 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
-import time
-from importNormativeTypes import importNormativeTypes
-from importHeatTypes import importHeatTypes
-from importCommon import *
+import 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> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
-
-def handleResults(results, updateversion):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- responseCodes = [200, 201]
-
- if(updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedResults) > 0):
- error_and_exit(1, None)
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+
+
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = 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", "--updateversion"):
- print arg
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- baseFileLocation = pathdir + "/../../../import/tosca/"
-
- fileLocation = baseFileLocation + "normative-types/"
- results = importNormativeTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(results, updateversion)
-
- fileLocation = baseFileLocation + "heat-types/"
- resultsHeat = importHeatTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsHeat, updateversion)
-
- fileLocation = baseFileLocation + "onap-types/"
- resultsOnap = importOnapTypes(beHost, bePort, adminUser, fileLocation, updateversion)
- handleResults(resultsOnap, updateversion)
-
- error_and_exit(0, None)
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
-if __name__ == "__main__":
- main(sys.argv[1:])
+ 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
index 972d792b20..cc2325f9fb 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py
@@ -1,11 +1,9 @@
-import pycurl
-import sys, getopt, os
-from StringIO import StringIO
-import json
-import copy
+import os
+
+import importCommon
from importCommon import *
from importNormativeTypes import createNormativeType
-import importCommon
+
#################################################################################################################################################################################################################################
# #
@@ -20,113 +18,117 @@ import importCommon
# #
#################################################################################################################################################################################################################################
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
-
-def handleResults(results, updateversion):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
- if (len(failedResults) > 0):
- error_and_exit(1, None)
+ print sys.argv[0], \
+ '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
+
+
+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.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- debugf = None
- updateversion = '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"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
-
- if (debugf != None):
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- baseFileLocation = pathdir + "/../../../import/tosca/"
- results = []
-
-
- ##########################################################################
- #---------------------------------for release 1702---------------------- #
- ##########################################################################
+ 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---------------------- #
+ ##########################################################################
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailPort", updateversion)
- results.append(result)
+ file_location = base_file_location + "heat-types/"
+ result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailPort", update_version)
+ results.append(result)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailV2VirtualMachineInterface", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "neutronPort", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailCompute", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "novaServer", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailV2VirtualNetwork", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "contrailVirtualNetwork", updateversion)
- 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)
- fileLocation = baseFileLocation + "heat-types/"
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileLocation, "neutronNet", updateversion)
- 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)
- handleResults(results, 'false')
+ error_and_exit(0, None)
- error_and_exit(0, None)
if __name__ == "__main__":
- main(sys.argv[1:])
-
+ 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
index 24a7b0e5b3..2074ba9c27 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py
@@ -1,12 +1,6 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
+import yaml
+
from importNormativeTypes import *
-import importCommon
-import json
################################################################################################################################################################################################
@@ -20,39 +14,44 @@ import json
# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
# #
################################################################################################################################################################################################
-def upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseDir, updateversion):
- responseCodes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+
+
+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)
- onapTypes = types["onap"]
- debug(onapTypes)
- onapFileDir = baseDir + "onap-types/"
- debug(onapFileDir)
- results = []
- for onapType in onapTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, onapFileDir, onapType.encode('ascii', 'ignore'), updateversion)
+ 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] == None or result[1] not in responseCodes):
- print "Failed creating onap type " + onapType + ". " + str(result[1])
+ if result[1] is None or result[1] not in response_codes:
+ print "Failed creating onap type " + onap_type + ". " + str(result[1])
except yaml.YAMLError as exc:
print(exc)
+ return results
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = 'true'
+ 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="])
+ 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')
@@ -63,37 +62,38 @@ def main(argv):
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ admin_user = arg
elif opt in ("-s", "--scheme"):
scheme = arg
elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
+ if arg.lower() == "false" or arg.lower() == "no":
+ update_version = 'false'
- print 'scheme =',scheme,', be host =',beHost, ', be port =', bePort, ', user =', adminUser
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
- if (beHost == None):
+ if be_host is None:
usage()
sys.exit(3)
- results = upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, "../../../import/tosca/", updateversion)
+ 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 "-----------------------------"
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ if update_version == 'false':
+ response_codes = [200, 201, 409]
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
+ 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)
@@ -101,4 +101,3 @@ def main(argv):
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
index d3e5a4b2da..e9cebfe9a8 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py
@@ -1,12 +1,6 @@
-import pycurl
-import sys, getopt
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
+import yaml
+
from importNormativeTypes import *
-import importCommon
-import json
################################################################################################################################################################################################
@@ -20,39 +14,43 @@ import json
# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
# #
################################################################################################################################################################################################
-def upgradeSolTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseDir, updateversion):
- responseCodes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+
+
+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)
- solTypes = types["sol"]
- debug(solTypes)
- solFileDir = baseDir + "sol-types/"
- debug(solFileDir)
- results = []
- for solType in solTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, solFileDir, solType.encode('ascii', 'ignore'), updateversion)
+ 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] == None or result[1] not in responseCodes):
+ if result[1] is None or result[1] not in response_codes:
print "Failed creating sol type " + solType + ". " + str(result[1])
except yaml.YAMLError as exc:
print(exc)
+ return results
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = 'true'
+ 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="])
+ 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')
@@ -63,37 +61,38 @@ def main(argv):
usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
- beHost = arg
+ be_host = arg
elif opt in ("-p", "--port"):
- bePort = arg
+ be_port = arg
elif opt in ("-u", "--user"):
- adminUser = arg
+ admin_user = arg
elif opt in ("-s", "--scheme"):
scheme = arg
elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
+ if arg.lower() == "false" or arg.lower() == "no":
+ update_version = 'false'
- print 'scheme =',scheme,', be host =',beHost, ', be port =', bePort, ', user =', adminUser
+ print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
- if (beHost == None):
+ if be_host is None:
usage()
sys.exit(3)
- results = upgradeSolTypesPerConfigFile(scheme, beHost, bePort, adminUser, "../../../import/tosca/", updateversion)
+ 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 "-----------------------------"
- responseCodes = [200, 201]
+ response_codes = [200, 201]
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
+ if update_version == 'false':
+ response_codes = [200, 201, 409]
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
+ 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)
@@ -101,4 +100,3 @@ def main(argv):
if __name__ == "__main__":
main(sys.argv[1:])
-