1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/networks/templates/create_net_block.html
catborise 50dcaba699 refactor(templates): the host pages' scripts load from static files
The host pages lose their last inline scripts: the overview's charts
(host_graphs.js), the New pool, New network and New interface dialogs
(pool_dialog.js, network_dialog.js, interface_dialog.js), a network's
and a network filter's XML editors and dialogs (network_page.js,
nwfilter_page.js, nwfilters_page.js), the secrets page's labels
(secrets_page.js, its texts from the view as usage_texts) and a pool's
page with the ISO upload (storage_page.js). Their URLs and messages are
data attributes of the elements they belong to; the upload reads its
token and address from its form. No template has an inline script or
an inline event handler any more.
2026-11-02 09:45:26 +03:00

134 lines
11 KiB
HTML

{% load i18n %}
{% load static %}
{% load bootstrap_icons %}
{% load form_fields %}
{% if request.user.is_superuser %}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#AddNetPool">
<span aria-hidden="true">{% bs_icon 'plus-lg' %}</span> {% trans "New network" %}
</button>
{# one form: a card per mode, the fields of the chosen one (the others hidden and disabled, so not sent) #}
<div class="modal fade" id="AddNetPool" tabindex="-1" aria-labelledby="AddNetPoolLabel" aria-hidden="true"
{% if form.errors %}data-open{% endif %}>
<div class="modal-dialog modal-lg modal-dialog-scrollable modal-fullscreen-sm-down">
<form method="post" class="modal-content" id="network-form">{% csrf_token %}
<div class="modal-header">
<div>
<h5 class="modal-title" id="AddNetPoolLabel">{% trans "New network" %}</h5>
<div class="small text-body-secondary">{% blocktrans with host=compute.name %}On {{ host }}{% endblocktrans %}</div>
</div>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans "Close" %}"></button>
</div>
<div class="modal-body">
{% include "instances/form_errors.html" %}
<fieldset class="mb-3">
<legend class="form-label fs-6">{% trans "Type" %}</legend>
<div class="row row-cols-1 row-cols-sm-2 g-2">
{% trans "NAT" as title %}{% trans "VMs reach out through the host's address, on a private subnet." as help %}
{% include "radio_card.html" with name="forward" value="nat" chosen=net_mode %}
{% trans "Routed" as title %}{% trans "The host routes the subnet; the upstream router needs a route back." as help %}
{% include "radio_card.html" with name="forward" value="route" chosen=net_mode %}
{% trans "Isolated" as title %}{% trans "VMs reach each other and the host only." as help %}
{% include "radio_card.html" with name="forward" value="none" chosen=net_mode %}
{% trans "Bridge" as title %}{% trans "VMs join a bridge of the host, on its outside network." as help %}
{% include "radio_card.html" with name="forward" value="bridge" chosen=net_mode %}
{% trans "Macvtap" as title %}{% trans "VMs share an interface of the host; the host cannot reach them through it." as help %}
{% include "radio_card.html" with name="forward" value="macvtap" chosen=net_mode %}
</div>
</fieldset>
<div class="mb-3">
<label for="net_name" class="form-label">{% trans "Network name" %}</label>
<input id="net_name" type="text" class="form-control{{ form.name|invalid }}" name="name" value="{{ form.name.value|default:"" }}"
placeholder="lab-net" maxlength="20" required pattern="[a-zA-Z0-9._\-]+" {% error_attrs form.name "net_name" "net_name_help" %}>
<div class="form-text" id="net_name_help">{% trans "Letters, digits, dots, dashes and underscores; up to 20." %}</div>
{% field_error form.name "net_name" %}
</div>
<fieldset data-kinds="nat route none">
<legend class="visually-hidden">{% trans "Addresses" %}</legend>
<div class="row g-3 mb-3">
<div class="col-sm-6">
<label for="net_subnet" class="form-label">{% trans "IPv4 subnet" %}</label>
<input id="net_subnet" type="text" class="form-control font-monospace{{ form.subnet|invalid }}" name="subnet" value="{{ form.subnet.value|default:"" }}"
placeholder="192.168.100.0/24" {% error_attrs form.subnet "net_subnet" "net_subnet_help" %}>
<div class="form-text" id="net_subnet_help">{% trans "The host takes its first address." %}</div>
{% field_error form.subnet "net_subnet" %}
</div>
<div class="col-sm-6">
<span class="form-label d-block">{% trans "DHCP" %}</span>
<div class="form-check form-switch mt-2">
<input class="form-check-input" type="checkbox" role="switch" id="net_dhcp4" name="dhcp4" value="true"{% if not form.is_bound or form.dhcp4.value %} checked{% endif %}>
<label class="form-check-label" for="net_dhcp4">{% trans "Give the VMs addresses from the subnet" %}</label>
</div>
</div>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="net_ipv6" name="enable_ipv6" value="true"{% if form.enable_ipv6.value %} checked{% endif %}>
<label class="form-check-label" for="net_ipv6">{% trans "IPv6 too" %}</label>
</div>
<div class="row g-3 mb-3" id="net_ipv6_fields">
<div class="col-sm-6">
<label for="net_subnet6" class="form-label">{% trans "IPv6 subnet" %}</label>
<input id="net_subnet6" type="text" class="form-control font-monospace{{ form.subnet6|invalid }}" name="subnet6" value="{{ form.subnet6.value|default:"" }}"
placeholder="fd00:dead:baba:1::/64" {% error_attrs form.subnet6 "net_subnet6" "net_subnet6_help" %}>
<div class="form-text" id="net_subnet6_help">{% trans "A /64." %}</div>
{% field_error form.subnet6 "net_subnet6" %}
</div>
<div class="col-sm-6">
<span class="form-label d-block">{% trans "DHCPv6" %}</span>
<div class="form-check form-switch mt-2">
<input class="form-check-input" type="checkbox" role="switch" id="net_dhcp6" name="dhcp6" value="true"{% if form.dhcp6.value %} checked{% endif %}>
<label class="form-check-label" for="net_dhcp6">{% trans "Give the VMs IPv6 addresses" %}</label>
</div>
</div>
</div>
</fieldset>
<fieldset data-kinds="bridge">
<legend class="visually-hidden">{% trans "Bridge" %}</legend>
<div class="mb-3">
<label for="net_bridge" class="form-label">{% trans "Host bridge" %}</label>
<input id="net_bridge" type="text" class="form-control font-monospace{% if net_mode == "bridge" %}{{ form.bridge_name|invalid }}{% endif %}" name="bridge_name"
value="{% if net_mode == "bridge" %}{{ form.bridge_name.value|default:"" }}{% endif %}" list="host-bridges" placeholder="br0" maxlength="20" required
{% if net_mode == "bridge" %}{% error_attrs form.bridge_name "net_bridge" "net_bridge_help" %}{% else %}aria-describedby="net_bridge_help"{% endif %}>
<datalist id="host-bridges">
{% for iface in host_ifaces %}{% if iface.type == "bridge" %}<option value="{{ iface.name }}">{% endif %}{% endfor %}
</datalist>
<div class="form-text" id="net_bridge_help">{% trans "A bridge the host already has; the field suggests the ones libvirt lists." %}</div>
{% if net_mode == "bridge" %}{% field_error form.bridge_name "net_bridge" %}{% endif %}
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="net_ovs" name="openvswitch" value="true"{% if form.openvswitch.value %} checked{% endif %}>
<label class="form-check-label" for="net_ovs">{% trans "It is an Open vSwitch bridge" %}</label>
</div>
</fieldset>
<fieldset data-kinds="macvtap">
<legend class="visually-hidden">{% trans "Macvtap" %}</legend>
<div class="mb-3">
<label for="net_iface" class="form-label">{% trans "Host interface" %}</label>
<input id="net_iface" type="text" class="form-control font-monospace{% if net_mode == "macvtap" %}{{ form.bridge_name|invalid }}{% endif %}" name="bridge_name"
value="{% if net_mode == "macvtap" %}{{ form.bridge_name.value|default:"" }}{% endif %}" list="host-ifaces" placeholder="eth0" maxlength="20" required
{% if net_mode == "macvtap" %}{% error_attrs form.bridge_name "net_iface" "net_iface_help" %}{% else %}aria-describedby="net_iface_help"{% endif %}>
<datalist id="host-ifaces">
{% for iface in host_ifaces %}{% if iface.type != "bridge" %}<option value="{{ iface.name }}">{% endif %}{% endfor %}
</datalist>
<div class="form-text" id="net_iface_help">{% trans "The interface the VMs share, such as the host's uplink." %}</div>
{% if net_mode == "macvtap" %}{% field_error form.bridge_name "net_iface" %}{% endif %}
</div>
</fieldset>
<p class="small text-body-secondary mb-0">{% bs_icon 'info-circle' %} {% trans "The network starts at once, and with the host from then on." %}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
<button type="submit" class="btn btn-primary" name="create">{% trans "Create network" %}</button>
</div>
</form>
</div>
</div>
<script src="{% static 'js/choice_dialog.js' %}"></script>
<script src="{% static 'js/network_dialog.js' %}"></script>
{% endif %}