Commit 6008ac97 by Chif Gergő

dashboard: Add SetMasterInterface form and view, and change network.html

The view gets the selected interface and forwards it to the operation. The form is ask if we aggree the operation. On the network page there is a button for the operation.
parent e8684154
...@@ -916,6 +916,20 @@ class VmDownloadDiskForm(OperationForm): ...@@ -916,6 +916,20 @@ class VmDownloadDiskForm(OperationForm):
return cleaned_data return cleaned_data
class VmSetMasterInterfaceForm(OperationForm):
def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices')
self.interface = kwargs.pop('default')
super(VmSetMasterInterfaceForm, self).__init__(*args, **kwargs)
self.fields['interface'] = forms.ModelChoiceField(
queryset=choices, initial=self.interface, required=True,
empty_label=None, label=_('Interface'))
if self.interface:
self.fields['interface'].widget = HiddenInput()
class VmRemoveInterfaceForm(OperationForm): class VmRemoveInterfaceForm(OperationForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices') choices = kwargs.pop('choices')
......
...@@ -18,10 +18,17 @@ ...@@ -18,10 +18,17 @@
<h3 class="list-group-item-heading dashboard-vm-details-network-h3"> <h3 class="list-group-item-heading dashboard-vm-details-network-h3">
<i class="fa fa-{% if i.host %}globe{% else %}link{% endif %}"></i> {{ i.vlan.name }} <i class="fa fa-{% if i.host %}globe{% else %}link{% endif %}"></i> {{ i.vlan.name }}
{% if not i.host%}({% trans "unmanaged" %}){% endif %} {% if not i.host%}({% trans "unmanaged" %}){% endif %}
{% if i.is_master %}({% trans "master" %}){% endif %}
{% if user.is_superuser and i.host %} {% if user.is_superuser and i.host %}
<a href="{{ i.host.get_absolute_url }}" <a href="{{ i.host.get_absolute_url }}"
class="btn btn-default btn-xs">{% trans "edit" %}</a> class="btn btn-default btn-xs">{% trans "edit" %}</a>
{% endif %} {% endif %}
{% with op=op.set_master_interface %}{% if op %}
<span class="operation-wrapper">
<a href="{{op.get_url}}?interface={{ i.pk }}"
class="btn btn-default btn-xs operation set-as-master">{% trans "set as master" %}</a>
</span>
{% endif %}{% endwith %}
{% with op=op.remove_interface %}{% if op %} {% with op=op.remove_interface %}{% if op %}
<span class="operation-wrapper"> <span class="operation-wrapper">
<a href="{{op.get_url}}?interface={{ i.pk }}" <a href="{{op.get_url}}?interface={{ i.pk }}"
......
...@@ -61,7 +61,8 @@ from .util import ( ...@@ -61,7 +61,8 @@ from .util import (
) )
from ..forms import ( from ..forms import (
AclUserOrGroupAddForm, VmResourcesForm, TraitsForm, RawDataForm, AclUserOrGroupAddForm, VmResourcesForm, TraitsForm, RawDataForm,
VmAddInterfaceForm, VmCreateDiskForm, VmDownloadDiskForm, VmSaveForm, VmAddInterfaceForm, VmCreateDiskForm, VmSetMasterInterfaceForm,
VmDownloadDiskForm, VmSaveForm,
VmRenewForm, VmStateChangeForm, VmListSearchForm, VmCustomizeForm, VmRenewForm, VmStateChangeForm, VmListSearchForm, VmCustomizeForm,
VmDiskResizeForm, RedeployForm, VmDiskRemoveForm, VmDiskResizeForm, RedeployForm, VmDiskRemoveForm,
VmMigrateForm, VmDeployForm, VmMigrateForm, VmDeployForm,
...@@ -368,6 +369,32 @@ class VmAddInterfaceView(FormOperationMixin, VmOperationView): ...@@ -368,6 +369,32 @@ class VmAddInterfaceView(FormOperationMixin, VmOperationView):
return val return val
class VmSetMasterInterfaceView(FormOperationMixin, VmOperationView):
op = 'set_master_interface'
form_class = VmSetMasterInterfaceForm
show_in_toolbar = False
effect = 'success'
icon = 'globe'
with_reload = True
def get_form_kwargs(self):
instance = self.get_op().instance
choices = instance.interface_set.all()
interface_pk = self.request.GET.get('interface')
if interface_pk:
try:
default = choices.get(pk=interface_pk)
except (ValueError, Interface.DoesNotExist):
raise Http404()
else:
default = None
val = super(VmSetMasterInterfaceView, self).get_form_kwargs()
val.update({'choices': choices, 'default': default})
return val
class VmDiskModifyView(FormOperationMixin, VmOperationView): class VmDiskModifyView(FormOperationMixin, VmOperationView):
show_in_toolbar = False show_in_toolbar = False
with_reload = True with_reload = True
...@@ -777,6 +804,7 @@ vm_ops = OrderedDict([ ...@@ -777,6 +804,7 @@ vm_ops = OrderedDict([
op='remove_disk', form_class=VmDiskRemoveForm, op='remove_disk', form_class=VmDiskRemoveForm,
icon='times', effect="danger")), icon='times', effect="danger")),
('add_interface', VmAddInterfaceView), ('add_interface', VmAddInterfaceView),
('set_master_interface', VmSetMasterInterfaceView),
('remove_interface', VmRemoveInterfaceView), ('remove_interface', VmRemoveInterfaceView),
('remove_port', VmPortRemoveView), ('remove_port', VmPortRemoveView),
('add_port', VmPortAddView), ('add_port', VmPortAddView),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment