Skip to content

Commit d534fc0

Browse files
committed
Getting started on administration API
1 parent 114b45f commit d534fc0

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

arangoasync/database.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
PermissionResetError,
4141
PermissionUpdateError,
4242
ServerEncryptionError,
43+
ServerEngineError,
4344
ServerStatusError,
4445
ServerTLSError,
4546
ServerTLSReloadError,
@@ -2437,6 +2438,28 @@ def response_handler(resp: Response) -> bool:
24372438

24382439
return await self._executor.execute(request, response_handler)
24392440

2441+
async def engine(self) -> Result[Json]:
2442+
"""Returns the storage engine the server is configured to use.
2443+
2444+
Returns:
2445+
dict: Database engine details.
2446+
2447+
Raises:
2448+
ServerEngineError: If the operation fails.
2449+
2450+
References:
2451+
- `get-the-storage-engine-type <https://docs.arangodb.com/stable/develop/http-api/administration/#get-the-storage-engine-type>`__
2452+
""" # noqa: E501
2453+
request = Request(method=Method.GET, endpoint="/_api/engine")
2454+
2455+
def response_handler(resp: Response) -> Json:
2456+
if not resp.is_success:
2457+
raise ServerEngineError(resp, request)
2458+
result: Json = self.deserializer.loads(resp.raw_body)
2459+
return result
2460+
2461+
return await self._executor.execute(request, response_handler)
2462+
24402463

24412464
class StandardDatabase(Database):
24422465
"""Standard database API wrapper.

arangoasync/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,16 @@ class SerializationError(ArangoClientError):
547547
"""Failed to serialize the request."""
548548

549549

550+
class ServerConnectionError(ArangoServerError):
551+
"""Failed to connect to ArangoDB server."""
552+
553+
550554
class ServerEncryptionError(ArangoServerError):
551555
"""Failed to reload user-defined encryption keys."""
552556

553557

554-
class ServerConnectionError(ArangoServerError):
555-
"""Failed to connect to ArangoDB server."""
558+
class ServerEngineError(ArangoServerError):
559+
"""Failed to retrieve database engine."""
556560

557561

558562
class ServerStatusError(ArangoServerError):

docs/admin.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Server Administration
2+
---------------------
3+
4+
ArangoDB provides operations for server administration and monitoring.
5+
Most of these operations can only be performed by admin users via the
6+
``_system`` database.
7+
8+
**Example:**
9+
10+
.. code-block:: python
11+
12+
from arangoasync import ArangoClient
13+
from arangoasync.auth import Auth
14+
15+
# Initialize the client for ArangoDB.
16+
async with ArangoClient(hosts="http://localhost:8529") as client:
17+
auth = Auth(username="root", password="passwd")
18+
19+
# Connect to "_system" database as root user.
20+
sys_db = await client.db("_system", auth=auth)
21+
22+
# Retrieve the database engine.
23+
await sys_db.engine()

tests/test_database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ async def test_database_misc_methods(sys_db, db, bad_db, cluster, db_version):
6464
with pytest.raises(CollectionKeyGeneratorsError):
6565
await bad_db.key_generators()
6666

67+
# Administration
68+
result = await db.engine()
69+
assert isinstance(result, dict)
70+
6771

6872
@pytest.mark.asyncio
6973
async def test_create_drop_database(

0 commit comments

Comments
 (0)