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:
Dan Smith 2014-06-23 12:20:35 -07:00
parent c4080c9760
commit 9b992b4819
1 changed files with 22 additions and 15 deletions

View File

@ -18,8 +18,8 @@ import webob.exc
from nova.api.openstack import extensions from nova.api.openstack import extensions
from nova.api.openstack import wsgi from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil from nova.api.openstack import xmlutil
from nova import db
from nova import exception from nova import exception
from nova import objects
from nova import utils from nova import utils
@ -73,7 +73,8 @@ class AgentController(object):
if 'hypervisor' in req.GET: if 'hypervisor' in req.GET:
hypervisor = req.GET['hypervisor'] 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, agents.append({'hypervisor': agent_build.hypervisor,
'os': agent_build.os, 'os': agent_build.os,
'architecture': agent_build.architecture, 'architecture': agent_build.architecture,
@ -105,10 +106,14 @@ class AgentController(object):
raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
try: try:
db.agent_build_update(context, id, agent = objects.Agent(context=context, id=id)
{'version': version, agent.obj_reset_changes()
'url': url, agent.version = version
'md5hash': md5hash}) agent.url = url
agent.md5hash = md5hash
agent.save()
except ValueError:
raise webob.exc.HTTPUnprocessableEntity()
except exception.AgentBuildNotFound as ex: except exception.AgentBuildNotFound as ex:
raise webob.exc.HTTPNotFound(explanation=ex.format_message()) raise webob.exc.HTTPNotFound(explanation=ex.format_message())
@ -126,7 +131,8 @@ class AgentController(object):
authorize(context) authorize(context)
try: try:
db.agent_build_destroy(context, id) agent = objects.Agent(context=context, id=id)
agent.destroy()
except exception.AgentBuildNotFound as ex: except exception.AgentBuildNotFound as ex:
raise webob.exc.HTTPNotFound(explanation=ex.format_message()) raise webob.exc.HTTPNotFound(explanation=ex.format_message())
@ -158,14 +164,15 @@ class AgentController(object):
raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
try: try:
agent_build_ref = db.agent_build_create(context, agent_obj = objects.Agent(context=context)
{'hypervisor': hypervisor, agent_obj.hypervisor = hypervisor
'os': os, agent_obj.os = os
'architecture': architecture, agent_obj.architecture = architecture
'version': version, agent_obj.version = version
'url': url, agent_obj.url = url
'md5hash': md5hash}) agent_obj.md5hash = md5hash
agent['agent_id'] = agent_build_ref.id agent_obj.create()
agent['agent_id'] = agent_obj.id
except exception.AgentBuildExists as ex: except exception.AgentBuildExists as ex:
raise webob.exc.HTTPServerError(explanation=ex.format_message()) raise webob.exc.HTTPServerError(explanation=ex.format_message())
return {'agent': agent} return {'agent': agent}