<s> import json <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 forms <EOL> from horizon import tables <EOL> from horizon . utils import memoized <EOL> from horizon import workflows <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . admin . flavors import forms as project_forms <EOL> from openstack_dashboard . dashboards . admin . flavors import tables as project_tables <EOL> from openstack_dashboard . dashboards . admin . flavors import workflows as flavor_workflows <EOL> INDEX_URL = "<STR_LIT>" <EOL> class IndexView ( tables . DataTableView ) : <EOL> table_class = project_tables . FlavorsTable <EOL> template_name = '<STR_LIT>' <EOL> def get_data ( self ) : <EOL> request = self . request <EOL> flavors = [ ] <EOL> try : <EOL> flavors = api . nova . flavor_list ( request , None ) <EOL> except Exception : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> flavors . sort ( key = lambda f : ( f . vcpus , f . ram , f . disk ) ) <EOL> return flavors <EOL> class CreateView ( workflows . WorkflowView ) : <EOL> workflow_class = flavor_workflows . CreateFlavor <EOL> template_name = '<STR_LIT>' <EOL> class UpdateView ( workflows . WorkflowView ) : <EOL> workflow_class = flavor_workflows . UpdateFlavor <EOL> template_name = '<STR_LIT>' <EOL> def get_initial ( self ) : <EOL> flavor_id = self . kwargs [ '<STR_LIT:id>' ] <EOL> try : <EOL> flavor = api . nova . flavor_get ( self . request , flavor_id ) <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = reverse_lazy ( INDEX_URL ) ) <EOL> return { '<STR_LIT>' : flavor . id , <EOL> '<STR_LIT:name>' : flavor . name , <EOL> '<STR_LIT>' : flavor . vcpus , <EOL> '<STR_LIT>' : flavor . ram , <EOL> '<STR_LIT>' : flavor . disk , <EOL> '<STR_LIT>' : flavor . swap or <NUM_LIT:0> , <EOL> '<STR_LIT>' : getattr ( flavor , '<STR_LIT>' , None ) } <EOL> class UpdateMetadataView ( forms . ModalFormView ) : <EOL> template_name = "<STR_LIT>" <EOL> form_class = project_forms . UpdateMetadataForm <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_initial ( self ) : <EOL> extra_specs_dict = self . get_object ( ) <EOL> return { '<STR_LIT:id>' : self . kwargs [ "<STR_LIT:id>" ] , '<STR_LIT>' : extra_specs_dict } <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( UpdateMetadataView , self ) . get_context_data ( ** kwargs ) <EOL> extra_specs_dict = self . get_object ( ) <EOL> context [ '<STR_LIT>' ] = json . dumps ( extra_specs_dict ) <EOL> resource_type = '<STR_LIT>' <EOL> namespaces = [ ] <EOL> try : <EOL> namespaces = [ <EOL> api . glance . metadefs_namespace_get ( self . request , x . namespace , <EOL> resource_type ) <EOL> for x in api . glance . metadefs_namespace_list ( <EOL> self . request , <EOL> filters = { '<STR_LIT>' : [ resource_type ] } <EOL> ) [ <NUM_LIT:0> ] <EOL> ] <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> context [ '<STR_LIT>' ] = json . dumps ( { '<STR_LIT>' : namespaces } ) <EOL> context [ '<STR_LIT:id>' ] = self . kwargs [ '<STR_LIT:id>' ] <EOL> return context <EOL> @ memoized . memoized_method <EOL> def get_object ( self ) : <EOL> flavor_id = self . kwargs [ '<STR_LIT:id>' ] <EOL> try : <EOL> extra_specs = api . nova . flavor_get_extras ( self . request , flavor_id ) <EOL> return dict ( ( i . key , i . value ) for i in extra_specs ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg , <EOL> redirect = reverse ( INDEX_URL ) ) </s>
