Skip to content

Commit 146dc44

Browse files
Added override for DB Engine Config view commands
1 parent ff292fc commit 146dc44

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

linodecli/overrides.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ def inner(func):
4747
return inner
4848

4949

50+
@output_override("databases", "mysql-config-view", OutputMode.table)
51+
def handle_databases_mysql_config_view(json_data) -> bool:
52+
"""
53+
Override the output of 'linode-cli databases mysql-config-view'
54+
to properly display the mysql engine config.
55+
"""
56+
return databases_mysql_config_view_output(json_data)
57+
58+
59+
@output_override("databases", "postgres-config-view", OutputMode.table)
60+
def handle_databases_postgres_config_view(json_data) -> bool:
61+
"""
62+
Override the output of 'linode-cli databases postgres-config-view'
63+
to properly display the postgresql engine config.
64+
"""
65+
return databases_postgres_config_view_output(json_data)
66+
67+
5068
@output_override("domains", "zone-file", OutputMode.delimited)
5169
def handle_domains_zone_file(operation, output_handler, json_data) -> bool:
5270
# pylint: disable=unused-argument
@@ -291,3 +309,97 @@ def pg_view_output(json_data) -> bool:
291309
console.print(output)
292310

293311
return False
312+
313+
314+
def add_param_row(output, param_name, param_data):
315+
"""
316+
Construct and add a row to the output table for DB Config view overrides.
317+
"""
318+
param_type = str(param_data.get("type", ""))
319+
example = str(param_data.get("example", ""))
320+
minimum = str(param_data.get("minimum", ""))
321+
maximum = str(param_data.get("maximum", ""))
322+
min_length = str(param_data.get("minLength", ""))
323+
max_length = str(param_data.get("maxLength", ""))
324+
pattern = str(param_data.get("pattern", ""))
325+
requires_restart = "YES" if param_data.get("requires_restart") else "NO"
326+
description = param_data.get("description", "")
327+
328+
output.add_row(
329+
param_name,
330+
param_type,
331+
example,
332+
minimum,
333+
maximum,
334+
min_length,
335+
max_length,
336+
pattern,
337+
requires_restart,
338+
Align(description, align="left"),
339+
)
340+
341+
342+
def databases_mysql_config_view_output(json_data) -> bool:
343+
"""
344+
Parse and format the MySQL configuration output table.
345+
"""
346+
output = Table(header_style="bold", show_lines=True)
347+
348+
output.add_column("Parameter", style="bold")
349+
output.add_column("Type", justify="center")
350+
output.add_column("Example", justify="center")
351+
output.add_column("Min", justify="center")
352+
output.add_column("Max", justify="center")
353+
output.add_column("Min Length", justify="center")
354+
output.add_column("Max Length", justify="center")
355+
output.add_column("Pattern", justify="center")
356+
output.add_column("Requires Restart", justify="center")
357+
output.add_column("Description", style="dim")
358+
359+
for field, params in json_data.items():
360+
if field in ["binlog_retention_period"]:
361+
add_param_row(output, field, params)
362+
else:
363+
for key, val in params.items():
364+
param_name = f"{field}.{key}"
365+
add_param_row(output, param_name, val)
366+
367+
console = Console()
368+
console.print(output)
369+
370+
return False
371+
372+
373+
def databases_postgres_config_view_output(json_data) -> bool:
374+
"""
375+
Parse and format the PostgreSQL configuration output table.
376+
"""
377+
output = Table(header_style="bold", show_lines=True)
378+
379+
output.add_column("Parameter", style="bold")
380+
output.add_column("Type", justify="center")
381+
output.add_column("Example", justify="center")
382+
output.add_column("Min", justify="center")
383+
output.add_column("Max", justify="center")
384+
output.add_column("Min Length", justify="center")
385+
output.add_column("Max Length", justify="center")
386+
output.add_column("Pattern", justify="center")
387+
output.add_column("Requires Restart", justify="center")
388+
output.add_column("Description", style="dim")
389+
390+
for field, params in json_data.items():
391+
if field in [
392+
"pg_stat_monitor_enable",
393+
"shared_buffers_percentage",
394+
"work_mem",
395+
]:
396+
add_param_row(output, field, params)
397+
else:
398+
for key, val in params.items():
399+
param_name = f"{field}.{key}"
400+
add_param_row(output, param_name, val)
401+
402+
console = Console()
403+
console.print(output)
404+
405+
return False

0 commit comments

Comments
 (0)