def networks(request, compute_id): """ :param request: :param compute_id: :return: """ if not request.user.is_superuser: return HttpResponseRedirect(reverse('index')) error_messages = [] compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type) networks = conn.get_networks_info() dhcp4 = netmask4 = gateway4 = '' dhcp6 = prefix6 = gateway6 = '' ipv4 = ipv6 = False if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = _("Network pool name already in use") error_messages.append(msg) if data['forward'] == 'bridge' and data['bridge_name'] == '': error_messages.append('Please enter bridge name') if data['subnet']: ipv4 = True gateway4, netmask4, dhcp4 = network_size(data['subnet'], data['dhcp4']) if data['subnet6']: ipv6 = True gateway6, prefix6, dhcp6 = network_size(data['subnet6'], data['dhcp6']) if prefix6 != '64': error_messages.append('For libvirt, the IPv6 network prefix must be /64') if not error_messages: conn.create_network(data['name'], data['forward'], ipv4, gateway4, netmask4, dhcp4, ipv6, gateway6, prefix6, dhcp6, data['bridge_name'], data['openvswitch'], data['fixed']) return HttpResponseRedirect(reverse('network', args=[compute_id, data['name']])) else: for msg_err in form.errors.values(): error_messages.append(msg_err.as_text()) conn.close() except libvirtError as lib_err: error_messages.append(lib_err) return render(request, 'networks.html', locals())
def networks(request, host_id): """ Networks block """ errors = [] object = {} try: compute = Compute.objects.get(id=host_id) conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = ("Pool name already in use") errors.append(msg) if data['forward'] == 'bridge' and data[ 'bridge_name'] == '': errors.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size( data['subnet'], data['dhcp']) except: msg = ("Input subnet pool error") errors.append(msg) if not errors: try: dns = None dns_params = request.POST.get('dns') if dns_params: dns = dns_params.split(',') conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed'], dns, data.get('forward_dev')) except libvirtError as err: errors.append(err) object = { 'errors': [str(error) for error in errors], 'response': {} } url = '/%s/network/%s/' % (host_id, data['name']) return redirect_or_json(object, url, request) conn.close() except Compute.DoesNotExist, e: object['errors'] = e.message
def networks(request, compute_id): """ :param request: :return: """ if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('index')) if not request.user.is_superuser: return HttpResponseRedirect(reverse('index')) error_messages = [] compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = _("Pool name already in use") error_messages.append(msg) if data['forward'] == 'bridge' and data[ 'bridge_name'] == '': error_messages.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size( data['subnet'], data['dhcp']) except: error_msg = _("Input subnet pool error") error_messages.append(error_msg) if not error_messages: conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed']) return HttpResponseRedirect( reverse('network', args=[compute_id, data['name']])) else: for msg_err in form.errors.values(): error_messages.append(msg_err.as_text()) conn.close() except libvirtError as lib_err: error_messages.append(lib_err) return render(request, 'networks.html', locals())
def networks(request, host_id): """ Networks block """ errors = [] object = {} try: compute = Compute.objects.get(id=host_id) conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = ("Pool name already in use") errors.append(msg) if data['forward'] == 'bridge' and data['bridge_name'] == '': errors.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size(data['subnet'], data['dhcp']) except: msg = ("Input subnet pool error") errors.append(msg) if not errors: try: dns = None dns_params = request.POST.get('dns') if dns_params: dns = dns_params.split(',') conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed'], dns, data.get('forward_dev')) except libvirtError as err: errors.append(err) object = { 'errors': [str(error) for error in errors], 'response': {} } url = '/%s/network/%s/' % (host_id, data['name']) return redirect_or_json(object, url, request) conn.close() except Compute.DoesNotExist, e: object['errors'] = e.message
def networks(request, compute_id): """ :param request: :return: """ if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('index')) if not request.user.is_superuser: return HttpResponseRedirect(reverse('index')) error_messages = [] compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = _("Pool name already in use") error_messages.append(msg) if data['forward'] == 'bridge' and data['bridge_name'] == '': error_messages.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size(data['subnet'], data['dhcp']) except: error_msg = _("Input subnet pool error") error_messages.append(error_msg) if not error_messages: conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed']) return HttpResponseRedirect(reverse('network', args=[compute_id, data['name']])) else: for msg_err in form.errors.values(): error_messages.append(msg_err.as_text()) conn.close() except libvirtError as lib_err: error_messages.append(lib_err) return render(request, 'networks.html', locals())
def networks(request, host_id): """ Networks block """ if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('login')) if not request.user.is_staff: raise PermissionDenied errors = [] compute = Compute.objects.get(id=host_id) try: conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type, compute.hypervisor) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = _("Pool name already in use") errors.append(msg) if data['forward'] == 'bridge' and data[ 'bridge_name'] == '': errors.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size( data['subnet'], data['dhcp']) except: msg = _("Input subnet pool error") errors.append(msg) if not errors: conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed']) return HttpResponseRedirect( reverse('network', args=[host_id, data['name']])) conn.close() except libvirtError as err: errors.append(err) return render_to_response('networks.html', locals(), context_instance=RequestContext(request))
def networks(request, host_id): """ Networks block """ if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('login')) if not request.user.is_staff: raise PermissionDenied errors = [] compute = Compute.objects.get(id=host_id) try: conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type, compute.hypervisor) networks = conn.get_networks_info() if request.method == 'POST': if 'create' in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data['name'] in networks: msg = _("Pool name already in use") errors.append(msg) if data['forward'] == 'bridge' and data['bridge_name'] == '': errors.append('Please enter bridge name') try: gateway, netmask, dhcp = network_size(data['subnet'], data['dhcp']) except: msg = _("Input subnet pool error") errors.append(msg) if not errors: conn.create_network(data['name'], data['forward'], gateway, netmask, dhcp, data['bridge_name'], data['openvswitch'], data['fixed']) return HttpResponseRedirect(reverse('network', args=[host_id, data['name']])) conn.close() except libvirtError as err: errors.append(err) return render_to_response('networks.html', locals(), context_instance=RequestContext(request))
def networks(request, compute_id): """ :param request: :param compute_id: :return: """ compute = get_object_or_404(Compute, pk=compute_id) errors = False try: conn = wvmNetworks( compute.hostname, compute.login, compute.password, compute.type, ) networks = conn.get_networks_info() dhcp4 = netmask4 = gateway4 = "" dhcp6 = prefix6 = gateway6 = "" ipv4 = ipv6 = False if request.method == "POST": if "create" in request.POST: form = AddNetPool(request.POST) if form.is_valid(): data = form.cleaned_data if data["name"] in networks: msg = _("Network pool name already in use") messages.error(request, msg) errors = True if data["forward"] in ["bridge", "macvtap" ] and data["bridge_name"] == "": messages.error(request, _("Please enter bridge/dev name")) errors = True if data["subnet"]: ipv4 = True gateway4, netmask4, dhcp4 = network_size( data["subnet"], data["dhcp4"]) if data["subnet6"]: ipv6 = True gateway6, prefix6, dhcp6 = network_size( data["subnet6"], data["dhcp6"]) if prefix6 != "64": messages.error( request, _("For libvirt, the IPv6 network prefix must be /64" )) errors = True if not errors: conn.create_network( data["name"], data["forward"], ipv4, gateway4, netmask4, dhcp4, ipv6, gateway6, prefix6, dhcp6, data["bridge_name"], data["openvswitch"], data["fixed"], ) return HttpResponseRedirect( reverse("network", args=[compute_id, data["name"]])) else: for msg_err in form.errors.values(): messages.error(request, msg_err.as_text()) conn.close() except libvirtError as lib_err: messages.error(request, lib_err) return render(request, "networks.html", locals())