Skip to content

Commit

Permalink
Merge pull request #3 from sandwichcloud/gatewaydns
Browse files Browse the repository at this point in the history
add gateway and dns servers to network
  • Loading branch information
rmb938 authored Nov 4, 2017
2 parents 2a7ae35 + f231dd4 commit b0dd6b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def upgrade():
sa.Column('current_task_id', sau.UUIDType, sa.ForeignKey('tasks.id')),

sa.Column('port_group', sa.String, unique=True, nullable=False),
sa.Column('gateway', sau.IPAddressType, nullable=False),
sa.Column('dns_servers', sa.ARRAY(sau.IPAddressType), nullable=False),

sa.Column('state', sa.Enum(NetworkState), default=NetworkState.CREATING, nullable=False),

Expand Down
11 changes: 11 additions & 0 deletions ingredients_db/models/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

from sqlalchemy import Column, String, Enum, text
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy_utils import UUIDType, generic_repr, IPAddressType, ArrowType

from ingredients_db.database import Base
Expand All @@ -27,6 +28,8 @@ class Network(Base, TaskMixin):
name = Column(String, unique=True, nullable=False)

port_group = Column(String, unique=True, nullable=False)
gateway = Column(IPAddressType, nullable=False)
dns_servers = Column(ARRAY(IPAddressType), nullable=False)

state = Column(Enum(NetworkState), default=NetworkState.CREATING, nullable=False)

Expand All @@ -47,6 +50,14 @@ def next_free_address(self, session) -> Optional[ipaddress.IPv4Address]:
start_host = ipaddress.IPv4Address(self.pool_start)
end_host = ipaddress.IPv4Address(self.pool_end)

if host == self.gateway:
# Skip the gateway
continue

if host in self.dns_servers:
# Skip dns servers if in range
continue

if start_host <= host <= end_host:
ip_addresses.append(host)

Expand Down

0 comments on commit b0dd6b1

Please sign in to comment.