Skip to content

Commit b987004

Browse files
committed
fix: apply suggestion (action
1 parent 156e87f commit b987004

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

src/openstack_mcp_server/tools/compute_tools.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import Any
23

34
from fastmcp import FastMCP
@@ -10,6 +11,24 @@
1011
from .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+
1332
class 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:

tests/tools/test_compute_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def test_action_server_success(self, mock_get_openstack_conn, action):
388388
# Verify the correct method was called with server ID
389389
action_method.assert_called_once_with(server_id)
390390

391-
def test_action_server_unsupported_action(self):
391+
def test_action_server_unsupported_action(self, mock_get_openstack_conn):
392392
"""Test action_server with unsupported action raises ValueError."""
393393
server_id = "test-server-id"
394394
unsupported_action = "invalid_action"

0 commit comments

Comments
 (0)