aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk
diff options
context:
space:
mode:
Diffstat (limited to 'src/onapsdk')
-rw-r--r--src/onapsdk/aai/aai_element.py33
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/cloud_region.py22
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/complex.py3
-rw-r--r--src/onapsdk/aai/mixins/__init__.py14
-rw-r--r--src/onapsdk/aai/mixins/link_to_complex.py47
-rw-r--r--src/onapsdk/aai/mixins/link_to_geo_region.py44
-rw-r--r--src/onapsdk/aai/network/site_resource.py36
-rw-r--r--src/onapsdk/configuration/global_settings.py2
8 files changed, 178 insertions, 23 deletions
diff --git a/src/onapsdk/aai/aai_element.py b/src/onapsdk/aai/aai_element.py
index 9472165..907028d 100644
--- a/src/onapsdk/aai/aai_element.py
+++ b/src/onapsdk/aai/aai_element.py
@@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import enum
from dataclasses import dataclass, field
from typing import Dict, Iterator, List, Optional
@@ -58,6 +59,38 @@ class Relationship:
return None
+@enum.unique
+class RelationshipLabelEnum(enum.Enum):
+ """Class to hold relationship labels."""
+
+ APPLIES_TO = "org.onap.relationships.inventory.AppliesTo"
+ BELONGS_TO = "org.onap.relationships.inventory.BelongsTo"
+ BINDS_TO = "org.onap.relationships.inventory.BindsTo"
+ CAN_BE_INSTANTIATED_IN = "org.onap.relationships.inventory.CanBeInstantiatedIn"
+ COMPOSED_OF = "org.onap.relationships.inventory.ComposedOf"
+ CONTROLLED_BY = "org.onap.relationships.inventory.ControlledBy"
+ DEPENDS_ON = "org.onap.relationships.inventory.DependsOn"
+ DESTINATION = "org.onap.relationships.inventory.Destination"
+ FORWARDS_TO = "org.onap.relationships.inventory.ForwardsTo"
+ IS_A = "org.onap.relationships.inventory.IsA"
+ IMPLEMENTS = "org.onap.relationships.inventory.Implements"
+ LINKS_TO = "org.onap.relationships.inventory.LinksTo"
+ LOCATED_IN = "org.onap.relationships.inventory.LocatedIn"
+ MEMBER_OF = "org.onap.relationships.inventory.MemberOf"
+ NETWORK_APPLIES_TO = "org.onap.relationships.inventory.network.AppliesTo"
+ NETWORK_BELONGS_TO = "org.onap.relationships.inventory.network.BelongsTo"
+ NETWORK_MEMBER_OF = "org.onap.relationships.inventory.network.MemberOf"
+ NETWORK_USES = "org.onap.relationships.inventory.network.Uses"
+ PART_OF = "org.onap.relationships.inventory.PartOf"
+ PRIMARY = "org.onap.relationships.inventory.Primary"
+ SECONDARY = "org.onap.relationships.inventory.Secondary"
+ SOURCE = "org.onap.relationships.inventory.Source"
+ SUPPORTS = "org.onap.relationships.inventory.Supports"
+ TARGET = "org.onap.relationships.inventory.Target"
+ TARGETS = "org.onap.relationships.inventory.Targets"
+ USES = "org.onap.relationships.inventory.Uses"
+
+
class AaiElement(OnapService):
"""Mother Class of all A&AI elements."""
diff --git a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
index d57a025..997f426 100644
--- a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
+++ b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
@@ -20,7 +20,8 @@ from onapsdk.msb.multicloud import Multicloud
from onapsdk.utils.jinja import jinja_env
from onapsdk.exceptions import ResourceNotFound
-from ..aai_element import AaiResource, Relationship
+from ..aai_element import AaiResource
+from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin
from .complex import Complex
from .tenant import Tenant
@@ -65,7 +66,7 @@ class EsrSystemInfo: # pylint: disable=too-many-instance-attributes
openstack_region_id: str = None
-class CloudRegion(AaiResource): # pylint: disable=too-many-instance-attributes
+class CloudRegion(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes
"""Cloud region class.
Represents A&AI cloud region object.
@@ -602,20 +603,3 @@ class CloudRegion(AaiResource): # pylint: disable=too-many-instance-attributes
self.url,
params={"resource-version": self.resource_version}
)
-
- def link_to_complex(self, complex_object: Complex) -> None:
- """Link cloud region to comples.
-
- It creates relationhip object and add it into cloud region.
- """
- relationship = Relationship(
- related_to="complex",
- related_link=(f"aai/v13/cloud-infrastructure/complexes/"
- f"complex/{complex_object.physical_location_id}"),
- relationship_data={
- "relationship-key": "complex.physical-location-id",
- "relationship-value": f"{complex_object.physical_location_id}",
- },
- relationship_label="org.onap.relationships.inventory.LocatedIn",
- )
- self.add_relationship(relationship)
diff --git a/src/onapsdk/aai/cloud_infrastructure/complex.py b/src/onapsdk/aai/cloud_infrastructure/complex.py
index a854f02..167234d 100644
--- a/src/onapsdk/aai/cloud_infrastructure/complex.py
+++ b/src/onapsdk/aai/cloud_infrastructure/complex.py
@@ -18,9 +18,10 @@ from urllib.parse import urlencode
from onapsdk.utils.jinja import jinja_env
from ..aai_element import AaiResource
+from ..mixins.link_to_geo_region import AaiResourceLinkToGeoRegionMixin
-class Complex(AaiResource): # pylint: disable=too-many-instance-attributes
+class Complex(AaiResource, AaiResourceLinkToGeoRegionMixin): # pylint: disable=too-many-instance-attributes
"""Complex class.
Collection of physical locations that can house cloud-regions.
diff --git a/src/onapsdk/aai/mixins/__init__.py b/src/onapsdk/aai/mixins/__init__.py
new file mode 100644
index 0000000..486ce72
--- /dev/null
+++ b/src/onapsdk/aai/mixins/__init__.py
@@ -0,0 +1,14 @@
+"""A&AI mixins package."""
+# Copyright 2023 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/src/onapsdk/aai/mixins/link_to_complex.py b/src/onapsdk/aai/mixins/link_to_complex.py
new file mode 100644
index 0000000..af43125
--- /dev/null
+++ b/src/onapsdk/aai/mixins/link_to_complex.py
@@ -0,0 +1,47 @@
+"""A&AI link to complex module."""
+# Copyright 2023 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from typing import TYPE_CHECKING
+
+from ..aai_element import Relationship, RelationshipLabelEnum
+
+if TYPE_CHECKING:
+ from ..cloud_infrastructure.complex import Complex
+
+
+class AaiResourceLinkToComplexMixin: # pylint: disable=too-few-public-methods
+ """Link aai resource to complex mixin."""
+
+ def link_to_complex(self, cmplx: "Complex",
+ relationship_label: RelationshipLabelEnum =\
+ RelationshipLabelEnum.LOCATED_IN) -> None:
+ """Create a relationship with complex resource.
+
+ Args:
+ cmplx (Complex): Complex object ot create relationship with.
+
+ """
+ relationship: Relationship = Relationship(
+ related_to="complex",
+ related_link=cmplx.url,
+ relationship_data=[
+ {
+ "relationship-key": "complex.physical-location-id",
+ "relationship-value": cmplx.physical_location_id,
+ }
+ ],
+ relationship_label=relationship_label.value,
+ )
+ self.add_relationship(relationship)
diff --git a/src/onapsdk/aai/mixins/link_to_geo_region.py b/src/onapsdk/aai/mixins/link_to_geo_region.py
new file mode 100644
index 0000000..b78c407
--- /dev/null
+++ b/src/onapsdk/aai/mixins/link_to_geo_region.py
@@ -0,0 +1,44 @@
+"""A&AI link to geo region mixin module."""
+# Copyright 2023 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from typing import TYPE_CHECKING
+
+from ..aai_element import Relationship, RelationshipLabelEnum
+
+if TYPE_CHECKING:
+ from ..cloud_infrastructure.geo_region import GeoRegion
+
+class AaiResourceLinkToGeoRegionMixin: # pylint: disable=too-few-public-methods
+ """Link aai resource to geo region mixin."""
+
+ def link_to_geo_region(self, geo_region: "GeoRegion") -> None:
+ """Create a relationship with geo region.
+
+ As few resources create same relationship with geo region
+
+ Args:
+ geo_region (GeoRegion): Geo region object
+ """
+ relationship: Relationship = Relationship(
+ related_to="geo-region",
+ related_link=geo_region.url,
+ relationship_data=[
+ {
+ "relationship-key": "geo-region.geo-region-id",
+ "relationship-value": geo_region.geo_region_id,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.MEMBER_OF.value,
+ )
+ self.add_relationship(relationship)
diff --git a/src/onapsdk/aai/network/site_resource.py b/src/onapsdk/aai/network/site_resource.py
index 3ac3c20..11a50c1 100644
--- a/src/onapsdk/aai/network/site_resource.py
+++ b/src/onapsdk/aai/network/site_resource.py
@@ -16,10 +16,12 @@
from typing import Iterable, Optional
from onapsdk.utils.jinja import jinja_env
-from ..aai_element import AaiResource
+from ..aai_element import AaiResource, Relationship, RelationshipLabelEnum
+from ..cloud_infrastructure import Complex
+from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin
-class SiteResource(AaiResource): # pylint: disable=too-many-instance-attributes
+class SiteResource(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes
"""Site resource class."""
def __init__(self, # pylint: disable=too-many-locals
@@ -242,3 +244,33 @@ class SiteResource(AaiResource): # pylint: disable=too-many-instance-attributes
data_source=data_source,
data_source_version=data_source_version))
return cls.get_by_site_resource_id(site_resource_id)
+
+ def link_to_complex(self, cmplx: Complex, relationship_label: RelationshipLabelEnum =\
+ RelationshipLabelEnum.USES) -> None: # pylint: disable=useless-super-delegation
+ """Create a relationship with complex resource.
+
+ Args:
+ cmplx (Complex): Complex object ot create relationship with.
+
+ """
+ return super().link_to_complex(cmplx, relationship_label)
+
+ def link_to_site_resource(self, site_resource: "SiteResource") -> None:
+ """Create a relationship with site-resource resource.
+
+ Args:
+ site_resource (SiteResource): Site resource object to create relationship with.
+
+ """
+ relationship: Relationship = Relationship(
+ related_to="site-resource",
+ related_link=site_resource.url,
+ relationship_data=[
+ {
+ "relationship-key": "site_resource.site-resource-id",
+ "relationship-value": site_resource.site_resource_id,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.SUPPORTS.value,
+ )
+ self.add_relationship(relationship)
diff --git a/src/onapsdk/configuration/global_settings.py b/src/onapsdk/configuration/global_settings.py
index 45dc249..559213a 100644
--- a/src/onapsdk/configuration/global_settings.py
+++ b/src/onapsdk/configuration/global_settings.py
@@ -22,7 +22,7 @@
## API
AAI_URL = "https://aai.api.sparky.simpledemo.onap.org:30233"
-AAI_API_VERSION = "v23"
+AAI_API_VERSION = "v27"
AAI_AUTH = "Basic QUFJOkFBSQ=="
AAI_BULK_CHUNK = 30
CDS_URL = "http://portal.api.simpledemo.onap.org:30449"