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

Add changing option of network model. Show model on instance network list

This commit is contained in:
catborise 2020-01-10 17:55:42 +03:00
parent 8b9fe4e887
commit c62e6ba3bc
4 changed files with 50 additions and 16 deletions

View file

@ -900,7 +900,7 @@
<div class="col-xs-12 col-sm-12"> <div class="col-xs-12 col-sm-12">
<p><strong>{% trans "Network Devices" %}</strong></p> <p><strong>{% trans "Network Devices" %}</strong></p>
<table class="table table-striped table-responsive"> <table class="table table-condensed table-responsive">
<thead> <thead>
<tr> <tr>
<th>{% trans 'Name' %}</th> <th>{% trans 'Name' %}</th>
@ -912,7 +912,15 @@
<tbody> <tbody>
{% for network in networks %} {% for network in networks %}
<tr> <tr>
<td rowspan="2">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</td> <td rowspan="2">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})
<form method="post">{% csrf_token %}
<input name="mac" value="{{ network.mac }}" hidden/>
<input name="set_link_state" value="{{ network.state }}" hidden/>
<input type="checkbox" {% if network.state == 'up' %} checked
{% endif %} onclick='submit();' />
{% trans 'active' %}
</form>
</td>
<th class="hidden-xs hidden-sm">{% trans 'MAC' %}</th> <th class="hidden-xs hidden-sm">{% trans 'MAC' %}</th>
<td>{{ network.mac }}</td> <td>{{ network.mac }}</td>
<th class="hidden-xs hidden-sm">{% trans 'Filter' %}</th> <th class="hidden-xs hidden-sm">{% trans 'Filter' %}</th>
@ -964,6 +972,16 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="form-group form-inline">
<label class="col-sm-3 control-label">{% trans "Model" %} </label>
<input class="form-control" type="text" value="{{ network.model }}" readonly/>
<label class="control-label"><em>to</em></label>
<select class="form-control" name="net-model-{{ forloop.counter0 }}">
{% for model in net_models_host %}
<option value="{{ model }}" {% ifequal model network.model %} selected {% endifequal %}>{{ model }}</option>
{% endfor %}
</select>
</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">{% trans 'Close' %}</button> <button class="btn btn-default" data-dismiss="modal">{% trans 'Close' %}</button>
@ -996,16 +1014,8 @@
{{ ipv6 }} {{ ipv6 }}
{% endfor %} {% endfor %}
</td> </td>
<th class="hidden-xs hidden-sm">{% trans 'LinkState' %}</th> <th class="hidden-xs hidden-sm">{% trans 'Model' %}</th>
<td> <td>{{ network.model }}</td>
<form method="post">{% csrf_token %}
<input name="mac" value="{{ network.mac }}" hidden/>
<input name="set_link_state" value="{{ network.state }}" hidden/>
<input type="checkbox" {% if network.state == 'up' %} checked
{% endif %} onclick='submit();' />
{% trans 'active' %}
</form>
</td>
<th>{% trans 'QoS' %}</th> <th>{% trans 'QoS' %}</th>
<td align="right"> <td align="right">
<form class="form-horizontal" method="post" name="add_qos{{ forloop.counter0 }}" role="form">{% csrf_token %} <form class="form-horizontal" method="post" name="add_qos{{ forloop.counter0 }}" role="form">{% csrf_token %}
@ -1014,6 +1024,10 @@
</form> </form>
</td> </td>
</tr> </tr>
<tr>
<td style="background-color: lightgray" class="hidden-xs hidden-sm" colspan="9"></td>
<td style="background-color: lightgray" class="visible-xs visible-sm" colspan="5"></td>
</tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View file

@ -353,6 +353,7 @@ def instance(request, compute_id, vname):
networks_host = sorted(conn.get_networks()) networks_host = sorted(conn.get_networks())
nwfilters_host = conn.get_nwfilters() nwfilters_host = conn.get_nwfilters()
storages_host = sorted(conn.get_storages(True)) storages_host = sorted(conn.get_storages(True))
net_models_host = conn.get_network_models()
try: try:
interfaces_host = sorted(conn.get_ifaces()) interfaces_host = sorted(conn.get_ifaces())

View file

@ -639,6 +639,10 @@ class wvmConnect(object):
return [v.text for v in ctx.xpath("/domainCapabilities/devices/hostdev/enum[@name='subsysType']/value")] return [v.text for v in ctx.xpath("/domainCapabilities/devices/hostdev/enum[@name='subsysType']/value")]
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list) return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list)
def get_network_models(self):
"""Get available image filename extensions"""
return ['default', 'e1000', 'virtio']
def get_image_formats(self): def get_image_formats(self):
"""Get available image formats""" """Get available image formats"""
return ['raw', 'qcow', 'qcow2'] return ['raw', 'qcow', 'qcow2']

View file

@ -354,6 +354,7 @@ class wvmInstance(wvmConnect):
target_inst = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0] target_inst = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
link_state = 'up' if not net.xpath('link') else net.xpath('link/@state')[0] link_state = 'up' if not net.xpath('link') else net.xpath('link/@state')[0]
filterref_inst = '' if not net.xpath('filterref/@filter') else net.xpath('filterref/@filter')[0] filterref_inst = '' if not net.xpath('filterref/@filter') else net.xpath('filterref/@filter')[0]
model_type = net.xpath('model/@type')[0]
if net.xpath('bandwidth/inbound'): if net.xpath('bandwidth/inbound'):
in_attr = net.xpath('bandwidth/inbound')[0] in_attr = net.xpath('bandwidth/inbound')[0]
in_av = in_attr.get('average') in_av = in_attr.get('average')
@ -375,6 +376,7 @@ class wvmInstance(wvmConnect):
'nic': nic_inst, 'nic': nic_inst,
'target': target_inst, 'target': target_inst,
'state': link_state, 'state': link_state,
'model': model_type,
'ipv4': ipv4, 'ipv4': ipv4,
'ipv6': ipv6, 'ipv6': ipv6,
'filterref': filterref_inst, 'filterref': filterref_inst,
@ -1312,14 +1314,21 @@ class wvmInstance(wvmConnect):
net_source = network_data.get('net-source-' + str(num)) net_source = network_data.get('net-source-' + str(num))
net_source_type = network_data.get('net-source-' + str(num) + '-type') net_source_type = network_data.get('net-source-' + str(num) + '-type')
net_filter = network_data.get('net-nwfilter-' + str(num)) net_filter = network_data.get('net-nwfilter-' + str(num))
net_model = network_data.get('net-model-' + str(num))
bridge_name = self.get_bridge_name(net_source, net_source_type) bridge_name = self.get_bridge_name(net_source, net_source_type)
if interface.get('type') == 'bridge': if interface.get('type') == 'bridge':
source = interface.find('mac') source = interface.find('mac')
source.set('address', net_mac) source.set('address', net_mac)
source = interface.find('source') source = interface.find('source')
source.set('bridge', bridge_name) source.set('bridge', bridge_name)
source = interface.find('filterref')
source = interface.find('model')
if net_model != 'default':
source.attrib['type'] = net_model
else:
interface.remove(source)
source = interface.find('filterref')
if net_filter: if net_filter:
if source is not None: source.set('filter', net_filter) if source is not None: source.set('filter', net_filter)
else: else:
@ -1333,8 +1342,14 @@ class wvmInstance(wvmConnect):
source.set('address', net_mac) source.set('address', net_mac)
source = interface.find('source') source = interface.find('source')
source.set('network', net_source) source.set('network', net_source)
source = interface.find('filterref')
source = interface.find('model')
if net_model != 'default':
source.attrib['type'] = net_model
else:
interface.remove(source)
source = interface.find('filterref')
if net_filter: if net_filter:
if source is not None: source.set('filter', net_filter) if source is not None: source.set('filter', net_filter)
else: else: