mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +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:
parent
33916c6a82
commit
39f3c9e12b
3 changed files with 26 additions and 0 deletions
|
@ -730,6 +730,8 @@
|
|||
<div class="col-sm-4">
|
||||
<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>
|
||||
<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>
|
||||
{% endfor %}
|
||||
|
@ -964,6 +966,14 @@
|
|||
}
|
||||
}
|
||||
</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>
|
||||
function update_clone_disk_name(new_vname) {
|
||||
vname = '{{ vname }}-clone';
|
||||
|
|
|
@ -8,4 +8,6 @@ urlpatterns = [
|
|||
views.inst_graph, name='inst_graph'),
|
||||
url(r'^status/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$',
|
||||
views.inst_status, name='inst_status'),
|
||||
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
|
||||
views.guess_mac_address, name='guess_mac_address'),
|
||||
]
|
||||
|
|
|
@ -666,3 +666,17 @@ def inst_graph(request, compute_id, vname):
|
|||
|
||||
response.write(data)
|
||||
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));
|
||||
|
|
Loading…
Reference in a new issue