functions.pgsql revision cf22150eaeeb72431bf1cf65c309a431454fb22b
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--- @file
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- ?????????????????????????
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Copyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- This file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- available from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- you can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- General Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Foundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- VirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- The contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- of the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- (CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- VirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- CDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- You may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- terms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync--
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync\connect testmanager;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncDROP FUNCTION authenticate_testbox(inet, uuid);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncDROP FUNCTION testbox_status_set(integer, TestBoxState_T);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Authenticate Test Box record by IP and UUID and set its state to IDLE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Args: IP, UUID
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCREATE OR REPLACE FUNCTION authenticate_testbox(inet, uuid) RETURNS testboxes AS $$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync DECLARE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ip ALIAS FOR $1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _uuidSystem ALIAS FOR $2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _box TestBoxes;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync BEGIN
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -- Find Test Box record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync SELECT *
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync FROM testboxes
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync WHERE ip=_ip AND uuidSystem=_uuidSystem INTO _box;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync IF FOUND THEN
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -- Update Test Box status if exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync UPDATE TestBoxStatuses SET enmState='idle' WHERE idTestBox=_box.idTestBox;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync IF NOT FOUND THEN
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -- Otherwise, add new record to TestBoxStatuses table
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync INSERT
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync INTO TestBoxStatuses(idTestBox, idGenTestBox, enmState)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync VALUES (_box.idTestBox, _box.idGenTestBox, 'idle');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync END IF;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync END IF;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return _box;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync END;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync$$ LANGUAGE plpgsql;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Set Test Box status and make sure if it has been set
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync-- Args: Test Box ID, new status
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCREATE OR REPLACE FUNCTION testbox_status_set(integer, TestBoxState_T) RETURNS VOID AS $$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync DECLARE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _box ALIAS FOR $1;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _status ALIAS FOR $2;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync BEGIN
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync -- Update Test Box status if exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync UPDATE TestBoxStatuses SET enmState=_status WHERE idTestBox=_box;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync IF NOT FOUND THEN
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync RAISE EXCEPTION 'Test Box (#%) was not found in database', _box;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync END IF;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync END;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync$$ LANGUAGE plpgsql;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync