aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorA200231121 <abhimanyu-kumar@t-systems.com>2024-01-05 15:18:46 +0530
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2024-01-18 15:32:15 +0100
commit21c7d95ef3c079c068dd98c1a19b3dbd8295139a (patch)
treef5fd67b103dd794d4e062c4e39dcdb3a0b6394e8 /src
parentda58d669b07dfe85053e6a49a74a65e5d364a5dd (diff)
Added resource related API in NBI class
Add Resource class Issue-ID: TEST-404 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I9b972f94aa613bbddb65f5492a1209ea0702b083
Diffstat (limited to 'src')
-rw-r--r--src/onapsdk/nbi/__init__.py2
-rw-r--r--src/onapsdk/nbi/nbi.py113
-rw-r--r--src/onapsdk/onap_service.py2
3 files changed, 114 insertions, 3 deletions
diff --git a/src/onapsdk/nbi/__init__.py b/src/onapsdk/nbi/__init__.py
index d3ceaf6..6d4470a 100644
--- a/src/onapsdk/nbi/__init__.py
+++ b/src/onapsdk/nbi/__init__.py
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from .nbi import Nbi, Service, ServiceOrder, ServiceSpecification
+from .nbi import Nbi, Service, ServiceOrder, ServiceSpecification, Resource
diff --git a/src/onapsdk/nbi/nbi.py b/src/onapsdk/nbi/nbi.py
index 3af85f6..502a4f2 100644
--- a/src/onapsdk/nbi/nbi.py
+++ b/src/onapsdk/nbi/nbi.py
@@ -14,7 +14,7 @@
# limitations under the License.
from abc import ABC
from enum import Enum
-from typing import Iterator, Optional
+from typing import Iterator, Optional, List
from uuid import uuid4
from onapsdk.aai.business.customer import Customer
@@ -493,3 +493,114 @@ class ServiceOrder(Nbi, WaitForFinishMixin): # pylint: disable=too-many-instanc
"""
return self.status not in [self.StatusEnum.ACKNOWLEDGED,
self.StatusEnum.IN_PROGRESS]
+
+
+# Import the Nbi class
+class Resource(Nbi): # pylint: disable=too-many-instance-attributes, too-many-arguments
+ """A class representing resource-related operations using NBI."""
+
+ def __init__(self, # pylint: disable=too-many-instance-attributes, too-many-arguments
+ unique_id: str,
+ href: str,
+ resource_type: Optional[str],
+ base_type: str,
+ value: str,
+ life_cycle_state: str,
+ resource_specification: dict,
+ resource_characteristics: Optional[List[dict]],
+ related_party: list,
+ note: Optional[List[dict]],
+ place: Optional[dict],
+ serial_number: Optional[str],
+ version_number: Optional[str]) -> None:
+ """Service object initialization.
+
+ Args:
+ unique_id (str): Resource id ,
+ href (str): Resource object href,
+ resource_type (str, optional): Type of resource,
+ base_type (str): Base type of resource,
+ value (str): Name of resource,
+ life_cycle_state (str): current state of resource,
+ resource_specification (dict): Resource specification,
+ resource_characteristics (list[dict], optional): List of resource characteristics,
+ related_party (list): List of related party in current resource,
+ note (list[dict], optional): List of note,
+ place (dict, optional): resource location
+ serial_number(str, optional),
+ version_number(str, optional)
+ """
+ super().__init__()
+ self.unique_id: str = unique_id
+ self.href: str = href
+ self.resource_type: Optional[str] = resource_type
+ self.base_type: str = base_type
+ self.value: str = value
+ self.life_cycle_state: str = life_cycle_state
+ self.resource_specification: dict = resource_specification
+ self.resource_characteristics: Optional[List[dict]] = resource_characteristics
+ self.related_party: list = related_party
+ self.note: Optional[List[dict]] = note
+ self.place: Optional[dict] = place
+ self.serial_number: Optional[str] = serial_number
+ self.version_number: Optional[str] = version_number
+
+ @classmethod
+ def get_all_resources(cls) -> Iterator["Resource"]:
+ """
+ Get a list of all resource from the NBI.
+
+ Returns:
+ Iterator[Resource]: This function will return list of resource object
+ """
+ resource_json = cls.send_message_json("GET", "Get resources from NBI",
+ f"{cls.base_url}{cls.api_version}/resource/")
+
+ # Converting response json to list of Response object
+ for resource in resource_json:
+
+ yield Resource(
+ resource["id"],
+ resource["href"],
+ resource.get("@type"),
+ resource["@baseType"],
+ resource["value"],
+ resource["lifeCyleState"],
+ resource["resourceSpecification"],
+ resource.get("resourceCharacteristics"),
+ resource["relatedParty"],
+ resource.get("note"),
+ resource.get("place"),
+ resource.get("serialNumber"),
+ resource.get("versionNumber")
+ )
+
+
+ @classmethod
+ def get_specific_resource(cls, resource_id: str) -> "Resource":
+ """
+ Get a specific resource by ID from the NBI.
+
+ Args:
+ resource_id (str): The ID of the resource to retrieve.
+
+ Returns:
+ Resource: An instance of the Resource class representing the specific resource.
+ """
+ response = cls.send_message_json("GET", "Get resources from NBI",
+ f"{cls.base_url}{cls.api_version}/resource/{resource_id}")
+ return Resource(
+ response["id"],
+ response["href"],
+ response.get("@type"),
+ response["@baseType"],
+ response["value"],
+ response["lifeCyleState"],
+ response["resourceSpecification"],
+ response.get("resourceCharacteristics"),
+ response["relatedParty"],
+ response.get("note"),
+ response.get("place"),
+ response.get("serialNumber"),
+ response.get("versionNumber")
+ )
diff --git a/src/onapsdk/onap_service.py b/src/onapsdk/onap_service.py
index a219f5a..566c9bc 100644
--- a/src/onapsdk/onap_service.py
+++ b/src/onapsdk/onap_service.py
@@ -224,7 +224,7 @@ class OnapService(ABC):
requests can be used here.
Raises:
- InvalidResponse: if JSON coudn't be decoded
+ InvalidResponse: if JSON couldn't be decoded
RequestError: if other exceptions weren't caught or didn't raise
APIError/ResourceNotFound: send_message() got an HTTP error code
ConnectionFailed: connection can't be established