Skip to content

Commit 4b5f5a3

Browse files
Added support for DB Configurable Params features
1 parent cf04ca6 commit 4b5f5a3

File tree

2 files changed

+299
-3
lines changed

2 files changed

+299
-3
lines changed

linode_api4/groups/database.py

+150-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
from typing import Any, Dict, Union
2+
3+
from linode_api4 import (
4+
MySQLDatabaseConfigOptions,
5+
PostgreSQLDatabaseConfigOptions,
6+
)
17
from linode_api4.errors import UnexpectedResponseError
28
from linode_api4.groups import Group
39
from linode_api4.objects import (
@@ -63,6 +69,26 @@ def engines(self, *filters):
6369
"""
6470
return self.client._get_and_filter(DatabaseEngine, *filters)
6571

72+
def mysql_config_options(self):
73+
"""
74+
Returns a detailed list of all the configuration options for MySQL Databases.
75+
76+
API Documentation: TODO
77+
78+
:returns: The JSON configuration options for MySQL Databases.
79+
"""
80+
return self.client.get("databases/mysql/config", model=self)
81+
82+
def postgresql_config_options(self):
83+
"""
84+
Returns a detailed list of all the configuration options for PostgreSQL Databases.
85+
86+
API Documentation: TODO
87+
88+
:returns: The JSON configuration options for PostgreSQL Databases.
89+
"""
90+
return self.client.get("databases/postgresql/config", model=self)
91+
6692
def instances(self, *filters):
6793
"""
6894
Returns a list of Managed Databases active on this account.
@@ -93,7 +119,15 @@ def mysql_instances(self, *filters):
93119
"""
94120
return self.client._get_and_filter(MySQLDatabase, *filters)
95121

96-
def mysql_create(self, label, region, engine, ltype, **kwargs):
122+
def mysql_create(
123+
self,
124+
label,
125+
region,
126+
engine,
127+
ltype,
128+
engine_config: Union[MySQLDatabaseConfigOptions, Dict[str, Any]] = None,
129+
**kwargs,
130+
):
97131
"""
98132
Creates an :any:`MySQLDatabase` on this account with
99133
the given label, region, engine, and node type. For example::
@@ -123,13 +157,16 @@ def mysql_create(self, label, region, engine, ltype, **kwargs):
123157
:type engine: str or Engine
124158
:param ltype: The Linode Type to use for this cluster
125159
:type ltype: str or Type
160+
:param engine_config: The configuration options for this MySQL cluster
161+
:type engine_config: Dict[str, Any] or MySQLDatabaseConfigOptions
126162
"""
127163

128164
params = {
129165
"label": label,
130166
"region": region,
131167
"engine": engine,
132168
"type": ltype,
169+
"engine_config": engine_config,
133170
}
134171
params.update(kwargs)
135172

@@ -201,6 +238,54 @@ def mysql_fork(self, source, restore_time, **kwargs):
201238
d = MySQLDatabase(self.client, result["id"], result)
202239
return d
203240

241+
def mysql_update_config(
242+
self,
243+
engine_config: Union[MySQLDatabaseConfigOptions, Dict[str, Any]] = None,
244+
**kwargs,
245+
):
246+
"""
247+
Updates the config of :any:`MySQLDatabase` on this account with
248+
the given engine_config.
249+
For example::
250+
251+
client = LinodeClient(TOKEN)
252+
253+
db_to_update_config = client.database.mysql_instances()[0]
254+
255+
new_engine_config = MySQLDatabaseConfigOptions(
256+
mysql=MySQLDatabaseConfigMySQLOptions(connect_timeout=20),
257+
service_log=True
258+
)
259+
260+
db_with_new_config = client.database.mysql_update_config(
261+
new_engine_config
262+
)
263+
264+
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instances
265+
266+
:param engine_config: The configuration options for this MySQL cluster
267+
:type engine_config: Dict[str, Any] or MySQLDatabaseConfigOptions
268+
"""
269+
270+
params = {
271+
"engine_config": engine_config,
272+
}
273+
params.update(kwargs)
274+
275+
result = self.client.post(
276+
"/databases/mysql/instances",
277+
data=_flatten_request_body_recursive(drop_null_keys(params)),
278+
)
279+
280+
if "id" not in result:
281+
raise UnexpectedResponseError(
282+
"Unexpected response when updating MySQL Database config",
283+
json=result,
284+
)
285+
286+
d = MySQLDatabase(self.client, result["id"], result)
287+
return d
288+
204289
def postgresql_instances(self, *filters):
205290
"""
206291
Returns a list of Managed PostgreSQL Databases active on this account.
@@ -216,7 +301,17 @@ def postgresql_instances(self, *filters):
216301
"""
217302
return self.client._get_and_filter(PostgreSQLDatabase, *filters)
218303

219-
def postgresql_create(self, label, region, engine, ltype, **kwargs):
304+
def postgresql_create(
305+
self,
306+
label,
307+
region,
308+
engine,
309+
ltype,
310+
engine_config: Union[
311+
PostgreSQLDatabaseConfigOptions, Dict[str, Any]
312+
] = None,
313+
**kwargs,
314+
):
220315
"""
221316
Creates an :any:`PostgreSQLDatabase` on this account with
222317
the given label, region, engine, and node type. For example::
@@ -246,13 +341,16 @@ def postgresql_create(self, label, region, engine, ltype, **kwargs):
246341
:type engine: str or Engine
247342
:param ltype: The Linode Type to use for this cluster
248343
:type ltype: str or Type
344+
:param engine_config: The configuration options for this PostgreSQL cluster
345+
:type engine_config: Dict[str, Any] or PostgreSQLDatabaseConfigOptions
249346
"""
250347

251348
params = {
252349
"label": label,
253350
"region": region,
254351
"engine": engine,
255352
"type": ltype,
353+
"engine_config": engine_config,
256354
}
257355
params.update(kwargs)
258356

@@ -325,3 +423,53 @@ def postgresql_fork(self, source, restore_time, **kwargs):
325423

326424
d = PostgreSQLDatabase(self.client, result["id"], result)
327425
return d
426+
427+
def postgresql_update_config(
428+
self,
429+
engine_config: Union[
430+
PostgreSQLDatabaseConfigOptions, Dict[str, Any]
431+
] = None,
432+
**kwargs,
433+
):
434+
"""
435+
Updates the config of :any:`PostgreSQLDatabase` on this account with
436+
the given engine_config.
437+
For example::
438+
439+
client = LinodeClient(TOKEN)
440+
441+
db_to_update_config = client.database.postgresql_instances()[0]
442+
443+
new_engine_config = PostgreSQLDatabaseConfigOptions(
444+
pg=PostgreSQLDatabaseConfigPGOptions(log_temp_files=200),
445+
service_log=True
446+
)
447+
448+
db_with_new_config = client.database.postgresql_update_config(
449+
new_engine_config
450+
)
451+
452+
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-postgresql-instances
453+
454+
:param engine_config: The configuration options for this PostgreSQL cluster
455+
:type engine_config: Dict[str, Any] or PostgreSQLDatabaseConfigOptions
456+
"""
457+
458+
params = {
459+
"engine_config": engine_config,
460+
}
461+
params.update(kwargs)
462+
463+
result = self.client.post(
464+
"/databases/postgresql/instances",
465+
data=_flatten_request_body_recursive(drop_null_keys(params)),
466+
)
467+
468+
if "id" not in result:
469+
raise UnexpectedResponseError(
470+
"Unexpected response when updating PostgreSQL Database config",
471+
json=result,
472+
)
473+
474+
d = PostgreSQLDatabase(self.client, result["id"], result)
475+
return d

linode_api4/objects/database.py

+149-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
14
from deprecated import deprecated
25

3-
from linode_api4.objects import Base, DerivedBase, MappedObject, Property
6+
from linode_api4.objects import (
7+
Base,
8+
DerivedBase,
9+
JSONObject,
10+
MappedObject,
11+
Property,
12+
)
413

514

615
class DatabaseType(Base):
@@ -128,6 +137,143 @@ class PostgreSQLDatabaseBackup(DatabaseBackup):
128137
api_endpoint = "/databases/postgresql/instances/{database_id}/backups/{id}"
129138

130139

140+
@dataclass
141+
class MySQLDatabaseConfigMySQLOptions(JSONObject):
142+
"""
143+
MySQLDatabaseConfigMySQLOptions represents the fields in the mysql
144+
field of the MySQLDatabaseConfigOptions class
145+
"""
146+
147+
connect_timeout: Optional[int] = None
148+
default_time_zone: Optional[str] = None
149+
group_concat_max_len: Optional[float] = None
150+
information_schema_stats_expiry: Optional[int] = None
151+
innodb_change_buffer_max_size: Optional[int] = None
152+
innodb_flush_neighbors: Optional[int] = None
153+
innodb_ft_min_token_size: Optional[int] = None
154+
innodb_ft_server_stopword_table: Optional[str] = None
155+
innodb_lock_wait_timeout: Optional[int] = None
156+
innodb_log_buffer_size: Optional[int] = None
157+
innodb_online_alter_log_max_size: Optional[int] = None
158+
innodb_print_all_deadlocks: Optional[bool] = None
159+
innodb_read_io_threads: Optional[int] = None
160+
innodb_rollback_on_timeout: Optional[bool] = None
161+
innodb_thread_concurrency: Optional[int] = None
162+
innodb_write_io_threads: Optional[int] = None
163+
interactive_timeout: Optional[int] = None
164+
internal_tmp_mem_storage_engine: Optional[str] = None
165+
log_output: Optional[str] = None
166+
long_query_time: Optional[float] = None
167+
max_allowed_packet: Optional[int] = None
168+
max_heap_table_size: Optional[int] = None
169+
net_buffer_length: Optional[int] = None
170+
net_read_timeout: Optional[int] = None
171+
net_write_timeout: Optional[int] = None
172+
slow_query_log: Optional[bool] = None
173+
sort_buffer_size: Optional[int] = None
174+
sql_mode: Optional[str] = None
175+
sql_require_primary_key: Optional[bool] = None
176+
tmp_table_size: Optional[int] = None
177+
wait_timeout: Optional[int] = None
178+
179+
180+
@dataclass
181+
class MySQLDatabaseConfigOptions(JSONObject):
182+
"""
183+
MySQLDatabaseConfigOptions is used to specify
184+
a MySQL Database Cluster's configuration options during its creation.
185+
"""
186+
187+
mysql: Optional[MySQLDatabaseConfigMySQLOptions] = None
188+
binlog_retention_period: Optional[int] = None
189+
service_log: Optional[bool] = None
190+
191+
192+
@dataclass
193+
class PostgreSQLDatabasePGLookoutConfigOptions(JSONObject):
194+
"""
195+
PostgreSQLDatabasePGLookoutConfigOptions represents the fields in the pglookout
196+
field of the PostgreSQLDatabasePGConfigOptions class
197+
"""
198+
199+
max_failover_replication_time_lag: Optional[int] = None
200+
201+
202+
@dataclass
203+
class PostgreSQLDatabasePGConfigOptions(JSONObject):
204+
"""
205+
PostgreSQLDatabasePGConfigOptions represents the fields in the pg
206+
field of the PostgreSQLDatabasePGConfigOptions class
207+
"""
208+
209+
autovacuum_analyze_scale_factor: Optional[float] = None
210+
autovacuum_analyze_threshold: Optional[int] = None
211+
autovacuum_freeze_max_age: Optional[int] = None
212+
autovacuum_max_workers: Optional[int] = None
213+
autovacuum_naptime: Optional[int] = None
214+
autovacuum_vacuum_cost_delay: Optional[int] = None
215+
autovacuum_vacuum_cost_limit: Optional[int] = None
216+
autovacuum_vacuum_scale_factor: Optional[float] = None
217+
autovacuum_vacuum_threshold: Optional[int] = None
218+
bgwriter_delay: Optional[int] = None
219+
bgwriter_flush_after: Optional[int] = None
220+
bgwriter_lru_maxpages: Optional[int] = None
221+
bgwriter_lru_multiplier: Optional[float] = None
222+
deadlock_timeout: Optional[int] = None
223+
default_toast_compression: Optional[str] = None
224+
idle_in_transaction_session_timeout: Optional[int] = None
225+
jit: Optional[bool] = None
226+
log_autovacuum_min_duration: Optional[int] = None
227+
log_error_verbosity: Optional[str] = None
228+
log_line_prefix: Optional[str] = None
229+
log_min_duration_statement: Optional[int] = None
230+
log_temp_files: Optional[int] = None
231+
max_files_per_process: Optional[int] = None
232+
max_locks_per_transaction: Optional[int] = None
233+
max_logical_replication_workers: Optional[int] = None
234+
max_parallel_workers: Optional[int] = None
235+
max_parallel_workers_per_gather: Optional[int] = None
236+
max_pred_locks_per_transaction: Optional[int] = None
237+
max_prepared_transactions: Optional[int] = None
238+
max_replication_slots: Optional[int] = None
239+
max_slot_wal_keep_size: Optional[int] = None
240+
max_stack_depth: Optional[int] = None
241+
max_standby_archive_delay: Optional[int] = None
242+
max_standby_streaming_delay: Optional[int] = None
243+
max_wal_senders: Optional[int] = None
244+
max_worker_processes: Optional[int] = None
245+
password_encryption: Optional[str] = None
246+
pg_partman_bgw_interval: Optional[int] = None
247+
pg_partman_bgw_role: Optional[str] = None
248+
pg_stat_monitor_pgsm_enable_query_plan: Optional[bool] = None
249+
pg_stat_monitor_pgsm_max_buckets: Optional[int] = None
250+
pg_stat_statements_track: Optional[str] = None
251+
temp_file_limit: Optional[int] = None
252+
timezone: Optional[str] = None
253+
track_activity_query_size: Optional[int] = None
254+
track_commit_timestamp: Optional[str] = None
255+
track_functions: Optional[str] = None
256+
track_io_timing: Optional[str] = None
257+
wal_sender_timeout: Optional[int] = None
258+
wal_writer_delay: Optional[int] = None
259+
260+
261+
@dataclass
262+
class PostgreSQLDatabaseConfigOptions(JSONObject):
263+
"""
264+
PostgreSQLDatabaseConfigOptions is used to specify
265+
a PostgreSQL Database Cluster's configuration options during its creation.
266+
"""
267+
268+
pg: Optional[PostgreSQLDatabasePGConfigOptions] = None
269+
pg_stat_monitor_enable: Optional[bool] = None
270+
pglookout: Optional[PostgreSQLDatabasePGLookoutConfigOptions] = None
271+
service_log: Optional[bool] = None
272+
shared_buffers_percentage: Optional[float] = None
273+
synchronous_replication: Optional[str] = None
274+
work_mem: Optional[int] = None
275+
276+
131277
class MySQLDatabase(Base):
132278
"""
133279
An accessible Managed MySQL Database.
@@ -158,6 +304,7 @@ class MySQLDatabase(Base):
158304
"updated": Property(volatile=True, is_datetime=True),
159305
"updates": Property(mutable=True),
160306
"version": Property(),
307+
"engine_config": Property(mutable=True),
161308
}
162309

163310
@property
@@ -321,6 +468,7 @@ class PostgreSQLDatabase(Base):
321468
"updated": Property(volatile=True, is_datetime=True),
322469
"updates": Property(mutable=True),
323470
"version": Property(),
471+
"engine_config": Property(mutable=True),
324472
}
325473

326474
@property

0 commit comments

Comments
 (0)