<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 workflows <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . networks import workflows as network_workflows <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class CreateSubnetInfoAction ( network_workflows . CreateSubnetInfoAction ) : <EOL> with_subnet = forms . BooleanField ( initial = True , required = False , <EOL> widget = forms . HiddenInput ( ) ) <EOL> msg = _ ( '<STR_LIT>' ) <EOL> class Meta : <EOL> name = _ ( "<STR_LIT>" ) <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def clean ( self ) : <EOL> cleaned_data = workflows . Action . clean ( self ) <EOL> self . _check_subnet_data ( cleaned_data ) <EOL> return cleaned_data <EOL> class CreateSubnetInfo ( network_workflows . CreateSubnetInfo ) : <EOL> action_class = CreateSubnetInfoAction <EOL> depends_on = ( "<STR_LIT>" , ) <EOL> class CreateSubnet ( network_workflows . CreateNetwork ) : <EOL> slug = "<STR_LIT>" <EOL> name = _ ( "<STR_LIT>" ) <EOL> finalize_button_name = _ ( "<STR_LIT>" ) <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> failure_message = _ ( '<STR_LIT>' ) <EOL> default_steps = ( CreateSubnetInfo , <EOL> network_workflows . CreateSubnetDetail ) <EOL> def format_status_message ( self , message ) : <EOL> name = self . context . get ( '<STR_LIT>' ) or self . context . get ( '<STR_LIT>' ) <EOL> return message % name <EOL> def get_success_url ( self ) : <EOL> return reverse ( "<STR_LIT>" , <EOL> args = ( self . context . get ( '<STR_LIT>' ) , ) ) <EOL> def get_failure_url ( self ) : <EOL> return reverse ( "<STR_LIT>" , <EOL> args = ( self . context . get ( '<STR_LIT>' ) , ) ) <EOL> def handle ( self , request , data ) : <EOL> subnet = self . _create_subnet ( request , data ) <EOL> return True if subnet else False <EOL> class UpdateSubnetInfoAction ( CreateSubnetInfoAction ) : <EOL> cidr = forms . IPField ( label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> initial = "<STR_LIT>" , <EOL> widget = forms . TextInput ( <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> help_text = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> version = forms . IPv4 | forms . IPv6 , <EOL> mask = True ) <EOL> ip_version = forms . ChoiceField ( choices = [ ( <NUM_LIT:4> , '<STR_LIT>' ) , ( <NUM_LIT:6> , '<STR_LIT>' ) ] , <EOL> widget = forms . HiddenInput ( ) , <EOL> label = _ ( "<STR_LIT>" ) ) <EOL> gateway_ip = forms . IPField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> initial = "<STR_LIT>" , <EOL> help_text = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> version = forms . IPv4 | forms . IPv6 , <EOL> mask = False ) <EOL> no_gateway = forms . BooleanField ( label = _ ( "<STR_LIT>" ) , <EOL> initial = False , required = False ) <EOL> class Meta : <EOL> name = _ ( "<STR_LIT>" ) <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def clean ( self ) : <EOL> cleaned_data = workflows . Action . clean ( self ) <EOL> self . _check_subnet_data ( cleaned_data , is_create = False ) <EOL> return cleaned_data <EOL> class UpdateSubnetInfo ( CreateSubnetInfo ) : <EOL> action_class = UpdateSubnetInfoAction <EOL> depends_on = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class UpdateSubnetDetailAction ( network_workflows . CreateSubnetDetailAction ) : <EOL> allocation_pools = forms . CharField ( widget = forms . HiddenInput ( ) , <EOL> required = False ) <EOL> def __init__ ( self , request , context , * args , ** kwargs ) : <EOL> super ( UpdateSubnetDetailAction , self ) . __init__ ( request , context , <EOL> * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . widget = forms . HiddenInput ( ) <EOL> self . fields [ '<STR_LIT>' ] . required = False <EOL> class Meta : <EOL> name = _ ( "<STR_LIT>" ) <EOL> help_text = _ ( '<STR_LIT>' ) <EOL> class UpdateSubnetDetail ( network_workflows . CreateSubnetDetail ) : <EOL> action_class = UpdateSubnetDetailAction <EOL> class UpdateSubnet ( network_workflows . CreateNetwork ) : <EOL> slug = "<STR_LIT>" <EOL> name = _ ( "<STR_LIT>" ) <EOL> finalize_button_name = _ ( "<STR_LIT>" ) <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> failure_message = _ ( '<STR_LIT>' ) <EOL> success_url = "<STR_LIT>" <EOL> failure_url = "<STR_LIT>" <EOL> default_steps = ( UpdateSubnetInfo , <EOL> UpdateSubnetDetail ) <EOL> def format_status_message ( self , message ) : <EOL> name = self . context . get ( '<STR_LIT>' ) or self . context . get ( '<STR_LIT>' ) <EOL> return message % name <EOL> def get_success_url ( self ) : <EOL> return reverse ( self . success_url , <EOL> args = ( self . context . get ( '<STR_LIT>' ) , ) ) <EOL> def _update_subnet ( self , request , data ) : <EOL> network_id = self . context . get ( '<STR_LIT>' ) <EOL> try : <EOL> subnet_id = self . context . get ( '<STR_LIT>' ) <EOL> params = { } <EOL> params [ '<STR_LIT:name>' ] = data [ '<STR_LIT>' ] <EOL> if data [ '<STR_LIT>' ] : <EOL> params [ '<STR_LIT>' ] = None <EOL> elif data [ '<STR_LIT>' ] : <EOL> params [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] <EOL> subnet = api . neutron . subnet_get ( request , subnet_id ) <EOL> if params [ '<STR_LIT>' ] == subnet . gateway_ip : <EOL> del params [ '<STR_LIT>' ] <EOL> self . _setup_subnet_parameters ( params , data , is_create = False ) <EOL> subnet = api . neutron . subnet_update ( request , subnet_id , ** params ) <EOL> msg = _ ( '<STR_LIT>' ) % data [ '<STR_LIT>' ] <EOL> LOG . debug ( msg ) <EOL> return subnet <EOL> except Exception as e : <EOL> msg = ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % <EOL> { "<STR_LIT>" : data [ '<STR_LIT>' ] , "<STR_LIT>" : e } ) <EOL> redirect = reverse ( self . failure_url , args = ( network_id , ) ) <EOL> exceptions . handle ( request , msg , redirect = redirect ) <EOL> return False <EOL> def handle ( self , request , data ) : <EOL> subnet = self . _update_subnet ( request , data ) <EOL> return True if subnet else False </s>
