mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
DS refactor, fixes/optimizations
This commit is contained in:
@@ -12,8 +12,7 @@
|
||||
## GNU General Public License for more details.
|
||||
|
||||
|
||||
from tabulate import tabulate
|
||||
from mktxp.cli.output.base_out import BaseOutputProcessor
|
||||
from mktxp.processor.output import BaseOutputProcessor
|
||||
from mktxp.datasource.dhcp_ds import DHCPMetricsDataSource
|
||||
|
||||
|
||||
@@ -35,17 +34,22 @@ class DHCPOutput:
|
||||
dhcp_by_server[server].append(dhcp_lease_record)
|
||||
else:
|
||||
dhcp_by_server[server] = [dhcp_lease_record]
|
||||
|
||||
output_entry = BaseOutputProcessor.OutputDHCPEntry
|
||||
output_table = BaseOutputProcessor.output_table(output_entry)
|
||||
|
||||
num_records = 0
|
||||
output_table = []
|
||||
output_records = 0
|
||||
lease_records = len(dhcp_lease_records)
|
||||
for key in dhcp_by_server.keys():
|
||||
for record in dhcp_by_server[key]:
|
||||
record['host_name'] = BaseOutputProcessor.dhcp_name(router_entry, record, drop_comment = True)
|
||||
output_table.append(BaseOutputProcessor.OutputDHCPEntry(**record))
|
||||
num_records += 1
|
||||
output_table.append({})
|
||||
print()
|
||||
print(tabulate(output_table, headers = "keys", tablefmt="github"))
|
||||
print(tabulate([{0:'DHCP Clients:', 1:num_records}], tablefmt="text"))
|
||||
|
||||
output_table.add_row(output_entry(**record))
|
||||
output_records += 1
|
||||
if output_records < lease_records:
|
||||
output_table.add_row(output_entry())
|
||||
|
||||
print (output_table.draw())
|
||||
|
||||
for server in dhcp_by_server.keys():
|
||||
print(f'{server} clients: {len(dhcp_by_server[server])}')
|
||||
print(f'Total DHCP clients: {output_records}', '\n')
|
||||
|
||||
Reference in New Issue
Block a user