Skip to content

Commit 3bf5a10

Browse files
Added override for DB Engine Config view commands
1 parent ff292fc commit 3bf5a10

File tree

1 file changed

+117
-4
lines changed

1 file changed

+117
-4
lines changed

linodecli/overrides.py

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

4949

50+
@output_override("databases", "mysql-config-view", OutputMode.table)
51+
def handle_databases_mysql_config_view(
52+
operation, output_handler, json_data
53+
) -> bool:
54+
"""
55+
Override the output of 'linode-cli databases mysql-config-view' to properly display the mysql engine config.
56+
"""
57+
return databases_mysql_config_view_output(json_data)
58+
59+
60+
@output_override("databases", "postgres-config-view", OutputMode.table)
61+
def handle_databases_postgres_config_view(
62+
operation, output_handler, json_data
63+
) -> bool:
64+
"""
65+
Override the output of 'linode-cli databases postgres-config-view' to properly display the postgresql engine config.
66+
"""
67+
return databases_postgres_config_view_output(json_data)
68+
69+
5070
@output_override("domains", "zone-file", OutputMode.delimited)
5171
def handle_domains_zone_file(operation, output_handler, json_data) -> bool:
5272
# pylint: disable=unused-argument
@@ -59,7 +79,7 @@ def handle_domains_zone_file(operation, output_handler, json_data) -> bool:
5979

6080
@output_override("linodes", "types", OutputMode.table)
6181
def handle_types_region_prices_list(
62-
operation, output_handler, json_data
82+
operation, output_handler, json_data
6383
) -> bool:
6484
"""
6585
Override the output of 'linode-cli linodes types' to display regional pricing.
@@ -96,7 +116,7 @@ def handle_placement_group_update(operation, output_handler, json_data) -> bool:
96116

97117
@output_override("placement", "assign-linode", OutputMode.table)
98118
def handle_placement_assign_linode(
99-
operation, output_handler, json_data
119+
operation, output_handler, json_data
100120
) -> bool:
101121
# pylint: disable=unused-argument
102122
"""
@@ -107,7 +127,7 @@ def handle_placement_assign_linode(
107127

108128
@output_override("placement", "unassign-linode", OutputMode.table)
109129
def handle_placement_unassign_linode(
110-
operation, output_handler, json_data
130+
operation, output_handler, json_data
111131
) -> bool:
112132
# pylint: disable=unused-argument
113133
"""
@@ -117,7 +137,7 @@ def handle_placement_unassign_linode(
117137

118138

119139
def linode_types_with_region_prices(
120-
operation, output_handler, json_data
140+
operation, output_handler, json_data
121141
) -> bool:
122142
# pylint: disable=unused-argument
123143
"""
@@ -291,3 +311,96 @@ def pg_view_output(json_data) -> bool:
291311
console.print(output)
292312

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

0 commit comments

Comments
 (0)