Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openstack_mcp_server/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def register_tool(mcp: FastMCP):
Register Openstack MCP tools.
"""

from .block_storage_tools import BlockStorageTools
from .compute_tools import ComputeTools
from .identity_tools import IdentityTools
from .image_tools import ImageTools
from .network_tools import NetworkTools
from .block_storage_tools import BlockStorageTools

ComputeTools().register_tools(mcp)
ImageTools().register_tools(mcp)
Expand Down
24 changes: 16 additions & 8 deletions src/openstack_mcp_server/tools/block_storage_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from fastmcp import FastMCP

from .base import get_openstack_conn
from .response.block_storage import (
Volume,
VolumeAttachment,
)
from .base import get_openstack_conn
from fastmcp import FastMCP


class BlockStorageTools:
Expand Down Expand Up @@ -39,7 +40,7 @@ def get_volumes(self) -> list[Volume]:
server_id=attachment.get("server_id"),
device=attachment.get("device"),
attachment_id=attachment.get("id"),
)
),
)

volume_list.append(
Expand All @@ -57,7 +58,7 @@ def get_volumes(self) -> list[Volume]:
is_encrypted=volume.is_encrypted,
description=volume.description,
attachments=attachments,
)
),
)

return volume_list
Expand All @@ -80,7 +81,7 @@ def get_volume_details(self, volume_id: str) -> Volume:
server_id=attachment.get("server_id"),
device=attachment.get("device"),
attachment_id=attachment.get("id"),
)
),
)

return Volume(
Expand Down Expand Up @@ -133,7 +134,10 @@ def create_volume(
volume_kwargs["availability_zone"] = availability_zone

volume = conn.block_storage.create_volume(
size=size, image=image, bootable=bootable, **volume_kwargs
size=size,
image=image,
bootable=bootable,
**volume_kwargs,
)

volume_obj = Volume(
Expand Down Expand Up @@ -162,7 +166,11 @@ def delete_volume(self, volume_id: str, force: bool = False) -> None:
"""
conn = get_openstack_conn()

conn.block_storage.delete_volume(volume_id, force=force, ignore_missing=False)
conn.block_storage.delete_volume(
volume_id,
force=force,
ignore_missing=False,
)

def extend_volume(self, volume_id: str, new_size: int) -> None:
"""
Expand All @@ -174,4 +182,4 @@ def extend_volume(self, volume_id: str, new_size: int) -> None:
"""
conn = get_openstack_conn()

conn.block_storage.extend_volume(volume_id, new_size)
conn.block_storage.extend_volume(volume_id, new_size)
23 changes: 16 additions & 7 deletions src/openstack_mcp_server/tools/identity_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastmcp import FastMCP

from .base import get_openstack_conn
from .response.identity import Region, Domain
from .response.identity import Domain, Region


class IdentityTools:
Expand All @@ -19,7 +19,7 @@ def register_tools(self, mcp: FastMCP):
mcp.tool()(self.create_region)
mcp.tool()(self.delete_region)
mcp.tool()(self.update_region)

mcp.tool()(self.get_domains)
mcp.tool()(self.get_domain)

Expand Down Expand Up @@ -103,7 +103,7 @@ def update_region(self, id: str, description: str = "") -> Region:
id=updated_region.id,
description=updated_region.description,
)

def get_domains(self) -> list[Domain]:
"""
Get the list of Identity domains.
Expand All @@ -115,7 +115,12 @@ def get_domains(self) -> list[Domain]:
domain_list = []
for domain in conn.identity.domains():
domain_list.append(
Domain(id=domain.id, name=domain.name, description=domain.description, is_enabled=domain.is_enabled),
Domain(
id=domain.id,
name=domain.name,
description=domain.description,
is_enabled=domain.is_enabled,
),
)
return domain_list

Expand All @@ -128,8 +133,12 @@ def get_domain(self, id: str) -> Domain:
:return: The Domain object.
"""
conn = get_openstack_conn()

domain = conn.identity.get_domain(domain=id)

return Domain(id=domain.id, name=domain.name, description=domain.description, is_enabled=domain.is_enabled)

return Domain(
id=domain.id,
name=domain.name,
description=domain.description,
is_enabled=domain.is_enabled,
)
2 changes: 1 addition & 1 deletion src/openstack_mcp_server/tools/response/block_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class Volume(BaseModel):
is_bootable: bool | None = None
is_encrypted: bool | None = None
description: str | None = None
attachments: list[VolumeAttachment] = []
attachments: list[VolumeAttachment] = []
1 change: 1 addition & 0 deletions src/openstack_mcp_server/tools/response/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Region(BaseModel):
id: str
description: str = ""


class Domain(BaseModel):
id: str
name: str
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def mock_openstack_connect_network():
):
yield mock_conn


@pytest.fixture
def mock_get_openstack_conn_block_storage():
"""Mock get_openstack_conn function for block_storage_tools."""
Expand Down
Loading