<s> from collections import OrderedDict <EOL> from django . core . urlresolvers import reverse_lazy <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import forms <EOL> from horizon import tables <EOL> from horizon . utils import memoized <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . networks import views as user_views <EOL> from openstack_dashboard . utils import filters <EOL> from openstack_dashboard . dashboards . admin . networks . agents import tables as agents_tables <EOL> from openstack_dashboard . dashboards . admin . networks import forms as project_forms <EOL> from openstack_dashboard . dashboards . admin . networks . ports import tables as ports_tables <EOL> from openstack_dashboard . dashboards . admin . networks . subnets import tables as subnets_tables <EOL> from openstack_dashboard . dashboards . admin . networks import tables as networks_tables <EOL> class IndexView ( tables . DataTableView ) : <EOL> table_class = networks_tables . NetworksTable <EOL> template_name = '<STR_LIT>' <EOL> page_title = _ ( "<STR_LIT>" ) <EOL> @ memoized . memoized_method <EOL> def _get_tenant_list ( self ) : <EOL> try : <EOL> tenants , has_more = api . keystone . tenant_list ( self . request ) <EOL> except Exception : <EOL> tenants = [ ] <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> exceptions . handle ( self . request , msg ) <EOL> tenant_dict = OrderedDict ( [ ( t . id , t ) for t in tenants ] ) <EOL> return tenant_dict <EOL> def _get_agents_data ( self , network ) : <EOL> agents = [ ] <EOL> data = _ ( "<STR_LIT>" ) <EOL> try : <EOL> if api . neutron . is_extension_supported ( self . request , <EOL> '<STR_LIT>' ) : <EOL> agents = api . neutron . list_dhcp_agent_hosting_networks ( <EOL> self . request , network ) <EOL> data = len ( agents ) <EOL> except Exception : <EOL> self . exception = True <EOL> return data <EOL> def get_data ( self ) : <EOL> try : <EOL> networks = api . neutron . network_list ( self . request ) <EOL> except Exception : <EOL> networks = [ ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> if networks : <EOL> self . exception = False <EOL> tenant_dict = self . _get_tenant_list ( ) <EOL> for n in networks : <EOL> tenant = tenant_dict . get ( n . tenant_id , None ) <EOL> n . tenant_name = getattr ( tenant , '<STR_LIT:name>' , None ) <EOL> n . num_agents = self . _get_agents_data ( n . id ) <EOL> if self . exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return networks <EOL> class CreateView ( forms . ModalFormView ) : <EOL> form_class = project_forms . CreateNetwork <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> page_title = _ ( "<STR_LIT>" ) <EOL> class DetailView ( tables . MultiTableView ) : <EOL> table_classes = ( subnets_tables . SubnetsTable , <EOL> ports_tables . PortsTable , <EOL> agents_tables . DHCPAgentsTable ) <EOL> template_name = '<STR_LIT>' <EOL> page_title = '<STR_LIT>' <EOL> def get_subnets_data ( self ) : <EOL> try : <EOL> network_id = self . kwargs [ '<STR_LIT>' ] <EOL> subnets = api . neutron . subnet_list ( self . request , <EOL> network_id = network_id ) <EOL> except Exception : <EOL> subnets = [ ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return subnets <EOL> def get_ports_data ( self ) : <EOL> try : <EOL> network_id = self . kwargs [ '<STR_LIT>' ] <EOL> ports = api . neutron . port_list ( self . request , network_id = network_id ) <EOL> except Exception : <EOL> ports = [ ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return ports <EOL> def get_agents_data ( self ) : <EOL> agents = [ ] <EOL> try : <EOL> network_id = self . kwargs [ '<STR_LIT>' ] <EOL> agents = api . neutron . list_dhcp_agent_hosting_networks ( self . request , <EOL> network_id ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return agents <EOL> @ memoized . memoized_method <EOL> def _get_data ( self ) : <EOL> try : <EOL> network_id = self . kwargs [ '<STR_LIT>' ] <EOL> network = api . neutron . network_get ( self . request , network_id ) <EOL> network . set_id_as_name_if_empty ( length = <NUM_LIT:0> ) <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % network_id , <EOL> redirect = self . get_redirect_url ( ) ) <EOL> return network <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( DetailView , self ) . get_context_data ( ** kwargs ) <EOL> network = self . _get_data ( ) <EOL> try : <EOL> dhcp_agent_support = api . neutron . is_extension_supported ( <EOL> self . request , '<STR_LIT>' ) <EOL> context [ '<STR_LIT>' ] = dhcp_agent_support <EOL> except Exception : <EOL> context [ '<STR_LIT>' ] = False <EOL> table = networks_tables . NetworksTable ( self . request ) <EOL> context [ "<STR_LIT>" ] = network <EOL> context [ "<STR_LIT:url>" ] = self . get_redirect_url ( ) <EOL> context [ "<STR_LIT>" ] = table . render_row_actions ( network ) <EOL> choices = networks_tables . project_tables . STATUS_DISPLAY_CHOICES <EOL> network . status_label = ( <EOL> filters . get_display_label ( choices , network . status ) ) <EOL> choices = networks_tables . DISPLAY_CHOICES <EOL> network . admin_state_label = ( <EOL> filters . get_display_label ( choices , network . admin_state ) ) <EOL> return context <EOL> @ staticmethod <EOL> def get_redirect_url ( ) : <EOL> return reverse_lazy ( '<STR_LIT>' ) <EOL> class UpdateView ( user_views . UpdateView ) : <EOL> form_class = project_forms . UpdateNetwork <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> submit_url = "<STR_LIT>" <EOL> def get_initial ( self ) : <EOL> network = self . _get_object ( ) <EOL> return { '<STR_LIT>' : network [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : network [ '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : network [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' : network [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : network [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : network [ '<STR_LIT>' ] } </s>
