aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk
diff options
context:
space:
mode:
authorAlexey Aleynikov <alexey.aleynikov@telekom.com>2023-06-01 13:12:47 +0300
committerAlexey Aleynikov <alexey.aleynikov@telekom.com>2023-06-07 22:02:43 +0300
commite05c376573b67f72a5b8df931ecce0b18841f540 (patch)
tree6a3f5fcc0ec22074b845a7dfd770f34360a50bef /src/onapsdk
parent3860bac3bf74c485eebb0327e9125d6b45685278 (diff)
added changes in CPS api v2 and code od anchor and dataspace
Issue-ID: TEST-395 Signed-off-by: Alexey Aleynikov <alexey.aleynikov@telekom.com> Change-Id: I6cd8fa6e35b5349533cac4688dcb6234f493aa60
Diffstat (limited to 'src/onapsdk')
-rw-r--r--src/onapsdk/configuration/global_settings.py2
-rw-r--r--src/onapsdk/cps/anchor.py34
-rw-r--r--src/onapsdk/cps/dataspace.py30
3 files changed, 46 insertions, 20 deletions
diff --git a/src/onapsdk/configuration/global_settings.py b/src/onapsdk/configuration/global_settings.py
index 559213a..25cdf80 100644
--- a/src/onapsdk/configuration/global_settings.py
+++ b/src/onapsdk/configuration/global_settings.py
@@ -29,7 +29,7 @@ CDS_URL = "http://portal.api.simpledemo.onap.org:30449"
CDS_AUTH = ("ccsdkapps", "ccsdkapps")
CPS_URL = "http://portal.api.simpledemo.onap.org:8080"
CPS_AUTH = ("cpsuser", "cpsr0cks!")
-CPS_VERSION = "v1"
+CPS_VERSION = "v2"
MSB_URL = "https://msb.api.simpledemo.onap.org:30283"
K8SPLUGIN_URL = "http://k8splugin.api.simpledemo.onap.org:30455"
SDC_BE_URL = "https://sdc.api.be.simpledemo.onap.org:30204"
diff --git a/src/onapsdk/cps/anchor.py b/src/onapsdk/cps/anchor.py
index 6e37a3c..b1f9014 100644
--- a/src/onapsdk/cps/anchor.py
+++ b/src/onapsdk/cps/anchor.py
@@ -43,9 +43,11 @@ class Anchor(CpsElement):
str: Human readable string
"""
- return f"Anchor(name={self.name}, "\
- f"schema set={self.schema_set.name}, "\
- f"dataspace={self.schema_set.dataspace.name})"
+ return (
+ f"Anchor(name={self.name}, "
+ f"schema set={self.schema_set.name}, "
+ f"dataspace={self.schema_set.dataspace.name})"
+ )
@property
def url(self) -> str:
@@ -60,10 +62,7 @@ class Anchor(CpsElement):
def delete(self) -> None:
"""Delete anchor."""
self.send_message(
- "DELETE",
- f"Delete {self.name} anchor",
- self.url,
- auth=self.auth
+ "DELETE", f"Delete {self.name} anchor", self.url, auth=self.auth
)
def create_node(self, node_data: str) -> None:
@@ -80,7 +79,7 @@ class Anchor(CpsElement):
f"Create {self.name} anchor node",
f"{self.url}/nodes",
data=node_data,
- auth=self.auth
+ auth=self.auth,
)
def get_node(self, xpath: str, include_descendants: bool = False) -> Dict[Any, Any]:
@@ -107,7 +106,8 @@ class Anchor(CpsElement):
def update_node(self, xpath: str, node_data: str) -> None:
"""Update anchor node data.
- Using XPATH update anchor's node data.
+ Using XPATH, update
+ anchor's node data.
Args:
xpath (str): Anchor node xpath.
@@ -119,7 +119,7 @@ class Anchor(CpsElement):
f"Update {self.name} anchor node with {xpath} xpath",
f"{self.url}/nodes?xpath={xpath}",
data=node_data,
- auth=self.auth
+ auth=self.auth,
)
def replace_node(self, xpath: str, node_data: str) -> None:
@@ -137,7 +137,7 @@ class Anchor(CpsElement):
f"Replace {self.name} anchor node with {xpath} xpath",
f"{self.url}/nodes?xpath={xpath}",
data=node_data,
- auth=self.auth
+ auth=self.auth,
)
def add_list_node(self, xpath: str, node_data: str) -> None:
@@ -153,15 +153,17 @@ class Anchor(CpsElement):
f"Add element to {self.name} anchor node with {xpath} xpath",
f"{self.url}/list-nodes?xpath={xpath}",
data=node_data,
- auth=self.auth
+ auth=self.auth,
)
- def query_node(self, query: str, include_descendants: bool = False) -> Dict[Any, Any]:
+ def query_node(
+ self, query: str, include_descendants: bool = False
+ ) -> Dict[Any, Any]:
"""Query CPS anchor data.
Args:
query (str): Query
- include_descendants (bool, optional): Determies if descendants should be included in
+ include_descendants (bool, optional): Determines if descendants should be included in
response. Defaults to False.
Returns:
@@ -172,7 +174,7 @@ class Anchor(CpsElement):
"GET",
f"Get {self.name} anchor node with {query} query",
f"{self.url}/nodes/query?cps-path={query}&include-descendants={include_descendants}",
- auth=self.auth
+ auth=self.auth,
)
def delete_nodes(self, xpath: str) -> None:
@@ -188,5 +190,5 @@ class Anchor(CpsElement):
"DELETE",
f"Delete {self.name} anchor nodes with {xpath} xpath",
f"{self.url}/nodes?xpath={xpath}",
- auth=self.auth
+ auth=self.auth,
)
diff --git a/src/onapsdk/cps/dataspace.py b/src/onapsdk/cps/dataspace.py
index 282880f..e574866 100644
--- a/src/onapsdk/cps/dataspace.py
+++ b/src/onapsdk/cps/dataspace.py
@@ -14,8 +14,8 @@
# limitations under the License.
from functools import wraps
-from typing import Any, Dict, Iterable
-from onapsdk.exceptions import (APIError, ResourceNotFound)
+from typing import Any, BinaryIO, Dict, Iterable, Union
+from ..exceptions import (APIError, ResourceNotFound)
from .anchor import Anchor
from .cps_element import CpsElement
@@ -89,6 +89,26 @@ class Dataspace(CpsElement):
)
return Dataspace(dataspace_name)
+ @classmethod
+ @exception_handler
+ def get_dataspace(cls, dataspace_name: str) -> "Dataspace":
+ """Get existing dataspace with given name.
+
+ Args:
+ dataspace_name (str): Dataspace name
+
+ Returns:
+ Dataspace: Dataspace object
+
+ """
+ dataspace_data = cls.send_message_json(
+ "GET",
+ f"Get {dataspace_name} dataspace",
+ f"{cls._url}/admin/dataspaces/{dataspace_name}",
+ auth=cls.auth
+ )
+ return Dataspace(name=dataspace_data["name"])
+
@exception_handler
def create_anchor(self, schema_set: SchemaSet, anchor_name: str) -> Anchor:
"""Create anchor.
@@ -188,7 +208,11 @@ class Dataspace(CpsElement):
)
@exception_handler
- def create_schema_set(self, schema_set_name: str, schema_set: bytes) -> SchemaSet:
+ def create_schema_set(
+ self,
+ schema_set_name: str,
+ schema_set: Union[bytes, BinaryIO]
+ ) -> SchemaSet:
"""Create schema set.
Create CPS schema set in dataspace