<s> from webob import exc <EOL> from nova . api . openstack import common <EOL> from nova . api . openstack import extensions <EOL> from nova . api . openstack import wsgi <EOL> from nova import compute <EOL> authorize_actions = extensions . extension_authorizer ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> authorize_events = extensions . soft_extension_authorizer ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ACTION_KEYS = [ '<STR_LIT:action>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:message>' ] <EOL> EVENT_KEYS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:result>' , '<STR_LIT>' ] <EOL> class InstanceActionsController ( wsgi . Controller ) : <EOL> def __init__ ( self ) : <EOL> super ( InstanceActionsController , self ) . __init__ ( ) <EOL> self . compute_api = compute . API ( ) <EOL> self . action_api = compute . InstanceActionAPI ( ) <EOL> def _format_action ( self , action_raw ) : <EOL> action = { } <EOL> for key in ACTION_KEYS : <EOL> action [ key ] = action_raw . get ( key ) <EOL> return action <EOL> def _format_event ( self , event_raw ) : <EOL> event = { } <EOL> for key in EVENT_KEYS : <EOL> event [ key ] = event_raw . get ( key ) <EOL> return event <EOL> def index ( self , req , server_id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ "<STR_LIT>" ] <EOL> instance = common . get_instance ( self . compute_api , context , server_id ) <EOL> authorize_actions ( context , target = instance ) <EOL> actions_raw = self . action_api . actions_get ( context , instance ) <EOL> actions = [ self . _format_action ( action ) for action in actions_raw ] <EOL> return { '<STR_LIT>' : actions } <EOL> def show ( self , req , server_id , id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> instance = common . get_instance ( self . compute_api , context , server_id ) <EOL> authorize_actions ( context , target = instance ) <EOL> action = self . action_api . action_get_by_request_id ( context , instance , <EOL> id ) <EOL> if action is None : <EOL> raise exc . HTTPNotFound ( ) <EOL> action_id = action [ '<STR_LIT:id>' ] <EOL> action = self . _format_action ( action ) <EOL> if authorize_events ( context ) : <EOL> events_raw = self . action_api . action_events_get ( context , instance , <EOL> action_id ) <EOL> action [ '<STR_LIT>' ] = [ self . _format_event ( evt ) for evt in events_raw ] <EOL> return { '<STR_LIT>' : action } <EOL> class Instance_actions ( extensions . ExtensionDescriptor ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = "<STR_LIT>" <EOL> namespace = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> updated = "<STR_LIT>" <EOL> def get_resources ( self ) : <EOL> ext = extensions . ResourceExtension ( '<STR_LIT>' , <EOL> InstanceActionsController ( ) , <EOL> parent = dict ( <EOL> member_name = '<STR_LIT>' , <EOL> collection_name = '<STR_LIT>' ) ) <EOL> return [ ext ] </s>
