Commit 583f2684 by Szabolcs Gelencser

Implement interface detach

parent d90e9949
...@@ -863,31 +863,18 @@ class VmDownloadDiskForm(OperationForm): ...@@ -863,31 +863,18 @@ class VmDownloadDiskForm(OperationForm):
class VmRemoveInterfaceForm(OperationForm): class VmRemoveInterfaceForm(OperationForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices') port_id = kwargs.pop('port_id')
self.interface = kwargs.pop('default')
super(VmRemoveInterfaceForm, self).__init__(*args, **kwargs) super(VmRemoveInterfaceForm, self).__init__(*args, **kwargs)
self.fields['interface'] = forms.ModelChoiceField( self.fields['port_id'] = forms.CharField(widget=forms.HiddenInput(), initial=port_id)
queryset=choices, initial=self.interface, required=True,
empty_label=None, label=_('Interface'))
if self.interface:
self.fields['interface'].widget = HiddenInput()
@property @property
def helper(self): def helper(self):
helper = super(VmRemoveInterfaceForm, self).helper helper = super(VmRemoveInterfaceForm, self).helper
if self.interface: helper.layout = Layout(
helper.layout = Layout( Field("port_id"),
AnyTag( )
"div",
HTML(format_html(
_("<label>Vlan:</label> {0}"),
self.interface.vlan)),
css_class="form-group",
),
Field("interface"),
)
return helper return helper
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
{% 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}}?port_id={{ i.port_id }}"
class="btn btn-{{op.effect}} btn-xs operation interface-remove" class="btn btn-{{op.effect}} btn-xs operation interface-remove"
{% if op.disabled %}disabled{% endif %}>{% trans "remove" %} {% if op.disabled %}disabled{% endif %}>{% trans "remove" %}
</a> </a>
......
...@@ -366,25 +366,14 @@ class VmRemoveInterfaceView(FormOperationMixin, VmOperationView): ...@@ -366,25 +366,14 @@ class VmRemoveInterfaceView(FormOperationMixin, VmOperationView):
op = 'remove_interface' op = 'remove_interface'
form_class = VmRemoveInterfaceForm form_class = VmRemoveInterfaceForm
show_in_toolbar = False show_in_toolbar = False
wait_for_result = 0.5
icon = 'times' icon = 'times'
effect = "danger" effect = "danger"
with_reload = True
def get_form_kwargs(self): def get_form_kwargs(self):
instance = self.get_op().instance port_id = self.request.GET.get('port_id')
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(VmRemoveInterfaceView, self).get_form_kwargs() val = super(VmRemoveInterfaceView, self).get_form_kwargs()
val.update({'choices': choices, 'default': default}) val.update({'port_id': port_id})
return val return val
......
...@@ -403,21 +403,11 @@ class RemoveInterfaceOperation(InstanceOperation): ...@@ -403,21 +403,11 @@ class RemoveInterfaceOperation(InstanceOperation):
description = _("Remove the specified network interface and erase IP " description = _("Remove the specified network interface and erase IP "
"address allocations, related firewall rules and " "address allocations, related firewall rules and "
"hostnames.") "hostnames.")
required_perms = ()
accept_states = ('STOPPED', 'PENDING', 'ACTIVE') accept_states = ('STOPPED', 'PENDING', 'ACTIVE')
os_policy_actions = (("compute", "compute:detach_interface"),)
def _operation(self, activity, user, system, interface): def _operation(self, request, port_id):
if self.instance.is_running: openstack_api.nova.interface_detach(request, self.instance.id, port_id)
self.instance._detach_network(interface=interface,
parent_activity=activity)
interface.shutdown()
interface.destroy()
interface.delete()
def get_activity_name(self, kwargs):
return create_readable(ugettext_noop("remove %(vlan)s interface"),
vlan=kwargs['interface'].vlan)
@register_operation @register_operation
......
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