<s> import webob . exc <EOL> from nova . api . openstack . compute . schemas import agents as schema <EOL> from nova . api . openstack import extensions <EOL> from nova . api . openstack import wsgi <EOL> from nova . api import validation <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova import utils <EOL> ALIAS = "<STR_LIT>" <EOL> authorize = extensions . os_compute_authorizer ( ALIAS ) <EOL> class AgentController ( wsgi . Controller ) : <EOL> """<STR_LIT>""" <EOL> @ extensions . expected_errors ( ( ) ) <EOL> def index ( self , req ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> hypervisor = None <EOL> agents = [ ] <EOL> if '<STR_LIT>' in req . GET : <EOL> hypervisor = req . GET [ '<STR_LIT>' ] <EOL> builds = objects . AgentList . get_all ( context , hypervisor = hypervisor ) <EOL> for agent_build in builds : <EOL> agents . append ( { '<STR_LIT>' : agent_build . hypervisor , <EOL> '<STR_LIT>' : agent_build . os , <EOL> '<STR_LIT>' : agent_build . architecture , <EOL> '<STR_LIT:version>' : agent_build . version , <EOL> '<STR_LIT>' : agent_build . md5hash , <EOL> '<STR_LIT>' : agent_build . id , <EOL> '<STR_LIT:url>' : agent_build . url } ) <EOL> return { '<STR_LIT>' : agents } <EOL> @ extensions . expected_errors ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> @ validation . schema ( schema . update ) <EOL> def update ( self , req , id , body ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> para = body [ '<STR_LIT>' ] <EOL> url = para [ '<STR_LIT:url>' ] <EOL> md5hash = para [ '<STR_LIT>' ] <EOL> version = para [ '<STR_LIT:version>' ] <EOL> try : <EOL> utils . validate_integer ( id , '<STR_LIT:id>' ) <EOL> except exception . InvalidInput as exc : <EOL> raise webob . exc . HTTPBadRequest ( explanation = exc . format_message ( ) ) <EOL> agent = objects . Agent ( context = context , id = id ) <EOL> agent . obj_reset_changes ( ) <EOL> agent . version = version <EOL> agent . url = url <EOL> agent . md5hash = md5hash <EOL> try : <EOL> agent . save ( ) <EOL> except exception . AgentBuildNotFound as ex : <EOL> raise webob . exc . HTTPNotFound ( explanation = ex . format_message ( ) ) <EOL> return { "<STR_LIT>" : { '<STR_LIT>' : id , '<STR_LIT:version>' : version , <EOL> '<STR_LIT:url>' : url , '<STR_LIT>' : md5hash } } <EOL> @ extensions . expected_errors ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> @ wsgi . response ( <NUM_LIT:200> ) <EOL> def delete ( self , req , id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> try : <EOL> utils . validate_integer ( id , '<STR_LIT:id>' ) <EOL> except exception . InvalidInput as exc : <EOL> raise webob . exc . HTTPBadRequest ( explanation = exc . format_message ( ) ) <EOL> try : <EOL> agent = objects . Agent ( context = context , id = id ) <EOL> agent . destroy ( ) <EOL> except exception . AgentBuildNotFound as ex : <EOL> raise webob . exc . HTTPNotFound ( explanation = ex . format_message ( ) ) <EOL> @ extensions . expected_errors ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> @ wsgi . response ( <NUM_LIT:200> ) <EOL> @ validation . schema ( schema . create ) <EOL> def create ( self , req , body ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> authorize ( context ) <EOL> agent = body [ '<STR_LIT>' ] <EOL> hypervisor = agent [ '<STR_LIT>' ] <EOL> os = agent [ '<STR_LIT>' ] <EOL> architecture = agent [ '<STR_LIT>' ] <EOL> version = agent [ '<STR_LIT:version>' ] <EOL> url = agent [ '<STR_LIT:url>' ] <EOL> md5hash = agent [ '<STR_LIT>' ] <EOL> agent_obj = objects . Agent ( context = context ) <EOL> agent_obj . hypervisor = hypervisor <EOL> agent_obj . os = os <EOL> agent_obj . architecture = architecture <EOL> agent_obj . version = version <EOL> agent_obj . url = url <EOL> agent_obj . md5hash = md5hash <EOL> try : <EOL> agent_obj . create ( ) <EOL> agent [ '<STR_LIT>' ] = agent_obj . id <EOL> except exception . AgentBuildExists as ex : <EOL> raise webob . exc . HTTPConflict ( explanation = ex . format_message ( ) ) <EOL> return { '<STR_LIT>' : agent } <EOL> class Agents ( extensions . V21APIExtensionBase ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = ALIAS <EOL> version = <NUM_LIT:1> <EOL> def get_resources ( self ) : <EOL> resource = [ extensions . ResourceExtension ( ALIAS , <EOL> AgentController ( ) ) ] <EOL> return resource <EOL> def get_controller_extensions ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ ] </s>
