aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk/aai
diff options
context:
space:
mode:
Diffstat (limited to 'src/onapsdk/aai')
-rw-r--r--src/onapsdk/aai/aai_element.py1
-rw-r--r--src/onapsdk/aai/business/customer.py52
-rw-r--r--src/onapsdk/aai/business/owning_entity.py26
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/cloud_region.py55
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/complex.py67
-rw-r--r--src/onapsdk/aai/templates/aai_owning_entity_create_update.json.j2 (renamed from src/onapsdk/aai/templates/aai_owning_entity_create.json.j2)0
-rw-r--r--src/onapsdk/aai/templates/cloud_region_create_update.json.j2 (renamed from src/onapsdk/aai/templates/cloud_region_create.json.j2)0
-rw-r--r--src/onapsdk/aai/templates/complex_create_update.json.j2 (renamed from src/onapsdk/aai/templates/complex_create.json.j2)0
-rw-r--r--src/onapsdk/aai/templates/customer_create_update.json.j2 (renamed from src/onapsdk/aai/templates/customer_create.json.j2)0
9 files changed, 197 insertions, 4 deletions
diff --git a/src/onapsdk/aai/aai_element.py b/src/onapsdk/aai/aai_element.py
index 5b72f95..69b2c71 100644
--- a/src/onapsdk/aai/aai_element.py
+++ b/src/onapsdk/aai/aai_element.py
@@ -99,6 +99,7 @@ class AaiElement(OnapService):
base_url = settings.AAI_URL
api_version = "/aai/" + settings.AAI_API_VERSION
headers = headers_aai_creator(OnapService.headers)
+ patch_headers = headers_aai_creator(OnapService.patch_headers)
@classmethod
def get_guis(cls) -> GuiItem:
diff --git a/src/onapsdk/aai/business/customer.py b/src/onapsdk/aai/business/customer.py
index 1df1bc2..6799fac 100644
--- a/src/onapsdk/aai/business/customer.py
+++ b/src/onapsdk/aai/business/customer.py
@@ -505,7 +505,7 @@ class Customer(AaiResource):
"declare customer",
url,
data=jinja_env()
- .get_template("customer_create.json.j2")
+ .get_template("customer_create_update.json.j2")
.render(
global_customer_id=global_customer_id,
subscriber_name=subscriber_name,
@@ -523,6 +523,56 @@ class Customer(AaiResource):
resource_version=response["resource-version"],
)
+ @classmethod
+ def update(cls,
+ global_customer_id: str,
+ subscriber_name: str,
+ subscriber_type: str,
+ service_subscriptions: Optional[Iterable[str]] = None) -> "Customer":
+ """Update customer.
+
+ Args:
+ global_customer_id (str): Global customer id used across ONAP
+ to uniquely identify customer.
+ subscriber_name (str): Subscriber name, an alternate way
+ to retrieve a customer.
+ subscriber_type (str): Subscriber type, a way to provide
+ VID with only the INFRA customers.
+ service_subscriptions (Optional[Iterable[str]], optional): Iterable
+ of service subscription names should be created for newly
+ created customer. Defaults to None.
+
+ Returns:
+ Customer: Customer object.
+
+ """
+ url: str = (
+ f"{cls.base_url}{cls.api_version}/business/customers/"
+ f"customer/{global_customer_id}"
+ )
+ cls.send_message(
+ "PATCH",
+ "update customer",
+ url,
+ data=jinja_env()
+ .get_template("customer_create_update.json.j2")
+ .render(
+ global_customer_id=global_customer_id,
+ subscriber_name=subscriber_name,
+ subscriber_type=subscriber_type,
+ service_subscriptions=service_subscriptions
+ ),
+ )
+ response: dict = cls.send_message_json(
+ "GET", "get updated customer", url
+ ) # Call API one more time to get Customer's resource version
+ return Customer(
+ global_customer_id=response["global-customer-id"],
+ subscriber_name=response["subscriber-name"],
+ subscriber_type=response["subscriber-type"],
+ resource_version=response["resource-version"],
+ )
+
@property
def url(self) -> str:
"""Return customer object url.
diff --git a/src/onapsdk/aai/business/owning_entity.py b/src/onapsdk/aai/business/owning_entity.py
index ebe9b11..1ef0a39 100644
--- a/src/onapsdk/aai/business/owning_entity.py
+++ b/src/onapsdk/aai/business/owning_entity.py
@@ -148,7 +148,31 @@ class OwningEntity(AaiResource, AaiResourceLinkToTenantMixin):
"Declare A&AI owning entity",
(f"{cls.base_url}{cls.api_version}/business/owning-entities/"
f"owning-entity/{owning_entity_id}"),
- data=jinja_env().get_template("aai_owning_entity_create.json.j2").render(
+ data=jinja_env().get_template("aai_owning_entity_create_update.json.j2").render(
+ owning_entity_name=name,
+ owning_entity_id=owning_entity_id
+ )
+ )
+ return cls.get_by_owning_entity_id(owning_entity_id)
+
+ @classmethod
+ def update(cls, name: str, owning_entity_id: str) -> "OwningEntity":
+ """Update owning entity A&AI resource.
+
+ Args:
+ name (str): owning entity name
+ owning_entity_id (str): owning entity ID.
+
+ Returns:
+ OwningEntity: Updated OwningEntity object
+
+ """
+ cls.send_message(
+ "PATCH",
+ "update A&AI owning entity",
+ (f"{cls.base_url}{cls.api_version}/business/owning-entities/"
+ f"owning-entity/{owning_entity_id}"),
+ data=jinja_env().get_template("aai_owning_entity_create_update.json.j2").render(
owning_entity_name=name,
owning_entity_id=owning_entity_id
)
diff --git a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
index 171be34..5f01548 100644
--- a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
+++ b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
@@ -270,7 +270,60 @@ class CloudRegion(AaiResource, AaiResourceLinkToComplexMixin, AaiResourceLinkToP
"Create cloud region",
url,
data=jinja_env()
- .get_template("cloud_region_create.json.j2")
+ .get_template("cloud_region_create_update.json.j2")
+ .render(cloud_region=cloud_region),
+ )
+ return cloud_region
+
+ @classmethod
+ def update(cls, # pylint: disable=too-many-locals
+ cloud_owner: str,
+ cloud_region_id: str,
+ orchestration_disabled: bool,
+ in_maint: bool,
+ *, # rest of parameters are keyword
+ cloud_type: str = "",
+ owner_defined_type: str = "",
+ cloud_region_version: str = "",
+ identity_url: str = "",
+ cloud_zone: str = "",
+ complex_name: str = "",
+ sriov_automation: str = "",
+ cloud_extra_info: str = "",
+ upgrade_cycle: str = "") -> "CloudRegion":
+ """Update CloudRegion object.
+
+ Update cloud region with given values.
+
+ Returns:
+ CloudRegion: Updated cloud region.
+
+ """
+ cloud_region: "CloudRegion" = CloudRegion(
+ cloud_owner=cloud_owner,
+ cloud_region_id=cloud_region_id,
+ orchestration_disabled=orchestration_disabled,
+ in_maint=in_maint,
+ cloud_type=cloud_type,
+ owner_defined_type=owner_defined_type,
+ cloud_region_version=cloud_region_version,
+ identity_url=identity_url,
+ cloud_zone=cloud_zone,
+ complex_name=complex_name,
+ sriov_automation=sriov_automation,
+ cloud_extra_info=cloud_extra_info,
+ upgrade_cycle=upgrade_cycle,
+ )
+ url: str = (
+ f"{cls.base_url}{cls.api_version}/cloud-infrastructure/cloud-regions/cloud-region/"
+ f"{cloud_region.cloud_owner}/{cloud_region.cloud_region_id}"
+ )
+ cls.send_message(
+ "PATCH",
+ "Update cloud region",
+ url,
+ data=jinja_env()
+ .get_template("cloud_region_create_update.json.j2")
.render(cloud_region=cloud_region),
)
return cloud_region
diff --git a/src/onapsdk/aai/cloud_infrastructure/complex.py b/src/onapsdk/aai/cloud_infrastructure/complex.py
index 167234d..1a1684a 100644
--- a/src/onapsdk/aai/cloud_infrastructure/complex.py
+++ b/src/onapsdk/aai/cloud_infrastructure/complex.py
@@ -179,7 +179,7 @@ class Complex(AaiResource, AaiResourceLinkToGeoRegionMixin): # pylint: disable=
data_source=data_source,
data_source_version=data_source_version
)
- payload: str = jinja_env().get_template("complex_create.json.j2").render(
+ payload: str = jinja_env().get_template("complex_create_update.json.j2").render(
complex=complex_object)
url: str = (
f"{cls.base_url}{cls.api_version}/cloud-infrastructure/complexes/complex/"
@@ -189,6 +189,71 @@ class Complex(AaiResource, AaiResourceLinkToGeoRegionMixin): # pylint: disable=
return complex_object
@classmethod
+ def update(cls, # pylint: disable=too-many-locals
+ physical_location_id: str,
+ *,
+ name: str = "",
+ data_center_code: str = "",
+ identity_url: str = "",
+ resource_version: str = "",
+ physical_location_type: str = "",
+ street1: str = "",
+ street2: str = "",
+ city: str = "",
+ state: str = "",
+ postal_code: str = "",
+ country: str = "",
+ region: str = "",
+ latitude: str = "",
+ longitude: str = "",
+ elevation: str = "",
+ lata: str = "",
+ timezone: str = "",
+ data_owner: str = "",
+ data_source: str = "",
+ data_source_version: str = "") -> "Complex":
+ """Update complex.
+
+ Update complex object by calling A&AI API.
+ If API request doesn't fail it returns Complex object.
+
+ Returns:
+ Complex: Updated complex object
+
+ """
+ complex_object: Complex = Complex(
+ name=name,
+ physical_location_id=physical_location_id,
+ data_center_code=data_center_code,
+ identity_url=identity_url,
+ resource_version=resource_version,
+ physical_location_type=physical_location_type,
+ street1=street1,
+ street2=street2,
+ city=city,
+ state=state,
+ postal_code=postal_code,
+ country=country,
+ region=region,
+ latitude=latitude,
+ longitude=longitude,
+ elevation=elevation,
+ lata=lata,
+ timezone=timezone,
+ data_owner=data_owner,
+ data_source=data_source,
+ data_source_version=data_source_version
+ )
+ payload: str = jinja_env().get_template("complex_create_update.json.j2").render(
+ complex=complex_object)
+ url: str = (
+ f"{cls.base_url}{cls.api_version}/cloud-infrastructure/complexes/complex/"
+ f"{complex_object.physical_location_id}"
+ )
+ cls.send_message("PATCH", "update complex", url, data=payload)
+ return complex_object
+
+ @classmethod
def get_all_url(cls) -> str: # pylint: disable=arguments-differ
"""Return an url to get all complexes.
diff --git a/src/onapsdk/aai/templates/aai_owning_entity_create.json.j2 b/src/onapsdk/aai/templates/aai_owning_entity_create_update.json.j2
index 2877a3d..2877a3d 100644
--- a/src/onapsdk/aai/templates/aai_owning_entity_create.json.j2
+++ b/src/onapsdk/aai/templates/aai_owning_entity_create_update.json.j2
diff --git a/src/onapsdk/aai/templates/cloud_region_create.json.j2 b/src/onapsdk/aai/templates/cloud_region_create_update.json.j2
index 65a7057..65a7057 100644
--- a/src/onapsdk/aai/templates/cloud_region_create.json.j2
+++ b/src/onapsdk/aai/templates/cloud_region_create_update.json.j2
diff --git a/src/onapsdk/aai/templates/complex_create.json.j2 b/src/onapsdk/aai/templates/complex_create_update.json.j2
index 681fdad..681fdad 100644
--- a/src/onapsdk/aai/templates/complex_create.json.j2
+++ b/src/onapsdk/aai/templates/complex_create_update.json.j2
diff --git a/src/onapsdk/aai/templates/customer_create.json.j2 b/src/onapsdk/aai/templates/customer_create_update.json.j2
index 0eea2ed..0eea2ed 100644
--- a/src/onapsdk/aai/templates/customer_create.json.j2
+++ b/src/onapsdk/aai/templates/customer_create_update.json.j2