diff options
Diffstat (limited to 'src/onapsdk/aai/cloud_infrastructure')
-rw-r--r-- | src/onapsdk/aai/cloud_infrastructure/cloud_region.py | 55 | ||||
-rw-r--r-- | src/onapsdk/aai/cloud_infrastructure/complex.py | 67 |
2 files changed, 120 insertions, 2 deletions
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. |