From c62e6ba3bcd69646d0713ac50dd753d94a523744 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 10 Jan 2020 17:55:42 +0300 Subject: [PATCH] Add changing option of network model. Show model on instance network list --- instances/templates/instance.html | 42 ++++++++++++++++++++----------- instances/views.py | 1 + vrtManager/connection.py | 4 +++ vrtManager/instance.py | 19 ++++++++++++-- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 764ef73..6ae0870 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -900,7 +900,7 @@

{% trans "Network Devices" %}

- +
@@ -910,9 +910,17 @@ - {% for network in networks %} + {% for network in networks %} - + @@ -964,6 +972,16 @@ {% endfor %} +
+ + + + +
- + + - {% endfor %} + + + + + {% endfor %}
{% trans 'Name' %}
eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})eth{{ forloop.counter0 }}({{ network.target|default:"no target" }}) +
{% csrf_token %} + + + + {% trans 'active' %} +
+
{{ network.mac }} -
{% csrf_token %} - - - - {% trans 'active' %} -
-
{{ network.model }} {% trans 'QoS' %}
{% csrf_token %} @@ -1014,7 +1024,11 @@
diff --git a/instances/views.py b/instances/views.py index 195dd7d..6d01486 100644 --- a/instances/views.py +++ b/instances/views.py @@ -353,6 +353,7 @@ def instance(request, compute_id, vname): networks_host = sorted(conn.get_networks()) nwfilters_host = conn.get_nwfilters() storages_host = sorted(conn.get_storages(True)) + net_models_host = conn.get_network_models() try: interfaces_host = sorted(conn.get_ifaces()) diff --git a/vrtManager/connection.py b/vrtManager/connection.py index 0d35d51..f0b8eb3 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -639,6 +639,10 @@ class wvmConnect(object): 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) + def get_network_models(self): + """Get available image filename extensions""" + return ['default', 'e1000', 'virtio'] + def get_image_formats(self): """Get available image formats""" return ['raw', 'qcow', 'qcow2'] diff --git a/vrtManager/instance.py b/vrtManager/instance.py index 26c1b16..d577094 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -354,6 +354,7 @@ class wvmInstance(wvmConnect): 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] 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'): in_attr = net.xpath('bandwidth/inbound')[0] in_av = in_attr.get('average') @@ -375,6 +376,7 @@ class wvmInstance(wvmConnect): 'nic': nic_inst, 'target': target_inst, 'state': link_state, + 'model': model_type, 'ipv4': ipv4, 'ipv6': ipv6, 'filterref': filterref_inst, @@ -1312,14 +1314,21 @@ class wvmInstance(wvmConnect): net_source = network_data.get('net-source-' + str(num)) net_source_type = network_data.get('net-source-' + str(num) + '-type') 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) 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') + 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 source is not None: source.set('filter', net_filter) else: @@ -1333,8 +1342,14 @@ class wvmInstance(wvmConnect): source.set('address', net_mac) source = interface.find('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 source is not None: source.set('filter', net_filter) else: