aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-03-05 13:12:27 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-24 06:01:11 +0000
commitcb30f3a566b73c78c3ea666acfcd3f288098684a (patch)
tree38cd1acb83ddde2b927485611d130bbeec3c1a4b /catalog-be/src/main/resources/scripts
parentbdbfc2e460ccb561c3e174260b2908b974996d4f (diff)
Refactoring the sdc-BE-init python scripts
Deeper refactoring of python script: - create the python package with init script - support for python 3.x - reuse code - new design - support for .json conf file - update the docker chef script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I02169eb7d0e3e90851ba1811536d1712c3b4145f
Diffstat (limited to 'catalog-be/src/main/resources/scripts')
-rw-r--r--catalog-be/src/main/resources/scripts/.gitignore132
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py35
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py75
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCommon.py90
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py76
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py75
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py137
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py115
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py170
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py145
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py78
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py108
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py77
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py136
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py82
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py177
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py160
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py92
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py76
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py92
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py223
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py108
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py111
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py101
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py130
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py108
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py102
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py134
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py146
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py101
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py100
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/__init__.py0
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/bColors.py8
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/helpers.py3
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/logger.py83
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/main.py16
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py107
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py121
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py117
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json5
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/onapTypesToUpgrade.json (renamed from catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json)0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/typesToUpgrade.json (renamed from catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json)2
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py42
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runGenericNormative.py37
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeElement.py71
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeType.py56
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py56
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementCandidate.py18
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py76
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeToUpdateList.py60
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypeCandidate.py14
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypesList.py161
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py59
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py59
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py0
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json44
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/run.py64
-rw-r--r--catalog-be/src/main/resources/scripts/setup.py43
64 files changed, 1453 insertions, 3361 deletions
diff --git a/catalog-be/src/main/resources/scripts/.gitignore b/catalog-be/src/main/resources/scripts/.gitignore
new file mode 100644
index 0000000000..be20befc81
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/.gitignore
@@ -0,0 +1,132 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Python template
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py
deleted file mode 100644
index 5f0d4ad421..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importAnnotationTypes.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import sys
-
-from importCommon import parse_cmd_line_params
-from importNormativeElements import import_element
-
-IMPORT_ANNOTATION_URL = "/sdc2/rest/v1/catalog/uploadType/annotationtypes"
-ANNOTATION_FILE_PATH = "../../../import/tosca/annotation-types/"
-ANNOTATION_ZIP_FILE = "annotationTypesZip"
-ANNOTATION_ELEMENT_NAME = "annotationTypes"
-
-#####################################################################################################################################################################################
-# #
-# Import tosca data types #
-# #
-# activation : #
-# python importAnnotaionTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importAnnotaionTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################
-
-
-def import_annotation_types(scheme, be_host, be_port, admin_user, exit_on_success):
- import_element(scheme, be_host, be_port, admin_user, exit_on_success, ANNOTATION_FILE_PATH, IMPORT_ANNOTATION_URL,
- ANNOTATION_ELEMENT_NAME, ANNOTATION_ZIP_FILE)
-
-
-def main(argv):
- scheme, be_host, be_port, admin_user = parse_cmd_line_params(argv)
- import_annotation_types(scheme, be_host, be_port, admin_user, True)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
deleted file mode 100644
index cb361c6fd5..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
+++ /dev/null
@@ -1,75 +0,0 @@
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#########################################################################################################################################################################################
-# #
-# Import categoriy types #
-# #
-# activation : #
-# python importCategoryTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importCategoryTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#########################################################################################################################################################################################
-
-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> ]'
-
-
-def importCategories(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/categories", "categoryTypes", "categoriesZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success is True:
- error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importCategories(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/categories/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
deleted file mode 100644
index 6f976d013f..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
+++ /dev/null
@@ -1,90 +0,0 @@
-import getopt
-import sys
-
-###############################################################################################################
-#
-#
-###############################################################################################################
-
-debugFlag = True
-
-
-def join_strings(lst):
- concat = ""
- for string in lst:
- if string is not None:
- if type(string) == int:
- string = str(string)
- concat += (string + " ")
- return concat
-
-
-def debug(desc, *args):
- if debugFlag:
- print desc, join_strings(args)
-
-
-def is_debug():
- return debugFlag
-
-
-def log(desc, arg=None):
- print desc, arg
-
-
-def error_and_exit(error_code, error_desc):
- if error_code > 0:
- print "status={0}. {1}".format(error_code, '' if error_desc is None else error_desc)
- else:
- print "status={0}".format(error_code)
- sys.exit(error_code)
-
-
-def print_name_and_return_code(name, code):
- print "{0:30} | {1:6}".format(name, code)
-
-
-def print_frame_line():
- print "----------------------------------------"
-
-
-def parse_cmd_line_params(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
- return scheme, be_host, be_port, admin_user
-
-
-def usage():
- print sys.argv[
- 0], '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> ' \
- '| --port=<be port> ] [-u <user userId> | --user=<user userId> ] '
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
deleted file mode 100644
index c37fc87d0f..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#####################################################################################################################################################################################
-# #
-# Import tosca data types #
-# #
-# activation : #
-# python importDataTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importDataTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################
-
-
-def usage():
- print sys.argv[0], \
- '[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")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success is True:
- error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- #print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importDataTypes(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/data-types/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
-
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
deleted file mode 100644
index 7db60331aa..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
+++ /dev/null
@@ -1,75 +0,0 @@
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#####################################################################################################################################################################################
-# #
-# Import tosca data types #
-# #
-# activation : #
-# python importGroupTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importGroupTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################
-
-def usage():
- print sys.argv[0], \
- '[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):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/grouptypes", "groupTypes", "groupTypesZip", True)
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success:
- error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importGroupTypes(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/group-types/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
deleted file mode 100644
index 92b8634437..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
+++ /dev/null
@@ -1,137 +0,0 @@
-from importNormativeTypes import *
-
-
-#####################################################################################################################################################################################
-# #
-# Import heat types #
-# #
-# activation : #
-# python importHeatTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importHeatTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################
-
-def importHeatTypes(scheme, be_host, be_port, admin_user, file_dir, update_version):
- heat_types = ["globalNetwork",
- "globalPort",
- "globalCompute",
- "volume",
- "cinderVolume",
- "contrailVirtualNetwork",
- "neutronNet",
- "neutronPort",
- "novaServer",
- "extVl",
- "internalVl",
- "extCp",
- "vl",
- "eline",
- "abstractSubstitute",
- "Generic_VFC",
- "Generic_VF",
- "Generic_CR",
- "Generic_PNF",
- "Generic_Service",
- "contrailNetworkRules",
- "contrailPort",
- "portMirroring",
- "serviceProxy",
- "contrailV2NetworkRules",
- "contrailV2VirtualNetwork",
- "securityRules",
- "contrailAbstractSubstitute",
- "contrailCompute",
- "contrailV2VirtualMachineInterface",
- "subInterface",
- "contrailV2VLANSubInterface",
- "multiFlavorVFC",
- "vnfConfiguration",
- "extCp2",
- "extNeutronCP",
- "extContrailCP",
- "portMirroringByPolicy",
- "forwardingPath",
- "configuration",
- "VRFObject",
- "extVirtualMachineInterfaceCP",
- "VLANNetworkReceptor",
- "VRFEntry",
- "subInterfaceV2",
- "contrailV2VLANSubInterfaceV2",
- "fabricConfiguration"]
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for heat_type in heat_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, heat_type, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + heat_type + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = importHeatTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/heat-types/", update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py
deleted file mode 100644
index ed68695475..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNfvTypes.py
+++ /dev/null
@@ -1,115 +0,0 @@
-from importNormativeTypes import *
-
-
-#####################################################################################################################################################################################################
-# #
-# Import Nfv Types from a given file #
-# #
-# activation : #
-# python importNfvTypes.py [optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################################
-
-def importNfvTypes(scheme, be_host, be_port, admin_user, file_dir, update_version):
- nfv_types = ["underlayVpn",
- "overlayTunnel",
- "genericNeutronNet",
- "allottedResource",
- "extImageFile",
- "extLocalStorage",
- "extZteCP",
- "extZteVDU",
- "extZteVL",
- "NSD",
- "VDU",
- "vduCompute",
- "Cp",
- "vduVirtualStorage",
- "vduVirtualBlockStorage",
- "vduVirtualFileStorage",
- "vduVirtualObjectStorage",
- "vduVirtualStorage",
- "vnfVirtualLink",
- "vnfExtCp",
- "vduCp",
- "VNF",
- "PonUni",
- "OltNni",
- "OntNni"]
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for nfv_type in nfv_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, nfv_type, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + nfv_type + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = importNfvTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/nfv-types/", update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
deleted file mode 100644
index 55521997f5..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
+++ /dev/null
@@ -1,170 +0,0 @@
-import json
-import os
-import zipfile
-from StringIO import StringIO
-
-import pycurl
-
-import importCommon
-from importCommon import *
-
-
-################################################################################################################################################
-# #
-################################################################################################################################################
-
-
-def createZipFromYml(ymlFile, zipFile):
- zip = zipfile.ZipFile(zipFile, 'w', zipfile.ZIP_DEFLATED)
-
- zip.write(ymlFile, os.path.basename(ymlFile))
- zip.close()
-
-
-def createUserNormativeType(scheme, be_host, be_port, admin_user, file_dir, element_name):
- try:
- log("in create normative type ", element_name)
- debug("userId", admin_user)
- debug("fileDir", file_dir)
-
- _buffer = StringIO()
- c = pycurl.Curl()
-
- url = scheme + '://' + be_host + ':' + be_port + '/sdc2/rest/v1/catalog/upload/multipart'
- c.setopt(c.URL, url)
- c.setopt(c.POST, 1)
-
- admin_header = 'USER_ID: ' + admin_user
- # c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
- c.setopt(pycurl.HTTPHEADER, [admin_header])
-
- ymlFile = file_dir + element_name + "/normative-types-new-" + element_name + ".yml"
- zipFile = file_dir + element_name + "/normative-types-new-" + element_name + ".zip"
- debug(ymlFile)
- debug(zipFile)
- path = zipFile
- debug("path=" + path)
- current_json_file = file_dir + element_name + "/" + element_name + ".json"
- debug(current_json_file)
- json_file = open(current_json_file)
-
- debug("before load json")
- json_data = json.load(json_file, strict=False)
- debug(json_data)
-
- json_as_str = json.dumps(json_data)
- debug(path)
- send = [('resourceMetadata', json_as_str), ('resourceZip', (pycurl.FORM_FILE, path))]
- debug(send)
- c.setopt(pycurl.HTTPPOST, send)
-
- c.setopt(c.WRITEFUNCTION, _buffer.write)
- if scheme == 'https':
- c.setopt(pycurl.SSL_VERIFYPEER, 0)
- c.setopt(pycurl.SSL_VERIFYHOST, 0)
-
- c.perform()
-
- # print("Before get response code")
- http_res = c.getinfo(c.RESPONSE_CODE)
- if http_res is not None:
- debug("http response=", http_res)
- # print('Status: ' + str(responseCode))
- debug(_buffer.getvalue())
- c.close()
-
- return element_name, http_res, _buffer.getvalue()
-
- except Exception as inst:
- print("ERROR=" + str(inst))
- return element_name, None, None
-
-
-def usage():
- print sys.argv[0], \
- '[optional -s <scheme> | --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.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- location = None
- element = None
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:l:e:h:s:",
- ["ip=", "port=", "user=", "location=", "element=", "debug=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-l", "--location"):
- location = arg
- elif opt in ("-e", "--element"):
- element = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if location is None:
- print 'Missing file location'
- usage()
- sys.exit(3)
-
- if element is None:
- print 'Missing element name. E.g. root, compute, ...'
- usage()
- sys.exit(3)
-
- # pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
-
- # baseFileLocation = pathdir + "/../../../import/tosca/"
- # fileDir = baseFileLocation + "user-normative-types/"
-
- # normativeType = "root1"
-
- result = createUserNormativeType(scheme, be_host, be_port, admin_user, location, element)
- # result = createUserNormativeType(beHost, bePort, adminUser, fileDir, normativeType)
- print "---------------------------------------"
- print "{0:30} | {1:6}".format(result[0], result[1])
- print "---------------------------------------"
-
- if result[1] is None or result[1] not in [200, 201]:
- print "Failed creating normative type " + element + ". " + str(result[1])
- error_and_exit(1, None)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
deleted file mode 100644
index c61b8bcc03..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
+++ /dev/null
@@ -1,145 +0,0 @@
-import os
-import time
-
-import importCommon
-from importAnnotationTypes import import_annotation_types
-from importCategoryTypes import importCategories
-from importCommon import *
-from importDataTypes import importDataTypes
-from importGroupTypes import importGroupTypes
-from importHeatTypes import importHeatTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from importNormativeRelationships import importNormativeRelationships
-from importNormativeTypes import importNormativeTypes
-from importPolicyTypes import importPolicyTypes
-
-
-#################################################################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importNormativeAll.py [-s <scheme> | --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>] #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python importNormativeAll.py #
-# #
-#################################################################################################################################################################################################################################
-
-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, update_version):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
- ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
- elif opt in ("-v", "--updateversion"):
- print arg
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
-
- file_location = base_file_location + "data-types/"
- importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- print 'sleep until data type cache is updated'
- time.sleep(70)
-
- file_location = base_file_location + "capability-types/"
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "relationship-types/"
- importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "categories/"
- importCategories(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "normative-types/"
- results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handleResults(results, update_version)
-
- file_location = base_file_location + "heat-types/"
- results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handleResults(results_heat, update_version)
-
- file_location = base_file_location + "group-types/"
- importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "policy-types/"
- importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- import_annotation_types(scheme, be_host, be_port, admin_user, False)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
deleted file mode 100644
index 989233d380..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
+++ /dev/null
@@ -1,78 +0,0 @@
-import importCommon
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#################################################################################################################################################################################################
-# #
-# Import normative capabilities #
-# #
-# activation : #
-# python importNormativeCapabilities.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importNormativeCapabilities.py [-f <input file> | --ifile=<input file> ] #
-# #
-#################################################################################################################################################################################################
-
-
-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> ]'
-
-
-def importNormativeCapabilities(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes",
- "capabilityTypeZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- importCommon.error_and_exit(1, None)
- else:
- if exit_on_success is True:
- importCommon.error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- importCommon.error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/capability-types/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
deleted file mode 100644
index 47ed633b06..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
+++ /dev/null
@@ -1,108 +0,0 @@
-import pycurl
-import zipfile
-from StringIO import StringIO
-import json
-import copy
-from importCommon import *
-
-
-#################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-#################################################################################################################################################################################
-def import_element(scheme, be_host, be_port, admin_user, exit_on_success, file_dir, url_suffix, element_name, element_form_name,
- with_metadata=False):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name, with_metadata)
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success:
- error_and_exit(0, None)
-
-
-
-def createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name,
- with_metadata=False):
- try:
- log("in create normative element ", element_name)
- buffer = StringIO()
- c = pycurl.Curl()
-
- url = scheme + '://' + be_host + ':' + be_port + url_suffix
- c.setopt(c.URL, url)
- c.setopt(c.POST, 1)
-
- admin_header = 'USER_ID: ' + admin_user
- c.setopt(pycurl.HTTPHEADER, [admin_header])
-
- type_file_name = file_dir + "/" + element_name
-
- multi_part_form_data = create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name)
-
- c.setopt(pycurl.HTTPPOST, multi_part_form_data)
- c.setopt(c.WRITEFUNCTION, buffer.write)
-
- if scheme == 'https':
- c.setopt(pycurl.SSL_VERIFYPEER, 0)
- c.setopt(pycurl.SSL_VERIFYHOST, 0)
-
- c.perform()
-
- http_res = c.getinfo(c.RESPONSE_CODE)
- if http_res is not None:
- debug("http response=", http_res)
- debug("response buffer", buffer.getvalue())
- c.close()
- return (element_name, http_res, buffer.getvalue())
-
- except Exception as inst:
- print("ERROR=" + str(inst))
- return (element_name, None, None)
-
-
-def create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name):
- tosca_type_zip_part = create_zip_file_multi_part(element_form_name, type_file_name, element_name)
- multi_part_form_data = [tosca_type_zip_part]
- if with_metadata:
- metadata_type_part = create_metadata_multipart(type_file_name)
- multi_part_form_data.append(metadata_type_part)
- debug(multi_part_form_data)
- return multi_part_form_data
-
-
-def create_metadata_multipart(type_file_name):
- metadata = create_json_metadata_str(type_file_name)
- return ("toscaTypeMetadata", metadata)
-
-
-def create_zip_file_multi_part(element_form_name, type_file_name, element_name):
- zf = zipfile.ZipFile(type_file_name + ".zip", "w")
- zf.write(type_file_name + '.yml', element_name + '.yml')
- zf.close()
-
- tosca_type_zip_path = type_file_name + ".zip"
- tosca_type_zip_part = (element_form_name, (pycurl.FORM_FILE, tosca_type_zip_path))
- return tosca_type_zip_part
-
-
-def create_json_metadata_str(file_name):
- type_metadata_json_file = file_name + ".json"
- debug(type_metadata_json_file)
- json_file = open(type_metadata_json_file)
-
- debug("before load json")
- json_data = json.load(json_file, strict=False)
- debug(json_data)
-
- return json.dumps(json_data)
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
deleted file mode 100644
index 1e6b9ca44f..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
+++ /dev/null
@@ -1,77 +0,0 @@
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#############################################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importNormativeInterfaceLifecycleTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importNormativeInterfaceLifecycleTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#############################################################################################################################################################################################################
-
-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> ]'
-
-
-def importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", "interfaceLifecycleTypes",
- "interfaceLifecycleTypeZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success is True:
- error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, True,
- "../../../import/tosca/interface-lifecycle-types//")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py
deleted file mode 100644
index b06959ae40..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeNoHeatAndNormativeTypes.py
+++ /dev/null
@@ -1,136 +0,0 @@
-import os
-import time
-
-import importCommon
-from importCommon import *
-from importDataTypes import importDataTypes
-from importGroupTypes import importGroupTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from importPolicyTypes import importPolicyTypes
-
-
-#####################################################################################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importNormativeNoHeatAndNormativeTypes.py [-s <scheme> | --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>] #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python importNormativeNoHeatAndNormativeTypes.py #
-# #
-#####################################################################################################################################################################################################################################################
-
-
-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, update_version):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
- ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
- elif opt in ("-v", "--updateversion"):
- print arg
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
-
- file_location = base_file_location + "data-types/"
- importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- print 'sleep until data type cache is updated'
- time.sleep(70)
-
- file_location = base_file_location + "capability-types/"
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
-
- # fileLocation = baseFileLocation + "categories/"
- # importCategories(beHost, bePort, adminUser, False, fileLocation)
-
- # fileLocation = baseFileLocation + "normative-types/"
- # results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
- # handleResults(results, updateversion)
-
- # fileLocation = baseFileLocation + "heat-types/"
- # resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
- # handleResults(resultsHeat, updateversion)
-
- file_location = base_file_location + "group-types/"
- importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "policy-types/"
- importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
deleted file mode 100644
index a6040d0215..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
+++ /dev/null
@@ -1,82 +0,0 @@
-import importCommon
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#################################################################################################################################################################################################
-# #
-# Import normative relationships
-# #
-# #
-# activation : #
-# python importNormativeRelationships.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p
-# <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importNormativeRelationships.py [-f <input file> | --ifile=<input file> ]
-# #
-# #
-#################################################################################################################################################################################################
-
-
-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> ]'
-
-
-def importNormativeRelationships(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/relationship", "relationshipTypes",
- "relationshipTypeZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- importCommon.error_and_exit(1, None)
- else:
- if exit_on_success is True:
- importCommon.error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- importCommon.error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importNormativeRelationships(scheme, be_host, be_port, admin_user, True,
- "../../../import/tosca/relationship-types/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
deleted file mode 100644
index 889ea05b66..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
+++ /dev/null
@@ -1,177 +0,0 @@
-import json
-import zipfile
-from StringIO import StringIO
-
-import pycurl
-
-from importCommon import *
-
-
-#########################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# [-v <true|false> | --updateversion=<true|false>] #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#########################################################################################################################################################################################
-
-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, be_host, be_port, admin_user, file_dir, update_version):
- normative_types = ["root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database",
- "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer",
- "port", "network"]
- # normative_types = [ "root" ]
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for normative_type in normative_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, normative_type, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating normative type " + normative_type + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', updateversion =', update_version
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = importNormativeTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/normative-types/",
- update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
deleted file mode 100644
index de67cd7e57..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
+++ /dev/null
@@ -1,160 +0,0 @@
-import os
-import time
-
-import importCommon
-from importCategoryTypes import importCategories
-from importCommon import *
-from importDataTypes import importDataTypes
-from importGroupTypes import importGroupTypes
-from importHeatTypes import importHeatTypes
-from importNfvTypes import importNfvTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from importNormativeRelationships import importNormativeRelationships
-# from importNormativeElements import createNormativeElement
-from importNormativeTypes import importNormativeTypes
-from importOnapTypes import importOnapTypes
-from importPolicyTypes import importPolicyTypes
-from importSolTypes import importSolTypes
-
-
-#################################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importNormativeAll.py [-s <scheme> | --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>] #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
-# python importNormativeAll.py #
-# #
-#################################################################################################################################################################################################
-
-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>]'
-
-
-def handle_results(results, update_version):
- if results is not None:
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debugf = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
- opts = []
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
- ["ip=", "port=", "user=", "debug=", "update_version=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
- elif opt in ("-v", "--update_version"):
- print arg
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debugf, ', update_version =', update_version
-
- if debugf is not None:
- print 'set debug mode to ' + str(debugf)
- importCommon.debugFlag = debugf
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- base_file_location = pathdir + "/../../../import/tosca/"
-
- file_location = base_file_location + "data-types/"
- importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- print 'sleep until data type cache is updated'
- time.sleep(70)
-
- file_location = base_file_location + "capability-types/"
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "relationship-types/"
- importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "categories/"
- importCategories(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "normative-types/"
- results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handle_results(results, update_version)
-
- file_location = base_file_location + "heat-types/"
- results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handle_results(results_heat, update_version)
-
- file_location = base_file_location + "nfv-types/"
- results_heat = importNfvTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handle_results(results_heat, update_version)
-
- file_location = base_file_location + "onap-types/"
- results_heat = importOnapTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handle_results(results_heat, update_version)
-
- file_location = base_file_location + "sol-types/"
- results_heat = importSolTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handle_results(results_heat, update_version)
-
- file_location = base_file_location + "group-types/"
- importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "policy-types/"
- importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py
deleted file mode 100644
index f6e4749b57..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importOnapTypes.py
+++ /dev/null
@@ -1,92 +0,0 @@
-from importNormativeTypes import *
-
-
-#####################################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importUsers.py [optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################################
-
-def importOnapTypes(scheme, be_host, be_port, admin_user, file_dir, update_version):
- # Add desired type names to the list
- onap_types = []
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for onap_type in onap_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, onap_type, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + onap_type + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "update_version="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--update_version"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = importOnapTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/onap-types/", update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
deleted file mode 100644
index 47f783d0a6..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from importCommon import *
-from importNormativeElements import createNormativeElement
-
-
-#####################################################################################################################################################################################
-# #
-# Import tosca data types #
-# #
-# activation : #
-# python importPolicyTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importPolicyTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################
-
-def usage():
- print sys.argv[
- 0], '[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 importPolicyTypes(scheme, be_host, be_port, admin_user, exit_on_success, file_dir):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir,
- "/sdc2/rest/v1/catalog/uploadType/policytypes", "policyTypes", "policyTypesZip",
- True)
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- if result[1] is None or result[1] not in [200, 201, 409]:
- error_and_exit(1, None)
- else:
- if exit_on_success:
- error_and_exit(0, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- importPolicyTypes(scheme, be_host, be_port, admin_user, True, "../../../import/tosca/policy-types/")
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py
deleted file mode 100644
index 5a8d2aaf70..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importSolTypes.py
+++ /dev/null
@@ -1,92 +0,0 @@
-from importNormativeTypes import *
-
-
-#####################################################################################################################################################################################################
-# #
-# Import Sol Types from a given file #
-# #
-# activation : #
-# python importSolTypes.py [optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-#####################################################################################################################################################################################################
-
-def importSolTypes(scheme, be_host, be_port, admin_user, file_dir, update_version):
- # Add desired type names to the list
- sol_types = []
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for onap_type in sol_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, onap_type, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + onap_type + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = importSolTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/sol-types/", update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
deleted file mode 100644
index 8cc8926ac5..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
+++ /dev/null
@@ -1,223 +0,0 @@
-import getopt
-import json
-import sys
-
-import pycurl
-import yaml
-
-
-#########################################################################################################################################################################################
-# #
-# Import all users from a given YAML file #
-# #
-# activation : #
-# python importUsersFromYaml.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsersFromYaml.py [-f <input file> | --ifile=<input file> ] #
-# #
-# PyYAML module shall be added to python. #
-# pip install PyYAML>=3.1.0 --proxy=http://one.proxy.att.com:8080 #
-#########################################################################################################################################################################################
-
-
-def importUsers(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> ]'
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- input_file = None
-
- admin_user = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:f:h:s:", ["ip=", "port=", "ifile=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-f", "--ifile"):
- input_file = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', users file =', input_file
-
- if input_file is None:
- usage()
- sys.exit(3)
-
- print 'Input file is ', input_file
-
- users_as_yaml_file = open(input_file, 'r')
- users_doc = yaml.load(users_as_yaml_file)
- print users_doc
-
- clone_users = []
- for users in users_doc.values():
- for x, y in users.items():
- copied_user = y
- copied_user['userId'] = x
- # print copiedUser
- clone_users.append(copied_user)
-
- print clone_users
-
- users_as_yaml_file.close()
-
- # activeUsers = filter(lambda x: x.get('status') == None or x['status'] == 'ACTIVE', cloneUsers)
-
- result_table = importUsers(scheme, be_host, be_port, clone_users, admin_user)
-
- g = lambda x: x[1] != 201 and x[1] != 409
-
- result = filter(g, result_table)
-
- if len(result) > 0:
- # print("ERROR: Failed to load the users " + ', '.join(map(lambda x: x[0],result)))
- error_and_exit(3, "Failed to load the users " + ', '.join(map(lambda x: x[0], result)))
-
- g = lambda x: x[1] == 409
- result = filter(g, result_table)
-
- print("-------------------------------------------")
- print("Existing users: " + ', '.join(map(lambda x: x[0], result)))
-
- result = filter(lambda x: x[1] == 201, result_table)
- if len(list(result)) == 0:
- print("-------------------------------------------")
- print("No NEW user was loaded. All users are already exist")
- print("-------------------------------------------")
- else:
- print("-------------------------------------------")
- print("Loaded users: " + ', '.join(map(lambda x: x[0], result)))
- print("-------------------------------------------")
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
deleted file mode 100644
index 7ba925038f..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
+++ /dev/null
@@ -1,108 +0,0 @@
-from importNormativeTypes import *
-
-
-################################################################################################################################################################################################
-# #
-# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file #
-# #
-# activation #
-# python upgradeHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-################################################################################################################################################################################################
-
-
-def upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version):
- response_codes = [200, 201]
- if update_version == 'false':
- response_codes = [200, 201, 409]
- with open("typesToUpgrade.json", 'r') as stream:
- try:
- types = json.load(stream)
- heat_types = types["heat"]
- debug(heat_types)
- normative_types = types["normative"]
- debug(normative_types)
- heat_file_dir = base_dir + "heat-types/"
- debug(heat_file_dir)
- normative_file_dir = base_dir + "normative-types/"
- debug(normative_file_dir)
- results = []
- for heat_type in heat_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, heat_file_dir,
- heat_type.encode('ascii', 'ignore'), update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + heat_type + ". " + str(result[1])
- for normativeType in normative_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, normative_file_dir,
- normativeType.encode('ascii', 'ignore'), update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating normative type " + normativeType + ". " + str(result[1])
- return results
- except Exception as exc:
- print(exc)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/", update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
deleted file mode 100644
index 5394864fdb..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
+++ /dev/null
@@ -1,111 +0,0 @@
-from importNormativeTypes import *
-
-
-#################################################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-#################################################################################################################################################################################
-
-
-def upgradeHeatTypes1707(scheme, be_host, be_port, admin_user, file_dir, update_version):
- heat_types = ["volume",
- "cinderVolume",
- "extVl",
- "extCp",
- "Generic_VFC",
- "Generic_VF",
- "Generic_PNF",
- "Generic_Service",
- "globalPort",
- "globalNetwork",
- "contrailV2VirtualMachineInterface",
- "contrailV2VLANSubInterface",
- "contrailPort",
- "contrailV2VirtualNetwork",
- "contrailVirtualNetwork",
- "neutronNet",
- "neutronPort",
- "multiFlavorVFC",
- "vnfConfiguration"]
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- results = []
- for heatType in heat_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, heatType, update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating heat type " + heatType + ". " + str(result[1])
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = upgradeHeatTypes1707(scheme, be_host, be_port, admin_user, "../../../import/tosca/heat-types/",
- update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py
deleted file mode 100644
index ce939878ae..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNfvTypes.py
+++ /dev/null
@@ -1,101 +0,0 @@
-from importNormativeTypes import *
-
-
-################################################################################################################################################################################################
-# #
-# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file #
-# #
-# activation #
-# python upgradeHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-################################################################################################################################################################################################
-
-
-def upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version):
- response_codes = [200, 201]
- results = []
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
- with open("onapTypesToUpgrade.json", 'r') as stream:
- try:
- types = json.load(stream)
- nfv_types = types["nfv"]
- debug(nfv_types)
- nfv_file_dir = base_dir + "nfv-types/"
- debug(nfv_file_dir)
- for nfvType in nfv_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, nfv_file_dir,
- nfvType.encode('ascii', 'ignore'), update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating nfv type " + nfvType + ". " + str(result[1])
- except Exception as exc:
- print(exc)
-
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/",
- update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
deleted file mode 100644
index c8f5ecf9e6..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
+++ /dev/null
@@ -1,130 +0,0 @@
-import os
-import time
-
-import importCommon
-from importAnnotationTypes import import_annotation_types
-from importCategoryTypes import importCategories
-from importCommon import *
-from importDataTypes import importDataTypes
-from importGroupTypes import importGroupTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from importNormativeRelationships import importNormativeRelationships
-from importPolicyTypes import importPolicyTypes
-from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
-
-
-#################################################################################################################################################################################################################################
-# #
-# Upgrades the normative types #
-# #
-# activation : #
-# python upgradeNormative.py [-s <scheme> | --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>] #
-# #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python upgradeNormative.py #
-# #
-#################################################################################################################################################################################################################################
-
-
-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):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
-
- file_location = base_file_location + "categories/"
- importCategories(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "relationship-types/"
- importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "data-types/"
- importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "policy-types/"
- importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "capability-types/"
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "group-types/"
- importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
-
- import_annotation_types(scheme, be_host, be_port, admin_user, False)
-
- print 'sleep until data type cache is updated'
- time.sleep(70)
-
- results_heat = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, update_version)
- handleResults(results_heat)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
deleted file mode 100644
index b5ba42f971..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
+++ /dev/null
@@ -1,108 +0,0 @@
-import os
-
-import importCommon
-from importCommon import *
-from importNormativeTypes import createNormativeType
-
-
-#################################################################################################################################################################################################################################
-# #
-# Upgrades the normative types #
-# #
-# activation : #
-# python upgradeNormative.py [-s <scheme> | --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>] #
-# #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python upgradeNormative.py #
-# #
-#################################################################################################################################################################################################################################
-
-
-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):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
- results = []
-
- ##########################################################################
- # ---------------------------------for release 1702---------------------- #
- ##########################################################################
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location,
- "contrailV2VirtualMachineInterface", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version)
- results.append(result)
-
- handleResults(results)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
deleted file mode 100644
index a5e2ebae67..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
+++ /dev/null
@@ -1,102 +0,0 @@
-import os
-
-import importCommon
-from importCommon import *
-from importHeatTypes import importHeatTypes
-from importNormativeTypes import importNormativeTypes
-from importOnapTypes import importOnapTypes
-
-
-def usage():
- print sys.argv[0], \
- '[optional -s <scheme> | --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.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
- ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
- elif opt in ("-v", "--updateversion"):
- print arg
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f, ', updateversion =', update_version
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
-
- file_location = base_file_location + "normative-types/"
- results = importNormativeTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handleResults(results, update_version)
-
- file_location = base_file_location + "heat-types/"
- results_heat = importHeatTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handleResults(results_heat, update_version)
-
- file_location = base_file_location + "onap-types/"
- results_onap = importOnapTypes(scheme, be_host, be_port, admin_user, file_location, update_version)
- handleResults(results_onap, update_version)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py
deleted file mode 100644
index cc2325f9fb..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionProd1702_3537.py
+++ /dev/null
@@ -1,134 +0,0 @@
-import os
-
-import importCommon
-from importCommon import *
-from importNormativeTypes import createNormativeType
-
-
-#################################################################################################################################################################################################################################
-# #
-# Upgrades the normative types #
-# #
-# activation : #
-# python upgradeNormative.py [-s <scheme> | --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>] #
-# #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python upgradeNormative.py #
-# #
-#################################################################################################################################################################################################################################
-
-
-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):
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results)
- if len(list(failed_results)) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- debug_f = None
- update_version = 'true'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- debug_f = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f
-
- if debug_f is not None:
- print 'set debug mode to ' + str(debug_f)
- importCommon.debugFlag = debug_f
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- path_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + path_dir)
-
- base_file_location = path_dir + "/../../../import/tosca/"
- results = []
-
- ##########################################################################
- # ---------------------------------for release 1702---------------------- #
- ##########################################################################
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailPort", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location,
- "contrailV2VirtualMachineInterface", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronPort", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailCompute", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "novaServer", update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailV2VirtualNetwork",
- update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "contrailVirtualNetwork",
- update_version)
- results.append(result)
-
- file_location = base_file_location + "heat-types/"
- result = createNormativeType(scheme, be_host, be_port, admin_user, file_location, "neutronNet", update_version)
- results.append(result)
-
- handleResults(results)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py
deleted file mode 100644
index 59fece9376..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py
+++ /dev/null
@@ -1,146 +0,0 @@
-import os
-import time
-from importCategoryTypes import importCategories
-from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
-from importDataTypes import importDataTypes
-from importPolicyTypes import importPolicyTypes
-from importGroupTypes import importGroupTypes
-from importNormativeCapabilities import importNormativeCapabilities
-from importNormativeRelationships import importNormativeRelationships
-from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
-from upgradeNfvTypes import upgradeNfvTypesPerConfigFile
-from upgradeONAPTypes import upgradeOnapTypesPerConfigFile
-from upgradeSolTypes import upgradeSolTypesPerConfigFile
-
-from importCommon import *
-import importCommon
-
-
-#################################################################################################################################################################################################
-# #
-# Upgrades the normative types #
-# #
-# activation : #
-# python upgradeNormative.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] #
-# #
-# #
-# shortest activation (be host = localhost, be port = 8080, user = jh0003): #
-# python upgradeNormative.py #
-# #
-#################################################################################################################################################################################################
-
-def usage():
- print sys.argv[
- 0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user ' \
- 'userId> ] [-d <true|false> | --debug=<true|false>] '
-
-
-def handle_results(results):
- if results is not None:
- print_frame_line()
- for result in results:
- print_name_and_return_code(result[0], result[1])
-
- print_frame_line()
-
- failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results)
- if len(failed_results) > 0:
- error_and_exit(1, None)
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- is_debug = None
- update_version = 'true'
- update_onap_version = 'false'
- importCommon.debugFlag = False
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s",
- ["scheme=", "ip=", "port=", "user=", "debug=", "updateversion="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-d", "--debug"):
- print arg
- is_debug = bool(arg.lower() == "true" or arg.lower() == "yes")
-
- print 'scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', is_debug
-
- if is_debug is not None:
- print 'set debug mode to ' + str(is_debug)
- importCommon.debugFlag = is_debug
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
- debug("path dir =" + pathdir)
-
- base_file_location = pathdir + "/../../../import/tosca/"
-
- file_location = base_file_location + "categories/"
- importCategories(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "relationship-types/"
- importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "data-types/"
- importDataTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "policy-types/"
- importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "group-types/"
- importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "capability-types/"
- importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location)
-
- file_location = base_file_location + "interface-lifecycle-types/"
- importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location)
-
- print 'sleep until data type cache is updated'
- time.sleep(70)
-
- results_heat = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, update_version)
- handle_results(results_heat)
-
- results_heat = upgradeNfvTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location,
- update_onap_version)
- handle_results(results_heat)
-
- results_heat = upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location,
- update_onap_version)
- handle_results(results_heat)
-
- results_heat = upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location,
- update_onap_version)
- handle_results(results_heat)
-
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py
deleted file mode 100644
index bb26659621..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py
+++ /dev/null
@@ -1,101 +0,0 @@
-from importNormativeTypes import *
-
-
-################################################################################################################################################################################################
-# #
-# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file #
-# #
-# activation #
-# python upgradeHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-################################################################################################################################################################################################
-
-
-def upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version):
- response_codes = [200, 201]
- results = []
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
- with open("onapTypesToUpgrade.json", 'r') as stream:
- try:
- types = json.load(stream)
- onap_types = types["onap"]
- debug(onap_types)
- onap_file_dir = base_dir + "onap-types/"
- debug(onap_file_dir)
- for onap_type in onap_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, onap_file_dir,
- onap_type.encode('ascii', 'ignore'), update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating onap type " + onap_type + ". " + str(result[1])
- except Exception as exc:
- print(exc)
-
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = upgradeOnapTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/",
- update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py
deleted file mode 100644
index aa60e4d49d..0000000000
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeSolTypes.py
+++ /dev/null
@@ -1,100 +0,0 @@
-from importNormativeTypes import *
-
-
-################################################################################################################################################################################################
-# #
-# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file #
-# #
-# activation #
-# python upgradeHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): #
-# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
-# #
-################################################################################################################################################################################################
-
-
-def upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_dir, update_version):
- response_codes = [200, 201]
- results = []
- if update_version == 'false':
- response_codes = [200, 201, 409]
- with open("onapTypesToUpgrade.json", 'r') as stream:
- try:
- types = json.load(stream)
- sol_types = types["sol"]
- debug(sol_types)
- sol_file_dir = base_dir + "sol-types/"
- debug(sol_file_dir)
- for solType in sol_types:
- result = createNormativeType(scheme, be_host, be_port, admin_user, sol_file_dir,
- solType.encode('ascii', 'ignore'), update_version)
- results.append(result)
- if result[1] is None or result[1] not in response_codes:
- print "Failed creating sol type " + solType + ". " + str(result[1])
- except Exception as exc:
- print(exc)
-
- return results
-
-
-def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- be_host = 'localhost'
- be_port = '8080'
- admin_user = 'jh0003'
- update_version = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- be_host = arg
- elif opt in ("-p", "--port"):
- be_port = arg
- elif opt in ("-u", "--user"):
- admin_user = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if arg.lower() == "false" or arg.lower() == "no":
- update_version = 'false'
-
- print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
-
- if be_host is None:
- usage()
- sys.exit(3)
-
- results = upgradeSolTypesPerConfigFile(scheme, be_host, be_port, admin_user, "../../../import/tosca/",
- update_version)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- response_codes = [200, 201]
-
- if update_version == 'false':
- response_codes = [200, 201, 409]
-
- failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
- if len(list(failed_normatives)) > 0:
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/bColors.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/bColors.py
new file mode 100755
index 0000000000..a14458bbec
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/bColors.py
@@ -0,0 +1,8 @@
+
+class BColors:
+
+ HEADER = '\033[95m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ END_C = '\033[0m'
+ BOLD = '\033[1m'
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/helpers.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/helpers.py
new file mode 100644
index 0000000000..0e6db5efbe
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/helpers.py
@@ -0,0 +1,3 @@
+
+def check_arguments_not_none(*args):
+ return None not in args
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/logger.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/logger.py
new file mode 100644
index 0000000000..e2e434fcff
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/logger.py
@@ -0,0 +1,83 @@
+import sys
+
+debugFlag = True
+
+
+def join_strings(lst):
+ return ''.join([str(string) for string in lst])
+
+
+def debug(desc, *args):
+ if debugFlag:
+ print(desc, join_strings(args))
+
+
+def log(desc, arg):
+ print(desc, arg)
+
+
+def error_and_exit(error_code, error_desc):
+ if error_code > 0:
+ print("status={0}. {1}".format(error_code, '' if not error_desc else error_desc))
+ else:
+ print("status={0}".format(error_code))
+ sys.exit(error_code)
+
+
+def print_name_and_return_code(name, code, with_line=True):
+ if _strings_correct(name, code):
+ if with_line:
+ print("----------------------------------------")
+ print("{0:30} | {1:6}".format(name, code))
+ if with_line:
+ print("----------------------------------------")
+ else:
+ print("name of the item or return code from request is none -> error occurred!!")
+
+
+def _strings_correct(*strings):
+ results = [(string is not None and string != "") for string in strings]
+ return all(results) is True
+
+# def parse_cmd_line_params(argv):
+# print('Number of arguments:', len(sys.argv), 'arguments.')
+#
+# opts = []
+#
+# be_host = 'localhost'
+# be_port = '8080'
+# admin_user = 'jh0003'
+# scheme = 'http'
+#
+# try:
+# opts, args = getopt.getopt(argv, "i:p:u:h:s:", ["ip=", "port=", "user=", "scheme="])
+# except getopt.GetoptError:
+# usage()
+# error_and_exit(2, 'Invalid input')
+#
+# for opt, arg in opts:
+# # print opt, arg
+# if opt == '-h':
+# usage()
+# sys.exit(3)
+# elif opt in ("-i", "--ip"):
+# be_host = arg
+# elif opt in ("-p", "--port"):
+# be_port = arg
+# elif opt in ("-u", "--user"):
+# admin_user = arg
+# elif opt in ("-s", "--scheme"):
+# scheme = arg
+#
+# print('scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user)
+#
+# if be_host is None:
+# usage()
+# sys.exit(3)
+# return scheme, be_host, be_port, admin_user
+#
+#
+# def usage():
+# print(sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http ] '
+# '[-i <be host> | --ip=<be host>] [-p <be port> | '
+# '--port=<be port> ] [-u <user userId> | --user=<user userId> ] ')
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/main.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/main.py
new file mode 100644
index 0000000000..a30d46d4d5
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/main.py
@@ -0,0 +1,16 @@
+from sdcBePy.common.normative.toscaElements import process_and_create_normative_element
+from sdcBePy.common.normative.toscaTypes import process_and_create_normative_types
+
+
+def process_element_list(normative_elements_list, sdc_be_proxy):
+ for normative_element in normative_elements_list:
+ process_and_create_normative_element(normative_element,
+ sdc_be_proxy=sdc_be_proxy)
+
+
+def process_type_list(normative_type_list, sdc_be_proxy, update_version):
+ for normative_type in normative_type_list:
+ process_and_create_normative_types(normative_type,
+ sdc_be_proxy=sdc_be_proxy,
+ update_version=update_version)
+
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py
new file mode 100644
index 0000000000..1d4e734351
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py
@@ -0,0 +1,107 @@
+import json
+import zipfile
+
+import pycurl
+
+from sdcBePy.common.logger import debug, log, print_name_and_return_code, error_and_exit
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+
+def process_and_create_normative_element(normative_element,
+ scheme=None, be_host=None, be_port=None, admin_user=None, sdc_be_proxy=None,
+ debug=False,
+ exit_on_success=False):
+ if sdc_be_proxy is None:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+
+ file_dir, url_suffix, element_name, element_from_name, with_metadata = normative_element.get_parameters()
+ _create_normative_element(sdc_be_proxy,
+ file_dir,
+ url_suffix,
+ element_name,
+ element_from_name,
+ with_metadata,
+ exit_on_success)
+
+
+def _create_normative_element(sdc_be_proxy, file_dir,
+ url_suffix, element_name, element_form_name, with_metadata=False,
+ exit_on_success=False):
+ result = _send_request(sdc_be_proxy,
+ file_dir,
+ url_suffix,
+ element_name,
+ element_form_name,
+ with_metadata)
+ print_and_check_result(result, exit_on_success)
+
+
+def _send_request(sdc_be_proxy, file_dir, url_suffix, element_name,
+ element_form_name,
+ with_metadata=False):
+ try:
+ log("create normative element ", element_name)
+
+ type_file_name = file_dir + element_name
+ multi_part_form_data = _create_multipart_form_data(element_form_name, type_file_name, with_metadata,
+ element_name)
+
+ http_res = sdc_be_proxy.post_file(url_suffix, multi_part_form_data)
+ if http_res is not None:
+ debug("http response =", http_res)
+ debug("response buffer", str(sdc_be_proxy.con.buffer.getvalue(), "UTF-8"))
+ # c.close()
+ return element_name, http_res, sdc_be_proxy.con.buffer.getvalue()
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return element_name, None, None
+
+
+def _create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name):
+ tosca_type_zip_part = _create_zip_file_multi_part(element_form_name, type_file_name, element_name)
+ multi_part_form_data = [tosca_type_zip_part]
+ if with_metadata:
+ metadata_type_part = _create_metadata_multipart(type_file_name)
+ multi_part_form_data.append(metadata_type_part)
+ debug(multi_part_form_data)
+ return multi_part_form_data
+
+
+def _create_metadata_multipart(type_file_name):
+ metadata = _create_json_metadata_str(type_file_name)
+ return "toscaTypeMetadata", metadata
+
+
+def _create_zip_file_multi_part(element_form_name, type_file_name, element_name):
+ zf = zipfile.ZipFile(type_file_name + ".zip", "w")
+ zf.write(type_file_name + '.yml', element_name + '.yml')
+ zf.close()
+
+ tosca_type_zip_path = type_file_name + ".zip"
+ tosca_type_zip_part = (element_form_name, (pycurl.FORM_FILE, tosca_type_zip_path))
+ return tosca_type_zip_part
+
+
+def _create_json_metadata_str(file_name):
+ type_metadata_json_file = file_name + ".json"
+ debug(type_metadata_json_file)
+ json_file = open(type_metadata_json_file)
+
+ debug("before load json")
+ json_data = json.load(json_file, strict=False)
+ debug(json_data)
+
+ return json.dumps(json_data)
+
+
+def print_and_check_result(result, exit_on_success):
+ if result is not None:
+ print_name_and_return_code(result[0], result[1])
+ if result[1] is None or result[1] not in [200, 201, 409]:
+ error_and_exit(1, "Failed to create the normatives elements!!")
+ else:
+ if exit_on_success is True:
+ error_and_exit(0, "All normatives elements created successfully!!")
+ else:
+ error_and_exit(1, "Results is None!!")
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py
new file mode 100644
index 0000000000..48b20ccb1e
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py
@@ -0,0 +1,121 @@
+import json
+import zipfile
+
+import pycurl
+
+from sdcBePy.common.logger import print_name_and_return_code, error_and_exit, log, debug
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+
+def process_and_create_normative_types(normative_type,
+ scheme=None, be_host=None, be_port=None, admin_user=None,
+ sdc_be_proxy=None,
+ update_version=False,
+ debug=False,
+ exit_on_success=False):
+ if sdc_be_proxy is None:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+
+ file_dir, normative_type_list = normative_type.get_parameters()
+
+ results = _create_normatives_type(file_dir, sdc_be_proxy, normative_type_list, update_version)
+ print_and_check_results(results, update_version, exit_on_success)
+
+
+def print_and_check_results(results, update_version, exit_on_success=False):
+ if results is not None:
+ if len(results) == 0:
+ return
+ print("----------------------------------------")
+ for result in results:
+ print_name_and_return_code(result[0], result[1], with_line=False)
+ print("----------------------------------------")
+ check_results_and_exit(results, update_version, exit_on_success)
+ else:
+ error_and_exit(1, "results is none -> error occurred!!")
+
+
+def check_results_and_exit(results, update_version, exit_on_success):
+ if not _results_ok(results, _get_response_code(update_version)):
+ error_and_exit(1, "Failed to create the normatives types !!")
+ else:
+ if exit_on_success:
+ error_and_exit(0, "All normatives types created successfully!!")
+
+
+def _create_normatives_type(file_dir, sdc_be_proxy, types, update_version):
+ results = []
+ response_codes = _get_response_code(update_version)
+ for normativeType in types:
+ result = _send_request(sdc_be_proxy, file_dir, normativeType, update_version)
+ results.append(result)
+ if result[1] is None or result[1] not in response_codes:
+ print("Failed creating normative type " + normativeType + ". " + str(result[1]))
+ return results
+
+
+def _send_request(sdc_be_proxy, file_dir, element_name, update_version):
+ try:
+ log("create normative type ", element_name)
+ debug("userId", sdc_be_proxy.con.user_header)
+ debug("fileDir", file_dir)
+
+ url = '/sdc2/rest/v1/catalog/upload/multipart'
+ if update_version is not None:
+ url += '?createNewVersion=' + _boolean_to_string(update_version)
+
+ send = _create_send_body(file_dir, element_name)
+
+ debug(send)
+ httpRes = sdc_be_proxy.post_file(url, send)
+ if httpRes is not None:
+ debug("http response=", httpRes)
+ debug(sdc_be_proxy.con.buffer.getvalue())
+
+ return element_name, httpRes, sdc_be_proxy.con.buffer.getvalue()
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return element_name, None, None
+
+
+def _create_send_body(file_dir, element_name):
+ 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"
+
+ jsonFile = open(current_json_file)
+
+ debug("before load json")
+ json_data = json.load(jsonFile, strict=False)
+ debug(json_data)
+
+ jsonAsStr = json.dumps(json_data)
+
+ return [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
+
+
+def _results_ok(results, response_codes):
+ for result in results:
+ if result[1] not in response_codes:
+ return False
+
+ return True
+
+
+def _get_response_code(update_version):
+ responseCodes = [200, 201]
+ if update_version is False:
+ responseCodes.append(409)
+
+ return responseCodes
+
+
+def _boolean_to_string(boolean_value):
+ return "true" if boolean_value else "false"
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
new file mode 100755
index 0000000000..48261704f7
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
@@ -0,0 +1,117 @@
+import json
+from io import BytesIO
+
+import pycurl
+
+from sdcBePy.common.helpers import check_arguments_not_none
+
+
+def get_url(ip, port, protocol):
+ return "%s://%s:%s" % (protocol, ip, port)
+
+
+class SdcBeProxy:
+
+ def __init__(self, be_ip, be_port, scheme, user_id="jh0003",
+ debug=False, connector=None):
+ if not check_arguments_not_none(be_ip, be_port, scheme, user_id):
+ raise AttributeError("The be_host, be_port, scheme or admin_user are missing")
+ url = get_url(be_ip, be_port, scheme)
+ self.con = connector if connector \
+ else CurlConnector(url, user_id, scheme=scheme, debug=debug)
+
+ def check_backend(self):
+ return self.con.get('/sdc2/rest/v1/user/jh0003')
+
+ def check_user(self, user_name):
+ return self.con.get("/sdc2/rest/v1/user/" + user_name)
+
+ def create_user(self, first_name, last_name, user_id, email, role):
+ return self.con.post('/sdc2/rest/v1/user', json.dumps({
+ 'firstName': first_name,
+ 'lastName': last_name,
+ 'userId': user_id,
+ 'email': email,
+ 'role': role
+ }))
+
+ def post_file(self, path, multi_part_form_data):
+ return self.con.post_file(path, multi_part_form_data)
+
+
+class CurlConnector:
+ CONTENT_TYPE_HEADER = "Content-Type: application/json"
+ ACCEPT_HEADER = "Accept: application/json; charset=UTF-8"
+
+ def __init__(self, url, user_id_header, buffer=None, scheme="http", debug=False):
+ self.c = pycurl.Curl()
+ self.c.setopt(pycurl.HEADER, True)
+
+ self.user_header = "USER_ID: " + user_id_header
+
+ if not debug:
+ # disable printing not necessary logs in the terminal
+ self.c.setopt(pycurl.WRITEFUNCTION, lambda x: None)
+ else:
+ self.c.setopt(pycurl.VERBOSE, 1)
+
+ if not buffer:
+ self.buffer = BytesIO()
+
+ self.url = url
+ self._check_schema(scheme)
+
+ def get(self, path):
+ try:
+ self.c.setopt(pycurl.URL, self.url + path)
+ self.c.setopt(pycurl.HTTPHEADER, [self.user_header,
+ CurlConnector.CONTENT_TYPE_HEADER,
+ CurlConnector.ACCEPT_HEADER])
+
+ self.c.perform()
+ return self.c.getinfo(pycurl.RESPONSE_CODE)
+ except pycurl.error:
+ return 111
+
+ def post(self, path, data):
+ try:
+ self.c.setopt(pycurl.URL, self.url + path)
+ self.c.setopt(pycurl.POST, 1)
+ self.c.setopt(pycurl.HTTPHEADER, [self.user_header,
+ CurlConnector.CONTENT_TYPE_HEADER,
+ CurlConnector.ACCEPT_HEADER])
+
+ self.c.setopt(pycurl.POSTFIELDS, data)
+
+ self.c.perform()
+ self.c.setopt(pycurl.POST, 0)
+
+ return self.c.getinfo(pycurl.RESPONSE_CODE)
+ except pycurl.error:
+ return 111
+
+ def post_file(self, path, post_body, buffer=None):
+ try:
+ self.c.setopt(pycurl.URL, self.url + path)
+ self.c.setopt(pycurl.POST, 1)
+ self.c.setopt(pycurl.HTTPHEADER, [self.user_header])
+
+ self.c.setopt(pycurl.HTTPPOST, post_body)
+
+ write = self.buffer.write if not buffer else buffer.write
+ self.c.setopt(pycurl.WRITEFUNCTION, write)
+
+ self.c.perform()
+ self.c.setopt(pycurl.POST, 0)
+
+ return self.c.getinfo(pycurl.RESPONSE_CODE)
+ except pycurl.error:
+ return 111
+
+ def _check_schema(self, scheme):
+ if scheme == 'https':
+ self.c.setopt(pycurl.SSL_VERIFYPEER, 0)
+ self.c.setopt(pycurl.SSL_VERIFYHOST, 0)
+
+ def __del__(self):
+ self.c.close()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json
new file mode 100644
index 0000000000..f8c740b94f
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json
@@ -0,0 +1,5 @@
+{
+ "beHost": "localhost",
+ "bePort": "8080",
+ "adminUser": "jh0003"
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/onapTypesToUpgrade.json
index cbe581acd2..cbe581acd2 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/onapTypesToUpgrade.json
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/typesToUpgrade.json
index 4d59e0248d..5dd20011c0 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/typesToUpgrade.json
@@ -1,4 +1,4 @@
{
"heat": [],
"normative": []
-}
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
new file mode 100644
index 0000000000..4d4eeaff6e
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+
+import sdcBePy.common.logger as logger
+from sdcBePy.common.normative.main import process_element_list, process_type_list
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
+ get_normative_element_with_metadata_list
+from sdcBePy.tosca.models.normativeTypesList import get_normative_type_candidate_list
+
+
+def main():
+ scheme, be_host, be_port, admin_user, update_version, debug = get_args()
+
+ if debug is False:
+ print('Disabling debug mode')
+ logger.debugFlag = debug
+
+ try:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+ # use to run script form this dir (not like the command)
+ # base_file_location = os.getcwd() + "/../../../../import/tosca/"
+ base_file_location = os.getcwd() + os.path.sep
+ logger.debug("working directory =" + base_file_location)
+
+ process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
+ process_type_list(get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version)
+ process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
+
+ logger.log("Script end ->", "All normatives imported successfully!")
+ logger.error_and_exit(0, None)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runGenericNormative.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runGenericNormative.py
new file mode 100644
index 0000000000..424c0ca7c5
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runGenericNormative.py
@@ -0,0 +1,37 @@
+import os
+import sys
+from argparse import ArgumentParser
+
+from sdcBePy.common.normative.toscaTypes import process_and_create_normative_types
+from sdcBePy.tosca.main import usage, get_args
+from sdcBePy.tosca.models.normativeTypeCandidate import NormativeTypeCandidate
+
+
+def get_normative_prams():
+ parser = ArgumentParser()
+
+ path = os.path.dirname(__file__)
+ parser.add_argument('--location', default=path + os.path.sep)
+ parser.add_argument('--element', "-e", required=True)
+
+ args = parser.parse_args()
+
+ return args.location, [args.element]
+
+
+def main():
+ scheme, be_host, be_port, admin_user, _, debug = get_args()
+
+ candidate = NormativeTypeCandidate(*get_normative_prams())
+ try:
+ process_and_create_normative_types(candidate,
+ scheme, be_host, be_port, admin_user,
+ debug=debug,
+ exit_on_success=True)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeElement.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeElement.py
new file mode 100644
index 0000000000..1bdb1504b2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeElement.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+
+import sys
+
+from sdcBePy.common.normative.toscaElements import process_and_create_normative_element
+from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.models.normativeElementsList import get_capability, get_data, get_relationship, \
+ get_interface_lifecycle, get_categories, get_group, get_policy, get_annotation
+
+
+def run(candidate):
+ scheme, be_host, be_port, admin_user, _, debug = get_args()
+ try:
+ process_and_create_normative_element(candidate,
+ scheme, be_host, be_port, admin_user,
+ debug=debug,
+ exit_on_success=True)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+
+def run_import_data():
+ data_candidate = get_data()
+ run(data_candidate)
+
+
+def run_import_capabilities():
+ capability_candidate = get_capability()
+ run(capability_candidate)
+
+
+def run_import_relationship():
+ relationship_candidate = get_relationship()
+ run(relationship_candidate)
+
+
+def run_import_interface_lifecycle():
+ interface_lifecycle_candidate = get_interface_lifecycle()
+ run(interface_lifecycle_candidate)
+
+
+def run_import_categories():
+ categories_candidate = get_categories()
+ run(categories_candidate)
+
+
+def run_import_group():
+ group_candidate = get_group()
+ run(group_candidate)
+
+
+def run_import_policy():
+ policy_candidate = get_policy()
+ run(policy_candidate)
+
+
+def run_import_annotation():
+ annotation_candidate = get_annotation()
+ run(annotation_candidate)
+
+
+if __name__ == '__main__':
+ run_import_data()
+ # run_import_capabilities()
+ # run_import_relationship()
+ # run_import_interface_lifecycle()
+ # run_import_categories()
+ # run_import_group()
+ # run_import_policy()
+ # run_import_annotation()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeType.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeType.py
new file mode 100644
index 0000000000..ee4e05b21a
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/runNormativeType.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+import sys
+
+from sdcBePy.common.normative.toscaTypes import process_and_create_normative_types
+from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.models.normativeTypesList import get_normative, get_heat, get_nfv, get_onap, get_sol
+
+
+def run(candidate, exit_on_success=True):
+ scheme, be_host, be_port, admin_user, update_version, debug = get_args()
+ try:
+ process_and_create_normative_types(candidate,
+ scheme,
+ be_host,
+ be_port,
+ admin_user,
+ update_version=update_version,
+ debug=debug,
+ exit_on_success=exit_on_success)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+
+def run_import_normative():
+ normative_candidate = get_normative()
+ run(normative_candidate)
+
+
+def run_import_heat():
+ heat_candidate = get_heat()
+ run(heat_candidate)
+
+
+def run_import_nfv():
+ nfv_candidate = get_nfv()
+ run(nfv_candidate)
+
+
+def run_import_onap():
+ onap_candidate = get_onap()
+ run(onap_candidate)
+
+
+def run_import_sol():
+ sol_candidate = get_sol()
+ run(sol_candidate)
+
+
+if __name__ == '__main__':
+ run_import_normative()
+ # run_import_heat()
+ # run_import_nfv()
+ # run_import_onap()
+ # run_import_sol()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py
new file mode 100644
index 0000000000..2535ba6d77
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py
@@ -0,0 +1,56 @@
+import json
+import os
+import sys
+from argparse import ArgumentParser
+
+
+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>]')
+
+
+def load_be_config(conf_path):
+ with open(conf_path, 'r') as f:
+ return json.load(f)
+
+
+def parse_param():
+ parser = ArgumentParser()
+
+ path = os.path.dirname(__file__)
+ parser.add_argument('--conf', default=os.path.join(path, 'data', 'beConfig.json'))
+
+ parser.add_argument('--ip', "-i")
+ parser.add_argument('--port', "-p")
+ parser.add_argument('--adminUser', "-a")
+ parser.add_argument('--https', action='store_true')
+ parser.add_argument('--updateVersion', action='store_false')
+ parser.add_argument('--debug', action='store_true')
+
+ args, _ = parser.parse_known_args()
+
+ return [args.conf, 'https' if args.https else 'http',
+ args.ip, args.port, args.adminUser, args.updateVersion,
+ args.debug]
+
+
+def get_args():
+ print('Number of arguments:', len(sys.argv), 'arguments.')
+
+ conf_path, scheme, be_host, be_port, admin_user, update_version, debug = parse_param()
+ defaults = load_be_config(conf_path)
+
+ # Use defaults if param not provided by the user
+ if be_host is None:
+ be_host = defaults["beHost"]
+ if be_port is None:
+ be_port = defaults["bePort"]
+ if admin_user is None:
+ admin_user = defaults["adminUser"]
+
+ print('scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user,
+ ', debug =', debug, ', update_version =', update_version)
+
+ return scheme, be_host, be_port, admin_user, update_version, debug
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementCandidate.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementCandidate.py
new file mode 100644
index 0000000000..96526ce82a
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementCandidate.py
@@ -0,0 +1,18 @@
+from sdcBePy.common.helpers import check_arguments_not_none
+
+
+class NormativeElementCandidate:
+
+ def __init__(self, file_dir, url_suffix,
+ element_name, element_from_name, with_metadata=False):
+ if not check_arguments_not_none(file_dir, url_suffix, element_name, element_from_name):
+ raise AttributeError("The file_dir, url_suffix, element_name, element_from_name are missing")
+
+ self.file_dir = file_dir
+ self.url_suffix = url_suffix
+ self.element_name = element_name
+ self.element_form_name = element_from_name
+ self.with_metadata = with_metadata
+
+ def get_parameters(self):
+ return self.file_dir, self.url_suffix, self.element_name, self.element_form_name, self.with_metadata
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py
new file mode 100644
index 0000000000..cfef95d427
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py
@@ -0,0 +1,76 @@
+from sdcBePy.tosca.models.normativeElementCandidate import NormativeElementCandidate
+
+
+def get_normative_element_candidate_list(base_file_location):
+ return [
+ get_data(base_file_location),
+ get_capability(base_file_location),
+ get_relationship(base_file_location),
+ get_interface_lifecycle(base_file_location),
+ get_categories(base_file_location)
+ ]
+
+
+def get_normative_element_with_metadata_list(base_file_location):
+ return [
+ get_group(base_file_location),
+ get_policy(base_file_location)
+ ]
+
+
+def get_data(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "data-types/",
+ "/sdc2/rest/v1/catalog/uploadType/datatypes",
+ "dataTypes",
+ "dataTypesZip")
+
+
+def get_capability(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "capability-types/",
+ "/sdc2/rest/v1/catalog/uploadType/capability",
+ "capabilityTypes",
+ "capabilityTypeZip")
+
+
+def get_relationship(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "relationship-types/",
+ "/sdc2/rest/v1/catalog/uploadType/relationship",
+ "relationshipTypes",
+ "relationshipTypeZip")
+
+
+def get_interface_lifecycle(base_file_location="../../../import/tosca/"):
+ return NormativeElementCandidate(base_file_location + "interface-lifecycle-types/",
+ "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle",
+ "interfaceLifecycleTypes",
+ "interfaceLifecycleTypeZip")
+
+
+def get_categories(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "categories/",
+ "/sdc2/rest/v1/catalog/uploadType/categories",
+ "categoryTypes",
+ "categoriesZip")
+
+
+def get_group(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "group-types/",
+ "/sdc2/rest/v1/catalog/uploadType/grouptypes",
+ "groupTypes",
+ "groupTypesZip",
+ with_metadata=True)
+
+
+def get_policy(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "policy-types/",
+ "/sdc2/rest/v1/catalog/uploadType/policytypes",
+ "policyTypes",
+ "policyTypesZip",
+ with_metadata=True)
+
+
+def get_annotation(base_file_location="/"):
+ return NormativeElementCandidate(base_file_location + "annotation-types",
+ "/sdc2/rest/v1/catalog/uploadType/annotationtypes",
+ "annotationTypesZip",
+ "annotationTypes")
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeToUpdateList.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeToUpdateList.py
new file mode 100644
index 0000000000..a2830185d5
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeToUpdateList.py
@@ -0,0 +1,60 @@
+import json
+
+from sdcBePy.tosca.models.normativeTypeCandidate import NormativeTypeCandidate
+
+
+class TypesToUpdate:
+
+ def __init__(self, files):
+ self.types_list = {}
+ self.load_files(files)
+
+ def load_files(self, files):
+ for file in files:
+ with open(file, 'r') as stream:
+ _types = json.load(stream)
+ for type_key, type_value in _types.items():
+ self.types_list[type_key] = type_value
+
+ def get_type(self, key):
+ return self.types_list[key]
+
+
+def get_heat_and_normative_to_update_list(types, base_file_location):
+ return [
+ get_heat(types, base_file_location),
+ get_normative(types, base_file_location)
+ ]
+
+
+def get_nfv_onap_sol_to_update_list(types, base_file_location):
+ return [
+ get_nfv(types, base_file_location),
+ get_onap(types, base_file_location),
+ get_sol(types, base_file_location)
+ ]
+
+
+def get_heat(types, base_location="/"):
+ return NormativeTypeCandidate(base_location + "heat-types/",
+ types.get_type("heat"))
+
+
+def get_normative(types, base_location="/"):
+ return NormativeTypeCandidate(base_location + "normative-types/",
+ types.get_type("normative"))
+
+
+def get_nfv(types, base_location="/"):
+ return NormativeTypeCandidate(base_location + "nfv-types/",
+ types.get_type("nfv"))
+
+
+def get_onap(types, base_location="/"):
+ return NormativeTypeCandidate(base_location + "onap-types/",
+ types.get_type("onap"))
+
+
+def get_sol(types, base_location="/"):
+ return NormativeTypeCandidate(base_location + "sol-types/",
+ types.get_type("sol"))
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypeCandidate.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypeCandidate.py
new file mode 100644
index 0000000000..929ec4f864
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypeCandidate.py
@@ -0,0 +1,14 @@
+from sdcBePy.common.helpers import check_arguments_not_none
+
+
+class NormativeTypeCandidate:
+
+ def __init__(self, file_dir, normative_types_list):
+ if not check_arguments_not_none(file_dir, normative_types_list):
+ raise AttributeError("The file_dir, normative_types_list are missing")
+
+ self.file_dir = file_dir
+ self.normative_types_list = normative_types_list
+
+ def get_parameters(self):
+ return self.file_dir, self.normative_types_list
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypesList.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypesList.py
new file mode 100644
index 0000000000..eea25436b3
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeTypesList.py
@@ -0,0 +1,161 @@
+from sdcBePy.tosca.models.normativeTypeCandidate import NormativeTypeCandidate
+
+
+def get_normative_type_candidate_list(base_file_location):
+ return [
+ get_normative(base_file_location),
+ get_heat(base_file_location),
+ get_nfv(base_file_location),
+ get_onap(base_file_location),
+ get_sol(base_file_location)
+ ]
+
+
+def get_normative(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "normative-types/",
+ ["root",
+ "compute",
+ "softwareComponent",
+ "webServer",
+ "webApplication",
+ "DBMS",
+ "database",
+ "objectStorage",
+ "blockStorage",
+ "containerRuntime",
+ "containerApplication",
+ "loadBalancer",
+ "port", "network"])
+
+
+def get_heat(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "heat-types/",
+ ["globalNetwork",
+ "globalPort",
+ "globalCompute",
+ "volume",
+ "cinderVolume",
+ "contrailVirtualNetwork",
+ "neutronNet",
+ "neutronPort",
+ "novaServer",
+ "extVl",
+ "internalVl",
+ "extCp",
+ "vl",
+ "eline",
+ "abstractSubstitute",
+ "Generic_VFC",
+ "Generic_VF",
+ "Generic_CR",
+ "Generic_PNF",
+ "Generic_Service",
+ "contrailNetworkRules",
+ "contrailPort",
+ "portMirroring",
+ "serviceProxy",
+ "contrailV2NetworkRules",
+ "contrailV2VirtualNetwork",
+ "securityRules",
+ "contrailAbstractSubstitute",
+ "contrailCompute",
+ "contrailV2VirtualMachineInterface",
+ "subInterface",
+ "contrailV2VLANSubInterface",
+ "multiFlavorVFC",
+ "vnfConfiguration",
+ "extCp2",
+ "extNeutronCP",
+ "extContrailCP",
+ "portMirroringByPolicy",
+ "forwardingPath",
+ "configuration",
+ "VRFObject",
+ "extVirtualMachineInterfaceCP",
+ "VLANNetworkReceptor",
+ "VRFEntry",
+ "subInterfaceV2",
+ "contrailV2VLANSubInterfaceV2",
+ "fabricConfiguration"])
+
+
+def get_nfv(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "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"])
+
+
+def get_onap(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "onap-types/",
+ # Add desired type names to the list
+ [])
+
+
+def get_sol(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "onap-types/",
+ # Add desired type names to the list
+ [])
+
+
+def get_heat1707(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "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"])
+
+
+def get_heat1702_3537(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "heat-types/",
+ ["contrailPort",
+ "contrailV2VirtualMachineInterface",
+ "neutronPort",
+ "contrailCompute",
+ "novaServer",
+ "contrailV2VirtualNetwork",
+ "contrailVirtualNetwork",
+ "neutronNet"])
+
+
+def get_heat_version(base_file_location="/"):
+ return NormativeTypeCandidate(base_file_location + "heat_types/",
+ ["contrailV2VirtualMachineInterface",
+ "neutronPort"])
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
new file mode 100644
index 0000000000..6d90a1c085
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+
+from sdcBePy.common import logger
+from sdcBePy.common.logger import error_and_exit
+from sdcBePy.common.normative.main import process_element_list, process_type_list
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
+ get_normative_element_with_metadata_list
+from sdcBePy.tosca.models.normativeToUpdateList import TypesToUpdate, get_heat_and_normative_to_update_list, \
+ get_nfv_onap_sol_to_update_list
+
+
+def main():
+ scheme, be_host, be_port, admin_user, _, debug = get_args()
+
+ update_version = True
+ update_onap_version = False
+
+ if debug is False:
+ print('Disabling debug mode')
+ logger.debugFlag = debug
+
+ try:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+ # use to run script form this dir (not like the command)
+ # base_file_location = os.getcwd() + "/../../../../import/tosca/"
+ base_file_location = os.getcwd() + "/"
+ logger.debug("working directory =" + base_file_location)
+ process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy)
+ process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
+
+ all_types = get_all_types()
+
+ heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location)
+ process_type_list(heat_and_normative_list, sdc_be_proxy, update_version)
+
+ nfv_onap_sol_list = get_nfv_onap_sol_to_update_list(all_types, base_file_location)
+ process_type_list(nfv_onap_sol_list, sdc_be_proxy, update_onap_version)
+
+ logger.log("Updating end ->", "All normatives updated successfully!")
+ error_and_exit(0, None)
+
+
+def get_all_types():
+ path = os.path.dirname(__file__)
+ return TypesToUpdate([path + "/../data/typesToUpgrade.json",
+ path + "/../data/onapTypesToUpgrade.json"])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py
new file mode 100644
index 0000000000..4b0d0cc8a2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+from sdcBePy.tosca.imports.runNormativeType import run
+from sdcBePy.tosca.models.normativeToUpdateList import get_heat, get_normative, get_nfv, get_onap, get_sol
+from sdcBePy.tosca.models.normativeTypesList import get_heat1707, get_heat1702_3537, get_heat_version
+from sdcBePy.tosca.upgrade.run import get_all_types
+
+all_types = get_all_types()
+
+
+def run_upgrade_heat():
+ normative_candidate = get_heat(all_types)
+ run(normative_candidate)
+
+
+def run_upgrade_normative():
+ normative_candidate = get_normative(all_types)
+ run(normative_candidate)
+
+
+def run_upgrade_nfv():
+ normative_candidate = get_nfv(all_types)
+ run(normative_candidate)
+
+
+def run_upgrade_onap():
+ normative_candidate = get_onap(all_types)
+ run(normative_candidate)
+
+
+def run_upgrade_sol():
+ normative_candidate = get_sol(all_types)
+ run(normative_candidate)
+
+
+def run_upgrade_heat1707():
+ normative_candidate = get_heat1707()
+ run(normative_candidate)
+
+
+def run_upgrade_heat1707_3537():
+ normative_candidate = get_heat1702_3537()
+ run(normative_candidate)
+
+
+def run_upgrade_heat_version():
+ normative_candidate = get_heat_version()
+ run(normative_candidate)
+
+
+if __name__ == '__main__':
+ run_upgrade_heat()
+ # run_upgrade_normative()
+ # run_upgrade_nfv()
+ # run_upgrade_onap()
+ # run_upgrade_sol()
+ # run_upgrade_heat1707()
+ # run_upgrade_heat1707_3537()
+ # run_upgrade_heat_version()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py
new file mode 100755
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
new file mode 100755
index 0000000000..9ce2be4dd3
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
@@ -0,0 +1,44 @@
+[
+ {
+ "userId": "demo",
+ "firstName": "demo",
+ "lastName": "demo",
+ "role": "ADMIN",
+ "email": "demo@openecomp.org"
+ },
+ {
+ "userId": "op0001",
+ "firstName": "Oper",
+ "lastName": "P",
+ "role": "OPS",
+ "email": "op0001@openecomp.org"
+ },
+ {
+ "userId": "gv0001",
+ "firstName": "Giuseppe",
+ "lastName": "Verdi",
+ "role": "GOVERNOR",
+ "email": "gv0001@openecomp.org"
+ },
+ {
+ "userId": "jh0003",
+ "firstName": "Jimmy",
+ "lastName": "Hendrix",
+ "role": "Admin",
+ "email": "jh0003@openecomp.org"
+ },
+ {
+ "userId": "jm0007",
+ "firstName": "Joni",
+ "lastName": "Mitchell",
+ "role": "TESTER",
+ "email": "jm0007@openecomp.org"
+ },
+ {
+ "userId": "cs0008",
+ "firstName": "Carlos",
+ "lastName": "Santana",
+ "role": "DESIGNER",
+ "email": "cs0008r@openecomp.org"
+ }
+] \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py
new file mode 100755
index 0000000000..b933afe7ca
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import json
+import os
+import time
+from argparse import ArgumentParser
+
+from sdcBePy.common.bColors import BColors
+from sdcBePy.common.healthCheck import check_backend, RETRY_ATTEMPTS
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+colors = BColors()
+
+
+def load_users(conf_path):
+ with open(conf_path, 'r') as f:
+ return json.load(f)
+
+
+def be_user_init(be_ip, be_port, protocol, conf_path):
+ sdc_be_proxy = SdcBeProxy(be_ip, be_port, protocol)
+ if check_backend(sdc_be_proxy, RETRY_ATTEMPTS):
+ users = load_users(conf_path)
+ for user in users:
+ if sdc_be_proxy.check_user(user['userId']) != 200:
+ result = sdc_be_proxy.create_user(user['firstName'],
+ user['lastName'],
+ user['userId'],
+ user['email'],
+ user['role'])
+ if result == 201:
+ print('[INFO]: ' + user['userId'] +
+ ' created, result: [' + str(result) + ']')
+ else:
+ print('[ERROR]: ' + colors.FAIL + user['userId'] + colors.END_C +
+ ' error creating , result: [' + str(result) + ']')
+ else:
+ print('[INFO]: ' + user['userId'] + ' already exists')
+ else:
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + 'Backend is DOWN :-(' + colors.END_C)
+ raise Exception("Cannot communicate with the backend!")
+
+
+def get_args():
+ parser = ArgumentParser()
+
+ parser.add_argument('-i', '--ip', required=True)
+ parser.add_argument('-p', '--port', required=True)
+ parser.add_argument('--https', action='store_true')
+ path = os.path.dirname(__file__)
+ parser.add_argument('--conf', default=os.path.join(path, 'data', 'users.json'))
+
+ args = parser.parse_args()
+
+ return [args.ip, args.port, 'https' if args.https else 'http', args.conf]
+
+
+def main():
+ be_user_init(*get_args())
+
+
+if __name__ == "__main__":
+ main()
diff --git a/catalog-be/src/main/resources/scripts/setup.py b/catalog-be/src/main/resources/scripts/setup.py
new file mode 100644
index 0000000000..9df26a7aa6
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/setup.py
@@ -0,0 +1,43 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='sdcBePy',
+ version='1.7',
+ packages=find_packages(),
+ url='',
+ license='',
+ author='',
+ author_email='',
+ description='',
+ package_data={'': ['data/*.json']},
+ include_package_data=True,
+ entry_points={
+ "console_scripts": [
+ "sdcuserinit=sdcBePy.users.run:main",
+ "sdcimportall=sdcBePy.tosca.imports.run:main",
+ "sdcimportdata=sdcBePy.tosca.imports.runNormativeElement:run_import_data",
+ "sdcimportcapabilities=sdcBePy.tosca.imports.runNormativeElement:run_import_capabilities",
+ "sdcimportrelationship=sdcBePy.tosca.imports.runNormativeElement:run_import_relationship",
+ "sdcimportinterfacelifecycle=sdcBePy.tosca.imports.runNormativeElement:run_import_interface_lifecycle",
+ "sdcimportcategories=sdcBePy.tosca.imports.runNormativeElement:run_import_categories",
+ "sdcimportgroup=sdcBePy.tosca.imports.runNormativeElement:run_import_group",
+ "sdcimportpolicy=sdcBePy.tosca.imports.runNormativeElement:run_import_policy",
+ "sdcimportnormative=sdcBePy.tosca.imports.runNormativeType:run_import_normative",
+ "sdcimportheat=sdcBePy.tosca.imports.runNormativeType:run_import_heat",
+ "sdcimportnfv=sdcBePy.tosca.imports.runNormativeType:run_import_nfv",
+ "sdcimportonap=sdcBePy.tosca.imports.runNormativeType:run_import_onap",
+ "sdcimportsol=sdcBePy.tosca.imports.runNormativeType:run_import_sol",
+ "sdcimportannotation=sdcBePy.tosca.imports.runNormativeType:run_import_annotation",
+ "sdcimportgeneric=sdcBePy.tosca.imports.runGenericNormative:main",
+ "sdcupgradeall=sdcBePy.tosca.upgrade.run:main",
+ "sdcupgradenfv=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_nfv",
+ "sdcupgradeonap=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_onap",
+ "sdcupgradesol=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_sol",
+ "sdcupgradeheat1707=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_heat1707",
+ "sdcupgradeheat1707_3537=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_heat1707_3537",
+ "sdcupgradeheatversion=sdcBePy.tosca.upgrade.runUpgradeNormative:run_upgrade_heat_version",
+ "sdccheckbackend=sdcBePy.common.healthCheck:main",
+ "sdcconsumerinit=sdcBePy.consumers.run:main"
+ ]
+ }, install_requires=['pycurl']
+)