def test_headers_aai_creator(): base_header = {} aai_headers_creator = headers_aai_creator(base_header) assert base_header != aai_headers_creator assert aai_headers_creator["x-fromappid"] == "AAI" assert aai_headers_creator["authorization"] assert aai_headers_creator["x-transactionid"]
class AaiElement(OnapService): """Mother Class of all A&AI elements.""" name: str = "AAI" server: str = "AAI" base_url = settings.AAI_URL api_version = "/aai/" + settings.AAI_API_VERSION headers = headers_aai_creator(OnapService.headers) @classmethod def get_guis(cls) -> GuiItem: """Retrieve the status of the AAI GUIs. Only one GUI is referenced for AAI the AAI sparky GUI Return the list of GUIs """ gui_url = settings.AAI_GUI_SERVICE aai_gui_response = cls.send_message("GET", "Get AAI GUI Status", gui_url) guilist = GuiList([]) guilist.add(GuiItem(gui_url, aai_gui_response.status_code)) return guilist
class AaiElement(OnapService): """Mother Class of all A&AI elements.""" name: str = "AAI" server: str = "AAI" base_url = settings.AAI_URL api_version = "/aai/v16" headers = headers_aai_creator(OnapService.headers) @classmethod def filter_none_key_values( cls, dict_to_filter: Dict[str, Optional[str]]) -> Dict[str, str]: """Filter out None key values from dictionary. Iterate throught given dictionary and filter None values. Args: dict_to_filter (Dict): Dictionary to filter out None Returns: Dict[str, str]: Filtered dictionary """ return dict( filter( lambda key_value_tuple: key_value_tuple[1] is not None, dict_to_filter.items(), )) @property def url(self) -> str: """Resource's url. Returns: str: Resource's url """ raise NotImplementedError @property def relationships(self) -> Iterator[Relationship]: """Resource relationships iterator. Yields: Relationship: resource relationship """ for relationship in self.send_message_json("GET", "Get object relationships", f"{self.url}/relationship-list")\ .get("relationship", []): yield Relationship( related_to=relationship.get("related-to"), relationship_label=relationship.get("relationship-label"), related_link=relationship.get("related-link"), relationship_data=relationship.get("relationship-data"), ) def add_relationship(self, relationship: Relationship) -> None: """Add relationship to aai resource. Add relationship to resource using A&AI API Args: relationship (Relationship): Relationship to add """ self.send_message( "PUT", "add relationship to cloud region", f"{self.url}/relationship-list/relationship", data=jinja_env().get_template("aai_add_relationship.json.j2"). render(relationship=relationship), )
class AaiElement(OnapService): """Mother Class of all A&AI elements.""" name: str = "AAI" server: str = "AAI" base_url = settings.AAI_URL api_version = "/aai/" + settings.AAI_API_VERSION headers = headers_aai_creator(OnapService.headers) @classmethod def filter_none_key_values( cls, dict_to_filter: Dict[str, Optional[str]]) -> Dict[str, str]: """Filter out None key values from dictionary. Iterate through given dictionary and filter None values. Args: dict_to_filter (Dict): Dictionary to filter out None Returns:dataclasse init a field Dict[str, str]: Filtered dictionary """ return dict( filter( lambda key_value_tuple: key_value_tuple[1] is not None, dict_to_filter.items(), )) @property def url(self) -> str: """Resource's url. Returns: str: Resource's urldataclasse init a field """ raise NotImplementedError @property def relationships(self) -> Iterator[Relationship]: """Resource relationships iterator. Yields: Relationship: resource relationship Raises: RelationshipNotFound: if request for relationships returned 404 """ try: generator = self.send_message_json("GET", "Get object relationships", f"{self.url}/relationship-list")\ .get("relationship", []) for relationship in generator: yield Relationship( related_to=relationship.get("related-to"), relationship_label=relationship.get("relationship-label"), related_link=relationship.get("related-link"), relationship_data=relationship.get("relationship-data"), ) except ResourceNotFound as exc: self._logger.error("Getting object relationships failed: %s", exc) msg = (f'{self.name} relationships not found.' f'Server: {self.server}. Url: {self.url}') raise RelationshipNotFound(msg) from exc def add_relationship(self, relationship: Relationship) -> None: """Add relationship to aai resource. Add relationship to resource using A&AI API Args: relationship (Relationship): Relationship to add """ self.send_message( "PUT", f"add relationship to {self.__class__.__name__}", f"{self.url}/relationship-list/relationship", data=jinja_env().get_template("aai_add_relationship.json.j2"). render(relationship=relationship), ) @classmethod def get_guis(cls) -> GuiItem: """Retrieve the status of the AAI GUIs. Only one GUI is referenced for AAI the AAI sparky GUI Return the list of GUIs """ gui_url = settings.AAI_GUI_SERVICE aai_gui_response = cls.send_message("GET", "Get AAI GUI Status", gui_url) guilist = GuiList([]) guilist.add(GuiItem(gui_url, aai_gui_response.status_code)) return guilist