From 82042ac2766b892d561836cd312656940522734a Mon Sep 17 00:00:00 2001 From: ivan-zhu Date: Wed, 21 Nov 2012 15:37:52 +0800 Subject: Add agent build API support for list/create/delete/modify agent build This adds an extension that provides REST API for list/create/delete/ modify agent build. The interface is accessed via GET /v2/{tenant_id}/os-agents PUT /v2/{tenant_id}/os-agents/id POST /v2/{tenant_id}/os-agents DELETE /v2/{tenant_id}/os-agents And this patch also create tests to get agent build API Samples. DocImpact Implements one workitem of blueprint apis-for-nova-manage The agent is talking about guest agent.The host can use this for things like accessing files on the disk, configuring networking, or running other applications/scripts in the guest while it is running. Typically this uses some hypervisor-specific transport to avoid being dependent on a working network configuration. Xen, VMware, and VirtualBox have guest agents,although the Xen driver is the only one with an implementation for managing them in openstack. KVM doesn't really have a concept of a guest agent (although one could be written). You can find the design of agent update in this link: http://wiki.openstack.org/AgentUpdate and find the code in nova.virt.xenapi.vmops.VMOps._boot_new_instance. In this design We need update agent in guest from host, so we need some interfaces to update the agent info in host. You can find more information about the design of the GuestAgent in the following link: http://wiki.openstack.org/GuestAgent http://wiki.openstack.org/GuestAgentXenStoreCommunication DocImpact Change-Id: I5830388a894efce5b13680fc6916e0cd81a16624 --- nova/db/api.py | 4 ++-- nova/db/sqlalchemy/api.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index ad928f585..cfa6a6487 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -1372,9 +1372,9 @@ def agent_build_get_by_triple(context, hypervisor, os, architecture): architecture) -def agent_build_get_all(context): +def agent_build_get_all(context, hypervisor=None): """Get all agent builds.""" - return IMPL.agent_build_get_all(context) + return IMPL.agent_build_get_all(context, hypervisor) def agent_build_destroy(context, agent_update_id): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index c1b6e66dd..e8eea7d02 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -3968,8 +3968,13 @@ def agent_build_get_by_triple(context, hypervisor, os, architecture, @require_admin_context -def agent_build_get_all(context): - return model_query(context, models.AgentBuild, read_deleted="no").\ +def agent_build_get_all(context, hypervisor=None): + if hypervisor: + return model_query(context, models.AgentBuild, read_deleted="no").\ + filter_by(hypervisor=hypervisor).\ + all() + else: + return model_query(context, models.AgentBuild, read_deleted="no").\ all() @@ -3977,12 +3982,15 @@ def agent_build_get_all(context): def agent_build_destroy(context, agent_build_id): session = get_session() with session.begin(): - model_query(context, models.AgentBuild, session=session, - read_deleted="yes").\ + agent_build_ref = model_query(context, models.AgentBuild, + session=session, read_deleted="yes").\ filter_by(id=agent_build_id).\ - update({'deleted': True, - 'deleted_at': timeutils.utcnow(), - 'updated_at': literal_column('updated_at')}) + first() + if not agent_build_ref: + raise exception.AgentBuildNotFound(id=agent_build_id) + agent_build_ref.update({'deleted': True, + 'deleted_at': timeutils.utcnow(), + 'updated_at': literal_column('updated_at')}) @require_admin_context @@ -3993,7 +4001,8 @@ def agent_build_update(context, agent_build_id, values): session=session, read_deleted="yes").\ filter_by(id=agent_build_id).\ first() - + if not agent_build_ref: + raise exception.AgentBuildNotFound(id=agent_build_id) agent_build_ref.update(values) agent_build_ref.save(session=session) -- cgit