@@ -45,6 +45,8 @@ def register_tools(self, mcp: FastMCP):
4545 mcp .tool ()(self .action_server )
4646 mcp .tool ()(self .update_server )
4747 mcp .tool ()(self .delete_server )
48+ mcp .tool ()(self .attach_volume )
49+ mcp .tool ()(self .detach_volume )
4850
4951 def get_servers (self ) -> list [Server ]:
5052 """
@@ -125,7 +127,7 @@ def get_flavors(self) -> list[Flavor]:
125127 flavor_list .append (Flavor (** flavor ))
126128 return flavor_list
127129
128- def action_server (self , id : str , action : ServerActionEnum ) -> None :
130+ def action_server (self , id : str , action : str ) -> None :
129131 """
130132 Perform an action on a Compute server.
131133
@@ -151,19 +153,19 @@ def action_server(self, id: str, action: ServerActionEnum) -> None:
151153 conn = get_openstack_conn ()
152154
153155 action_methods = {
154- ServerActionEnum .PAUSE : conn .compute .pause_server ,
155- ServerActionEnum .UNPAUSE : conn .compute .unpause_server ,
156- ServerActionEnum .SUSPEND : conn .compute .suspend_server ,
157- ServerActionEnum .RESUME : conn .compute .resume_server ,
158- ServerActionEnum .LOCK : conn .compute .lock_server ,
159- ServerActionEnum .UNLOCK : conn .compute .unlock_server ,
160- ServerActionEnum .RESCUE : conn .compute .rescue_server ,
161- ServerActionEnum .UNRESCUE : conn .compute .unrescue_server ,
162- ServerActionEnum .START : conn .compute .start_server ,
163- ServerActionEnum .STOP : conn .compute .stop_server ,
164- ServerActionEnum .SHELVE : conn .compute .shelve_server ,
165- ServerActionEnum .SHELVE_OFFLOAD : conn .compute .shelve_offload_server ,
166- ServerActionEnum .UNSHELVE : conn .compute .unshelve_server ,
156+ ServerActionEnum .PAUSE . value : conn .compute .pause_server ,
157+ ServerActionEnum .UNPAUSE . value : conn .compute .unpause_server ,
158+ ServerActionEnum .SUSPEND . value : conn .compute .suspend_server ,
159+ ServerActionEnum .RESUME . value : conn .compute .resume_server ,
160+ ServerActionEnum .LOCK . value : conn .compute .lock_server ,
161+ ServerActionEnum .UNLOCK . value : conn .compute .unlock_server ,
162+ ServerActionEnum .RESCUE . value : conn .compute .rescue_server ,
163+ ServerActionEnum .UNRESCUE . value : conn .compute .unrescue_server ,
164+ ServerActionEnum .START . value : conn .compute .start_server ,
165+ ServerActionEnum .STOP . value : conn .compute .stop_server ,
166+ ServerActionEnum .SHELVE . value : conn .compute .shelve_server ,
167+ ServerActionEnum .SHELVE_OFFLOAD . value : conn .compute .shelve_offload_server ,
168+ ServerActionEnum .UNSHELVE . value : conn .compute .unshelve_server ,
167169 }
168170
169171 if action not in action_methods :
@@ -214,3 +216,28 @@ def delete_server(self, id: str) -> None:
214216 """
215217 conn = get_openstack_conn ()
216218 conn .compute .delete_server (id )
219+
220+ def attach_volume (
221+ self , server_id : str , volume_id : str , device : str | None = None
222+ ) -> None :
223+ """
224+ Attach a volume to a Compute server.
225+
226+ :param server_id: The UUID of the server.
227+ :param volume_id: The UUID of the volume to attach.
228+ :param device: Name of the device such as, /dev/vdb. If you specify this parameter, the device must not exist in the guest operating system.
229+ """
230+ conn = get_openstack_conn ()
231+ conn .compute .create_volume_attachment (
232+ server_id , volume_id = volume_id , device = device
233+ )
234+
235+ def detach_volume (self , server_id : str , volume_id : str ) -> None :
236+ """
237+ Detach a volume from a Compute server.
238+
239+ :param server_id: The UUID of the server.
240+ :param volume_id: The UUID of the volume to detach.
241+ """
242+ conn = get_openstack_conn ()
243+ conn .compute .delete_volume_attachment (server_id , volume_id )
0 commit comments