<s> import logging <EOL> from django . core . urlresolvers import reverse <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 tables <EOL> from openstack_dashboard import api <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class CheckNetworkEditable ( object ) : <EOL> """<STR_LIT>""" <EOL> def allowed ( self , request , datum = None ) : <EOL> network = self . table . _get_network ( ) <EOL> if network . shared : <EOL> return False <EOL> return True <EOL> class DeleteSubnet ( CheckNetworkEditable , tables . DeleteAction ) : <EOL> data_type_singular = _ ( "<STR_LIT>" ) <EOL> data_type_plural = _ ( "<STR_LIT>" ) <EOL> def delete ( self , request , obj_id ) : <EOL> try : <EOL> api . neutron . subnet_delete ( request , obj_id ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) % obj_id <EOL> LOG . info ( msg ) <EOL> network_id = self . table . kwargs [ '<STR_LIT>' ] <EOL> redirect = reverse ( '<STR_LIT>' , <EOL> args = [ network_id ] ) <EOL> exceptions . handle ( request , msg , redirect = redirect ) <EOL> class CreateSubnet ( CheckNetworkEditable , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def get_link_url ( self , datum = None ) : <EOL> network_id = self . table . kwargs [ '<STR_LIT>' ] <EOL> return reverse ( self . url , args = ( network_id , ) ) <EOL> class UpdateSubnet ( CheckNetworkEditable , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def get_link_url ( self , subnet ) : <EOL> network_id = self . table . kwargs [ '<STR_LIT>' ] <EOL> return reverse ( self . url , args = ( network_id , subnet . id ) ) <EOL> class SubnetsTable ( tables . DataTable ) : <EOL> name = tables . Column ( "<STR_LIT:name>" , verbose_name = _ ( "<STR_LIT:Name>" ) , <EOL> link = '<STR_LIT>' ) <EOL> cidr = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> ip_version = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> gateway_ip = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> failure_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def _get_network ( self ) : <EOL> if not hasattr ( self , "<STR_LIT>" ) : <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> msg = _ ( '<STR_LIT>' ) % ( network_id ) <EOL> exceptions . handle ( self . request , msg , redirect = self . failure_url ) <EOL> self . _network = network <EOL> return self . _network <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = ( CreateSubnet , DeleteSubnet ) <EOL> row_actions = ( UpdateSubnet , DeleteSubnet ) </s>
