1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +00:00

settings tab for changing devices/interface/source/bridge added

TODO: handle multiple interfaces
This commit is contained in:
Jan Krcmar 2016-01-14 16:59:50 +01:00
parent 1499af1eef
commit 50ddda98f2
4 changed files with 59 additions and 2 deletions

View file

@ -491,6 +491,11 @@
{% trans "VNC" %}
</a>
</li>
<li role="presentation">
<a href="#network" aria-controls="network" role="tab" data-toggle="tab">
{% trans "Network" %}
</a>
</li>
<li role="presentation">
<a href="#clone" aria-controls="clone" role="tab" data-toggle="tab">
{% trans "Clone" %}
@ -652,6 +657,33 @@
</form>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="network">
<p>{% trans "Assign network device to bridge" %}</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 %}
<div class="form-group">
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="net-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div>
<div class="col-sm-3">
<input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}"/>
</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>
{% endfor %}
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_network">{% trans "Change" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled" name="change_network">{% trans "Change" %}</button>
{% endifequal %}
</form>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="clone">
<p style="font-weight:bold;">{% trans "Create a clone" %}</p>
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
@ -1117,7 +1149,7 @@
}
});
}
if (~$.inArray(hash, ['#media', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate'])) {
if (~$.inArray(hash, ['#media', '#network', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate'])) {
var btnsect = $('#navbtn>li>a');
$(btnsect).each(function () {
if ($(this).attr('href') === '#settings') {

View file

@ -503,6 +503,18 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']]))
if 'change_network' in request.POST:
network_data = {}
for post in request.POST:
if 'net-' in post:
network_data[post] = request.POST.get(post, '')
conn.change_network(network_data)
msg = _("Edit network")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#network')
conn.close()
except libvirtError as lib_err:

View file

@ -679,3 +679,16 @@ class wvmInstance(wvmConnect):
storage.clone_volume(vol_name, target_file)
self._defineXML(ElementTree.tostring(tree))
def change_network(self, network_data):
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)
for interface in tree.findall('devices/interface'):
if interface.get('type') == 'bridge':
source = interface.find('source')
source.set('bridge', network_data['net-source-0'])
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)

View file

@ -8,7 +8,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '4y(f4rfqc6f2!i8_vfuu)kav6tdv5#sc=n%o451dm+th0&3uci'
DEBUG = False
DEBUG = True
TEMPLATE_DEBUG = DEBUG