mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
#addInstanceNetwork modal box
This commit is contained in:
parent
21ef6871cf
commit
9c37dcc2dc
4 changed files with 79 additions and 5 deletions
42
instances/templates/add_instance_network_block.html
Normal file
42
instances/templates/add_instance_network_block.html
Normal file
|
@ -0,0 +1,42 @@
|
|||
{% load i18n %}
|
||||
{% if request.user.is_superuser and status == 5 %}
|
||||
<a href="#addInstanceNetwork" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</a>
|
||||
|
||||
<!-- Modal pool -->
|
||||
<div class="modal fade" id="addInstanceNetwork" tabindex="-1" role="dialog" aria-labelledby="addInstanceNetworkLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">{% trans "Add Instance Network" %}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">{% trans "Mac" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" name="add-net-mac">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">{% trans "Network" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select class="form-control" name="add-net-network">
|
||||
{% for c_net in compute_networks %}
|
||||
<option value="{{ c_net }}">{{ c_net }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
|
||||
<button type="submit" class="btn btn-primary" name="add_network">{% trans "Add" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div> <!-- /.modal-content -->
|
||||
</div> <!-- /.modal-dialog -->
|
||||
</div> <!-- /.modal -->
|
||||
{% endif %}
|
|
@ -827,7 +827,10 @@
|
|||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="network">
|
||||
<p>{% trans "Assign network device to bridge" %}</p>
|
||||
<p>
|
||||
{% trans "Assign network device to bridge" %}
|
||||
{% include 'add_instance_network_block.html' %}
|
||||
</p>
|
||||
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
|
||||
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
||||
{% for network in networks %}
|
||||
|
@ -898,7 +901,7 @@
|
|||
</div>
|
||||
<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>
|
||||
onclick="random_mac('clone-net-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('#clone_name', {{ forloop.counter0 }})" style="margin-top: 2px;">{% trans "Guess" %}</button>
|
||||
</div>
|
||||
|
@ -1230,7 +1233,7 @@
|
|||
<script>
|
||||
function random_mac(net) {
|
||||
$.getJSON('/instance/random_mac_address/', function(data) {
|
||||
$('input[name="clone-net-mac-'+net+'"]').val(data['mac']);
|
||||
$('input[name="'+net+'"]').val(data['mac']);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
@ -1339,7 +1342,8 @@
|
|||
});
|
||||
{% if request.user.is_superuser %}
|
||||
$(document).ready(function () {
|
||||
random_mac(0);
|
||||
random_mac('clone-net-mac-0');
|
||||
random_mac('add-net-mac');
|
||||
});
|
||||
{% else %}
|
||||
$('#select_clone_name').on('change', function () {
|
||||
|
|
|
@ -696,6 +696,17 @@ def instance(request, compute_id, vname):
|
|||
messages.success(request, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'add_network' in request.POST:
|
||||
mac = request.POST.get('add-net-mac')
|
||||
network = request.POST.get('add-net-network')
|
||||
|
||||
conn.add_network(mac, network)
|
||||
msg = _("Edit network")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
||||
messages.success(request, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'add_owner' in request.POST:
|
||||
user_id = int(request.POST.get('user_id', ''))
|
||||
|
||||
|
|
|
@ -742,6 +742,23 @@ class wvmInstance(wvmConnect):
|
|||
|
||||
return self.get_instance(clone_data['name']).UUIDString()
|
||||
|
||||
def add_network(self, mac_address, network, interface_type='bridge', model='virtio'):
|
||||
tree = ElementTree.fromstring(self._XMLDesc(0))
|
||||
net = self.get_network(network)
|
||||
xml_interface = """
|
||||
<interface type='%s'>
|
||||
<mac address='%s'/>
|
||||
<source bridge='%s'/>
|
||||
<model type='%s'/>
|
||||
</interface>
|
||||
""" % (interface_type, mac_address, net.bridgeName(), model)
|
||||
if self.get_status() == 5:
|
||||
devices = tree.find('devices')
|
||||
elm_interface = ElementTree.fromstring(xml_interface)
|
||||
devices.append(elm_interface)
|
||||
xmldom = ElementTree.tostring(tree)
|
||||
self._defineXML(xmldom)
|
||||
|
||||
def change_network(self, network_data):
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
tree = ElementTree.fromstring(xml)
|
||||
|
|
Loading…
Reference in a new issue