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

add MAC address inputs for instance create methods

This commit is contained in:
catborise 2021-12-03 16:41:50 +03:00
parent 61d822efaa
commit c354393685
3 changed files with 46 additions and 14 deletions

View file

@ -178,6 +178,12 @@
</div> </div>
</div> </div>
<div class="collapse" id="flavAddCollapse"> <div class="collapse" id="flavAddCollapse">
<div class="row">
<label class="col-sm-4 col-form-label">{% trans "MAC" %}</label>
<div class="col-sm-7">
<input type="text" class="form-control" name="mac" maxlength="17" value="{{ mac_auto }}" required pattern="[a-zA-Z0-9:]+">
</div>
</div>
<div class="row"> <div class="row">
<label class="col-sm-4 col-form-label">{% trans "NWFilter" %}</label> <label class="col-sm-4 col-form-label">{% trans "NWFilter" %}</label>
<div class="col-sm-7"> <div class="col-sm-7">
@ -200,12 +206,6 @@
</select> </select>
</div> </div>
</div> </div>
<div class="row">
<label class="col-sm-4 col-form-label">{% trans "MAC" %}</label>
<div class="col-sm-7">
<input type="text" class="form-control" name="mac" maxlength="17" value="{{ mac_auto }}" required pattern="[a-zA-Z0-9:]+">
</div>
</div>
{% if dom_caps.graphics_support == 'yes' %} {% if dom_caps.graphics_support == 'yes' %}
<div class="row"> <div class="row">
<label class="col-sm-4 col-form-label">{% trans "Graphics" %}</label> <label class="col-sm-4 col-form-label">{% trans "Graphics" %}</label>
@ -396,6 +396,7 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<input id="mac" type="hidden" name="mac" value=""/>
</div> </div>
<div class="row"> <div class="row">
<label class="col-sm-3 col-form-label">{% trans "Advanced" %}</label> <label class="col-sm-3 col-form-label">{% trans "Advanced" %}</label>
@ -601,14 +602,17 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<label class="col-sm-3 col-form-label">{% trans "Network" %}</label> <label class="col-sm-3 col-form-label">{% trans "Network/MAC" %}</label>
<div class="col-sm-7"> <div class="col-sm-3">
<select class="form-select" name="networks"> <select class="form-select" name="networks">
{% for network in networks %} {% for network in networks %}
<option value="{{ network }}">{{ network }}</option> <option value="{{ network }}">{{ network }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="col-sm-4">
<input type="text" class="form-control" name="mac" maxlength="17" value="{{ mac_auto }}" required pattern="[a-zA-Z0-9:]+">
</div>
</div> </div>
<div class="row"> <div class="row">
<label class="col-sm-3 col-form-label">{% trans "Advanced" %}</label> <label class="col-sm-3 col-form-label">{% trans "Advanced" %}</label>
@ -810,21 +814,39 @@
let input_value = toggleValue($('#networks').val(), element.val(), checked); let input_value = toggleValue($('#networks').val(), element.val(), checked);
$('#networks').val(input_value); $('#networks').val(input_value);
let selected_list_html = ''; let selected_list_html = '';
let counter = 0; mac_array = [];
net_counter = 0;
if (input_value != '') { if (input_value != '') {
$.each(input_value.split(','), function (index, value) { $.each(input_value.split(','), function (index, value) {
let li = '<li>eth' + counter + let li = '<li><input type="text" class="input-xs" name="mac'+ net_counter +'" maxlength="17" required pattern="[a-zA-Z0-9:]+" onchange="populate_mac(' + net_counter +')">' +
' eth' + net_counter +
' -> ' + value + ' ' + ' -> ' + value + ' ' +
'<a class="btn-link float-end" onclick="$(\'#network-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a></li>'; '<a class="btn-link float-end" onclick="$(\'#network-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a></li>';
random_mac(net_counter);
selected_list_html += li; selected_list_html += li;
counter++; net_counter++;
}); });
} }
$('#net-list').html(selected_list_html); $('#net-list').html(selected_list_html);
} }
}); });
}); });
var mac_array = [];
function random_mac(c) {
$.getJSON("{% url 'instances:random_mac_address' %}", function (data) {
mac_array[c] = data['mac'];
$('input[name="mac' + c + '"').val(data['mac']);
populate_mac(c);
});
}
function populate_mac(c){
mac_array[c] = $('input[name="mac' + c + '"').val();
$('input[name="mac"').val(mac_array.join(","));
}
$("id[vcpu_mode]").multiselect(); $("id[vcpu_mode]").multiselect();
function get_cust_vols(compute_id, pool) { function get_cust_vols(compute_id, pool) {
@ -866,7 +888,7 @@
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
<script> <script>
function goto_compute() { function goto_compute() {
let compute = {{ compute.id }} let compute = {{ compute.id }};
window.location.href = "{% url 'instances:create_instance_select_type' 1 %}".replace(1, compute); window.location.href = "{% url 'instances:create_instance_select_type' 1 %}".replace(1, compute);
} }
</script> </script>

View file

@ -173,3 +173,11 @@ p {
a { a {
outline: 0; outline: 0;
} }
.input-xs {
height: 22px;
padding: 2px 5px;
font-size: 12px;
line-height: 1.5; /* If Placeholder of the input is moved up, rem/modify this. */
border-radius: 2px;
}

View file

@ -338,10 +338,12 @@ class wvmCreate(wvmConnect):
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), "virtio") xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), "virtio")
xml += """</disk>""" xml += """</disk>"""
for net in networks.split(","): if mac:
macs = mac.split(',')
for idx, net in enumerate(networks.split(",")):
xml += """<interface type='network'>""" xml += """<interface type='network'>"""
if mac: if mac:
xml += f"""<mac address='{mac}'/>""" xml += f"""<mac address='{macs[idx]}'/>"""
xml += f"""<source network='{net}'/>""" xml += f"""<source network='{net}'/>"""
if nwfilter: if nwfilter:
xml += f"""<filterref filter='{nwfilter}'/>""" xml += f"""<filterref filter='{nwfilter}'/>"""