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

instance/settings: inputs renamed according to action type (net -> clone-net-mac, net -> net-mac)

instance/network: correct multiple interfaces handling, add mac handling
This commit is contained in:
Jan Krcmar 2016-02-10 17:52:50 +01:00
parent 71c6161291
commit 96982ce58b
3 changed files with 11 additions and 13 deletions

View file

@ -674,16 +674,12 @@
{% for network in networks %} {% for network in networks %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}</label> <label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}</label>
<div class="col-sm-3"> <div class="col-sm-4">
<input type="text" class="form-control" name="net-{{ forloop.counter0 }}" value="{{ network.mac }}"/> <input type="text" class="form-control" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}"/> <input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}"/>
</div> </div>
<div class="col-sm-1">
<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 MAC" %}</button>
</div>
</div> </div>
{% endfor %} {% endfor %}
{% ifequal status 5 %} {% ifequal status 5 %}
@ -725,7 +721,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }} ({{ network.nic }})</label> <label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }} ({{ network.nic }})</label>
<div class="col-sm-4"> <div class="col-sm-4">
<input type="text" class="form-control" name="net-{{ forloop.counter0 }}" value="{{ network.mac }}"/> <input type="text" class="form-control" name="clone-net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div> </div>
<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 }}"
@ -954,7 +950,7 @@
macAddress+=hexDigits.charAt(Math.round(Math.random()*16)); macAddress+=hexDigits.charAt(Math.round(Math.random()*16));
if (i != 2) macAddress+=":"; if (i != 2) macAddress+=":";
} }
$('input[name="net-'+net+'"]').val(macAddress); $('input[name="clone-net-mac-'+net+'"]').val(macAddress);
}; };
</script> </script>
<script> <script>
@ -970,7 +966,7 @@
function guess_mac_address(net) { function guess_mac_address(net) {
new_vname = $('#clone_name').val(); new_vname = $('#clone_name').val();
$.getJSON('/instance/guess_mac_address/' + new_vname + '/', function(data) { $.getJSON('/instance/guess_mac_address/' + new_vname + '/', function(data) {
$('input[name="net-'+net+'"]').val(data['mac']); $('input[name="clone-net-mac-'+net+'"]').val(data['mac']);
}); });
} }
</script> </script>

View file

@ -511,7 +511,7 @@ def instance(request, compute_id, vname):
network_data = {} network_data = {}
for post in request.POST: for post in request.POST:
if 'net-' in post: if post.startswith('net-'):
network_data[post] = request.POST.get(post, '') network_data[post] = request.POST.get(post, '')
conn.change_network(network_data) conn.change_network(network_data)

View file

@ -632,7 +632,7 @@ class wvmInstance(wvmConnect):
for num, net in enumerate(tree.findall('devices/interface')): for num, net in enumerate(tree.findall('devices/interface')):
elm = net.find('mac') elm = net.find('mac')
mac_address = self.fix_mac(clone_data['net-' + str(num)]) mac_address = self.fix_mac(clone_data['clone-net-mac-' + str(num)])
elm.set('address', mac_address) elm.set('address', mac_address)
for disk in tree.findall('devices/disk'): for disk in tree.findall('devices/disk'):
@ -693,10 +693,12 @@ class wvmInstance(wvmConnect):
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE) xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml) tree = ElementTree.fromstring(xml)
for interface in tree.findall('devices/interface'): for num, interface in enumerate(tree.findall('devices/interface')):
if interface.get('type') == 'bridge': if interface.get('type') == 'bridge':
source = interface.find('mac')
source.set('address', network_data['net-mac-' + str(num)])
source = interface.find('source') source = interface.find('source')
source.set('bridge', network_data['net-source-0']) source.set('bridge', network_data['net-source-' + str(num)])
new_xml = ElementTree.tostring(tree) new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml) self._defineXML(new_xml)