From 510e0e6ee586629a7fae2c9375e648dcd0dcfa4a Mon Sep 17 00:00:00 2001 From: Jan Krcmar Date: Thu, 11 Feb 2016 14:48:41 +0100 Subject: [PATCH] guess_mac checks for existing dhcp_file --- instances/views.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/instances/views.py b/instances/views.py index 361c1c2..f69f356 100644 --- a/instances/views.py +++ b/instances/views.py @@ -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