Object-ify APIv2 agents extension
This makes the APIv2 agents extension use the Agent object instead of direct database access. Related to blueprint compute-manager-objects-juno Change-Id: I79d68be5d14c8af0f96164608f6c535530ef6d5e
This commit is contained in:
parent
c4080c9760
commit
9b992b4819
|
@ -18,8 +18,8 @@ import webob.exc
|
|||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
from nova.api.openstack import xmlutil
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
@ -73,7 +73,8 @@ class AgentController(object):
|
|||
if 'hypervisor' in req.GET:
|
||||
hypervisor = req.GET['hypervisor']
|
||||
|
||||
for agent_build in db.agent_build_get_all(context, hypervisor):
|
||||
builds = objects.AgentList.get_all(context, hypervisor=hypervisor)
|
||||
for agent_build in builds:
|
||||
agents.append({'hypervisor': agent_build.hypervisor,
|
||||
'os': agent_build.os,
|
||||
'architecture': agent_build.architecture,
|
||||
|
@ -105,10 +106,14 @@ class AgentController(object):
|
|||
raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
|
||||
|
||||
try:
|
||||
db.agent_build_update(context, id,
|
||||
{'version': version,
|
||||
'url': url,
|
||||
'md5hash': md5hash})
|
||||
agent = objects.Agent(context=context, id=id)
|
||||
agent.obj_reset_changes()
|
||||
agent.version = version
|
||||
agent.url = url
|
||||
agent.md5hash = md5hash
|
||||
agent.save()
|
||||
except ValueError:
|
||||
raise webob.exc.HTTPUnprocessableEntity()
|
||||
except exception.AgentBuildNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.format_message())
|
||||
|
||||
|
@ -126,7 +131,8 @@ class AgentController(object):
|
|||
authorize(context)
|
||||
|
||||
try:
|
||||
db.agent_build_destroy(context, id)
|
||||
agent = objects.Agent(context=context, id=id)
|
||||
agent.destroy()
|
||||
except exception.AgentBuildNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.format_message())
|
||||
|
||||
|
@ -158,14 +164,15 @@ class AgentController(object):
|
|||
raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
|
||||
|
||||
try:
|
||||
agent_build_ref = db.agent_build_create(context,
|
||||
{'hypervisor': hypervisor,
|
||||
'os': os,
|
||||
'architecture': architecture,
|
||||
'version': version,
|
||||
'url': url,
|
||||
'md5hash': md5hash})
|
||||
agent['agent_id'] = agent_build_ref.id
|
||||
agent_obj = objects.Agent(context=context)
|
||||
agent_obj.hypervisor = hypervisor
|
||||
agent_obj.os = os
|
||||
agent_obj.architecture = architecture
|
||||
agent_obj.version = version
|
||||
agent_obj.url = url
|
||||
agent_obj.md5hash = md5hash
|
||||
agent_obj.create()
|
||||
agent['agent_id'] = agent_obj.id
|
||||
except exception.AgentBuildExists as ex:
|
||||
raise webob.exc.HTTPServerError(explanation=ex.format_message())
|
||||
return {'agent': agent}
|
||||
|
|
Loading…
Reference in New Issue