From 4d14fdceea517933afa1cca5d625f36c8d4d3530 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 24 Sep 2018 14:41:13 +0300 Subject: [PATCH] selection added to domain creation for nwfilters. Add nwfilter option while adding network card. NWfilters minor fixes --- create/forms.py | 1 + create/templates/create_instance.html | 33 +++++++++++++++++++ create/views.py | 4 +-- .../templates/add_instance_network_block.html | 12 +++++++ instances/templates/instance.html | 7 ++-- instances/views.py | 4 ++- nwfilters/templates/nwfilter.html | 2 +- nwfilters/views.py | 4 +-- vrtManager/connection.py | 2 +- vrtManager/instance.py | 11 +++++-- 10 files changed, 65 insertions(+), 15 deletions(-) diff --git a/create/forms.py b/create/forms.py index 0f208ce..d1e5bf0 100644 --- a/create/forms.py +++ b/create/forms.py @@ -38,6 +38,7 @@ class NewVMForm(forms.Form): disk = forms.IntegerField(required=False) memory = forms.IntegerField(error_messages={'required': _('No RAM size has been entered')}) networks = forms.CharField(error_messages={'required': _('No Network pool has been choice')}) + nwfilter = forms.CharField(required=False) storage = forms.CharField(max_length=20, required=False) template = forms.CharField(required=False) images = forms.CharField(required=False) diff --git a/create/templates/create_instance.html b/create/templates/create_instance.html index 88b5fbe..8b741f2 100644 --- a/create/templates/create_instance.html +++ b/create/templates/create_instance.html @@ -107,6 +107,17 @@ {% endfor %} + +
+ +
+ +
@@ -226,6 +237,17 @@
+
+ +
+ +
+
@@ -379,6 +401,17 @@
+
+ +
+ +
+
diff --git a/create/views.py b/create/views.py index 0c39a1d..9fb846e 100644 --- a/create/views.py +++ b/create/views.py @@ -28,7 +28,6 @@ def create_instance(request, compute_id): storages = [] networks = [] meta_prealloc = False - #computes = Compute.objects.all() compute = get_object_or_404(Compute, pk=compute_id) flavors = Flavor.objects.filter().order_by('id') @@ -40,6 +39,7 @@ def create_instance(request, compute_id): storages = sorted(conn.get_storages(only_actives=True)) networks = sorted(conn.get_networks()) + nwfilters = conn.get_nwfilters() instances = conn.get_instances() videos = conn.get_video() cache_modes = sorted(conn.get_cache_modes().items()) @@ -139,7 +139,7 @@ def create_instance(request, compute_id): try: conn.create_instance(data['name'], data['memory'], data['vcpu'], data['host_model'], uuid, volumes, data['cache_mode'], data['networks'], data['virtio'], - data["listener_addr"], None, data["video"], data["console_pass"], + data["listener_addr"], data["nwfilter"], data["video"], data["console_pass"], data['mac']) create_instance = Instance(compute_id=compute_id, name=data['name'], uuid=uuid) create_instance.save() diff --git a/instances/templates/add_instance_network_block.html b/instances/templates/add_instance_network_block.html index 990c524..afb0ae5 100644 --- a/instances/templates/add_instance_network_block.html +++ b/instances/templates/add_instance_network_block.html @@ -33,12 +33,24 @@
+
+ +
+ +
+ + diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 9b34878..4dbfa6d 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -859,11 +859,8 @@ {% endfor %} - {% ifequal status 5 %} - - {% else %} - - {% endifequal %} + +
diff --git a/instances/views.py b/instances/views.py index ec6adbc..0f4469f 100644 --- a/instances/views.py +++ b/instances/views.py @@ -364,6 +364,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: @@ -708,9 +709,10 @@ def instance(request, compute_id, vname): if 'add_network' in request.POST: mac = request.POST.get('add-net-mac') + nwfilter = request.POST.get('nwfilter') (source, source_type) = get_network_tuple(request.POST.get('add-net-network')) - conn.add_network(mac, source, source_type) + 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.") diff --git a/nwfilters/templates/nwfilter.html b/nwfilters/templates/nwfilter.html index 0d2e2f1..9f97831 100644 --- a/nwfilters/templates/nwfilter.html +++ b/nwfilters/templates/nwfilter.html @@ -22,7 +22,7 @@ {% trans "Interfaces" %}
  • - {% trans "NWFilters" %} + {% trans "NWFilters" %}
  • {% trans "Secrets" %} diff --git a/nwfilters/views.py b/nwfilters/views.py index 99686ed..c0dd8d8 100644 --- a/nwfilters/views.py +++ b/nwfilters/views.py @@ -98,7 +98,7 @@ def nwfilters(request, compute_id): addlogmsg(request.user.username, compute.hostname, msg) for nwf in conn.get_nwfilters(): - nwfilters_all.append(conn.get_nwfilter_info(nwf.name())) + nwfilters_all.append(conn.get_nwfilter_info(nwf)) conn.close() except libvirtError as lib_err: @@ -132,7 +132,7 @@ def nwfilter(request, compute_id, nwfltr): compute.type) for nwf in conn.get_nwfilters(): - nwfilters_all.append(conn.get_nwfilter_info(nwf.name())) + nwfilters_all.append(conn.get_nwfilter_info(nwf)) uuid = nwfilter.get_uuid() name = nwfilter.get_name() diff --git a/vrtManager/connection.py b/vrtManager/connection.py index 96a4fbf..1a16f4e 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -391,7 +391,7 @@ class wvmConnect(object): def get_nwfilters(self): nwfilters = [] - for nwfilter in self.wvm.listAllNWFilters(): + for nwfilter in self.wvm.listNWFilters(): nwfilters.append(nwfilter) return nwfilters diff --git a/vrtManager/instance.py b/vrtManager/instance.py index ca5568f..dd2db64 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -788,7 +788,7 @@ class wvmInstance(wvmConnect): bridge_name = net.bridgeName() return bridge_name - def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio'): + def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio', nwfilter=None): tree = ElementTree.fromstring(self._XMLDesc(0)) bridge_name = self.get_bridge_name(source, source_type) xml_interface = """ @@ -796,8 +796,13 @@ class wvmInstance(wvmConnect): - - """ % (interface_type, mac_address, bridge_name, model) + """ % (interface_type, mac_address, bridge_name, model) + if nwfilter: + xml_interface += """ + + """ % nwfilter + xml_interface += """""" + if self.get_status() == 5: devices = tree.find('devices') elm_interface = ElementTree.fromstring(xml_interface)