diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2020-03-05 13:12:27 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-06-24 06:01:11 +0000 |
commit | cb30f3a566b73c78c3ea666acfcd3f288098684a (patch) | |
tree | 38cd1acb83ddde2b927485611d130bbeec3c1a4b /catalog-be/src/main/resources/scripts/sdcBePy/tosca/models | |
parent | bdbfc2e460ccb561c3e174260b2908b974996d4f (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/sdcBePy/tosca/models')
6 files changed, 329 insertions, 0 deletions
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"]) |