From 9a535a1f848c7813169fdd7d042a29678c554092 Mon Sep 17 00:00:00 2001 From: Yosef Hoffman Date: Thu, 5 May 2016 11:12:23 -0400 Subject: [PATCH] Improve security rule notification message If from_port and to_port are both "-1" then return "any port" instead of "-1:-1". For example, instead of ``ALLOW -1:-1/icmp from 0.0.0.0/0`` return ``ALLOW any port/icmp from 0.0.0.0/0`` Change-Id: I0ded50a40089406fd69c8fa869839e46eecef352 Closes-Bug: #1430005 --- openstack_dashboard/api/nova.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index 0333714b7a..a66459248d 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -232,20 +232,18 @@ class SecurityGroupRule(base.APIResourceWrapper): _attrs = ['id', 'ip_protocol', 'from_port', 'to_port', 'ip_range', 'group'] def __str__(self): + vals = { + 'range': '%s:%s' % (self.from_port, self.to_port), + 'ip_protocol': self.ip_protocol + } + if self.from_port == -1 and self.to_port == -1: + vals['range'] = 'any port' if 'name' in self.group: - vals = {'from': self.from_port, - 'to': self.to_port, - 'ip_protocol': self.ip_protocol, - 'group': self.group['name']} - return (_('ALLOW %(from)s:%(to)s/%(ip_protocol)s from %(group)s') % - vals) + vals['group'] = self.group['name'] + return (_('ALLOW %(range)s/%(ip_protocol)s from %(group)s') % vals) else: - vals = {'from': self.from_port, - 'to': self.to_port, - 'ip_protocol': self.ip_protocol, - 'cidr': self.ip_range['cidr']} - return (_('ALLOW %(from)s:%(to)s/%(ip_protocol)s from %(cidr)s') % - vals) + vals['cidr'] = self.ip_range['cidr'] + return (_('ALLOW %(range)s/%(ip_protocol)s from %(cidr)s') % vals) # The following attributes are defined to keep compatibility with Neutron @property