1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

instance/clone added Guess mac address button. search for mac address of Clone Name via ajax request. Currently scans only local dhcpd configuration file.

This commit is contained in:
Jan Krcmar 2016-02-08 12:28:52 +01:00
parent 33916c6a82
commit 39f3c9e12b
3 changed files with 26 additions and 0 deletions

View file

@ -730,6 +730,8 @@
<div class="col-sm-4"> <div class="col-sm-4">
<button type="button" class="btn btn-sm btn-success pull-left" name="random-mac-{{ forloop.counter0 }}" <button type="button" class="btn btn-sm btn-success pull-left" name="random-mac-{{ forloop.counter0 }}"
onclick="random_mac({{ forloop.counter0 }})" style="margin-top: 2px;">{% trans "Random" %}</button> onclick="random_mac({{ forloop.counter0 }})" style="margin-top: 2px;">{% trans "Random" %}</button>
<button type="button" class="btn btn-sm btn-success pull-left" name="guess-mac-{{ forloop.counter0 }}"
onclick="guess_mac_address({{ forloop.counter0 }})" style="margin-top: 2px;">{% trans "Guess" %}</button>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
@ -964,6 +966,14 @@
} }
} }
</script> </script>
<script>
function guess_mac_address(net) {
new_vname = $('#clone_name').val();
$.getJSON('/instance/guess_mac_address/' + new_vname + '/', function(data) {
$('input[name="net-'+net+'"]').val(data['mac']);
});
}
</script>
<script> <script>
function update_clone_disk_name(new_vname) { function update_clone_disk_name(new_vname) {
vname = '{{ vname }}-clone'; vname = '{{ vname }}-clone';

View file

@ -8,4 +8,6 @@ urlpatterns = [
views.inst_graph, name='inst_graph'), views.inst_graph, name='inst_graph'),
url(r'^status/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', url(r'^status/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$',
views.inst_status, name='inst_status'), views.inst_status, name='inst_status'),
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
views.guess_mac_address, name='guess_mac_address'),
] ]

View file

@ -666,3 +666,17 @@ def inst_graph(request, compute_id, vname):
response.write(data) response.write(data)
return response return response
@login_required
def guess_mac_address(request, vname):
dhcp_file = '/srv/webvirtcloud/dhcpd.hype.ipv4.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
return HttpResponse(json.dumps(data));