Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6998: dhcp.py fix datetime to be zone aware, add fix for hostname #4277

Open
wants to merge 2 commits into
base: current
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions src/op_mode/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _get_raw_server_leases(family='inet', pool=None, sorted=None, state=[], orig
lifetime = lease['valid-lft']
expiry = (lease['cltt'] + lifetime)

lease['start_timestamp'] = datetime.fromtimestamp(expiry - lifetime, timezone.utc)
lease['start_timestamp'] = datetime.fromtimestamp(lease['cltt'], timezone.utc)
lease['expire_timestamp'] = datetime.fromtimestamp(expiry, timezone.utc) if expiry else None

data_lease = {}
Expand All @@ -113,7 +113,7 @@ def _get_raw_server_leases(family='inet', pool=None, sorted=None, state=[], orig
data_lease['origin'] = 'local' # TODO: Determine remote in HA
data_lease['hostname'] = lease.get('hostname', '-')
# remove trailing dot to ensure consistency for `vyos-hostsd-client`
if data_lease['hostname'][-1] == '.':
if len(data_lease['hostname']) > 1 and data_lease['hostname'][-1] == '.':
data_lease['hostname'] = data_lease['hostname'][:-1]

if family == 'inet':
Expand Down Expand Up @@ -170,10 +170,8 @@ def _get_formatted_server_leases(raw_data, family='inet'):
ipaddr = lease.get('ip')
hw_addr = lease.get('mac')
state = lease.get('state')
start = lease.get('start')
start = _utc_to_local(start).strftime('%Y/%m/%d %H:%M:%S')
end = lease.get('end')
end = _utc_to_local(end).strftime('%Y/%m/%d %H:%M:%S') if end else '-'
start = datetime.fromtimestamp(lease.get('start'), timezone.utc)
end = datetime.fromtimestamp(lease.get('end'), timezone.utc) if lease.get('end') else '-'
remain = lease.get('remaining')
pool = lease.get('pool')
hostname = lease.get('hostname')
Expand All @@ -187,10 +185,8 @@ def _get_formatted_server_leases(raw_data, family='inet'):
for lease in raw_data:
ipaddr = lease.get('ip')
state = lease.get('state')
start = lease.get('last_communication')
start = _utc_to_local(start).strftime('%Y/%m/%d %H:%M:%S')
end = lease.get('end')
end = _utc_to_local(end).strftime('%Y/%m/%d %H:%M:%S')
start = datetime.fromtimestamp(lease.get('last_communication'), timezone.utc)
end = datetime.fromtimestamp(lease.get('end'), timezone.utc) if lease.get('end') else '-'
remain = lease.get('remaining')
lease_type = lease.get('type')
pool = lease.get('pool')
Expand Down
Loading