Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions linode_api4/groups/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from linode_api4.objects import (
Database,
DatabaseEngine,
DatabasePrivateNetwork,
DatabaseType,
MySQLDatabase,
PostgreSQLDatabase,
Expand Down Expand Up @@ -126,6 +127,7 @@ def mysql_create(
engine,
ltype,
engine_config: Union[MySQLDatabaseConfigOptions, Dict[str, Any]] = None,
private_network: Union[DatabasePrivateNetwork, Dict[str, Any]] = None,
**kwargs,
):
"""
Expand Down Expand Up @@ -159,6 +161,8 @@ def mysql_create(
:type ltype: str or Type
:param engine_config: The configuration options for this MySQL cluster
:type engine_config: Dict[str, Any] or MySQLDatabaseConfigOptions
:param private_network: The private network settings to use for this cluster
:type private_network: Dict[str, Any] or DatabasePrivateNetwork
"""

params = {
Expand All @@ -167,6 +171,7 @@ def mysql_create(
"engine": engine,
"type": ltype,
"engine_config": engine_config,
"private_network": private_network,
}
params.update(kwargs)

Expand Down Expand Up @@ -262,6 +267,7 @@ def postgresql_create(
engine_config: Union[
PostgreSQLDatabaseConfigOptions, Dict[str, Any]
] = None,
private_network: Union[DatabasePrivateNetwork, Dict[str, Any]] = None,
**kwargs,
):
"""
Expand Down Expand Up @@ -295,6 +301,8 @@ def postgresql_create(
:type ltype: str or Type
:param engine_config: The configuration options for this PostgreSQL cluster
:type engine_config: Dict[str, Any] or PostgreSQLDatabaseConfigOptions
:param private_network: The private network settings to use for this cluster
:type private_network: Dict[str, Any] or DatabasePrivateNetwork
"""

params = {
Expand All @@ -303,6 +311,7 @@ def postgresql_create(
"engine": engine,
"type": ltype,
"engine_config": engine_config,
"private_network": private_network,
}
params.update(kwargs)

Expand Down
21 changes: 21 additions & 0 deletions linode_api4/objects/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def invalidate(self):
Base.invalidate(self)


@dataclass
class DatabasePrivateNetwork(JSONObject):
"""
DatabasePrivateNetwork is used to specify
a Database Cluster's private network settings during its creation.
"""

vpc_id: Optional[int] = None
subnet_id: Optional[int] = None
public_access: Optional[bool] = None


@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
Expand Down Expand Up @@ -304,6 +316,9 @@ class MySQLDatabase(Base):
"engine_config": Property(
mutable=True, json_object=MySQLDatabaseConfigOptions
),
"private_network": Property(
mutable=True, json_object=DatabasePrivateNetwork, nullable=True
),
}

@property
Expand Down Expand Up @@ -470,6 +485,9 @@ class PostgreSQLDatabase(Base):
"engine_config": Property(
mutable=True, json_object=PostgreSQLDatabaseConfigOptions
),
"private_network": Property(
mutable=True, json_object=DatabasePrivateNetwork, nullable=True
),
}

@property
Expand Down Expand Up @@ -636,6 +654,9 @@ class Database(Base):
"updated": Property(),
"updates": Property(),
"version": Property(),
"private_network": Property(
json_object=DatabasePrivateNetwork, nullable=True
),
}

@property
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/databases_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
"hour_of_day": 0,
"week_of_month": null
},
"version": "8.0.26"
"version": "8.0.26",
"private_network": {
"vpc_id": 1234,
"subnet_id": 5678,
"public_access": true
}
}
],
"page": 1,
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/databases_mysql_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
"tmp_table_size": 16777216,
"wait_timeout": 28800
}
},
"private_network": {
"vpc_id": 1234,
"subnet_id": 5678,
"public_access": true
}
}
],
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/databases_postgresql_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
},
"shared_buffers_percentage": 41.5,
"work_mem": 4
},
"private_network": {
"vpc_id": 1234,
"subnet_id": 5678,
"public_access": true
}
}
],
Expand Down
11 changes: 11 additions & 0 deletions test/unit/groups/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def test_get_databases(self):
self.assertEqual(dbs[0].region, "us-east")
self.assertEqual(dbs[0].updates.duration, 3)
self.assertEqual(dbs[0].version, "8.0.26")
self.assertEqual(dbs[0].private_network.vpc_id, 1234)
self.assertEqual(dbs[0].private_network.subnet_id, 5678)
self.assertEqual(dbs[0].private_network.public_access, True)

def test_database_instance(self):
"""
Expand Down Expand Up @@ -1338,6 +1341,10 @@ def test_get_mysql_instances(self):
self.assertEqual(dbs[0].engine_config.mysql.tmp_table_size, 16777216)
self.assertEqual(dbs[0].engine_config.mysql.wait_timeout, 28800)

self.assertEqual(dbs[0].private_network.vpc_id, 1234)
self.assertEqual(dbs[0].private_network.subnet_id, 5678)
self.assertEqual(dbs[0].private_network.public_access, True)

def test_get_postgresql_instances(self):
"""
Test that postgresql instances can be retrieved properly
Expand Down Expand Up @@ -1452,3 +1459,7 @@ def test_get_postgresql_instances(self):
self.assertEqual(dbs[0].engine_config.pg.track_io_timing, "off")
self.assertEqual(dbs[0].engine_config.pg.wal_sender_timeout, 60000)
self.assertEqual(dbs[0].engine_config.pg.wal_writer_delay, 50)

self.assertEqual(dbs[0].private_network.vpc_id, 1234)
self.assertEqual(dbs[0].private_network.subnet_id, 5678)
self.assertEqual(dbs[0].private_network.public_access, True)
46 changes: 46 additions & 0 deletions test/unit/objects/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from test.unit.base import ClientBaseCase

from linode_api4 import (
DatabasePrivateNetwork,
MySQLDatabaseConfigMySQLOptions,
MySQLDatabaseConfigOptions,
PostgreSQLDatabase,
Expand Down Expand Up @@ -41,6 +42,11 @@ def test_create(self):
),
binlog_retention_period=200,
),
private_network=DatabasePrivateNetwork(
vpc_id=1234,
subnet_id=5678,
public_access=True,
),
)
except Exception as e:
logger.warning(
Expand All @@ -61,6 +67,12 @@ def test_create(self):
m.call_data["engine_config"]["binlog_retention_period"], 200
)

self.assertEqual(m.call_data["private_network"]["vpc_id"], 1234)
self.assertEqual(m.call_data["private_network"]["subnet_id"], 5678)
self.assertEqual(
m.call_data["private_network"]["public_access"], True
)

def test_update(self):
"""
Test that the MySQL database can be updated
Expand All @@ -78,6 +90,11 @@ def test_update(self):
mysql=MySQLDatabaseConfigMySQLOptions(connect_timeout=20),
binlog_retention_period=200,
)
db.private_network = DatabasePrivateNetwork(
vpc_id=1234,
subnet_id=5678,
public_access=True,
)

db.save()

Expand All @@ -93,6 +110,12 @@ def test_update(self):
m.call_data["engine_config"]["binlog_retention_period"], 200
)

self.assertEqual(m.call_data["private_network"]["vpc_id"], 1234)
self.assertEqual(m.call_data["private_network"]["subnet_id"], 5678)
self.assertEqual(
m.call_data["private_network"]["public_access"], True
)

def test_list_backups(self):
"""
Test that MySQL backups list properly
Expand Down Expand Up @@ -259,6 +282,11 @@ def test_create(self):
),
work_mem=4,
),
private_network=DatabasePrivateNetwork(
vpc_id=1234,
subnet_id=5678,
public_access=True,
),
)
except Exception:
pass
Expand Down Expand Up @@ -302,6 +330,12 @@ def test_create(self):
)
self.assertEqual(m.call_data["engine_config"]["work_mem"], 4)

self.assertEqual(m.call_data["private_network"]["vpc_id"], 1234)
self.assertEqual(m.call_data["private_network"]["subnet_id"], 5678)
self.assertEqual(
m.call_data["private_network"]["public_access"], True
)

def test_update(self):
"""
Test that the PostgreSQL database can be updated
Expand All @@ -322,6 +356,12 @@ def test_update(self):
work_mem=4,
)

db.private_network = DatabasePrivateNetwork(
vpc_id=1234,
subnet_id=5678,
public_access=True,
)

db.save()

self.assertEqual(m.method, "put")
Expand All @@ -337,6 +377,12 @@ def test_update(self):
)
self.assertEqual(m.call_data["engine_config"]["work_mem"], 4)

self.assertEqual(m.call_data["private_network"]["vpc_id"], 1234)
self.assertEqual(m.call_data["private_network"]["subnet_id"], 5678)
self.assertEqual(
m.call_data["private_network"]["public_access"], True
)

def test_list_backups(self):
"""
Test that PostgreSQL backups list properly
Expand Down