Skip to content

Commit

Permalink
Fix MAC address support for Docker containers
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Sep 18, 2024
1 parent 3214f52 commit a1666dd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gns3server/api/routes/compute/docker_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def create_docker_node(project_id: UUID, node_data: schemas.DockerCreate)
start_command=node_data.get("start_command"),
environment=node_data.get("environment"),
adapters=node_data.get("adapters"),
mac_address=node_data.get("mac_address"),
console=node_data.get("console"),
console_type=node_data.get("console_type"),
console_resolution=node_data.get("console_resolution", "1024x768"),
Expand Down Expand Up @@ -124,6 +125,8 @@ async def update_docker_node(node_data: schemas.DockerUpdate, node: DockerVM = D
"start_command",
"environment",
"adapters",
"mac_address",
"custom_adapters",
"extra_hosts",
"extra_volumes",
"memory",
Expand Down
4 changes: 2 additions & 2 deletions gns3server/compute/docker/docker_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
aux=None,
start_command=None,
adapters=None,
mac_address="",
environment=None,
console_type="telnet",
aux_type="none",
Expand Down Expand Up @@ -106,7 +107,6 @@ def __init__(
self._environment = environment
self._cid = None
self._ethernet_adapters = []
self._mac_address = ""
self._temporary_directory = None
self._telnet_servers = []
self._vnc_process = None
Expand All @@ -132,7 +132,7 @@ def __init__(
else:
self.adapters = adapters

self.mac_address = "" # this will generate a MAC address
self.mac_address = mac_address

log.debug(
"{module}: {name} [{image}] initialized.".format(
Expand Down
1 change: 1 addition & 0 deletions gns3server/db/models/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class DockerTemplate(Template):
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
image = Column(String)
adapters = Column(Integer)
mac_address = Column(String)
start_command = Column(String)
environment = Column(String)
console_type = Column(String)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""add mac_address field in Docker templates table
Revision ID: 9a5292aa4389
Revises: 7ceeddd9c9a8
Create Date: 2024-09-18 17:52:53.429522
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9a5292aa4389'
down_revision = '7ceeddd9c9a8'
branch_labels = None
depends_on = None


def upgrade() -> None:

op.add_column('docker_templates', sa.Column('mac_address', sa.String()))


def downgrade() -> None:

op.drop_column('docker_templates', 'mac_address')

1 change: 1 addition & 0 deletions gns3server/schemas/compute/docker_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DockerBase(BaseModel):
usage: Optional[str] = Field(None, description="How to use the Docker container")
start_command: Optional[str] = Field(None, description="Docker CMD entry")
adapters: Optional[int] = Field(None, ge=0, le=99, description="Number of adapters")
mac_address: Optional[str] = Field(None, description="Base MAC address", pattern="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$")
environment: Optional[str] = Field(None, description="Docker environment variables")
extra_hosts: Optional[str] = Field(None, description="Docker extra hosts (added to /etc/hosts)")
extra_volumes: Optional[List[str]] = Field(None, description="Additional directories to make persistent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DockerTemplate(TemplateBase):
symbol: Optional[str] = "docker_guest"
image: str = Field(..., description="Docker image name")
adapters: Optional[int] = Field(1, ge=0, le=100, description="Number of adapters")
mac_address: Optional[str] = Field("", description="Base MAC address", pattern="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$|^$")
start_command: Optional[str] = Field("", description="Docker CMD entry")
environment: Optional[str] = Field("", description="Docker environment variables")
console_type: Optional[ConsoleType] = Field("telnet", description="Console type")
Expand Down

0 comments on commit a1666dd

Please sign in to comment.