1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

selection added to domain creation for nwfilters. Add nwfilter option while adding network card. NWfilters minor fixes

This commit is contained in:
catborise 2018-09-24 14:41:13 +03:00
parent f45666d88b
commit 4d14fdceea
10 changed files with 65 additions and 15 deletions

View file

@ -38,6 +38,7 @@ class NewVMForm(forms.Form):
disk = forms.IntegerField(required=False) disk = forms.IntegerField(required=False)
memory = forms.IntegerField(error_messages={'required': _('No RAM size has been entered')}) memory = forms.IntegerField(error_messages={'required': _('No RAM size has been entered')})
networks = forms.CharField(error_messages={'required': _('No Network pool has been choice')}) 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) storage = forms.CharField(max_length=20, required=False)
template = forms.CharField(required=False) template = forms.CharField(required=False)
images = forms.CharField(required=False) images = forms.CharField(required=False)

View file

@ -107,6 +107,17 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "NWFilter" %}</label>
<div class="col-sm-6">
<select name="nwfilter" class="form-control">
<option value="">{% trans "None" %}</option>
{% for nwfilter in nwfilters %}
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
{% endfor %}
</select>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "Video" %}</label> <label class="col-sm-3 control-label">{% trans "Video" %}</label>
@ -226,6 +237,17 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "NWFilter" %}</label>
<div class="col-sm-6">
<select name="nwfilter" class="form-control">
<option value="">{% trans "None" %}</option>
{% for nwfilter in nwfilters %}
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label> <label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
@ -379,6 +401,17 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "NWFilter" %}</label>
<div class="col-sm-6">
<select name="nwfilter" class="form-control">
<option value="">{% trans "None" %}</option>
{% for nwfilter in nwfilters %}
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "MAC" %}</label> <label class="col-sm-3 control-label">{% trans "MAC" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">

View file

@ -28,7 +28,6 @@ def create_instance(request, compute_id):
storages = [] storages = []
networks = [] networks = []
meta_prealloc = False meta_prealloc = False
#computes = Compute.objects.all()
compute = get_object_or_404(Compute, pk=compute_id) compute = get_object_or_404(Compute, pk=compute_id)
flavors = Flavor.objects.filter().order_by('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)) storages = sorted(conn.get_storages(only_actives=True))
networks = sorted(conn.get_networks()) networks = sorted(conn.get_networks())
nwfilters = conn.get_nwfilters()
instances = conn.get_instances() instances = conn.get_instances()
videos = conn.get_video() videos = conn.get_video()
cache_modes = sorted(conn.get_cache_modes().items()) cache_modes = sorted(conn.get_cache_modes().items())
@ -139,7 +139,7 @@ def create_instance(request, compute_id):
try: try:
conn.create_instance(data['name'], data['memory'], data['vcpu'], data['host_model'], conn.create_instance(data['name'], data['memory'], data['vcpu'], data['host_model'],
uuid, volumes, data['cache_mode'], data['networks'], data['virtio'], 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']) data['mac'])
create_instance = Instance(compute_id=compute_id, name=data['name'], uuid=uuid) create_instance = Instance(compute_id=compute_id, name=data['name'], uuid=uuid)
create_instance.save() create_instance.save()

View file

@ -33,12 +33,24 @@
</select> </select>
</div> </div>
</div> </div>
<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">
<option value="">{% trans "None" %}</option>
{% for nwfilter in nwfilters %}
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
{% endfor %}
</select>
</div> </div>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button> <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="add_network">{% trans "Add" %}</button> <button type="submit" class="btn btn-primary" name="add_network">{% trans "Add" %}</button>
</div> </div>
</form> </form>
</div>
</div> <!-- /.modal-content --> </div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog --> </div> <!-- /.modal-dialog -->
</div> <!-- /.modal --> </div> <!-- /.modal -->

View file

@ -859,11 +859,8 @@
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" id="btn_change_network" name="change_network" disabled>{% trans "Change" %}</button> <button type="submit" class="btn btn-lg btn-success pull-right" id="btn_change_network" name="change_network" disabled>{% trans "Change" %}</button>
{% else %}
<button type="submit" class="btn btn-lg btn-success pull-right" id="btn_change_network" name="change_network" disabled>{% trans "Change" %}</button>
{% endifequal %}
</form> </form>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>

View file

@ -364,6 +364,7 @@ def instance(request, compute_id, vname):
else: else:
media_iso = [] media_iso = []
networks = conn.get_net_device() networks = conn.get_net_device()
nwfilters = conn.get_nwfilters()
vcpu_range = conn.get_max_cpus() vcpu_range = conn.get_max_cpus()
memory_range = [256, 512, 768, 1024, 2048, 4096, 6144, 8192, 16384] memory_range = [256, 512, 768, 1024, 2048, 4096, 6144, 8192, 16384]
if memory not in memory_range: if memory not in memory_range:
@ -708,9 +709,10 @@ def instance(request, compute_id, vname):
if 'add_network' in request.POST: if 'add_network' in request.POST:
mac = request.POST.get('add-net-mac') mac = request.POST.get('add-net-mac')
nwfilter = request.POST.get('nwfilter')
(source, source_type) = get_network_tuple(request.POST.get('add-net-network')) (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") msg = _("Edit network")
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
msg = _("Network Devices are changed. Please reboot instance to activate.") msg = _("Network Devices are changed. Please reboot instance to activate.")

View file

@ -22,7 +22,7 @@
<i class="fa fa-wifi"></i> <a href="{% url 'interfaces' compute.id %}">{% trans "Interfaces" %}</a> <i class="fa fa-wifi"></i> <a href="{% url 'interfaces' compute.id %}">{% trans "Interfaces" %}</a>
</li> </li>
<li> <li>
<i class="fa fa-filter"></i> {% trans "NWFilters" %} <i class="fa fa-filter"></i> <a href="{% url 'nwfilters' compute.id %}">{% trans "NWFilters" %}</a>
</li> </li>
<li> <li>
<i class="fa fa-key"></i> <a href="{% url 'secrets' compute.id %}">{% trans "Secrets" %}</a> <i class="fa fa-key"></i> <a href="{% url 'secrets' compute.id %}">{% trans "Secrets" %}</a>

View file

@ -98,7 +98,7 @@ def nwfilters(request, compute_id):
addlogmsg(request.user.username, compute.hostname, msg) addlogmsg(request.user.username, compute.hostname, msg)
for nwf in conn.get_nwfilters(): 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() conn.close()
except libvirtError as lib_err: except libvirtError as lib_err:
@ -132,7 +132,7 @@ def nwfilter(request, compute_id, nwfltr):
compute.type) compute.type)
for nwf in conn.get_nwfilters(): 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() uuid = nwfilter.get_uuid()
name = nwfilter.get_name() name = nwfilter.get_name()

View file

@ -391,7 +391,7 @@ class wvmConnect(object):
def get_nwfilters(self): def get_nwfilters(self):
nwfilters = [] nwfilters = []
for nwfilter in self.wvm.listAllNWFilters(): for nwfilter in self.wvm.listNWFilters():
nwfilters.append(nwfilter) nwfilters.append(nwfilter)
return nwfilters return nwfilters

View file

@ -788,7 +788,7 @@ class wvmInstance(wvmConnect):
bridge_name = net.bridgeName() bridge_name = net.bridgeName()
return bridge_name 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)) tree = ElementTree.fromstring(self._XMLDesc(0))
bridge_name = self.get_bridge_name(source, source_type) bridge_name = self.get_bridge_name(source, source_type)
xml_interface = """ xml_interface = """
@ -796,8 +796,13 @@ class wvmInstance(wvmConnect):
<mac address='%s'/> <mac address='%s'/>
<source bridge='%s'/> <source bridge='%s'/>
<model type='%s'/> <model type='%s'/>
</interface>
""" % (interface_type, mac_address, bridge_name, model) """ % (interface_type, mac_address, bridge_name, model)
if nwfilter:
xml_interface += """
<filterref filter='%s'/>
""" % nwfilter
xml_interface += """</interface>"""
if self.get_status() == 5: if self.get_status() == 5:
devices = tree.find('devices') devices = tree.find('devices')
elm_interface = ElementTree.fromstring(xml_interface) elm_interface = ElementTree.fromstring(xml_interface)