<s> from django . core . urlresolvers import reverse <EOL> from django . forms import ValidationError <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 openstack_dashboard . api import cinder <EOL> class CreateVolumeType ( forms . SelfHandlingForm ) : <EOL> name = forms . CharField ( max_length = <NUM_LIT:255> , label = _ ( "<STR_LIT:Name>" ) ) <EOL> vol_type_description = forms . CharField ( <EOL> max_length = <NUM_LIT:255> , <EOL> widget = forms . Textarea ( attrs = { '<STR_LIT>' : <NUM_LIT:4> } ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> def clean_name ( self ) : <EOL> cleaned_name = self . cleaned_data [ '<STR_LIT:name>' ] <EOL> if len ( cleaned_name . strip ( ) ) == <NUM_LIT:0> : <EOL> raise ValidationError ( _ ( '<STR_LIT>' ) ) <EOL> return cleaned_name <EOL> def handle ( self , request , data ) : <EOL> try : <EOL> volume_type = cinder . volume_type_create ( <EOL> request , <EOL> data [ '<STR_LIT:name>' ] , <EOL> data [ '<STR_LIT>' ] ) <EOL> messages . success ( request , _ ( '<STR_LIT>' ) <EOL> % data [ '<STR_LIT:name>' ] ) <EOL> return volume_type <EOL> except Exception as e : <EOL> if getattr ( e , '<STR_LIT:code>' , None ) == <NUM_LIT> : <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % data [ '<STR_LIT:name>' ] <EOL> self . _errors [ '<STR_LIT:name>' ] = self . error_class ( [ msg ] ) <EOL> else : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> class CreateQosSpec ( forms . SelfHandlingForm ) : <EOL> name = forms . CharField ( max_length = <NUM_LIT:255> , label = _ ( "<STR_LIT:Name>" ) ) <EOL> consumer = forms . ChoiceField ( label = _ ( "<STR_LIT>" ) , <EOL> choices = cinder . CONSUMER_CHOICES ) <EOL> def handle ( self , request , data ) : <EOL> try : <EOL> qos_spec = cinder . qos_spec_create ( request , <EOL> data [ '<STR_LIT:name>' ] , <EOL> { '<STR_LIT>' : data [ '<STR_LIT>' ] } ) <EOL> messages . success ( request , <EOL> _ ( '<STR_LIT>' ) <EOL> % data [ '<STR_LIT:name>' ] ) <EOL> return qos_spec <EOL> except Exception as ex : <EOL> if getattr ( ex , '<STR_LIT:code>' , None ) == <NUM_LIT> : <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % data [ '<STR_LIT:name>' ] <EOL> self . _errors [ '<STR_LIT:name>' ] = self . error_class ( [ msg ] ) <EOL> else : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> class CreateVolumeTypeEncryption ( forms . SelfHandlingForm ) : <EOL> name = forms . CharField ( label = _ ( "<STR_LIT:Name>" ) , required = False , <EOL> widget = forms . TextInput ( attrs = { '<STR_LIT>' : <EOL> '<STR_LIT>' } ) ) <EOL> provider = forms . CharField ( max_length = <NUM_LIT:255> , label = _ ( "<STR_LIT>" ) ) <EOL> control_location = forms . ChoiceField ( label = _ ( "<STR_LIT>" ) , <EOL> choices = ( ( '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) ) ) <EOL> ) <EOL> cipher = forms . CharField ( label = _ ( "<STR_LIT>" ) , required = False ) <EOL> key_size = forms . IntegerField ( label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> min_value = <NUM_LIT:1> ) <EOL> volume_type_id = forms . CharField ( widget = forms . HiddenInput ( ) ) <EOL> def handle ( self , request , data ) : <EOL> try : <EOL> if data [ '<STR_LIT>' ] == u'<STR_LIT>' : <EOL> data [ '<STR_LIT>' ] = None <EOL> volume_type = cinder . volume_encryption_type_create ( request , <EOL> data [ '<STR_LIT>' ] , <EOL> data ) <EOL> messages . success ( request , _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % data [ '<STR_LIT:name>' ] ) <EOL> return volume_type <EOL> except Exception : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> class UpdateVolumeTypeEncryption ( CreateVolumeTypeEncryption ) : <EOL> def handle ( self , request , data ) : <EOL> try : <EOL> if data [ '<STR_LIT>' ] == u'<STR_LIT>' : <EOL> data [ '<STR_LIT>' ] = None <EOL> volume_type = cinder . volume_encryption_type_update ( request , <EOL> data [ '<STR_LIT>' ] , <EOL> data ) <EOL> messages . success ( request , _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % data [ '<STR_LIT:name>' ] ) <EOL> return volume_type <EOL> except NotImplementedError : <EOL> messages . error ( request , _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> except Exception : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> return False <EOL> class ManageQosSpecAssociation ( forms . SelfHandlingForm ) : <EOL> qos_spec_choice = forms . ChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> def __init__ ( self , request , * args , ** kwargs ) : <EOL> super ( ManageQosSpecAssociation , self ) . __init__ ( request , <EOL> * args , <EOL> ** kwargs ) <EOL> qos_spec_field = self . fields [ '<STR_LIT>' ] <EOL> qos_spec_field . choices = self . populate_qos_spec_choices ( ) <EOL> def populate_qos_spec_choices ( self ) : <EOL> qos_specs = self . initial [ "<STR_LIT>" ] <EOL> current_qos_spec = self . initial [ "<STR_LIT>" ] <EOL> qos_spec_list = [ ( qos_spec . id , qos_spec . name ) <EOL> for qos_spec in qos_specs <EOL> if qos_spec . id != current_qos_spec ] <EOL> if current_qos_spec : <EOL> qos_spec_list . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> if qos_spec_list : <EOL> qos_spec_list . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> else : <EOL> qos_spec_list . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> return qos_spec_list <EOL> def handle ( self , request , data ) : <EOL> vol_type_id = self . initial [ '<STR_LIT>' ] <EOL> new_qos_spec_id = data [ '<STR_LIT>' ] <EOL> try : <EOL> cur_qos_spec_id = self . initial [ '<STR_LIT>' ] <EOL> if cur_qos_spec_id : <EOL> qos_spec = cinder . qos_spec_get ( request , <EOL> cur_qos_spec_id ) <EOL> cinder . qos_spec_disassociate ( request , <EOL> qos_spec , <EOL> vol_type_id ) <EOL> if new_qos_spec_id != '<STR_LIT>' : <EOL> qos_spec = cinder . qos_spec_get ( request , <EOL> new_qos_spec_id ) <EOL> cinder . qos_spec_associate ( request , <EOL> qos_spec , <EOL> vol_type_id ) <EOL> messages . success ( request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> return True <EOL> except Exception : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> class EditQosSpecConsumer ( forms . SelfHandlingForm ) : <EOL> current_consumer = forms . CharField ( label = _ ( "<STR_LIT>" ) , <EOL> widget = forms . TextInput ( <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> required = False ) <EOL> consumer_choice = forms . ChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> choices = cinder . CONSUMER_CHOICES , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> def __init__ ( self , request , * args , ** kwargs ) : <EOL> super ( EditQosSpecConsumer , self ) . __init__ ( request , * args , ** kwargs ) <EOL> consumer_field = self . fields [ '<STR_LIT>' ] <EOL> qos_spec = self . initial [ "<STR_LIT>" ] <EOL> self . fields [ '<STR_LIT>' ] . initial = qos_spec . consumer <EOL> choices = [ choice for choice in cinder . CONSUMER_CHOICES <EOL> if choice [ <NUM_LIT:0> ] != qos_spec . consumer ] <EOL> choices . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> consumer_field . choices = choices <EOL> def handle ( self , request , data ) : <EOL> qos_spec_id = self . initial [ '<STR_LIT>' ] <EOL> new_consumer = data [ '<STR_LIT>' ] <EOL> try : <EOL> cinder . qos_spec_set_keys ( request , <EOL> qos_spec_id , <EOL> { '<STR_LIT>' : new_consumer } ) <EOL> messages . success ( request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> return True <EOL> except Exception : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> exceptions . handle ( request , _ ( '<STR_LIT>' ) , <EOL> redirect = redirect ) <EOL> class EditVolumeType ( forms . SelfHandlingForm ) : <EOL> name = forms . CharField ( max_length = <NUM_LIT:255> , <EOL> label = _ ( "<STR_LIT:Name>" ) ) <EOL> description = forms . CharField ( max_length = <NUM_LIT:255> , <EOL> widget = forms . Textarea ( attrs = { '<STR_LIT>' : <NUM_LIT:4> } ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> def clean_name ( self ) : <EOL> cleaned_name = self . cleaned_data [ '<STR_LIT:name>' ] <EOL> if len ( cleaned_name . strip ( ) ) == <NUM_LIT:0> : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> self . _errors [ '<STR_LIT:name>' ] = self . error_class ( [ msg ] ) <EOL> return cleaned_name <EOL> def handle ( self , request , data ) : <EOL> volume_type_id = self . initial [ '<STR_LIT:id>' ] <EOL> try : <EOL> cinder . volume_type_update ( request , <EOL> volume_type_id , <EOL> data [ '<STR_LIT:name>' ] , <EOL> data [ '<STR_LIT:description>' ] ) <EOL> message = _ ( '<STR_LIT>' ) <EOL> messages . success ( request , message ) <EOL> return True <EOL> except Exception as ex : <EOL> redirect = reverse ( "<STR_LIT>" ) <EOL> if ex . code == <NUM_LIT> : <EOL> error_message = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> error_message = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( request , error_message , <EOL> redirect = redirect ) </s>
