Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devplayer0 committed Sep 22, 2019
1 parent 7afa8ef commit 866bb1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions net-dhcp/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,28 @@ def create_endpoint():
.set('state', 'up')
.commit())

time.sleep(0.5)
if_container = (ndb.interfaces[if_container]
.set('state', 'up')
.commit())
(bridge
.add_port(if_host)
.commit())
try:
start = time.time()
while isinstance(if_container, str) and time.time() - start < 10:
try:
if_container = (ndb.interfaces[if_container]
.set('state', 'up')
.commit())
except KeyError:
time.sleep(0.5)
if isinstance(if_container, str):
raise NetDhcpError(f'timed out waiting for {if_container} to appear in host')

res_iface = {
'MacAddress': '',
'Address': '',
'AddressIPv6': ''
}
(bridge
.add_port(if_host)
.commit())

res_iface = {
'MacAddress': '',
'Address': '',
'AddressIPv6': ''
}

try:
if 'MacAddress' in req_iface and req_iface['MacAddress']:
(if_container
.set('address', req_iface['MacAddress'])
Expand Down Expand Up @@ -199,9 +206,10 @@ def try_addr(type_):
except Exception as e:
logger.exception(e)

(bridge
.del_port(if_host)
.commit())
if not isinstance(if_container, str):
(bridge
.del_port(if_host)
.commit())
(if_host
.remove()
.commit())
Expand Down
2 changes: 1 addition & 1 deletion net-dhcp/udhcpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, iface, v6=False, once=False, hostname=None, event_listener=No
self._event_queue = posix_ipc.MessageQueue(f'/udhcpc{self._suffix}_{iface["address"].replace(":", "_")}', \
flags=os.O_CREAT | os.O_EXCL, max_messages=2, max_message_size=1024)
self.proc = Popen(cmdline, env={'EVENT_QUEUE': self._event_queue.name}, stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, preexec_fn=close_fds)
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if hostname:
logger.debug('[udhcpc%s#%d] using hostname "%s"', self._suffix, self.proc.pid, hostname)

Expand Down

0 comments on commit 866bb1b

Please sign in to comment.