<s> import logging <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import forms <EOL> from horizon import messages <EOL> from neutronclient . common import exceptions as neutron_exc <EOL> from openstack_dashboard . api import neutron as api <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class AddRouterRoute ( forms . SelfHandlingForm ) : <EOL> destination = forms . IPField ( label = _ ( "<STR_LIT>" ) , mask = True ) <EOL> nexthop = forms . IPField ( label = _ ( "<STR_LIT>" ) ) <EOL> failure_url = '<STR_LIT>' <EOL> def handle ( self , request , data , ** kwargs ) : <EOL> router_id = self . initial [ '<STR_LIT>' ] <EOL> try : <EOL> route = { '<STR_LIT>' : data [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] } <EOL> api . router_static_route_add ( request , <EOL> router_id , <EOL> route ) <EOL> msg = _ ( '<STR_LIT>' ) <EOL> LOG . debug ( msg ) <EOL> messages . success ( request , msg ) <EOL> return True <EOL> except neutron_exc . BadRequest as e : <EOL> msg = ( _ ( '<STR_LIT>' ) % e ) <EOL> LOG . info ( msg ) <EOL> messages . error ( request , msg ) <EOL> redirect = reverse ( self . failure_url , args = [ router_id ] ) <EOL> exceptions . handle ( request , msg , redirect = redirect ) <EOL> except Exception as e : <EOL> msg = ( _ ( '<STR_LIT>' ) % e ) <EOL> LOG . info ( msg ) <EOL> messages . error ( request , msg ) <EOL> redirect = reverse ( self . failure_url , args = [ router_id ] ) <EOL> exceptions . handle ( request , msg , redirect = redirect ) </s>
