<s> """<STR_LIT>""" <EOL> from django . core . urlresolvers import reverse_lazy <EOL> from django . utils . datastructures import SortedDict <EOL> from django . utils . translation import pgettext_lazy <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 horizon import tables <EOL> from horizon import tabs <EOL> from horizon . utils import memoized <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . routers import forms as project_forms <EOL> from openstack_dashboard . dashboards . project . routers import tables as rtables <EOL> from openstack_dashboard . dashboards . project . routers import tabs as rdtabs <EOL> class IndexView ( tables . DataTableView ) : <EOL> table_class = rtables . RoutersTable <EOL> template_name = '<STR_LIT>' <EOL> def _get_routers ( self , search_opts = None ) : <EOL> try : <EOL> tenant_id = self . request . user . tenant_id <EOL> routers = api . neutron . router_list ( self . request , <EOL> tenant_id = tenant_id , <EOL> search_opts = search_opts ) <EOL> except Exception : <EOL> routers = [ ] <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> ext_net_dict = self . _list_external_networks ( ) <EOL> for r in routers : <EOL> r . name = r . name_or_id <EOL> self . _set_external_network ( r , ext_net_dict ) <EOL> return routers <EOL> def get_data ( self ) : <EOL> routers = self . _get_routers ( ) <EOL> return routers <EOL> def _list_external_networks ( self ) : <EOL> try : <EOL> search_opts = { '<STR_LIT>' : True } <EOL> ext_nets = api . neutron . network_list ( self . request , <EOL> ** search_opts ) <EOL> ext_net_dict = SortedDict ( ( n [ '<STR_LIT:id>' ] , n . name_or_id ) <EOL> for n in ext_nets ) <EOL> except Exception as e : <EOL> msg = _ ( '<STR_LIT>' ) % e <EOL> exceptions . handle ( self . request , msg ) <EOL> ext_net_dict = { } <EOL> return ext_net_dict <EOL> def _set_external_network ( self , router , ext_net_dict ) : <EOL> gateway_info = router . external_gateway_info <EOL> if gateway_info : <EOL> ext_net_id = gateway_info [ '<STR_LIT>' ] <EOL> if ext_net_id in ext_net_dict : <EOL> gateway_info [ '<STR_LIT>' ] = ext_net_dict [ ext_net_id ] <EOL> else : <EOL> msg_params = { '<STR_LIT>' : ext_net_id , '<STR_LIT>' : router . id } <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % msg_params <EOL> messages . error ( self . request , msg ) <EOL> gateway_info [ '<STR_LIT>' ] = pgettext_lazy ( <EOL> '<STR_LIT>' , <EOL> u'<STR_LIT>' ) % ext_net_id <EOL> class DetailView ( tabs . TabbedTableView ) : <EOL> tab_group_class = rdtabs . RouterDetailTabs <EOL> template_name = '<STR_LIT>' <EOL> failure_url = reverse_lazy ( '<STR_LIT>' ) <EOL> @ memoized . memoized_method <EOL> def _get_data ( self ) : <EOL> try : <EOL> router_id = self . kwargs [ '<STR_LIT>' ] <EOL> router = api . neutron . router_get ( self . request , router_id ) <EOL> router . set_id_as_name_if_empty ( length = <NUM_LIT:0> ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) % router_id <EOL> exceptions . handle ( self . request , msg , redirect = self . failure_url ) <EOL> if router . external_gateway_info : <EOL> ext_net_id = router . external_gateway_info [ '<STR_LIT>' ] <EOL> try : <EOL> ext_net = api . neutron . network_get ( self . request , ext_net_id , <EOL> expand_subnet = False ) <EOL> ext_net . set_id_as_name_if_empty ( length = <NUM_LIT:0> ) <EOL> router . external_gateway_info [ '<STR_LIT>' ] = ext_net . name <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) % ext_net_id <EOL> exceptions . handle ( self . request , msg ) <EOL> router . external_gateway_info [ '<STR_LIT>' ] = ext_net_id <EOL> return router <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( DetailView , self ) . get_context_data ( ** kwargs ) <EOL> router = self . _get_data ( ) <EOL> table = rtables . RoutersTable ( self . request ) <EOL> context [ "<STR_LIT>" ] = router <EOL> context [ "<STR_LIT:url>" ] = self . failure_url <EOL> context [ "<STR_LIT>" ] = table . render_row_actions ( router ) <EOL> context [ '<STR_LIT>' ] = api . neutron . get_feature_permission ( <EOL> self . request , "<STR_LIT>" , "<STR_LIT>" ) <EOL> context [ '<STR_LIT>' ] = api . neutron . get_feature_permission ( <EOL> self . request , "<STR_LIT>" , "<STR_LIT>" ) <EOL> return context <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> router = self . _get_data ( ) <EOL> self . kwargs [ '<STR_LIT>' ] = router <EOL> return super ( DetailView , self ) . get ( request , * args , ** kwargs ) <EOL> class CreateView ( forms . ModalFormView ) : <EOL> form_class = project_forms . CreateForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( "<STR_LIT>" ) <EOL> class UpdateView ( forms . ModalFormView ) : <EOL> form_class = project_forms . UpdateForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( "<STR_LIT>" ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( UpdateView , self ) . get_context_data ( ** kwargs ) <EOL> context [ "<STR_LIT>" ] = self . kwargs [ '<STR_LIT>' ] <EOL> return context <EOL> def _get_object ( self , * args , ** kwargs ) : <EOL> router_id = self . kwargs [ '<STR_LIT>' ] <EOL> try : <EOL> return api . neutron . router_get ( self . request , router_id ) <EOL> except Exception : <EOL> redirect = self . success_url <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg , redirect = redirect ) <EOL> def get_initial ( self ) : <EOL> router = self . _get_object ( ) <EOL> initial = { '<STR_LIT>' : router [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : router [ '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : router [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' : router [ '<STR_LIT>' ] } <EOL> if hasattr ( router , '<STR_LIT>' ) : <EOL> initial [ '<STR_LIT>' ] = ( '<STR_LIT>' if router . distributed <EOL> else '<STR_LIT>' ) <EOL> if hasattr ( router , '<STR_LIT>' ) : <EOL> initial [ '<STR_LIT>' ] = router . ha <EOL> return initial </s>
