mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
guess_mac checks for existing dhcp_file
This commit is contained in:
parent
16510dee59
commit
510e0e6ee5
1 changed files with 10 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import time
|
||||
import json
|
||||
import socket
|
||||
|
@ -676,14 +677,15 @@ def inst_graph(request, compute_id, vname):
|
|||
def guess_mac_address(request, vname):
|
||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||
data = { 'vname': vname, 'mac': '52:54:00:' }
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
for line in f:
|
||||
if "host %s." % vname in line:
|
||||
name_found = True
|
||||
if name_found and "hardware ethernet" in line:
|
||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||
break
|
||||
if os.path.isfile(dhcp_file):
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
for line in f:
|
||||
if "host %s." % vname in line:
|
||||
name_found = True
|
||||
if name_found and "hardware ethernet" in line:
|
||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||
break
|
||||
return HttpResponse(json.dumps(data));
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue