22
33from .base import get_openstack_conn
44from .response .block_storage import (
5+ Attachment ,
6+ ConnectionInfo ,
57 Volume ,
68 VolumeAttachment ,
79)
@@ -22,6 +24,8 @@ def register_tools(self, mcp: FastMCP):
2224 mcp .tool ()(self .delete_volume )
2325 mcp .tool ()(self .extend_volume )
2426
27+ mcp .tool ()(self .get_attachment_details )
28+
2529 def get_volumes (self ) -> list [Volume ]:
2630 """
2731 Get the list of Block Storage volumes.
@@ -39,7 +43,7 @@ def get_volumes(self) -> list[Volume]:
3943 VolumeAttachment (
4044 server_id = attachment .get ("server_id" ),
4145 device = attachment .get ("device" ),
42- attachment_id = attachment .get ("id " ),
46+ attachment_id = attachment .get ("attachment_id " ),
4347 ),
4448 )
4549
@@ -183,3 +187,41 @@ def extend_volume(self, volume_id: str, new_size: int) -> None:
183187 conn = get_openstack_conn ()
184188
185189 conn .block_storage .extend_volume (volume_id , new_size )
190+
191+ def get_attachment_details (self , attachment_id : str ) -> Attachment :
192+ """
193+ Get detailed information about a specific attachment.
194+
195+ :param attachment_id: The ID of the attachment to get details for
196+ :return: An Attachment object with detailed information
197+ """
198+ conn = get_openstack_conn ()
199+
200+ attachment = conn .block_storage .get_attachment (attachment_id )
201+
202+ # NOTE: We exclude the auth_* fields for security reasons
203+ connection_info = attachment .connection_info
204+ filtered_connection_info = ConnectionInfo (
205+ access_mode = connection_info .get ("access_mode" ),
206+ cacheable = connection_info .get ("cacheable" ),
207+ driver_volume_type = connection_info .get ("driver_volume_type" ),
208+ encrypted = connection_info .get ("encrypted" ),
209+ qos_specs = connection_info .get ("qos_specs" ),
210+ target_discovered = connection_info .get ("target_discovered" ),
211+ target_iqn = connection_info .get ("target_iqn" ),
212+ target_lun = connection_info .get ("target_lun" ),
213+ target_portal = connection_info .get ("target_portal" ),
214+ )
215+
216+ params = {
217+ "id" : attachment .id ,
218+ "instance" : attachment .instance ,
219+ "volume_id" : attachment .volume_id ,
220+ "attached_at" : attachment .attached_at ,
221+ "detached_at" : attachment .detached_at ,
222+ "attach_mode" : attachment .attach_mode ,
223+ "connection_info" : filtered_connection_info ,
224+ "connector" : attachment .connector ,
225+ }
226+
227+ return Attachment (** params )
0 commit comments