diff --git a/src/middlewared/middlewared/alembic/versions/24.10/2024-08-30_20-33_docker_addr_pool.py b/src/middlewared/middlewared/alembic/versions/24.10/2024-08-30_20-33_docker_addr_pool.py new file mode 100644 index 0000000000000..e29eae389b628 --- /dev/null +++ b/src/middlewared/middlewared/alembic/versions/24.10/2024-08-30_20-33_docker_addr_pool.py @@ -0,0 +1,32 @@ +""" +Add docker cidr subnet + +Revision ID: 98c1ebde0079 +Revises: 7b13df980355 +Create Date: 2024-08-30 20:33:47.996994+00:00 +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '98c1ebde0079' +down_revision = '7b13df980355' +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table('services_docker', schema=None) as batch_op: + batch_op.add_column( + sa.Column( + 'address_pools', + sa.TEXT(), + nullable=False, + server_default='[{"base": "172.30.0.0/16", "size": 27}, {"base": "172.31.0.0/16", "size": 27}]' + ) + ) + + +def downgrade(): + pass diff --git a/src/middlewared/middlewared/plugins/docker/update.py b/src/middlewared/middlewared/plugins/docker/update.py index b1b0ec6e9a2b9..d4d0d455375bb 100644 --- a/src/middlewared/middlewared/plugins/docker/update.py +++ b/src/middlewared/middlewared/plugins/docker/update.py @@ -1,8 +1,9 @@ import middlewared.sqlalchemy as sa -from middlewared.schema import accepts, Bool, Dict, Int, Patch, Str, ValidationErrors +from middlewared.schema import accepts, Bool, Dict, Int, IPAddr, List, Patch, Str, ValidationErrors from middlewared.service import CallError, ConfigService, job, private, returns from middlewared.utils.zfs import query_imported_fast_impl +from middlewared.validators import Range from .state_utils import Status from .utils import applications_ds_name @@ -15,6 +16,10 @@ class DockerModel(sa.Model): pool = sa.Column(sa.String(255), default=None, nullable=True) enable_image_updates = sa.Column(sa.Boolean(), default=True) nvidia = sa.Column(sa.Boolean(), default=False) + address_pools = sa.Column(sa.JSON(list), default=[ + {'base': '172.30.0.0/16', 'size': 27}, + {'base': '172.31.0.0/16', 'size': 27} + ]) class DockerService(ConfigService): @@ -32,6 +37,13 @@ class Config: Str('dataset', required=True), Str('pool', required=True, null=True), Bool('nvidia', required=True), + List('address_pools', items=[ + Dict( + 'address_pool', + IPAddr('base', cidr=True), + Int('size', validators=[Range(min_=0, max_=32)]) + ) + ]), update=True, )