'Update an existing agent build.'

@extensions.expected_errors((400, 404))
@validation.schema(schema.update)
def update(self, req, id, body):

    context = req.environ['nova.context']
    context.can(agents_policies.BASE_POLICY_NAME)
    para = body['para']
    url = para['url']
    md5hash = para['md5hash']
    version = para['version']
    try:
        utils.validate_integer(id, 'id')
    except exception.InvalidInput as exc:
        raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
    agent = objects.Agent(context=context, id=id)
    agent.obj_reset_changes()
    agent.version = version
    agent.url = url
    agent.md5hash = md5hash
    try:
        agent.save()
    except exception.AgentBuildNotFound as ex:
        raise webob.exc.HTTPNotFound(explanation=ex.format_message())
    return {'agent': {'agent_id': id, 'version': version, 'url': url, 'md5hash': md5hash}}
