Commit 896412ac by Szabolcs Gelencser

Implement floating IP remove operation

parent 02238427
......@@ -1027,6 +1027,21 @@ class VmPublicIpAddForm(OperationForm):
)
return helper
class VmPublicIpRemoveForm(OperationForm):
def __init__(self, *args, **kwargs):
public_ip_id = kwargs.pop('public_ip_id')
super(VmPublicIpRemoveForm, self).__init__(*args, **kwargs)
self.fields['public_ip_id'] = forms.CharField(widget=forms.HiddenInput(), initial=public_ip_id)
@property
def helper(self):
helper = super(VmPublicIpRemoveForm, self).helper
helper.layout = Layout(
Field("public_ip_id"),
)
return helper
class CircleAuthenticationForm(AuthenticationForm):
# fields: username, password
......
......@@ -53,7 +53,17 @@
<span class="pull-right">
{% if i.public_ip %}
<dl>
<dt>{% trans "Public IP address" %}:</dt>
<dt>
{% trans "Public IP address" %}
{% with op=op.remove_public_ip %}{% if op %}
<span class="operation-wrapper">
<a href="{{op.get_url}}?public_ip_id={{ i.public_ip_id }}"
class="btn btn-{{op.effect}} btn-xs operation"
{% if op.disabled %}disabled{% endif %}>{% trans "remove" %}
</a>
</span>
{% endif %}{% endwith %}
</dt>
<dd>{{ i.public_ip }}</dd>
</dl>
{% else %}
......
......@@ -63,7 +63,7 @@ from .util import (
)
from ..forms import (
AclUserOrGroupAddForm, VmResourcesForm, VmCustomizeForm, VmDeployForm, VmFromPlainImageForm, VmRemoveInterfaceForm,
VmAddInterfaceForm, VmSaveForm, VmPortAddForm, VmPublicIpAddForm)
VmAddInterfaceForm, VmSaveForm, VmPortAddForm, VmPublicIpAddForm, VmPublicIpRemoveForm)
logger = logging.getLogger(__name__)
......@@ -185,6 +185,7 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
if floating_ip.port_id in instance_ports_by_id.keys():
port = instance_ports_by_id[floating_ip.port_id]
instance_networks[port.network_id].public_ip = floating_ip.ip
instance_networks[port.network_id].public_ip_id = floating_ip.id
context['networks'] = instance_networks.values()
......@@ -571,6 +572,22 @@ class VmPublicIpAddView(FormOperationMixin, VmOperationView):
return val
class VmPublicIpRemoveView(FormOperationMixin, VmOperationView):
op = 'remove_public_ip'
show_in_toolbar = False
icon = 'times'
effect = "danger"
form_class = VmPublicIpRemoveForm
def get_form_kwargs(self):
public_ip_id = self.request.GET.get('public_ip_id')
val = super(VmPublicIpRemoveView, self).get_form_kwargs()
val.update({'public_ip_id': public_ip_id})
return val
class VmSaveView(FormOperationMixin, VmOperationView):
op = 'save_as_template'
......@@ -837,6 +854,7 @@ vm_ops = OrderedDict([
# ('remove_port', VmPortRemoveView),
# ('add_port', VmPortAddView),
('add_public_ip', VmPublicIpAddView),
('remove_public_ip', VmPublicIpRemoveView),
# ('renew', VmRenewView),
# ('resources_change', VmResourcesChangeView),
# ('password_reset', VmOperationView.factory(
......
......@@ -465,6 +465,15 @@ class AddPublicIPOperation(InstanceOperation):
openstack_api.neutron.floating_ip_associate(request, floating_ip.id, port_id)
@register_operation
class RemovePublicIPOperation(InstanceOperation):
id = 'remove_public_ip'
name = _("remove public ip")
def _operation(self, request, public_ip_id):
openstack_api.neutron.floating_ip_disassociate(request, public_ip_id)
openstack_api.neutron.tenant_floating_ip_release(request, public_ip_id)
@register_operation
class RemoveDiskOperation(InstanceOperation):
id = 'remove_disk'
name = _("remove disk")
......
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