1 | -- $Id: functions.pgsql 52776 2014-09-17 14:51:43Z vboxsync $
|
---|
2 | --- @file
|
---|
3 | -- ?????????????????????????
|
---|
4 | --
|
---|
5 |
|
---|
6 | --
|
---|
7 | -- Copyright (C) 2012-2014 Oracle Corporation
|
---|
8 | --
|
---|
9 | -- This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | -- available from http://www.virtualbox.org. This file is free software;
|
---|
11 | -- you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | -- General Public License (GPL) as published by the Free Software
|
---|
13 | -- Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | -- VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | -- hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | --
|
---|
17 | -- The contents of this file may alternatively be used under the terms
|
---|
18 | -- of the Common Development and Distribution License Version 1.0
|
---|
19 | -- (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | -- VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | -- CDDL are applicable instead of those of the GPL.
|
---|
22 | --
|
---|
23 | -- You may elect to license modified versions of this file under the
|
---|
24 | -- terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | --
|
---|
26 |
|
---|
27 | \connect testmanager;
|
---|
28 |
|
---|
29 | DROP FUNCTION authenticate_testbox(inet, uuid);
|
---|
30 | DROP FUNCTION testbox_status_set(integer, TestBoxState_T);
|
---|
31 |
|
---|
32 | -- Authenticate Test Box record by IP and UUID and set its state to IDLE
|
---|
33 | -- Args: IP, UUID
|
---|
34 | CREATE OR REPLACE FUNCTION authenticate_testbox(inet, uuid) RETURNS testboxes AS $$
|
---|
35 | DECLARE
|
---|
36 | _ip ALIAS FOR $1;
|
---|
37 | _uuidSystem ALIAS FOR $2;
|
---|
38 | _box TestBoxes;
|
---|
39 | BEGIN
|
---|
40 | -- Find Test Box record
|
---|
41 | SELECT *
|
---|
42 | FROM testboxes
|
---|
43 | WHERE ip=_ip AND uuidSystem=_uuidSystem INTO _box;
|
---|
44 | IF FOUND THEN
|
---|
45 | -- Update Test Box status if exists
|
---|
46 | UPDATE TestBoxStatuses SET enmState='idle' WHERE idTestBox=_box.idTestBox;
|
---|
47 | IF NOT FOUND THEN
|
---|
48 | -- Otherwise, add new record to TestBoxStatuses table
|
---|
49 | INSERT
|
---|
50 | INTO TestBoxStatuses(idTestBox, idGenTestBox, enmState)
|
---|
51 | VALUES (_box.idTestBox, _box.idGenTestBox, 'idle');
|
---|
52 | END IF;
|
---|
53 | END IF;
|
---|
54 | return _box;
|
---|
55 | END;
|
---|
56 | $$ LANGUAGE plpgsql;
|
---|
57 |
|
---|
58 | -- Set Test Box status and make sure if it has been set
|
---|
59 | -- Args: Test Box ID, new status
|
---|
60 | CREATE OR REPLACE FUNCTION testbox_status_set(integer, TestBoxState_T) RETURNS VOID AS $$
|
---|
61 | DECLARE
|
---|
62 | _box ALIAS FOR $1;
|
---|
63 | _status ALIAS FOR $2;
|
---|
64 | BEGIN
|
---|
65 | -- Update Test Box status if exists
|
---|
66 | UPDATE TestBoxStatuses SET enmState=_status WHERE idTestBox=_box;
|
---|
67 | IF NOT FOUND THEN
|
---|
68 | RAISE EXCEPTION 'Test Box (#%) was not found in database', _box;
|
---|
69 | END IF;
|
---|
70 | END;
|
---|
71 | $$ LANGUAGE plpgsql;
|
---|
72 |
|
---|