1313)
1414from videoipath_automation_tool .apps .inventory .model .device_status import DeviceStatus
1515from videoipath_automation_tool .apps .inventory .model .drivers import CustomSettingsType , DriverLiteral
16+ from videoipath_automation_tool .apps .inventory .model .global_snmp_config import SnmpConfiguration
17+ from videoipath_automation_tool .apps .inventory .model .global_snmp_request_rpc import SnmpRequestRpc
1618from videoipath_automation_tool .apps .inventory .model .inventory_device import InventoryDevice
1719from videoipath_automation_tool .apps .inventory .model .inventory_discovered_device import DiscoveredInventoryDevice
1820from videoipath_automation_tool .apps .inventory .model .inventory_request_rpc import InventoryRequestRpc
@@ -664,16 +666,16 @@ def get_discovered_device(self, discovered_device_id: str) -> DiscoveredInventor
664666 response .data ["status" ]["devman" ]["discoveredDevices" ]["_items" ][0 ]
665667 )
666668
667- # --- Global Configuration Helpers ---
668- def get_global_snmp_config_id_by_label (self , label : str ) -> Optional [str ]:
669+ # --- Global SNMP Configuration Helpers ---
670+ def get_global_snmp_config_id_by_label (self , label : str ) -> Optional [str | List [ str ] ]:
669671 """Method to get the global SNMP configuration id by label.
670- Note: If multiple SNMP configurations with the same label exist, the first one is returned.
672+ Note: If multiple SNMP configurations with the same label exist, a list of ids is returned.
671673
672674 Args:
673675 label (str): Label of the SNMP configuration
674676
675677 Returns:
676- Optional[str] : SNMP configuration id, None if not found
678+ Optional[str | List[str]] : SNMP configuration id, None if not found, List of ids if multiple configurations with the same label exist
677679 """
678680 if not label :
679681 raise ValueError ("Label must not be empty." )
@@ -687,9 +689,9 @@ def get_global_snmp_config_id_by_label(self, label: str) -> Optional[str]:
687689 return list (matches .keys ())[0 ]
688690 elif len (matches ) > 1 :
689691 self ._logger .warning (
690- f"Multiple SNMP configurations found with label '{ label } '. Returning the first one ."
692+ f"Multiple SNMP configurations found with label '{ label } '' . Returning all matching ids ."
691693 )
692- return list (matches .keys ())[ 0 ]
694+ return list (matches .keys ())
693695 return None
694696
695697 def get_global_snmp_config_label_by_id (self , snmp_config_id : str ) -> Optional [str ]:
@@ -705,9 +707,10 @@ def get_global_snmp_config_label_by_id(self, snmp_config_id: str) -> Optional[st
705707 raise ValueError ("SNMP configuration id must not be empty." )
706708
707709 url = f"/rest/v2/data/config/system/snmp/session/{ snmp_config_id } /descriptor/label"
708- response = self .vip_connector .rest .get (url )
709- if response .data and response .data ["config" ]["system" ]["snmp" ]["session" ][snmp_config_id ]:
710- return response .data ["config" ]["system" ]["snmp" ]["session" ][snmp_config_id ]["descriptor" ]["label" ]
710+ response = self .vip_connector .rest .get (url , node_check = False )
711+ if response .data and response .data ["config" ]["system" ]["snmp" ]["session" ]:
712+ if snmp_config_id in response .data ["config" ]["system" ]["snmp" ]["session" ]:
713+ return response .data ["config" ]["system" ]["snmp" ]["session" ][snmp_config_id ]["descriptor" ]["label" ]
711714 return None
712715
713716 def get_all_global_snmp_config_ids (self ) -> dict [str , str ]:
@@ -726,6 +729,106 @@ def get_all_global_snmp_config_ids(self) -> dict[str, str]:
726729 snmp_config_id : snmp_config ["descriptor" ]["label" ] for snmp_config_id , snmp_config in snmp_configs .items ()
727730 }
728731
732+ # --- Global SNMP Configuration CRUD Methods ---
733+ def get_global_snmp_config (self , snmp_config_id : str ) -> SnmpConfiguration :
734+ """Method to get a global SNMP configuration by id from VideoIPath-Inventory
735+
736+ Args:
737+ snmp_config_id (str): SNMP configuration id
738+
739+ Returns:
740+ GlobalSnmpConfig: Global SNMP configuration object
741+ """
742+ if not snmp_config_id :
743+ raise ValueError ("SNMP configuration id must not be empty." )
744+
745+ url = f"/rest/v2/data/config/system/snmp/session/{ snmp_config_id } /**"
746+ response = self .vip_connector .rest .get (url )
747+ if not response .data :
748+ raise ValueError ("Response data is empty." )
749+
750+ return SnmpConfiguration .parse_from_dict (response .data ["config" ]["system" ]["snmp" ]["session" ])
751+
752+ def add_global_snmp_config (self , snmp_config : SnmpConfiguration ) -> SnmpConfiguration :
753+ """Method to add a new global SNMP configuration
754+
755+ Args:
756+ snmp_config (SnmpConfiguration): SNMP configuration object to add
757+
758+ Returns:
759+ SnmpConfiguration: Added SNMP configuration object
760+ """
761+ if not snmp_config .id :
762+ raise ValueError ("SNMP configuration id must be set." )
763+
764+ self ._logger .debug (f"Adding new global SNMP configuration with id '{ snmp_config .id } '." )
765+
766+ existing_configs_label = self .get_global_snmp_config_label_by_id (snmp_config .id )
767+ if existing_configs_label is not None :
768+ raise ValueError (f"SNMP configuration with id '{ snmp_config .id } ' already exists. Please update it instead." )
769+
770+ body = SnmpRequestRpc ()
771+ body .add (snmp_config )
772+
773+ response = self .vip_connector .rpc .post ("/api/updateSnmpConfig" , body = body )
774+
775+ if response .header .status != "OK" :
776+ raise ValueError (f"Failed to add global SNMP configuration. Error: { response } " )
777+
778+ return self .get_global_snmp_config (snmp_config_id = snmp_config .id )
779+
780+ def update_global_snmp_config (self , snmp_config : SnmpConfiguration ) -> SnmpConfiguration :
781+ """Method to update a global SNMP configuration
782+
783+ Args:
784+ snmp_config (SnmpConfiguration): SNMP configuration object to update
785+
786+ Returns:
787+ SnmpConfiguration: Updated SNMP configuration object
788+ """
789+ if not snmp_config .id :
790+ raise ValueError ("SNMP configuration id must be set." )
791+
792+ self ._logger .debug (f"Updating global SNMP configuration with id '{ snmp_config .id } '." )
793+
794+ existing_configs_label = self .get_global_snmp_config_label_by_id (snmp_config .id )
795+ if existing_configs_label is None :
796+ raise ValueError (f"SNMP configuration with id '{ snmp_config .id } ' does not exist. Please add it first." )
797+
798+ body = SnmpRequestRpc ()
799+ body .update (snmp_config )
800+
801+ response = self .vip_connector .rpc .post ("/api/updateSnmpConfig" , body = body )
802+
803+ if response .header .status != "OK" :
804+ raise ValueError (f"Failed to update global SNMP configuration. Error: { response } " )
805+
806+ return self .get_global_snmp_config (snmp_config_id = snmp_config .id )
807+
808+ def remove_global_snmp_config (self , snmp_config_id : str ) -> ResponseRPC :
809+ """Method to remove a global SNMP configuration by id from VideoIPath-Inventory
810+
811+ Args:
812+ snmp_config_id (str): SNMP configuration id
813+
814+ Returns:
815+ ResponseRPC: Response object
816+ """
817+ if not snmp_config_id :
818+ raise ValueError ("SNMP configuration id must be set." )
819+
820+ self ._logger .debug (f"Removing global SNMP configuration with id '{ snmp_config_id } '." )
821+
822+ body = SnmpRequestRpc ()
823+ body .remove (snmp_config_id )
824+
825+ response = self .vip_connector .rpc .post ("/api/updateSnmpConfig" , body = body )
826+
827+ if response .header .status != "OK" :
828+ raise ValueError (f"Failed to remove global SNMP configuration. Error: { response } " )
829+
830+ return response
831+
729832 # --- Deprecated Methods ---
730833 @deprecated (
731834 "The method `fetch_device_ids_list` is deprecated and will be removed in a future release. " ,
0 commit comments