<s> """<STR_LIT>""" <EOL> from nova . api . openstack import api_version_request <EOL> from nova . api . openstack import extensions <EOL> from nova . api . openstack import wsgi <EOL> from nova import compute <EOL> ALIAS = "<STR_LIT>" <EOL> authorize = extensions . os_compute_soft_authorizer ( ALIAS ) <EOL> soft_authorize = extensions . os_compute_soft_authorizer ( '<STR_LIT>' ) <EOL> class ExtendedServerAttributesController ( wsgi . Controller ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ExtendedServerAttributesController , self ) . __init__ ( * args , <EOL> ** kwargs ) <EOL> self . compute_api = compute . API ( skip_policy_check = True ) <EOL> def _extend_server ( self , context , server , instance , req ) : <EOL> key = "<STR_LIT>" <EOL> server [ key ] = instance . node <EOL> properties = [ '<STR_LIT:host>' , '<STR_LIT:name>' ] <EOL> if api_version_request . is_supported ( req , min_version = '<STR_LIT>' ) : <EOL> properties += [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for attr in properties : <EOL> if attr == '<STR_LIT:name>' : <EOL> key = "<STR_LIT>" % attr <EOL> else : <EOL> key = "<STR_LIT>" % attr <EOL> server [ key ] = instance [ attr ] <EOL> def _server_host_status ( self , context , server , instance , req ) : <EOL> host_status = self . compute_api . get_instance_host_status ( instance ) <EOL> server [ '<STR_LIT>' ] = host_status <EOL> @ wsgi . extends <EOL> def show ( self , req , resp_obj , id ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize_extend = False <EOL> authorize_host_status = False <EOL> if authorize ( context ) : <EOL> authorize_extend = True <EOL> if ( api_version_request . is_supported ( req , min_version = '<STR_LIT>' ) and <EOL> soft_authorize ( context , action = '<STR_LIT>' ) ) : <EOL> authorize_host_status = True <EOL> if authorize_extend or authorize_host_status : <EOL> server = resp_obj . obj [ '<STR_LIT>' ] <EOL> db_instance = req . get_db_instance ( server [ '<STR_LIT:id>' ] ) <EOL> if authorize_extend : <EOL> self . _extend_server ( context , server , db_instance , req ) <EOL> if authorize_host_status : <EOL> self . _server_host_status ( context , server , db_instance , req ) <EOL> @ wsgi . extends <EOL> def detail ( self , req , resp_obj ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize_extend = False <EOL> authorize_host_status = False <EOL> if authorize ( context ) : <EOL> authorize_extend = True <EOL> if ( api_version_request . is_supported ( req , min_version = '<STR_LIT>' ) and <EOL> soft_authorize ( context , action = '<STR_LIT>' ) ) : <EOL> authorize_host_status = True <EOL> if authorize_extend or authorize_host_status : <EOL> servers = list ( resp_obj . obj [ '<STR_LIT>' ] ) <EOL> instances = req . get_db_instances ( ) <EOL> if authorize_host_status : <EOL> host_statuses = self . compute_api . get_instances_host_statuses ( <EOL> instances . values ( ) ) <EOL> for server in servers : <EOL> if authorize_extend : <EOL> instance = instances [ server [ '<STR_LIT:id>' ] ] <EOL> self . _extend_server ( context , server , instance , req ) <EOL> if authorize_host_status : <EOL> server [ '<STR_LIT>' ] = host_statuses [ server [ '<STR_LIT:id>' ] ] <EOL> class ExtendedServerAttributes ( extensions . V21APIExtensionBase ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = ALIAS <EOL> version = <NUM_LIT:1> <EOL> def get_controller_extensions ( self ) : <EOL> controller = ExtendedServerAttributesController ( ) <EOL> extension = extensions . ControllerExtension ( self , '<STR_LIT>' , controller ) <EOL> return [ extension ] <EOL> def get_resources ( self ) : <EOL> return [ ] </s>
