Commit 583f2684 by Szabolcs Gelencser

Implement interface detach

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