1+ from enum import Enum
12from typing import Any
23
34from fastmcp import FastMCP
1011from .base import get_openstack_conn
1112
1213
14+ class ServerActionEnum (str , Enum ):
15+ """available actions without parameter for compute tools"""
16+
17+ PAUSE = "pause"
18+ UNPAUSE = "unpause"
19+ SUSPEND = "suspend"
20+ RESUME = "resume"
21+ LOCK = "lock"
22+ UNLOCK = "unlock"
23+ RESCUE = "rescue"
24+ UNRESCUE = "unrescue"
25+ START = "start"
26+ STOP = "stop"
27+ SHELVE = "shelve"
28+ SHELVE_OFFLOAD = "shelve_offload"
29+ UNSHELVE = "unshelve"
30+
31+
1332class ComputeTools :
1433 """
1534 A class to encapsulate Compute-related tools and utilities.
@@ -104,7 +123,7 @@ def get_flavors(self) -> list[Flavor]:
104123 flavor_list .append (Flavor (** flavor ))
105124 return flavor_list
106125
107- def action_server (self , id : str , action : str ) -> None :
126+ def action_server (self , id : str , action : ServerActionEnum ) :
108127 """
109128 Perform an action on a Compute server.
110129
@@ -125,25 +144,24 @@ def action_server(self, id: str, action: str) -> None:
125144 - shelve_offload: Shelf-offloads, or removes, a shelved server
126145 - unshelve: Unshelves, or restores, a shelved server
127146 Only above actions are currently supported
128- :return: None
129147 :raises ValueError: If the action is not supported or invalid(ConflictException).
130148 """
131149 conn = get_openstack_conn ()
132150
133151 action_methods = {
134- "pause" : conn .compute .pause_server ,
135- "unpause" : conn .compute .unpause_server ,
136- "suspend" : conn .compute .suspend_server ,
137- "resume" : conn .compute .resume_server ,
138- "lock" : conn .compute .lock_server ,
139- "unlock" : conn .compute .unlock_server ,
140- "rescue" : conn .compute .rescue_server ,
141- "unrescue" : conn .compute .unrescue_server ,
142- "start" : conn .compute .start_server ,
143- "stop" : conn .compute .stop_server ,
144- "shelve" : conn .compute .shelve_server ,
145- "shelve_offload" : conn .compute .shelve_offload_server ,
146- "unshelve" : conn .compute .unshelve_server ,
152+ ServerActionEnum . PAUSE : conn .compute .pause_server ,
153+ ServerActionEnum . UNPAUSE : conn .compute .unpause_server ,
154+ ServerActionEnum . SUSPEND : conn .compute .suspend_server ,
155+ ServerActionEnum . RESUME : conn .compute .resume_server ,
156+ ServerActionEnum . LOCK : conn .compute .lock_server ,
157+ ServerActionEnum . UNLOCK : conn .compute .unlock_server ,
158+ ServerActionEnum . RESCUE : conn .compute .rescue_server ,
159+ ServerActionEnum . UNRESCUE : conn .compute .unrescue_server ,
160+ ServerActionEnum . START : conn .compute .start_server ,
161+ ServerActionEnum . STOP : conn .compute .stop_server ,
162+ ServerActionEnum . SHELVE : conn .compute .shelve_server ,
163+ ServerActionEnum . SHELVE_OFFLOAD : conn .compute .shelve_offload_server ,
164+ ServerActionEnum . UNSHELVE : conn .compute .unshelve_server ,
147165 }
148166
149167 if action not in action_methods :
0 commit comments