<s> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import messages <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 . api import keystone <EOL> from openstack_dashboard import policy <EOL> from openstack_dashboard import usage <EOL> from openstack_dashboard . usage import quotas <EOL> from openstack_dashboard . dashboards . identity . projects import tables as project_tables <EOL> from openstack_dashboard . dashboards . identity . projects import workflows as project_workflows <EOL> from openstack_dashboard . dashboards . project . overview import views as project_views <EOL> PROJECT_INFO_FIELDS = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:name>" , <EOL> "<STR_LIT:description>" , <EOL> "<STR_LIT>" ) <EOL> INDEX_URL = "<STR_LIT>" <EOL> class TenantContextMixin ( object ) : <EOL> @ memoized . memoized_method <EOL> def get_object ( self ) : <EOL> tenant_id = self . kwargs [ '<STR_LIT>' ] <EOL> try : <EOL> return api . keystone . tenant_get ( self . request , tenant_id , admin = True ) <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = reverse ( INDEX_URL ) ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( TenantContextMixin , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . get_object ( ) <EOL> return context <EOL> class IndexView ( tables . DataTableView ) : <EOL> table_class = project_tables . TenantsTable <EOL> template_name = '<STR_LIT>' <EOL> def has_more_data ( self , table ) : <EOL> return self . _more <EOL> def get_data ( self ) : <EOL> tenants = [ ] <EOL> marker = self . request . GET . get ( <EOL> project_tables . TenantsTable . _meta . pagination_param , None ) <EOL> domain_context = self . request . session . get ( '<STR_LIT>' , None ) <EOL> if policy . check ( ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) , <EOL> self . request ) : <EOL> try : <EOL> tenants , self . _more = api . keystone . tenant_list ( <EOL> self . request , <EOL> domain = domain_context , <EOL> paginate = True , <EOL> marker = marker ) <EOL> except Exception : <EOL> self . _more = False <EOL> exceptions . handle ( self . request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> elif policy . check ( ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) , <EOL> self . request ) : <EOL> try : <EOL> tenants , self . _more = api . keystone . tenant_list ( <EOL> self . request , <EOL> user = self . request . user . id , <EOL> paginate = True , <EOL> marker = marker , <EOL> admin = False ) <EOL> except Exception : <EOL> self . _more = False <EOL> exceptions . handle ( self . request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> else : <EOL> self . _more = False <EOL> msg = _ ( "<STR_LIT>" ) <EOL> messages . info ( self . request , msg ) <EOL> return tenants <EOL> class ProjectUsageView ( usage . UsageView ) : <EOL> table_class = usage . ProjectUsageTable <EOL> usage_class = usage . ProjectUsage <EOL> template_name = '<STR_LIT>' <EOL> csv_response_class = project_views . ProjectUsageCsvRenderer <EOL> csv_template_name = '<STR_LIT>' <EOL> def get_data ( self ) : <EOL> super ( ProjectUsageView , self ) . get_data ( ) <EOL> return self . usage . get_instances ( ) <EOL> class CreateProjectView ( workflows . WorkflowView ) : <EOL> workflow_class = project_workflows . CreateProject <EOL> def get_initial ( self ) : <EOL> initial = super ( CreateProjectView , self ) . get_initial ( ) <EOL> domain = api . keystone . get_default_domain ( self . request ) <EOL> initial [ "<STR_LIT>" ] = domain . id <EOL> initial [ "<STR_LIT>" ] = domain . name <EOL> try : <EOL> quota_defaults = quotas . get_default_quota_data ( self . request ) <EOL> try : <EOL> if api . base . is_service_enabled ( self . request , '<STR_LIT>' ) and api . neutron . is_quotas_extension_supported ( <EOL> self . request ) : <EOL> project_id = self . request . user . project_id <EOL> quota_defaults += api . neutron . tenant_quota_get ( <EOL> self . request , <EOL> tenant_id = project_id ) <EOL> except Exception : <EOL> error_msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . add_error_to_step ( error_msg , '<STR_LIT>' ) <EOL> for field in quotas . QUOTA_FIELDS : <EOL> initial [ field ] = quota_defaults . get ( field ) . limit <EOL> except Exception : <EOL> error_msg = _ ( '<STR_LIT>' ) <EOL> self . add_error_to_step ( error_msg , '<STR_LIT>' ) <EOL> return initial <EOL> class UpdateProjectView ( workflows . WorkflowView ) : <EOL> workflow_class = project_workflows . UpdateProject <EOL> def get_initial ( self ) : <EOL> initial = super ( UpdateProjectView , self ) . get_initial ( ) <EOL> project_id = self . kwargs [ '<STR_LIT>' ] <EOL> initial [ '<STR_LIT>' ] = project_id <EOL> try : <EOL> project_info = api . keystone . tenant_get ( self . request , project_id , <EOL> admin = True ) <EOL> for field in PROJECT_INFO_FIELDS : <EOL> initial [ field ] = getattr ( project_info , field , None ) <EOL> if keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> try : <EOL> domain = api . keystone . domain_get ( self . request , <EOL> initial [ "<STR_LIT>" ] ) <EOL> initial [ "<STR_LIT>" ] = domain . name <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = reverse ( INDEX_URL ) ) <EOL> quota_data = quotas . get_tenant_quota_data ( self . request , <EOL> tenant_id = project_id ) <EOL> if api . base . is_service_enabled ( self . request , '<STR_LIT>' ) and api . neutron . is_quotas_extension_supported ( self . request ) : <EOL> quota_data += api . neutron . tenant_quota_get ( <EOL> self . request , tenant_id = project_id ) <EOL> for field in quotas . QUOTA_FIELDS : <EOL> initial [ field ] = quota_data . get ( field ) . limit <EOL> except Exception : <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = reverse ( INDEX_URL ) ) <EOL> return initial </s>
