Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
84 changes: 81 additions & 3 deletions src/openstack_mcp_server/tools/identity_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def register_tools(self, mcp: FastMCP):

mcp.tool()(self.get_domains)
mcp.tool()(self.get_domain)
mcp.tool()(self.create_domain)
mcp.tool()(self.delete_domain)
mcp.tool()(self.update_domain)

def get_regions(self) -> list[Region]:
"""
Expand Down Expand Up @@ -124,21 +127,96 @@ def get_domains(self) -> list[Domain]:
)
return domain_list

def get_domain(self, id: str) -> Domain:
def get_domain(self, name: str) -> Domain:
"""
Get a domain.

:param id: The ID of the domain. (required)
:param name: The name of the domain. (required)

:return: The Domain object.
"""
conn = get_openstack_conn()

domain = conn.identity.get_domain(domain=id)
domain = conn.identity.find_domain(name_or_id=name)

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

def create_domain(
self,
name: str,
description: str = "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring에서 명시된 optional 이랑 실제 인자정보가 다른것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석이랑 함께 수정하겠습니다!

is_enabled: bool = False,
) -> Domain:
"""
Create a new domain.

:param name: The name of the domain. (required)
:param description: The description of the domain. (optional)
:param is_enabled: Whether the domain is enabled. (optional)
"""
conn = get_openstack_conn()

domain = conn.identity.create_domain(
name=name,
description=description,
enabled=is_enabled,
)

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

def delete_domain(self, name: str) -> None:
"""
Delete a domain.

:param name: The name of the domain. (required)
"""
conn = get_openstack_conn()

domain = conn.identity.find_domain(name_or_id=name)
conn.identity.delete_domain(domain=domain, ignore_missing=False)

return None

def update_domain(
self,
id: str,
name: str | None = None,
description: str | None = None,
is_enabled: bool | None = None,
) -> Domain:
"""
Update a domain.

:param id: The ID of the domain. (required)
:param name: The name of the domain. (optional)
:param description: The description of the domain. (optional)
:param is_enabled: Whether the domain is enabled. (optional)
"""
conn = get_openstack_conn()

args = {}
if name is not None:
args["name"] = name
if description is not None:
args["description"] = description
if is_enabled is not None:
args["is_enabled"] = is_enabled

updated_domain = conn.identity.update_domain(domain=id, **args)

return Domain(
id=updated_domain.id,
name=updated_domain.name,
description=updated_domain.description,
is_enabled=updated_domain.is_enabled,
)
Loading