<s> import json <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . views . decorators . debug import sensitive_variables <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 . instances import utils as instance_utils <EOL> from openstack_dashboard . dashboards . project . instances . workflows import create_instance <EOL> class SetFlavorChoiceAction ( workflows . Action ) : <EOL> old_flavor_id = forms . CharField ( required = False , widget = forms . HiddenInput ( ) ) <EOL> old_flavor_name = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> widget = forms . TextInput ( attrs = { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> required = False , <EOL> ) <EOL> flavor = forms . ChoiceField ( label = _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> name = _ ( "<STR_LIT>" ) <EOL> slug = '<STR_LIT>' <EOL> help_text_template = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def clean ( self ) : <EOL> cleaned_data = super ( SetFlavorChoiceAction , self ) . clean ( ) <EOL> flavor = cleaned_data . get ( '<STR_LIT>' , None ) <EOL> if flavor is None or flavor == cleaned_data [ '<STR_LIT>' ] : <EOL> raise forms . ValidationError ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> return cleaned_data <EOL> def populate_flavor_choices ( self , request , context ) : <EOL> flavors = context . get ( '<STR_LIT>' ) . values ( ) <EOL> if len ( flavors ) > <NUM_LIT:1> : <EOL> flavors = instance_utils . sort_flavor_list ( request , flavors ) <EOL> if flavors : <EOL> flavors . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> else : <EOL> flavors . insert ( <NUM_LIT:0> , ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) ) <EOL> return flavors <EOL> def get_help_text ( self ) : <EOL> extra = { } <EOL> try : <EOL> extra [ '<STR_LIT>' ] = api . nova . tenant_absolute_limits ( self . request ) <EOL> extra [ '<STR_LIT>' ] = json . dumps ( extra [ '<STR_LIT>' ] ) <EOL> flavors = json . dumps ( [ f . _info for f in <EOL> instance_utils . flavor_list ( self . request ) ] ) <EOL> extra [ '<STR_LIT>' ] = flavors <EOL> extra [ '<STR_LIT>' ] = True <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> return super ( SetFlavorChoiceAction , self ) . get_help_text ( extra ) <EOL> class SetFlavorChoice ( workflows . Step ) : <EOL> action_class = SetFlavorChoiceAction <EOL> depends_on = ( "<STR_LIT>" , "<STR_LIT:name>" ) <EOL> contributes = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class ResizeInstance ( workflows . Workflow ) : <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> default_steps = ( SetFlavorChoice , create_instance . SetAdvanced ) <EOL> def format_status_message ( self , message ) : <EOL> return message % self . context . get ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> @ sensitive_variables ( '<STR_LIT>' ) <EOL> def handle ( self , request , context ) : <EOL> instance_id = context . get ( '<STR_LIT>' , None ) <EOL> flavor = context . get ( '<STR_LIT>' , None ) <EOL> disk_config = context . get ( '<STR_LIT>' , None ) <EOL> try : <EOL> api . nova . server_resize ( request , instance_id , flavor , disk_config ) <EOL> return True <EOL> except Exception : <EOL> exceptions . handle ( request ) <EOL> return False </s>
