diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2023-03-03 08:11:10 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2023-03-03 08:24:25 +0000 |
commit | 70c6a75709b0001e9ffe26987563e14e3e6c6b3d (patch) | |
tree | 0a439f2fa76985e45c42925c1c78504e1ff9b4a9 /src/onapsdk/sdc | |
parent | 04d216408b1fe94337775a6e528175733d055f25 (diff) |
Archive Vendor Software Product
Add a method to archive SDC VSP resource
Issue-ID: INT-2193
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: If643ff47e6b7385eff5d745a5896bf4cb76c5c67
Diffstat (limited to 'src/onapsdk/sdc')
-rw-r--r-- | src/onapsdk/sdc/__init__.py | 6 | ||||
-rw-r--r-- | src/onapsdk/sdc/sdc_element.py | 9 | ||||
-rw-r--r-- | src/onapsdk/sdc/sdc_resource.py | 5 | ||||
-rw-r--r-- | src/onapsdk/sdc/vsp.py | 44 |
4 files changed, 50 insertions, 14 deletions
diff --git a/src/onapsdk/sdc/__init__.py b/src/onapsdk/sdc/__init__.py index 15280d9..c96c77f 100644 --- a/src/onapsdk/sdc/__init__.py +++ b/src/onapsdk/sdc/__init__.py @@ -458,9 +458,10 @@ class SdcOnboardable(SDC, ABC): @abstractmethod def _really_submit(self) -> None: """Really submit the SDC Vf in order to enable it.""" - @staticmethod + @abstractmethod - def _action_url(base: str, + def _action_url(self, + base: str, subpath: str, version_path: str, action_type: str = None) -> str: @@ -471,6 +472,7 @@ class SdcOnboardable(SDC, ABC): NotImplementedError: this is an abstract method. """ + @classmethod @abstractmethod def _sdc_path(cls) -> None: diff --git a/src/onapsdk/sdc/sdc_element.py b/src/onapsdk/sdc/sdc_element.py index f82fcb2..9273861 100644 --- a/src/onapsdk/sdc/sdc_element.py +++ b/src/onapsdk/sdc/sdc_element.py @@ -115,7 +115,7 @@ class SdcElement(SdcOnboardable, ABC): """ subpath = self._sdc_path() - if action == const.COMMIT: + if action in (const.COMMIT, const.ARCHIVE): subpath = "items" return subpath @@ -129,10 +129,7 @@ class SdcElement(SdcOnboardable, ABC): """ return "{}/versions/{}".format(self.identifier, self.version) - @staticmethod - def _action_url(base: str, - subpath: str, - version_path: str, + def _action_url(self, base: str, subpath: str, version_path: str, action_type: str = None) -> str: """ Generate action URL for SDC. @@ -183,7 +180,7 @@ class SdcElement(SdcOnboardable, ABC): str: Url which can be used to delete SDC element """ - return f"{self._get_all_url()}/{self.identifier}" + return f"{self._base_url()}/{self._sdc_path()}/{self.identifier}" def _copy_object(self, obj: 'SdcElement') -> None: """ diff --git a/src/onapsdk/sdc/sdc_resource.py b/src/onapsdk/sdc/sdc_resource.py index 29615db..bdd89ed 100644 --- a/src/onapsdk/sdc/sdc_resource.py +++ b/src/onapsdk/sdc/sdc_resource.py @@ -167,10 +167,7 @@ class SdcResource(SdcOnboardable, ABC): # pylint: disable=too-many-instance-att """ return self.unique_identifier - def _action_url(self, - base: str, - subpath: str, - version_path: str, + def _action_url(self, base: str, subpath: str, version_path: str, action_type: str = None) -> str: """ Generate action URL for SDC. diff --git a/src/onapsdk/sdc/vsp.py b/src/onapsdk/sdc/vsp.py index a6c4c24..a04b3c0 100644 --- a/src/onapsdk/sdc/vsp.py +++ b/src/onapsdk/sdc/vsp.py @@ -139,6 +139,13 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes self._generic_action, action=const.SUBMIT) + def archive(self) -> None: + """Archive VSP.""" + self._action("archive", + const.CERTIFIED, + self._generic_action, + action=const.ARCHIVE) + def create_csar(self) -> None: """Create the CSAR package in the SDC Vsp.""" self._action("create CSAR package", const.CERTIFIED, @@ -226,7 +233,10 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes def _generic_action(self, action=None): """Do a generic action for real.""" if action: - self._action_to_sdc(action, action_type="lifecycleState") + if action == const.ARCHIVE: + self._action_to_sdc(action, action_type=const.ARCHIVE) + else: + self._action_to_sdc(action, action_type="lifecycleState") def _create_csar_action(self): """Create CSAR package for real.""" @@ -320,6 +330,36 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes return {} @classmethod + def _get_all_url(cls) -> str: + """ + Get URL for all elements in SDC. + + Returns: + str: the url + + """ + return f"{cls._base_url()}/items?itemType=vsp" + + def _action_url(self, base: str, subpath: str, version_path: str, + action_type: str = None) -> str: + """Generate action URL for VSP to send to SDC. + + Args: + base (str): base part of vsp action url + subpath (str): subpath of vsp action url + version_path (str): version path. If action is equal to ARCHIVE + it's going to be edited + action_type (str, optional): the type of action. + + Returns: + str: the URL to use + + """ + if action_type == const.ARCHIVE: + version_path = version_path.split("/")[0] + return super()._action_url(base, subpath, version_path, action_type) + + @classmethod def import_from_sdc(cls, values: Dict[str, Any]) -> 'Vsp': """ Import Vsp from SDC. @@ -334,7 +374,7 @@ class Vsp(SdcElement): # pylint: disable=too-many-instance-attributes cls._logger.debug("importing VSP %s from SDC", values['name']) vsp = Vsp(values['name']) vsp.identifier = values['id'] - vsp.vendor = Vendor(name=values['vendorName']) + vsp.vendor = Vendor(name=values['properties']['vendorName']) return vsp def _really_submit(self) -> None: |