Ensure log messages are not translated
Previously translated messages are included in log messages and it was determined what language is chosen by users. It makes difficult for operators to understand log messgaes. This commit tries to use English messages for all log messages. The following policies are applied based on the past discussions in the bug 1406333 and related reviews. - English messages are used for log messages. - log messages include exception messages if possible to help operators identify what happens. - Use ID rather than name for log messages as ID is much more unique compared to name. - LOG.debug() in success code path are deleted. We don't log success messages in most places and API calls to back-end services can be logged from python bindings. Change-Id: Ie554463908327435d886d0d0f1671fd327c0cd00 Closes-Bug: #1406333
This commit is contained in:
parent
c88d5c1de3
commit
ced987815d
@ -66,13 +66,14 @@ class JSONMessage(object):
|
|||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
self.failed = True
|
self.failed = True
|
||||||
|
|
||||||
msg = _("Message json file '%(path)s' is malformed."
|
params = {'path': self._path, 'exception': exc}
|
||||||
" %(exception)s")
|
|
||||||
msg = msg % {'path': self._path, 'exception': str(exc)}
|
|
||||||
if self.fail_silently:
|
if self.fail_silently:
|
||||||
LOG.warning(msg)
|
LOG.warning("Message json file '%(path)s' is malformed. "
|
||||||
|
"%(exception)s", params)
|
||||||
else:
|
else:
|
||||||
raise exceptions.MessageFailure(msg)
|
raise exceptions.MessageFailure(
|
||||||
|
_("Message json file '%(path)s' is malformed. "
|
||||||
|
"%(exception)s") % params)
|
||||||
else:
|
else:
|
||||||
level_name = attrs.get('level', 'info')
|
level_name = attrs.get('level', 'info')
|
||||||
if level_name in self.MESSAGE_LEVELS:
|
if level_name in self.MESSAGE_LEVELS:
|
||||||
@ -89,13 +90,14 @@ class JSONMessage(object):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.failed = True
|
self.failed = True
|
||||||
|
|
||||||
msg = _("Error processing message json file '%(path)s': "
|
params = {'path': self._path, 'exception': exc}
|
||||||
"%(exception)s")
|
|
||||||
msg = msg % {'path': self._path, 'exception': str(exc)}
|
|
||||||
if self.fail_silently:
|
if self.fail_silently:
|
||||||
LOG.warning(msg)
|
LOG.warning("Error processing message json file '%(path)s': "
|
||||||
|
"%(exception)s", params)
|
||||||
else:
|
else:
|
||||||
raise exceptions.MessageFailure(msg)
|
raise exceptions.MessageFailure(
|
||||||
|
_("Error processing message json file '%(path)s': "
|
||||||
|
"%(exception)s") % params)
|
||||||
|
|
||||||
def send_message(self, request):
|
def send_message(self, request):
|
||||||
if self.failed:
|
if self.failed:
|
||||||
|
@ -391,10 +391,9 @@ class Column(html.HTMLElement):
|
|||||||
# Basic object lookups
|
# Basic object lookups
|
||||||
data = getattr(datum, self.transform, None)
|
data = getattr(datum, self.transform, None)
|
||||||
if not hasattr(datum, self.transform):
|
if not hasattr(datum, self.transform):
|
||||||
msg = _("The attribute %(attr)s doesn't exist on "
|
msg = "The attribute %(attr)s doesn't exist on %(obj)s."
|
||||||
"%(obj)s.") % {'attr': self.transform, 'obj': datum}
|
LOG.debug(termcolors.colorize(msg, **PALETTE['ERROR']),
|
||||||
msg = termcolors.colorize(msg, **PALETTE['ERROR'])
|
{'attr': self.transform, 'obj': datum})
|
||||||
LOG.debug(msg)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_data(self, datum):
|
def get_data(self, datum):
|
||||||
|
@ -45,8 +45,8 @@ def get_microversion_for_feature(service, feature, wrapper_class,
|
|||||||
try:
|
try:
|
||||||
service_features = MICROVERSION_FEATURES[service]
|
service_features = MICROVERSION_FEATURES[service]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.debug("'%s' could not be found in the MICROVERSION_FEATURES "
|
LOG.debug("'%s' could not be found in the MICROVERSION_FEATURES dict",
|
||||||
"dict" % service)
|
service)
|
||||||
return None
|
return None
|
||||||
feature_versions = service_features[feature]
|
feature_versions = service_features[feature]
|
||||||
for version in reversed(feature_versions):
|
for version in reversed(feature_versions):
|
||||||
|
@ -1123,9 +1123,9 @@ def servers_update_addresses(request, servers, all_tenants=False):
|
|||||||
networks = list_resources_with_long_filters(
|
networks = list_resources_with_long_filters(
|
||||||
network_list, 'id', set([port.network_id for port in ports]),
|
network_list, 'id', set([port.network_id for port in ports]),
|
||||||
request=request)
|
request=request)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.error('Unable to connect to Neutron: %s', e)
|
||||||
error_message = _('Unable to connect to Neutron.')
|
error_message = _('Unable to connect to Neutron.')
|
||||||
LOG.error(error_message)
|
|
||||||
messages.error(request, error_message)
|
messages.error(request, error_message)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1160,9 +1160,10 @@ def _server_get_addresses(request, server, ports, floating_ips, network_names):
|
|||||||
def _format_address(mac, ip, type):
|
def _format_address(mac, ip, type):
|
||||||
try:
|
try:
|
||||||
version = netaddr.IPAddress(ip).version
|
version = netaddr.IPAddress(ip).version
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.error('Unable to parse IP address %(ip)s: %(exc)s',
|
||||||
|
{'ip': ip, 'exc': e})
|
||||||
error_message = _('Unable to parse IP address %s.') % ip
|
error_message = _('Unable to parse IP address %s.') % ip
|
||||||
LOG.error(error_message)
|
|
||||||
messages.error(request, error_message)
|
messages.error(request, error_message)
|
||||||
raise
|
raise
|
||||||
return {u'OS-EXT-IPS-MAC:mac_addr': mac,
|
return {u'OS-EXT-IPS-MAC:mac_addr': mac,
|
||||||
@ -1283,10 +1284,9 @@ def get_feature_permission(request, feature, operation=None):
|
|||||||
network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
|
network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
|
||||||
feature_info = FEATURE_MAP.get(feature)
|
feature_info = FEATURE_MAP.get(feature)
|
||||||
if not feature_info:
|
if not feature_info:
|
||||||
# Translators: Only used inside Horizon code and invisible to users
|
raise ValueError("The requested feature '%(feature)s' is unknown. "
|
||||||
raise ValueError(_("The requested feature '%(feature)s' is unknown. "
|
|
||||||
"Please make sure to specify a feature defined "
|
"Please make sure to specify a feature defined "
|
||||||
"in FEATURE_MAP."))
|
"in FEATURE_MAP.")
|
||||||
|
|
||||||
# Check dashboard settings
|
# Check dashboard settings
|
||||||
feature_config = feature_info.get('config')
|
feature_config = feature_info.get('config')
|
||||||
@ -1300,10 +1300,9 @@ def get_feature_permission(request, feature, operation=None):
|
|||||||
if feature_policies:
|
if feature_policies:
|
||||||
policy_name = feature_policies.get(operation)
|
policy_name = feature_policies.get(operation)
|
||||||
if not policy_name:
|
if not policy_name:
|
||||||
# Translators: Only used inside Horizon code and invisible to users
|
raise ValueError("The 'operation' parameter for "
|
||||||
raise ValueError(_("The 'operation' parameter for "
|
|
||||||
"get_feature_permission '%(feature)s' "
|
"get_feature_permission '%(feature)s' "
|
||||||
"is invalid. It should be one of %(allowed)s")
|
"is invalid. It should be one of %(allowed)s"
|
||||||
% {'feature': feature,
|
% {'feature': feature,
|
||||||
'allowed': ' '.join(feature_policies.keys())})
|
'allowed': ' '.join(feature_policies.keys())})
|
||||||
role = (('network', policy_name),)
|
role = (('network', policy_name),)
|
||||||
@ -1316,9 +1315,8 @@ def get_feature_permission(request, feature, operation=None):
|
|||||||
try:
|
try:
|
||||||
return is_extension_supported(request, feature_extension)
|
return is_extension_supported(request, feature_extension)
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = (_("Failed to check Neutron '%s' extension is not supported")
|
LOG.info("Failed to check Neutron '%s' extension is not supported",
|
||||||
% feature_extension)
|
feature_extension)
|
||||||
LOG.info(msg)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If all checks are passed, now a given feature is allowed.
|
# If all checks are passed, now a given feature is allowed.
|
||||||
|
@ -349,8 +349,8 @@ class SecurityGroupManager(network_base.SecurityGroupManager):
|
|||||||
self.client.servers.remove_security_group(instance_id, group)
|
self.client.servers.remove_security_group(instance_id, group)
|
||||||
num_groups_to_modify -= 1
|
num_groups_to_modify -= 1
|
||||||
except nova_exceptions.ClientException as err:
|
except nova_exceptions.ClientException as err:
|
||||||
LOG.error(_("Failed to modify %(num_groups_to_modify)d instance "
|
LOG.error("Failed to modify %(num_groups_to_modify)d instance "
|
||||||
"security groups: %(err)s"),
|
"security groups: %(err)s",
|
||||||
{'num_groups_to_modify': num_groups_to_modify,
|
{'num_groups_to_modify': num_groups_to_modify,
|
||||||
'err': err})
|
'err': err})
|
||||||
# reraise novaclient.exceptions.ClientException, but with
|
# reraise novaclient.exceptions.ClientException, but with
|
||||||
|
@ -54,8 +54,8 @@ class DeleteDHCPAgent(tables.DeleteAction):
|
|||||||
api.neutron.remove_network_from_dhcp_agent(request, obj_id,
|
api.neutron.remove_network_from_dhcp_agent(request, obj_id,
|
||||||
network_id)
|
network_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete agent: %s', e)
|
||||||
msg = _('Failed to delete agent: %s') % e
|
msg = _('Failed to delete agent: %s') % e
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse('horizon:admin:networks:detail',
|
redirect = reverse('horizon:admin:networks:detail',
|
||||||
args=[network_id])
|
args=[network_id])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -263,7 +263,7 @@ class CreateNetwork(forms.SelfHandlingForm):
|
|||||||
params['provider:segmentation_id'] = (
|
params['provider:segmentation_id'] = (
|
||||||
data['segmentation_id'])
|
data['segmentation_id'])
|
||||||
network = api.neutron.network_create(request, **params)
|
network = api.neutron.network_create(request, **params)
|
||||||
LOG.debug(_('Network %s was successfully created.'), data['name'])
|
LOG.debug('Network %s was successfully created.', data['name'])
|
||||||
return network
|
return network
|
||||||
except Exception:
|
except Exception:
|
||||||
redirect = reverse('horizon:admin:networks:index')
|
redirect = reverse('horizon:admin:networks:index')
|
||||||
@ -329,11 +329,11 @@ class UpdateNetwork(forms.SelfHandlingForm):
|
|||||||
self.initial['network_id'],
|
self.initial['network_id'],
|
||||||
**params)
|
**params)
|
||||||
msg = _('Network %s was successfully updated.') % data['name']
|
msg = _('Network %s was successfully updated.') % data['name']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return network
|
return network
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update network %(id)s: %(exc)s',
|
||||||
|
{'id': self.initial['network_id'], 'exc': e})
|
||||||
msg = _('Failed to update network %s') % data['name']
|
msg = _('Failed to update network %s') % data['name']
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -124,15 +124,15 @@ class CreatePort(project_forms.CreatePort):
|
|||||||
|
|
||||||
port = api.neutron.port_create(request, **params)
|
port = api.neutron.port_create(request, **params)
|
||||||
msg = _('Port %s was successfully created.') % port['id']
|
msg = _('Port %s was successfully created.') % port['id']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return port
|
return port
|
||||||
except Exception:
|
except Exception as e:
|
||||||
msg = _('Failed to create a port for network %s') \
|
net_id = data['network_id']
|
||||||
% data['network_id']
|
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
|
||||||
LOG.info(msg)
|
{'id': net_id, 'exc': e})
|
||||||
|
msg = _('Failed to create a port for network %s') % net_id
|
||||||
redirect = reverse(self.failure_url,
|
redirect = reverse(self.failure_url,
|
||||||
args=(data['network_id'],))
|
args=(net_id,))
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
|
||||||
@ -185,12 +185,12 @@ class UpdatePort(project_forms.UpdatePort):
|
|||||||
mac_address=data['mac_address'],
|
mac_address=data['mac_address'],
|
||||||
**extension_kwargs)
|
**extension_kwargs)
|
||||||
msg = _('Port %s was successfully updated.') % data['port_id']
|
msg = _('Port %s was successfully updated.') % data['port_id']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return port
|
return port
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update port %(id)s: %(exc)s',
|
||||||
|
{'id': data['port_id'], 'exc': e})
|
||||||
msg = _('Failed to update port %s') % data['port_id']
|
msg = _('Failed to update port %s') % data['port_id']
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.failure_url,
|
redirect = reverse(self.failure_url,
|
||||||
args=[data['network_id']])
|
args=[data['network_id']])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -54,9 +54,10 @@ class DeleteSubnet(proj_tables.SubnetPolicyTargetMixin, tables.DeleteAction):
|
|||||||
def delete(self, request, obj_id):
|
def delete(self, request, obj_id):
|
||||||
try:
|
try:
|
||||||
api.neutron.subnet_delete(request, obj_id)
|
api.neutron.subnet_delete(request, obj_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete subnet %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
msg = _('Failed to delete subnet %s') % obj_id
|
msg = _('Failed to delete subnet %s') % obj_id
|
||||||
LOG.info(msg)
|
|
||||||
network_id = self.table.kwargs['network_id']
|
network_id = self.table.kwargs['network_id']
|
||||||
redirect = reverse('horizon:admin:networks:detail',
|
redirect = reverse('horizon:admin:networks:detail',
|
||||||
args=[network_id])
|
args=[network_id])
|
||||||
|
@ -64,10 +64,11 @@ class CreateSubnet(project_workflows.CreateSubnet):
|
|||||||
# created for if admin user does not belong to the tenant.
|
# created for if admin user does not belong to the tenant.
|
||||||
network = api.neutron.network_get(request,
|
network = api.neutron.network_get(request,
|
||||||
self.context['network_id'])
|
self.context['network_id'])
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to retrieve network %(id)s for a subnet: %(exc)s',
|
||||||
|
{'id': data['network_id'], 'exc': e})
|
||||||
msg = (_('Failed to retrieve network %s for a subnet') %
|
msg = (_('Failed to retrieve network %s for a subnet') %
|
||||||
data['network_id'])
|
data['network_id'])
|
||||||
LOG.info(msg)
|
|
||||||
redirect = self.get_failure_url()
|
redirect = self.get_failure_url()
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
subnet = self._create_subnet(request, data,
|
subnet = self._create_subnet(request, data,
|
||||||
|
@ -53,9 +53,10 @@ class DeleteNetwork(policy.PolicyTargetMixin, tables.DeleteAction):
|
|||||||
def delete(self, request, obj_id):
|
def delete(self, request, obj_id):
|
||||||
try:
|
try:
|
||||||
api.neutron.network_delete(request, obj_id)
|
api.neutron.network_delete(request, obj_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete network %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
msg = _('Failed to delete network %s') % obj_id
|
msg = _('Failed to delete network %s') % obj_id
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse('horizon:admin:networks:index')
|
redirect = reverse('horizon:admin:networks:index')
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ class AddProtocolForm(forms.SelfHandlingForm):
|
|||||||
try:
|
try:
|
||||||
mappings = api.keystone.mapping_list(request)
|
mappings = api.keystone.mapping_list(request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to get mapping list %s', e)
|
||||||
msg = _('Failed to get mapping list %s') % e
|
msg = _('Failed to get mapping list %s') % e
|
||||||
LOG.info(msg)
|
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
|
|
||||||
choices = [(m.id, m.id) for m in mappings]
|
choices = [(m.id, m.id) for m in mappings]
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import abc
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@ -89,13 +88,13 @@ class UpdateRule(forms.SelfHandlingForm):
|
|||||||
try:
|
try:
|
||||||
rule = api.fwaas.rule_update(request, rule_id, **context)
|
rule = api.fwaas.rule_update(request, rule_id, **context)
|
||||||
msg = _('Rule %s was successfully updated.') % name_or_id
|
msg = _('Rule %s was successfully updated.') % name_or_id
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return rule
|
return rule
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.error('Failed to update rule %(id)s: %(reason)s',
|
||||||
|
{'id': rule_id, 'reason': e})
|
||||||
msg = (_('Failed to update rule %(name)s: %(reason)s') %
|
msg = (_('Failed to update rule %(name)s: %(reason)s') %
|
||||||
{'name': name_or_id, 'reason': e})
|
{'name': name_or_id, 'reason': e})
|
||||||
LOG.error(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -115,13 +114,13 @@ class UpdatePolicy(forms.SelfHandlingForm):
|
|||||||
try:
|
try:
|
||||||
policy = api.fwaas.policy_update(request, policy_id, **context)
|
policy = api.fwaas.policy_update(request, policy_id, **context)
|
||||||
msg = _('Policy %s was successfully updated.') % name_or_id
|
msg = _('Policy %s was successfully updated.') % name_or_id
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return policy
|
return policy
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to update policy %(name)s: %(reason)s') % {
|
LOG.error('Failed to update policy %(id)s: %(reason)s',
|
||||||
'name': name_or_id, 'reason': e}
|
{'id': policy_id, 'reason': e})
|
||||||
LOG.error(msg)
|
msg = (_('Failed to update policy %(name)s: %(reason)s') %
|
||||||
|
{'name': name_or_id, 'reason': e})
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -170,13 +169,13 @@ class UpdateFirewall(forms.SelfHandlingForm):
|
|||||||
firewall = api.fwaas.firewall_update(request, firewall_id,
|
firewall = api.fwaas.firewall_update(request, firewall_id,
|
||||||
**context)
|
**context)
|
||||||
msg = _('Firewall %s was successfully updated.') % name_or_id
|
msg = _('Firewall %s was successfully updated.') % name_or_id
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return firewall
|
return firewall
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to update firewall %(name)s: %(reason)s') % {
|
LOG.error('Failed to update firewall %(id)s: %(reason)s',
|
||||||
'name': name_or_id, 'reason': e}
|
{'id': firewall_id, 'reason': e})
|
||||||
LOG.error(msg)
|
msg = (_('Failed to update firewall %(name)s: %(reason)s') %
|
||||||
|
{'name': name_or_id, 'reason': e})
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -210,8 +209,8 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
|
|||||||
current_choices = [(r.id, r.name_or_id) for r in current_rules]
|
current_choices = [(r.id, r.name_or_id) for r in current_rules]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.error('Failed to retrieve available rules: %s', e)
|
||||||
msg = _('Failed to retrieve available rules: %s') % e
|
msg = _('Failed to retrieve available rules: %s') % e
|
||||||
LOG.error(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -233,13 +232,13 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
|
|||||||
'%(policy)s.') % {
|
'%(policy)s.') % {
|
||||||
'rule': insert_rule.name or insert_rule.id,
|
'rule': insert_rule.name or insert_rule.id,
|
||||||
'policy': policy_name_or_id}
|
'policy': policy_name_or_id}
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return policy
|
return policy
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to insert rule to policy %(name)s: %(reason)s') % {
|
LOG.error('Failed to insert rule to policy %(id)s: %(reason)s',
|
||||||
'name': policy_id, 'reason': e}
|
{'id': policy_id, 'reason': e})
|
||||||
LOG.error(msg)
|
msg = (_('Failed to insert rule to policy %(name)s: %(reason)s') %
|
||||||
|
{'name': policy_id, 'reason': e})
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -263,9 +262,12 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm):
|
|||||||
|
|
||||||
current_choices = [(r.id, r.name_or_id) for r in current_rules]
|
current_choices = [(r.id, r.name_or_id) for r in current_rules]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to retrieve current rules in policy %(name)s: '
|
LOG.error('Failed to retrieve current rules in policy %(id)s: '
|
||||||
'%(reason)s') % {'name': self.initial['name'], 'reason': e}
|
'%(reason)s',
|
||||||
LOG.error(msg)
|
{'id': self.initial['policy_id'], 'reason': e})
|
||||||
|
msg = (_('Failed to retrieve current rules in policy %(name)s: '
|
||||||
|
'%(reason)s') %
|
||||||
|
{'name': self.initial['name'], 'reason': e})
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -283,58 +285,18 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm):
|
|||||||
'%(policy)s.') % {
|
'%(policy)s.') % {
|
||||||
'rule': remove_rule.name or remove_rule.id,
|
'rule': remove_rule.name or remove_rule.id,
|
||||||
'policy': policy_name_or_id}
|
'policy': policy_name_or_id}
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return policy
|
return policy
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to remove rule from policy %(name)s: '
|
LOG.error('Failed to remove rule from policy %(id)s: %(reason)s',
|
||||||
'%(reason)s') % {'name': self.initial['name'],
|
{'id': policy_id, 'reason': e})
|
||||||
'reason': e}
|
msg = (_('Failed to remove rule from policy %(name)s: %(reason)s')
|
||||||
LOG.error(msg)
|
% {'name': self.initial['name'], 'reason': e})
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
|
||||||
class RouterInsertionFormBase(forms.SelfHandlingForm):
|
class AddRouterToFirewall(forms.SelfHandlingForm):
|
||||||
|
|
||||||
def __init__(self, request, *args, **kwargs):
|
|
||||||
super(RouterInsertionFormBase, self).__init__(request, *args, **kwargs)
|
|
||||||
try:
|
|
||||||
router_choices = self.get_router_choices(request, kwargs)
|
|
||||||
self.fields['router_ids'].choices = router_choices
|
|
||||||
except Exception as e:
|
|
||||||
msg = self.init_failure_msg % {'name': self.initial['name'],
|
|
||||||
'reason': e}
|
|
||||||
LOG.error(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def get_router_choices(self, request, kwargs):
|
|
||||||
"""Return a list of selectable routers."""
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def get_new_router_ids(self, context):
|
|
||||||
"""Return a new list of router IDs associated with the firewall."""
|
|
||||||
|
|
||||||
def handle(self, request, context):
|
|
||||||
firewall_id = self.initial['firewall_id']
|
|
||||||
firewall_name_or_id = self.initial['name'] or firewall_id
|
|
||||||
try:
|
|
||||||
body = {'router_ids': self.get_new_router_ids(context)}
|
|
||||||
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
|
|
||||||
msg = self.success_msg % {'firewall': firewall_name_or_id}
|
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
|
||||||
return firewall
|
|
||||||
except Exception as e:
|
|
||||||
msg = self.failure_msg % {'name': firewall_name_or_id, 'reason': e}
|
|
||||||
LOG.error(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
|
||||||
|
|
||||||
|
|
||||||
class AddRouterToFirewall(RouterInsertionFormBase):
|
|
||||||
router_ids = forms.MultipleChoiceField(
|
router_ids = forms.MultipleChoiceField(
|
||||||
label=_("Add Routers"),
|
label=_("Add Routers"),
|
||||||
required=False,
|
required=False,
|
||||||
@ -342,10 +304,17 @@ class AddRouterToFirewall(RouterInsertionFormBase):
|
|||||||
help_text=_("Add selected router(s) to the firewall."))
|
help_text=_("Add selected router(s) to the firewall."))
|
||||||
|
|
||||||
failure_url = 'horizon:project:firewalls:index'
|
failure_url = 'horizon:project:firewalls:index'
|
||||||
success_msg = _('Router(s) was/were successfully added to firewall '
|
|
||||||
'%(firewall)s.')
|
def __init__(self, request, *args, **kwargs):
|
||||||
failure_msg = _('Failed to add router(s) to firewall %(name)s: %(reason)s')
|
super(AddRouterToFirewall, self).__init__(request, *args, **kwargs)
|
||||||
init_failure_msg = _('Failed to retrieve available routers: %(reason)s')
|
try:
|
||||||
|
router_choices = self.get_router_choices(request, kwargs)
|
||||||
|
self.fields['router_ids'].choices = router_choices
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error('Failed to retrieve available routers: %s', e)
|
||||||
|
msg = _('Failed to retrieve available routers: %s') % e
|
||||||
|
redirect = reverse(self.failure_url)
|
||||||
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
def get_router_choices(self, request, kwargs):
|
def get_router_choices(self, request, kwargs):
|
||||||
tenant_id = self.request.user.tenant_id
|
tenant_id = self.request.user.tenant_id
|
||||||
@ -358,8 +327,28 @@ class AddRouterToFirewall(RouterInsertionFormBase):
|
|||||||
add_router_ids = context['router_ids']
|
add_router_ids = context['router_ids']
|
||||||
return add_router_ids + existing_router_ids
|
return add_router_ids + existing_router_ids
|
||||||
|
|
||||||
|
def handle(self, request, context):
|
||||||
|
firewall_id = self.initial['firewall_id']
|
||||||
|
firewall_name_or_id = self.initial['name'] or firewall_id
|
||||||
|
try:
|
||||||
|
body = {'router_ids': self.get_new_router_ids(context)}
|
||||||
|
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
|
||||||
|
msg = (_('Router(s) was/were successfully added to firewall '
|
||||||
|
'%(firewall)s.') %
|
||||||
|
{'firewall': firewall_name_or_id})
|
||||||
|
messages.success(request, msg)
|
||||||
|
return firewall
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error('Failed to add router(s) to firewall %(id)s: %(reason)s',
|
||||||
|
{'id': firewall_id, 'reason': e})
|
||||||
|
msg = (_('Failed to add router(s) to firewall %(name)s: '
|
||||||
|
'%(reason)s') %
|
||||||
|
{'name': firewall_name_or_id, 'reason': e})
|
||||||
|
redirect = reverse(self.failure_url)
|
||||||
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
class RemoveRouterFromFirewall(RouterInsertionFormBase):
|
|
||||||
|
class RemoveRouterFromFirewall(forms.SelfHandlingForm):
|
||||||
router_ids = forms.MultipleChoiceField(
|
router_ids = forms.MultipleChoiceField(
|
||||||
label=_("Associated Routers"),
|
label=_("Associated Routers"),
|
||||||
required=False,
|
required=False,
|
||||||
@ -367,12 +356,22 @@ class RemoveRouterFromFirewall(RouterInsertionFormBase):
|
|||||||
help_text=_("Unselect the router(s) to be removed from firewall."))
|
help_text=_("Unselect the router(s) to be removed from firewall."))
|
||||||
|
|
||||||
failure_url = 'horizon:project:firewalls:index'
|
failure_url = 'horizon:project:firewalls:index'
|
||||||
success_msg = _('Router(s) was successfully removed from firewall '
|
|
||||||
'%(firewall)s.')
|
def __init__(self, request, *args, **kwargs):
|
||||||
failure_msg = _('Failed to remove router(s) from firewall %(name)s: '
|
super(RemoveRouterFromFirewall, self).__init__(request,
|
||||||
'%(reason)s')
|
*args, **kwargs)
|
||||||
init_failure_msg = _('Failed to retrieve current routers in firewall '
|
try:
|
||||||
'%(name)s: %(reason)s')
|
router_choices = self.get_router_choices(request, kwargs)
|
||||||
|
self.fields['router_ids'].choices = router_choices
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error('Failed to retrieve current routers in firewall %(id)s: '
|
||||||
|
'%(reason)s',
|
||||||
|
{'id': self.initial['firewall_id'], 'reason': e})
|
||||||
|
msg = (_('Failed to retrieve current routers in firewall '
|
||||||
|
'%(name)s: %(reason)s') %
|
||||||
|
{'name': self.initial['name'], 'reason': e})
|
||||||
|
redirect = reverse(self.failure_url)
|
||||||
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
def get_router_choices(self, request, kwargs):
|
def get_router_choices(self, request, kwargs):
|
||||||
tenant_id = self.request.user.tenant_id
|
tenant_id = self.request.user.tenant_id
|
||||||
@ -384,3 +383,23 @@ class RemoveRouterFromFirewall(RouterInsertionFormBase):
|
|||||||
def get_new_router_ids(self, context):
|
def get_new_router_ids(self, context):
|
||||||
# context[router_ids] is router IDs to be kept.
|
# context[router_ids] is router IDs to be kept.
|
||||||
return context['router_ids']
|
return context['router_ids']
|
||||||
|
|
||||||
|
def handle(self, request, context):
|
||||||
|
firewall_id = self.initial['firewall_id']
|
||||||
|
firewall_name_or_id = self.initial['name'] or firewall_id
|
||||||
|
try:
|
||||||
|
body = {'router_ids': self.get_new_router_ids(context)}
|
||||||
|
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
|
||||||
|
msg = (_('Router(s) was successfully removed from firewall '
|
||||||
|
'%(firewall)s.') %
|
||||||
|
{'firewall': firewall_name_or_id})
|
||||||
|
messages.success(request, msg)
|
||||||
|
return firewall
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error('Failed to remove router(s) from firewall %(id)s: '
|
||||||
|
'%(reason)s', {'id': firewall_id, 'reason': e})
|
||||||
|
msg = (_('Failed to remove router(s) from firewall %(name)s: '
|
||||||
|
'%(reason)s') %
|
||||||
|
{'name': firewall_name_or_id, 'reason': e})
|
||||||
|
redirect = reverse(self.failure_url)
|
||||||
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -409,7 +409,6 @@ class FirewallsTable(tables.DataTable):
|
|||||||
'fwaasrouterinsertion'):
|
'fwaasrouterinsertion'):
|
||||||
del self.columns['router_ids']
|
del self.columns['router_ids']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to verify extension support %(reason)s') % {
|
LOG.error('Failed to verify extension support %s', e)
|
||||||
'reason': e}
|
msg = _('Failed to verify extension support %s') % e
|
||||||
LOG.error(msg)
|
|
||||||
exceptions.handle(request, msg)
|
exceptions.handle(request, msg)
|
||||||
|
@ -65,11 +65,11 @@ class UpdateNetwork(forms.SelfHandlingForm):
|
|||||||
data['network_id'],
|
data['network_id'],
|
||||||
**params)
|
**params)
|
||||||
msg = _('Network %s was successfully updated.') % data['name']
|
msg = _('Network %s was successfully updated.') % data['name']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return network
|
return network
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update network %(id)s: %(exc)s',
|
||||||
|
{'id': data['network_id'], 'exc': e})
|
||||||
msg = _('Failed to update network %s') % data['name']
|
msg = _('Failed to update network %s') % data['name']
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -156,13 +156,13 @@ class CreatePort(forms.SelfHandlingForm):
|
|||||||
msg = _('Port %s was successfully created.') % port['name']
|
msg = _('Port %s was successfully created.') % port['name']
|
||||||
else:
|
else:
|
||||||
msg = _('Port %s was successfully created.') % port['id']
|
msg = _('Port %s was successfully created.') % port['id']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return port
|
return port
|
||||||
except Exception:
|
except Exception as e:
|
||||||
msg = _('Failed to create a port for network %s') \
|
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
|
||||||
% data['network_id']
|
{'id': data['network_id'], 'exc': e})
|
||||||
LOG.info(msg)
|
msg = (_('Failed to create a port for network %s')
|
||||||
|
% data['network_id'])
|
||||||
redirect = reverse(self.failure_url,
|
redirect = reverse(self.failure_url,
|
||||||
args=(data['network_id'],))
|
args=(data['network_id'],))
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
@ -248,12 +248,12 @@ class UpdatePort(forms.SelfHandlingForm):
|
|||||||
admin_state_up=data['admin_state'],
|
admin_state_up=data['admin_state'],
|
||||||
**extension_kwargs)
|
**extension_kwargs)
|
||||||
msg = _('Port %s was successfully updated.') % data['port_id']
|
msg = _('Port %s was successfully updated.') % data['port_id']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return port
|
return port
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update port %(id)s: %(exc)s',
|
||||||
|
{'id': data['port_id'], 'exc': e})
|
||||||
msg = _('Failed to update port %s') % data['port_id']
|
msg = _('Failed to update port %s') % data['port_id']
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.failure_url,
|
redirect = reverse(self.failure_url,
|
||||||
args=[data['network_id']])
|
args=[data['network_id']])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -106,9 +106,10 @@ class DeletePort(policy.PolicyTargetMixin, tables.DeleteAction):
|
|||||||
failure_url = "horizon:project:networks:detail"
|
failure_url = "horizon:project:networks:detail"
|
||||||
try:
|
try:
|
||||||
api.neutron.port_delete(request, port_id)
|
api.neutron.port_delete(request, port_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
msg = _('Failed to delete port: %s') % port_id
|
LOG.info('Failed to delete port %(id)s: %(exc)s',
|
||||||
LOG.info(msg)
|
{'id': port_id, 'exc': e})
|
||||||
|
msg = _('Failed to delete port %s') % port_id
|
||||||
network_id = self.table.kwargs['network_id']
|
network_id = self.table.kwargs['network_id']
|
||||||
redirect = reverse(failure_url,
|
redirect = reverse(failure_url,
|
||||||
args=[network_id])
|
args=[network_id])
|
||||||
|
@ -79,9 +79,10 @@ class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
|
|||||||
def delete(self, request, obj_id):
|
def delete(self, request, obj_id):
|
||||||
try:
|
try:
|
||||||
api.neutron.subnet_delete(request, obj_id)
|
api.neutron.subnet_delete(request, obj_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete subnet %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
msg = _('Failed to delete subnet %s') % obj_id
|
msg = _('Failed to delete subnet %s') % obj_id
|
||||||
LOG.info(msg)
|
|
||||||
network_id = self.table.kwargs['network_id']
|
network_id = self.table.kwargs['network_id']
|
||||||
redirect = reverse('horizon:project:networks:detail',
|
redirect = reverse('horizon:project:networks:detail',
|
||||||
args=[network_id])
|
args=[network_id])
|
||||||
|
@ -75,9 +75,10 @@ class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable,
|
|||||||
LOG.debug('Deleted subnet %s', subnet_id)
|
LOG.debug('Deleted subnet %s', subnet_id)
|
||||||
api.neutron.network_delete(request, network_id)
|
api.neutron.network_delete(request, network_id)
|
||||||
LOG.debug('Deleted network %s successfully', network_id)
|
LOG.debug('Deleted network %s successfully', network_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete network %(id)s: %(exc)s',
|
||||||
|
{'id': network_id, 'exc': e})
|
||||||
msg = _('Failed to delete network %s')
|
msg = _('Failed to delete network %s')
|
||||||
LOG.info(msg, network_id)
|
|
||||||
redirect = reverse("horizon:project:networks:index")
|
redirect = reverse("horizon:project:networks:index")
|
||||||
exceptions.handle(request, msg % network_name, redirect=redirect)
|
exceptions.handle(request, msg % network_name, redirect=redirect)
|
||||||
|
|
||||||
|
@ -471,9 +471,9 @@ class CreateNetwork(workflows.Workflow):
|
|||||||
network.name_or_id)
|
network.name_or_id)
|
||||||
return network
|
return network
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to create network: %s', e)
|
||||||
msg = (_('Failed to create network "%(network)s": %(reason)s') %
|
msg = (_('Failed to create network "%(network)s": %(reason)s') %
|
||||||
{"network": data['net_name'], "reason": e})
|
{"network": data['net_name'], "reason": e})
|
||||||
LOG.info(msg)
|
|
||||||
redirect = self.get_failure_url()
|
redirect = self.get_failure_url()
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
return False
|
return False
|
||||||
@ -562,15 +562,17 @@ class CreateNetwork(workflows.Workflow):
|
|||||||
"""Delete the created network when subnet creation failed."""
|
"""Delete the created network when subnet creation failed."""
|
||||||
try:
|
try:
|
||||||
api.neutron.network_delete(request, network.id)
|
api.neutron.network_delete(request, network.id)
|
||||||
|
LOG.debug('Delete the created network %s '
|
||||||
|
'due to subnet creation failure.', network.id)
|
||||||
msg = _('Delete the created network "%s" '
|
msg = _('Delete the created network "%s" '
|
||||||
'due to subnet creation failure.') % network.name
|
'due to subnet creation failure.') % network.name
|
||||||
LOG.debug(msg)
|
|
||||||
redirect = self.get_failure_url()
|
redirect = self.get_failure_url()
|
||||||
messages.info(request, msg)
|
messages.info(request, msg)
|
||||||
raise exceptions.Http302(redirect)
|
raise exceptions.Http302(redirect)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete network %(id)s: %(exc)s',
|
||||||
|
{'id': network.id, 'exc': e})
|
||||||
msg = _('Failed to delete network "%s"') % network.name
|
msg = _('Failed to delete network "%s"') % network.name
|
||||||
LOG.info(msg)
|
|
||||||
redirect = self.get_failure_url()
|
redirect = self.get_failure_url()
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
@ -43,18 +43,18 @@ class AddRouterRoute(forms.SelfHandlingForm):
|
|||||||
router_id,
|
router_id,
|
||||||
route)
|
route)
|
||||||
msg = _('Static route added')
|
msg = _('Static route added')
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return True
|
return True
|
||||||
except neutron_exc.BadRequest as e:
|
except neutron_exc.BadRequest as e:
|
||||||
msg = (_('Invalid format for routes : %s') % e)
|
LOG.info('Invalid format for routes %(route)s: %(exc)s',
|
||||||
LOG.info(msg)
|
{'route': route, 'exc': e})
|
||||||
|
msg = _('Invalid format for routes: %s') % e
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
redirect = reverse(self.failure_url, args=[router_id])
|
redirect = reverse(self.failure_url, args=[router_id])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = (_('Failed to add route : %s') % e)
|
LOG.info('Failed to add route: %s', e)
|
||||||
LOG.info(msg)
|
msg = _('Failed to add route: %s') % e
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
redirect = reverse(self.failure_url, args=[router_id])
|
redirect = reverse(self.failure_url, args=[router_id])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -36,9 +36,9 @@ class ExtraRoutesTab(tabs.TableTab):
|
|||||||
def allowed(self, request):
|
def allowed(self, request):
|
||||||
try:
|
try:
|
||||||
return api.is_extension_supported(request, 'extraroute')
|
return api.is_extension_supported(request, 'extraroute')
|
||||||
except Exception:
|
except Exception as e:
|
||||||
LOG.info(_("Failed to check if Neutron extraroute extension is "
|
LOG.info("Failed to check if Neutron extraroute extension is "
|
||||||
"supported"))
|
"supported: %s", e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_extra_routes_data(self):
|
def get_extra_routes_data(self):
|
||||||
|
@ -75,9 +75,9 @@ class CreateForm(forms.SelfHandlingForm):
|
|||||||
search_opts = {'router:external': True}
|
search_opts = {'router:external': True}
|
||||||
try:
|
try:
|
||||||
networks = api.neutron.network_list(request, **search_opts)
|
networks = api.neutron.network_list(request, **search_opts)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to get network list: %s', e)
|
||||||
msg = _('Failed to get network list.')
|
msg = _('Failed to get network list.')
|
||||||
LOG.info(msg)
|
|
||||||
messages.warning(request, msg)
|
messages.warning(request, msg)
|
||||||
networks = []
|
networks = []
|
||||||
|
|
||||||
@ -104,11 +104,11 @@ class CreateForm(forms.SelfHandlingForm):
|
|||||||
messages.success(request, message)
|
messages.success(request, message)
|
||||||
return router
|
return router
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
LOG.info('Failed to create router: %s', exc)
|
||||||
if exc.status_code == 409:
|
if exc.status_code == 409:
|
||||||
msg = _('Quota exceeded for resource router.')
|
msg = _('Quota exceeded for resource router.')
|
||||||
else:
|
else:
|
||||||
msg = _('Failed to create router "%s".') % data['name']
|
msg = _('Failed to create router "%s".') % data['name']
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
return False
|
return False
|
||||||
@ -164,10 +164,10 @@ class UpdateForm(forms.SelfHandlingForm):
|
|||||||
router = api.neutron.router_update(request, data['router_id'],
|
router = api.neutron.router_update(request, data['router_id'],
|
||||||
**params)
|
**params)
|
||||||
msg = _('Router %s was successfully updated.') % data['name']
|
msg = _('Router %s was successfully updated.') % data['name']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return router
|
return router
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
|
LOG.info('Failed to update router %(id)s: %(exc)s',
|
||||||
|
{'id': data['router_id'], 'exc': exc})
|
||||||
msg = _('Failed to update router %s') % data['name']
|
msg = _('Failed to update router %s') % data['name']
|
||||||
LOG.info(msg)
|
|
||||||
exceptions.handle(request, msg, redirect=self.redirect_url)
|
exceptions.handle(request, msg, redirect=self.redirect_url)
|
||||||
|
@ -59,8 +59,8 @@ class AddInterface(forms.SelfHandlingForm):
|
|||||||
router_subnet_ids = [fixed_ip["subnet_id"] for port in ports
|
router_subnet_ids = [fixed_ip["subnet_id"] for port in ports
|
||||||
for fixed_ip in port.fixed_ips]
|
for fixed_ip in port.fixed_ips]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to get network list %s') % e
|
LOG.info('Failed to get network list: %s', e)
|
||||||
LOG.info(msg)
|
msg = _('Failed to get network list: %s') % e
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
if router_id:
|
if router_id:
|
||||||
redirect = reverse(self.failure_url, args=[router_id])
|
redirect = reverse(self.failure_url, args=[router_id])
|
||||||
@ -92,7 +92,6 @@ class AddInterface(forms.SelfHandlingForm):
|
|||||||
msg = _('Interface added')
|
msg = _('Interface added')
|
||||||
if port:
|
if port:
|
||||||
msg += ' ' + port.fixed_ips[0]['ip_address']
|
msg += ' ' + port.fixed_ips[0]['ip_address']
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -136,17 +135,18 @@ class AddInterface(forms.SelfHandlingForm):
|
|||||||
return port
|
return port
|
||||||
|
|
||||||
def _handle_error(self, request, router_id, reason):
|
def _handle_error(self, request, router_id, reason):
|
||||||
msg = _('Failed to add_interface: %s') % reason
|
LOG.info('Failed to add_interface: %s', reason)
|
||||||
LOG.info(msg)
|
msg = _('Failed to add interface: %s') % reason
|
||||||
redirect = reverse(self.failure_url, args=[router_id])
|
redirect = reverse(self.failure_url, args=[router_id])
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
def _delete_port(self, request, port):
|
def _delete_port(self, request, port):
|
||||||
try:
|
try:
|
||||||
api.neutron.port_delete(request, port.id)
|
api.neutron.port_delete(request, port.id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete port %(id)s: %(exc)s',
|
||||||
|
{'id': port.id, 'exc': e})
|
||||||
msg = _('Failed to delete port %s') % port.id
|
msg = _('Failed to delete port %s') % port.id
|
||||||
LOG.info(msg)
|
|
||||||
exceptions.handle(request, msg)
|
exceptions.handle(request, msg)
|
||||||
|
|
||||||
|
|
||||||
@ -170,8 +170,8 @@ class SetGatewayForm(forms.SelfHandlingForm):
|
|||||||
try:
|
try:
|
||||||
networks = api.neutron.network_list(request, **search_opts)
|
networks = api.neutron.network_list(request, **search_opts)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to get network list %s') % e
|
LOG.info('Faield to get network list: %s', e)
|
||||||
LOG.info(msg)
|
msg = _('Failed to get network list: %s') % e
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
@ -190,11 +190,11 @@ class SetGatewayForm(forms.SelfHandlingForm):
|
|||||||
data['router_id'],
|
data['router_id'],
|
||||||
data['network_id'])
|
data['network_id'])
|
||||||
msg = _('Gateway interface is added')
|
msg = _('Gateway interface is added')
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('Failed to set gateway %s') % e
|
LOG.info('Failed to set gateway to router %(id)s: %(exc)s',
|
||||||
LOG.info(msg)
|
{'id': data['router_id'], 'exc': e})
|
||||||
|
msg = _('Failed to set gateway: %s') % e
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
@ -81,9 +81,10 @@ class RemoveInterface(policy.PolicyTargetMixin, tables.DeleteAction):
|
|||||||
api.neutron.router_remove_interface(request,
|
api.neutron.router_remove_interface(request,
|
||||||
router_id,
|
router_id,
|
||||||
port_id=obj_id)
|
port_id=obj_id)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to delete interface %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
msg = _('Failed to delete interface %s') % obj_id
|
msg = _('Failed to delete interface %s') % obj_id
|
||||||
LOG.info(msg)
|
|
||||||
router_id = self.table.kwargs['router_id']
|
router_id = self.table.kwargs['router_id']
|
||||||
redirect = reverse(self.failure_url,
|
redirect = reverse(self.failure_url,
|
||||||
args=[router_id])
|
args=[router_id])
|
||||||
|
@ -64,16 +64,23 @@ class DeleteRouter(policy.PolicyTargetMixin, tables.DeleteAction):
|
|||||||
port_id=port.id)
|
port_id=port.id)
|
||||||
api.neutron.router_delete(request, obj_id)
|
api.neutron.router_delete(request, obj_id)
|
||||||
except q_ext.NeutronClientException as e:
|
except q_ext.NeutronClientException as e:
|
||||||
msg = _('Unable to delete router "%s"') % e
|
# TODO(amotoki): Revisit why Http302 needs to be raised.
|
||||||
LOG.info(msg)
|
# We have this pattern ONLY HERE.
|
||||||
messages.error(request, msg)
|
# Can't we merge two except clauses?
|
||||||
redirect = reverse(self.redirect_url)
|
LOG.info('Unable to delete router %(id)s: %(exc)s',
|
||||||
raise exceptions.Http302(redirect, message=msg)
|
{'id': obj_id, 'exc': e})
|
||||||
except Exception:
|
obj = self.table.get_object_by_id(obj_id)
|
||||||
|
name = self.table.get_object_display(obj)
|
||||||
|
msg = _('Unable to delete router "%s"') % name
|
||||||
|
messages.error(request, msg)
|
||||||
|
redirect = reverse(self.redirect_url)
|
||||||
|
raise exceptions.Http302(redirect, message=msg)
|
||||||
|
except Exception as e:
|
||||||
|
LOG.info('Unable to delete router %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
obj = self.table.get_object_by_id(obj_id)
|
obj = self.table.get_object_by_id(obj_id)
|
||||||
name = self.table.get_object_display(obj)
|
name = self.table.get_object_display(obj)
|
||||||
msg = _('Unable to delete router "%s"') % name
|
msg = _('Unable to delete router "%s"') % name
|
||||||
LOG.info(msg)
|
|
||||||
exceptions.handle(request, msg)
|
exceptions.handle(request, msg)
|
||||||
|
|
||||||
def allowed(self, request, router=None):
|
def allowed(self, request, router=None):
|
||||||
@ -158,10 +165,11 @@ class ClearGateway(policy.PolicyTargetMixin, tables.BatchAction):
|
|||||||
try:
|
try:
|
||||||
api.neutron.router_remove_gateway(request, obj_id)
|
api.neutron.router_remove_gateway(request, obj_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Unable to clear gateway for router %(id)s: %(exc)s',
|
||||||
|
{'id': obj_id, 'exc': e})
|
||||||
msg = (_('Unable to clear gateway for router '
|
msg = (_('Unable to clear gateway for router '
|
||||||
'"%(name)s": "%(msg)s"')
|
'"%(name)s": "%(msg)s"')
|
||||||
% {"name": name, "msg": e})
|
% {"name": name, "msg": e})
|
||||||
LOG.info(msg)
|
|
||||||
redirect = reverse(self.redirect_url)
|
redirect = reverse(self.redirect_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ class UpdateVPNService(forms.SelfHandlingForm):
|
|||||||
request, context['vpnservice_id'], **data)
|
request, context['vpnservice_id'], **data)
|
||||||
msg = (_('VPN Service %s was successfully updated.')
|
msg = (_('VPN Service %s was successfully updated.')
|
||||||
% context['name'])
|
% context['name'])
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return vpnservice
|
return vpnservice
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update VPN Service %(id)s: %(exc)s',
|
||||||
|
{'id': context['vpnservice_id'], 'exc': e})
|
||||||
msg = _('Failed to update VPN Service %s') % context['name']
|
msg = _('Failed to update VPN Service %s') % context['name']
|
||||||
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -131,12 +131,12 @@ class UpdateIKEPolicy(forms.SelfHandlingForm):
|
|||||||
request, context['ikepolicy_id'], **data)
|
request, context['ikepolicy_id'], **data)
|
||||||
msg = (_('IKE Policy %s was successfully updated.')
|
msg = (_('IKE Policy %s was successfully updated.')
|
||||||
% context['name'])
|
% context['name'])
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return ikepolicy
|
return ikepolicy
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update IKE Policy %(id)s: %(exc)s',
|
||||||
|
{'id': context['ikepolicy_id'], 'exc': e})
|
||||||
msg = _('Failed to update IKE Policy %s') % context['name']
|
msg = _('Failed to update IKE Policy %s') % context['name']
|
||||||
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -209,12 +209,12 @@ class UpdateIPSecPolicy(forms.SelfHandlingForm):
|
|||||||
request, context['ipsecpolicy_id'], **data)
|
request, context['ipsecpolicy_id'], **data)
|
||||||
msg = (_('IPSec Policy %s was successfully updated.')
|
msg = (_('IPSec Policy %s was successfully updated.')
|
||||||
% context['name'])
|
% context['name'])
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return ipsecpolicy
|
return ipsecpolicy
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update IPSec Policy %(id)s: %(exc)s',
|
||||||
|
{'id': context['ipsecpolicy_id'], 'exc': e})
|
||||||
msg = _('Failed to update IPSec Policy %s') % context['name']
|
msg = _('Failed to update IPSec Policy %s') % context['name']
|
||||||
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
|
||||||
@ -318,12 +318,12 @@ class UpdateIPSecSiteConnection(forms.SelfHandlingForm):
|
|||||||
request, context['ipsecsiteconnection_id'], **data)
|
request, context['ipsecsiteconnection_id'], **data)
|
||||||
msg = (_('IPSec Site Connection %s was successfully updated.')
|
msg = (_('IPSec Site Connection %s was successfully updated.')
|
||||||
% context['name'])
|
% context['name'])
|
||||||
LOG.debug(msg)
|
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return ipsecsiteconnection
|
return ipsecsiteconnection
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
LOG.info('Failed to update IPSec Site Connection %(id)s: %(exc)s',
|
||||||
|
{'id': context['ipsecsiteconnection_id'], 'exc': e})
|
||||||
msg = (_('Failed to update IPSec Site Connection %s')
|
msg = (_('Failed to update IPSec Site Connection %s')
|
||||||
% context['name'])
|
% context['name'])
|
||||||
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
|
|
||||||
redirect = reverse(self.failure_url)
|
redirect = reverse(self.failure_url)
|
||||||
exceptions.handle(request, msg, redirect=redirect)
|
exceptions.handle(request, msg, redirect=redirect)
|
||||||
|
Loading…
Reference in New Issue
Block a user