mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
instance network tab modified. Changing function modified. deleting function added. network info of nwfilters added. and some small fixes applied
This commit is contained in:
parent
ba212971fa
commit
b916c9dcf9
4 changed files with 93 additions and 40 deletions
|
@ -36,9 +36,9 @@
|
|||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">{% trans "NWFilter" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select class="form-control" name="nwfilter">
|
||||
<select class="form-control" name="add-net-nwfilter">
|
||||
<option value="">{% trans "None" %}</option>
|
||||
{% for nwfilter in nwfilters %}
|
||||
{% for nwfilter in compute_nwfilters %}
|
||||
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
|
@ -833,36 +833,63 @@
|
|||
{% if request.user.is_superuser %}
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="network">
|
||||
<p>
|
||||
{% trans "Assign network device to bridge" %}
|
||||
{% include 'add_instance_network_block.html' %}
|
||||
{% 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>
|
||||
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
||||
<div class="col-xs-12 col-sm-12">
|
||||
<form method="post" role="form">{% csrf_token %}
|
||||
{% for network in networks %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<label>eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}" disabled/>
|
||||
<div class="panel-body">
|
||||
<div class="form-group form-inline">
|
||||
<label class="col-sm-2 col-sm-offset-1 control-label">{% trans "MAC" %} </label>
|
||||
<input class="form-control" type="text" value="{{ network.mac }}" readonly/>
|
||||
<label class="control-label"><em>to</em></label>
|
||||
<input class="form-control" type="text" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
|
||||
</div>
|
||||
<div class="form-group form-inline">
|
||||
<label class="col-sm-2 col-sm-offset-1 control-label">{% trans "NIC" %} </label>
|
||||
<input class="form-control" type="text" value="{{ network.nic }}" readonly/>
|
||||
<label class="control-label"><em>to</em></label>
|
||||
<select class="form-control" name="net-source-{{ forloop.counter0 }}">
|
||||
{% for c_net in compute_networks %}
|
||||
<option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>Network {{ c_net }}</option>
|
||||
{% endfor %}
|
||||
{% for c_iface in compute_interfaces %}
|
||||
<option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>Interface {{ c_iface }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-inline">
|
||||
<label class="col-sm-2 col-sm-offset-1">{% trans "Filter" %} </label>
|
||||
<input class="form-control" type="text" value="{{ network.filterref }}" readonly/>
|
||||
<label class="control-label"><em>to</em></label>
|
||||
<select class="form-control" name="net-nwfilter-{{ forloop.counter0 }}">
|
||||
<option value="">{% trans "None" %}</option>
|
||||
{% for c_filters in compute_nwfilters %}
|
||||
<option value="{{ c_filters }}" {% ifequal c_filters network.filterref %} selected {% endifequal %}>{{ c_filters }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<select name="net-source-{{ forloop.counter0 }}" class="form-control" id="network_select" onchange="network_select_enable()">
|
||||
{% for c_nets in compute_networks %}
|
||||
<option value="net:{{ c_nets }}" {% if c_nets == network.nic %}selected{% endif %}>Network {{ c_nets }}</option>
|
||||
{% endfor %}
|
||||
{% for c_iface in compute_interfaces %}
|
||||
<option value="iface:{{ c_iface }}" {% if c_iface == network.nic %}selected{% endif %}>Interface {{ c_iface }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<div class="panel-footer">
|
||||
<button class="btn btn-sm btn-primary" name="change_network" title="{% trans "Change" %}">{% trans "Change" %}</button>
|
||||
<button class="btn btn-sm pull-right btn-danger" value="{{ network.mac }}" name="delete_network" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">{% trans "Delete" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-lg btn-success pull-right" id="btn_change_network" name="change_network" disabled>{% trans "Change" %}</button>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser or request.user.userattributes.can_clone_instances %}
|
||||
|
@ -1367,12 +1394,6 @@
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function network_select_enable(){
|
||||
// set network button enabled
|
||||
$('button[name="change_network"]').removeAttr('disabled');
|
||||
}
|
||||
</script>
|
||||
<script src="{% static "js/Chart.min.js" %}"></script>
|
||||
<script>
|
||||
$('#chartgraphs').on('shown.bs.tab', function (event) {
|
||||
|
|
|
@ -348,6 +348,7 @@ def instance(request, compute_id, vname):
|
|||
vname)
|
||||
compute_networks = sorted(conn.get_networks())
|
||||
compute_interfaces = sorted(conn.get_ifaces())
|
||||
compute_nwfilters = conn.get_nwfilters()
|
||||
status = conn.get_status()
|
||||
autostart = conn.get_autostart()
|
||||
vcpu = conn.get_vcpu()
|
||||
|
@ -364,7 +365,7 @@ def instance(request, compute_id, vname):
|
|||
else:
|
||||
media_iso = []
|
||||
networks = conn.get_net_device()
|
||||
nwfilters = conn.get_nwfilters()
|
||||
|
||||
vcpu_range = conn.get_max_cpus()
|
||||
memory_range = [256, 512, 768, 1024, 2048, 4096, 6144, 8192, 16384]
|
||||
if memory not in memory_range:
|
||||
|
@ -690,6 +691,7 @@ def instance(request, compute_id, vname):
|
|||
return HttpResponseRedirect(reverse('instance', args=[new_compute.id, vname]))
|
||||
|
||||
if 'change_network' in request.POST:
|
||||
msg = _("Change network")
|
||||
network_data = {}
|
||||
|
||||
for post in request.POST:
|
||||
|
@ -701,24 +703,31 @@ def instance(request, compute_id, vname):
|
|||
network_data[post] = request.POST.get(post, '')
|
||||
|
||||
conn.change_network(network_data)
|
||||
msg = _("Edit network")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
||||
messages.success(request, msg)
|
||||
if conn.get_status() != 5: messages.success(request, _("Network Devices are changed. Please reboot instance to activate."))
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'add_network' in request.POST:
|
||||
msg = _("Add network")
|
||||
mac = request.POST.get('add-net-mac')
|
||||
nwfilter = request.POST.get('nwfilter')
|
||||
nwfilter = request.POST.get('add-net-nwfilter')
|
||||
(source, source_type) = get_network_tuple(request.POST.get('add-net-network'))
|
||||
|
||||
conn.add_network(mac, source, source_type, nwfilter=nwfilter)
|
||||
msg = _("Edit network")
|
||||
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
||||
messages.success(request, msg)
|
||||
if conn.get_status() != 5: messages.success(request, _("Network Device is added. Please reboot instance to activate."))
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
|
||||
if 'delete_network' in request.POST:
|
||||
msg = _("Delete network")
|
||||
mac_address = request.POST.get('delete_network', '')
|
||||
|
||||
conn.delete_network(mac_address)
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
if conn.get_status() != 5: messages.success(request, _("Network Device is deleted. Please reboot instance to activate."))
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'add_owner' in request.POST:
|
||||
user_id = int(request.POST.get('user_id', ''))
|
||||
|
||||
|
|
|
@ -232,12 +232,13 @@ class wvmInstance(wvmConnect):
|
|||
mac_host = net.xpath('mac/@address')[0]
|
||||
network_host = net.xpath('source/@network|source/@bridge|source/@dev')[0]
|
||||
target_host = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
|
||||
filterref_host = '' if not net.xpath('filterref/@filter') else net.xpath('filterref/@filter')[0]
|
||||
try:
|
||||
net = self.get_network(network_host)
|
||||
ip = get_mac_ipaddr(net, mac_host)
|
||||
except libvirtError as e:
|
||||
ip = None
|
||||
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host,'ip': ip})
|
||||
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host,'ip': ip, 'filterref': filterref_host})
|
||||
return result
|
||||
|
||||
return util.get_xml_path(self._XMLDesc(0), func=networks)
|
||||
|
@ -810,20 +811,42 @@ class wvmInstance(wvmConnect):
|
|||
xmldom = ElementTree.tostring(tree)
|
||||
self._defineXML(xmldom)
|
||||
|
||||
def delete_network(self, mac_address):
|
||||
tree = ElementTree.fromstring(self._XMLDesc(0))
|
||||
devices = tree.find('devices')
|
||||
for interface in tree.findall('devices/interface'):
|
||||
source = interface.find('mac')
|
||||
if source.get('address', '') == mac_address:
|
||||
source = None
|
||||
devices.remove(interface)
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
def change_network(self, network_data):
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
for num, interface in enumerate(tree.findall('devices/interface')):
|
||||
net_source = network_data['net-source-' + str(num)]
|
||||
net_source_type = network_data['net-source-' + str(num) + '-type']
|
||||
net_mac = network_data['net-mac-' + str(num)]
|
||||
net_filter = network_data['net-nwfilter-' + str(num)]
|
||||
bridge_name = self.get_bridge_name(net_source, net_source_type)
|
||||
if interface.get('type') == 'bridge':
|
||||
source = interface.find('mac')
|
||||
source.set('address', net_mac)
|
||||
source = interface.find('source')
|
||||
source.set('bridge', bridge_name)
|
||||
source = interface.find('filterref')
|
||||
|
||||
if net_filter:
|
||||
if source is not None: source.set('filter', net_filter)
|
||||
else:
|
||||
element = ElementTree.Element("filterref")
|
||||
element.attrib['filter'] = net_filter
|
||||
interface.append(element)
|
||||
else:
|
||||
if source is not None: interface.remove(source)
|
||||
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
|
|
Loading…
Reference in a new issue