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
100 changes: 89 additions & 11 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 All @@ -43,7 +46,7 @@ def get_region(self, id: str) -> Region:
"""
Get a region.

:param id: The ID of the region. (required)
:param id: The ID of the region.

:return: The Region object.
"""
Expand All @@ -53,12 +56,12 @@ def get_region(self, id: str) -> Region:

return Region(id=region.id, description=region.description)

def create_region(self, id: str, description: str = "") -> Region:
def create_region(self, id: str, description: str | None = None) -> Region:
"""
Create a new region.

:param id: The ID of the region. (required)
:param description: The description of the region. (optional)
:param id: The ID of the region.
:param description: The description of the region.

:return: The created Region object.
"""
Expand All @@ -72,7 +75,7 @@ def delete_region(self, id: str) -> None:
"""
Delete a region.

:param id: The ID of the region. (required)
:param id: The ID of the region.

:return: None
"""
Expand All @@ -83,12 +86,12 @@ def delete_region(self, id: str) -> None:

return None

def update_region(self, id: str, description: str = "") -> Region:
def update_region(self, id: str, description: str | None = None) -> Region:
"""
Update a region.

:param id: The ID of the region. (required)
:param description: The string description of the region. (optional)
:param id: The ID of the region.
:param description: The string description of the region.

:return: The updated Region object.
"""
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.

: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 | None = None,
is_enabled: bool | None = False,
) -> Domain:
"""
Create a new domain.

:param name: The name of the domain.
:param description: The description of the domain.
:param is_enabled: Whether the domain is enabled.
"""
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.
"""
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.
:param name: The name of the domain.
:param description: The description of the domain.
:param is_enabled: Whether the domain is enabled.
"""
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,
)
6 changes: 3 additions & 3 deletions src/openstack_mcp_server/tools/response/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# In this case, we are only using description field as optional.
class Region(BaseModel):
id: str
description: str = ""
description: str | None = None


class Domain(BaseModel):
id: str
name: str
description: str = ""
is_enabled: bool = False
description: str | None = None
is_enabled: bool | None = None
Loading