Skip to content

Commit 42214ac

Browse files
Added support for DB Configurable Params features
1 parent cf04ca6 commit 42214ac

File tree

2 files changed

+293
-2
lines changed

2 files changed

+293
-2
lines changed

linode_api4/groups/database.py

Lines changed: 150 additions & 2 deletions
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

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
14
from deprecated import deprecated
25

6+
from linode_api4 import JSONObject
37
from linode_api4.objects import Base, DerivedBase, MappedObject, Property
48

59

@@ -128,6 +132,143 @@ class PostgreSQLDatabaseBackup(DatabaseBackup):
128132
api_endpoint = "/databases/postgresql/instances/{database_id}/backups/{id}"
129133

130134

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

163305
@property
@@ -321,6 +463,7 @@ class PostgreSQLDatabase(Base):
321463
"updated": Property(volatile=True, is_datetime=True),
322464
"updates": Property(mutable=True),
323465
"version": Property(),
466+
"engine_config": Property(mutable=True),
324467
}
325468

326469
@property

0 commit comments

Comments
 (0)