--
-- PostgreSQL database dump
--

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: engine
--

CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO engine;

SET search_path = public, pg_catalog;

--
-- Name: all_storage_usage_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE all_storage_usage_rs AS (
	quota_storage_id uuid,
	quota_id uuid,
	storage_id uuid,
	storage_name character varying(250),
	storage_size_gb bigint,
	storage_size_gb_usage double precision
);


ALTER TYPE public.all_storage_usage_rs OWNER TO engine;

--
-- Name: all_vds_group_usage_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE all_vds_group_usage_rs AS (
	quota_vds_group_id uuid,
	quota_id uuid,
	vds_group_id uuid,
	vds_group_name character varying(40),
	virtual_cpu integer,
	virtual_cpu_usage integer,
	mem_size_mb bigint,
	mem_size_mb_usage bigint
);


ALTER TYPE public.all_vds_group_usage_rs OWNER TO engine;

--
-- Name: async_tasks_info_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE async_tasks_info_rs AS (
	dc_id uuid,
	dc_name character varying,
	spm_host_id uuid,
	spm_host_name character varying,
	task_count integer
);


ALTER TYPE public.async_tasks_info_rs OWNER TO engine;

--
-- Name: booleanresulttype; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE booleanresulttype AS (
	result boolean
);


ALTER TYPE public.booleanresulttype OWNER TO engine;

--
-- Name: disks_basic_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE disks_basic_rs AS (
	disk_id uuid,
	disk_alias character varying(255),
	size bigint
);


ALTER TYPE public.disks_basic_rs OWNER TO engine;

--
-- Name: get_all_commands_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE get_all_commands_rs AS (
	command_id uuid,
	command_type character varying(256)
);


ALTER TYPE public.get_all_commands_rs OWNER TO engine;

--
-- Name: getallfromsnapshotsbyvmid_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getallfromsnapshotsbyvmid_rs AS (
	snapshot_id uuid,
	vm_id uuid,
	snapshot_type character varying(32),
	status character varying(32),
	description character varying(4000),
	creation_date timestamp with time zone,
	app_list text,
	memory_volume character varying(255),
	vm_configuration text,
	vm_configuration_available boolean
);


ALTER TYPE public.getallfromsnapshotsbyvmid_rs OWNER TO engine;

--
-- Name: getallfromvm_pools_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getallfromvm_pools_rs AS (
	vm_pool_id uuid,
	assigned_vm_count integer,
	vm_running_count integer,
	vm_pool_description character varying(4000),
	vm_pool_comment text,
	vm_pool_name character varying(255),
	vm_pool_type integer,
	parameters character varying(200),
	prestarted_vms integer,
	vds_group_id uuid,
	vds_group_name character varying(40),
	max_assigned_vms_per_user smallint,
	spice_proxy character varying(255)
);


ALTER TYPE public.getallfromvm_pools_rs OWNER TO engine;

--
-- Name: getnamesofvmstaticdedicatedtovds_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getnamesofvmstaticdedicatedtovds_rs AS (
	vm_name character varying
);


ALTER TYPE public.getnamesofvmstaticdedicatedtovds_rs OWNER TO engine;

--
-- Name: getorderedvmguidsforrunmultipleactions_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getorderedvmguidsforrunmultipleactions_rs AS (
	vm_guid uuid
);


ALTER TYPE public.getorderedvmguidsforrunmultipleactions_rs OWNER TO engine;

--
-- Name: getrepo_files_in_all_storage_pools_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getrepo_files_in_all_storage_pools_rs AS (
	storage_domain_id uuid,
	last_refreshed bigint,
	file_type integer
);


ALTER TYPE public.getrepo_files_in_all_storage_pools_rs OWNER TO engine;

--
-- Name: getstoragedomainidsbystoragepoolidandstatus_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getstoragedomainidsbystoragepoolidandstatus_rs AS (
	storage_id uuid
);


ALTER TYPE public.getstoragedomainidsbystoragepoolidandstatus_rs OWNER TO engine;

--
-- Name: getsystem_statistics_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE getsystem_statistics_rs AS (
	val integer
);


ALTER TYPE public.getsystem_statistics_rs OWNER TO engine;

--
-- Name: idtexttype; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE idtexttype AS (
	id text
);


ALTER TYPE public.idtexttype OWNER TO engine;

--
-- Name: iduuidtype; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE iduuidtype AS (
	id uuid
);


ALTER TYPE public.iduuidtype OWNER TO engine;

--
-- Name: networkviewclustertype; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE networkviewclustertype AS (
	id uuid,
	name character varying(50),
	description character varying(4000),
	free_text_comment text,
	type integer,
	addr character varying(50),
	subnet character varying(20),
	gateway character varying(20),
	vlan_id integer,
	stp boolean,
	storage_pool_id uuid,
	mtu integer,
	vm_network boolean,
	label text,
	provider_network_provider_id uuid,
	provider_network_external_id text,
	qos_id uuid,
	network_id uuid,
	cluster_id uuid,
	status integer,
	is_display boolean,
	required boolean,
	migration boolean
);


ALTER TYPE public.networkviewclustertype OWNER TO engine;

--
-- Name: user_permissions; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE user_permissions AS (
	permission_id uuid,
	role_id uuid,
	user_id uuid
);


ALTER TYPE public.user_permissions OWNER TO engine;

--
-- Name: vds_group_usage_rs; Type: TYPE; Schema: public; Owner: engine
--

CREATE TYPE vds_group_usage_rs AS (
	virtual_cpu_usage integer,
	mem_size_mb_usage bigint
);


ALTER TYPE public.vds_group_usage_rs OWNER TO engine;

--
-- Name: activateallmaterializedviews(boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION activateallmaterializedviews(v_active boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
    update materialized_views set active = v_active;
    RETURN;
 END; ';


ALTER FUNCTION public.activateallmaterializedviews(v_active boolean) OWNER TO engine;

--
-- Name: activatematerializedview(name, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION activatematerializedview(v_matview name, v_active boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
    END IF;

    update materialized_views set active = v_active
    where  mv_name = v_matview;
    RETURN;
 END; ';


ALTER FUNCTION public.activatematerializedview(v_matview name, v_active boolean) OWNER TO engine;

--
-- Name: addconnectiontoiscsibond(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION addconnectiontoiscsibond(v_iscsi_bond_id uuid, v_connection_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO iscsi_bonds_storage_connections_map(iscsi_bond_id, connection_id)
      VALUES(v_iscsi_bond_id, v_connection_id);
END; ';


ALTER FUNCTION public.addconnectiontoiscsibond(v_iscsi_bond_id uuid, v_connection_id character varying) OWNER TO engine;

--
-- Name: addnetworktoiscsibond(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION addnetworktoiscsibond(v_iscsi_bond_id uuid, v_network_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO iscsi_bonds_networks_map(iscsi_bond_id, network_id)
      VALUES(v_iscsi_bond_id, v_network_id);
END; ';


ALTER FUNCTION public.addnetworktoiscsibond(v_iscsi_bond_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: attach_user_to_su_role(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION attach_user_to_su_role(v_permission_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_user_entry VARCHAR(255);
   v_user_id  UUID;
   v_name  VARCHAR(255);
   v_domain  VARCHAR(255);
   v_user_name  VARCHAR(255);

   v_document  VARCHAR(64);
   v_index  INTEGER;
BEGIN

   select   option_value INTO v_user_entry from vdc_options where option_name = ''AdUserId'';
   select   option_value INTO v_name from vdc_options where option_name = ''AdUserName'';
   select   option_value INTO v_domain from vdc_options where option_name = ''DomainName'';

   v_index := POSITION('':'' IN v_user_entry);
   if ( v_index <> 0 ) then
      v_user_entry := substring( v_user_entry from v_index + 1 );
      v_user_id := CAST( v_user_entry AS uuid );
   end if;

   v_index := POSITION('':'' IN v_name);
   if ( v_index <> 0 ) then
      v_name := substring( v_name from v_index + 1 );
   end if;

-- find if name already includes domain (@)
   v_index := POSITION(''@'' IN v_name);

   if (v_index = 0) then
      v_user_name := coalesce(v_name,'''') || ''@'' || coalesce(v_domain,'''');
   else
      v_user_name := v_name;
   end if;


insert into users(user_id,name,domain,username,groups,active) select v_user_id, v_name, v_domain, v_user_name,'''',true where not exists (select user_id,name,domain,username,groups,active from users where user_id = v_user_id and name = v_name and domain = v_domain and username = v_user_name and groups = '''' and active);

insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select v_permission_id, ''00000000-0000-0000-0000-000000000001'', v_user_id, getGlobalIds(''system''), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = ''00000000-0000-0000-0000-000000000001'' and ad_element_id = v_user_id and object_id= getGlobalIds(''system'') and object_type_id = 1);
END; ';


ALTER FUNCTION public.attach_user_to_su_role(v_permission_id uuid) OWNER TO engine;

--
-- Name: attach_user_to_su_role(uuid, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION attach_user_to_su_role(v_permission_id uuid, v_user_id character varying, v_name character varying, v_domain character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_user_name VARCHAR(255);
   v_document  VARCHAR(64);
   v_index  INTEGER;
   input_uuid uuid;
   v_external_id BYTEA;
BEGIN
   input_uuid = CAST( v_user_id AS uuid );
-- find if name already includes domain (@)
   v_index := POSITION(''@'' IN v_name);

   if (v_index = 0) then
      v_user_name := coalesce(v_name,'''') || ''@'' || coalesce(v_domain,'''');
   else
      v_user_name := v_name;
   end if;

   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   v_external_id := decode(replace(v_user_id::text, ''-'', ''''), ''hex'');

insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select input_uuid, v_external_id, v_name, v_domain, v_user_name,'''',true,true where not exists (select user_id,name,domain,username,groups,active from users where user_id = input_uuid);

insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select v_permission_id, ''00000000-0000-0000-0000-000000000001'', input_uuid, getGlobalIds(''system''), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = ''00000000-0000-0000-0000-000000000001'' and ad_element_id = input_uuid and object_id= getGlobalIds(''system'') and object_type_id = 1);
END; ';


ALTER FUNCTION public.attach_user_to_su_role(v_permission_id uuid, v_user_id character varying, v_name character varying, v_domain character varying) OWNER TO engine;

--
-- Name: calculateallstorageusage(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION calculateallstorageusage() RETURNS SETOF all_storage_usage_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    -- Summarize size of all disks that are active.
    RETURN QUERY SELECT
        quota_limitation.id AS quota_storage_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.storage_id as storage_id,
        storage_domain_static.storage_name,
        quota_limitation.storage_size_gb,
        cast(COALESCE(sum(size * cast(active as integer) + disk_image_dynamic.actual_size * cast((not active) as integer)) / 1073741824 ,0) as double precision)  as storage_usage -- 1073741824 is 1024^3 (for GB)
    FROM quota_limitation
        LEFT JOIN image_storage_domain_map ON quota_limitation.quota_id = image_storage_domain_map.quota_id
        LEFT JOIN images ON images.image_guid = image_storage_domain_map.image_id
        LEFT JOIN disk_image_dynamic ON images.image_guid = disk_image_dynamic.image_id
        LEFT JOIN storage_domain_static ON image_storage_domain_map.storage_domain_id = storage_domain_static.id
    WHERE quota_limitation.storage_size_gb IS NOT NULL
    GROUP BY quota_limitation.quota_id, storage_id,quota_limitation.id,storage_domain_static.storage_name,quota_limitation.storage_size_gb;
END; ';


ALTER FUNCTION public.calculateallstorageusage() OWNER TO engine;

--
-- Name: calculateallvdsgroupusage(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION calculateallvdsgroupusage() RETURNS SETOF all_vds_group_usage_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT
        quota_limitation.id AS quota_vds_group_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.vds_group_id as vds_group_id,
        vds_groups.name AS vds_group_name,
        quota_limitation.virtual_cpu,
        cast(COALESCE(sum(num_of_sockets * cpu_per_socket * cast(vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses()) as INTEGER)), 0) as INTEGER) as virtual_cpu_usage,
        quota_limitation.mem_size_mb,
        COALESCE(sum(vm_static.mem_size_mb), 0) as mem_size_mb_usage
    FROM quota_limitation
        LEFT JOIN vm_static ON vm_static.quota_id = quota_limitation.quota_id
        LEFT JOIN vm_dynamic ON vm_dynamic.vm_guid = vm_static.vm_guid
        LEFT JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
    WHERE quota_limitation.virtual_cpu IS NOT NULL
        AND quota_limitation.mem_size_mb IS NOT NULL
    GROUP BY quota_limitation.quota_id, quota_limitation.vds_group_id, vds_group_name, quota_limitation.virtual_cpu, quota_limitation.mem_size_mb,
        vm_static.quota_id, vds_groups.vds_group_id, vm_static.vds_group_id, quota_limitation.id;
END; ';


ALTER FUNCTION public.calculateallvdsgroupusage() OWNER TO engine;

--
-- Name: calculatestorageusage(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION calculatestorageusage(v_quota_id uuid, v_storage_id uuid) RETURNS double precision
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
	v_virtual_size double precision;
	v_actual_size double precision;
BEGIN
	-- Summarize size of all disks that are active.
    SELECT COALESCE(sum(size) / (1024 * 1024 * 1024),0) INTO v_virtual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid in (SELECT image_guid FROM  images WHERE  active = TRUE)
	AND quota_id = v_quota_id
    AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);

	-- Summarize the actual size of all the rest disks that are read only disks such as snapshots, not active, template disks.
	SELECT COALESCE(sum(disk_image_dynamic.actual_size) / (1024 * 1024 * 1024),0) INTO v_actual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid not in (SELECT image_guid
                           FROM   images i JOIN vm_device vd ON i.image_group_id = vd.device_id
                           WHERE  active = TRUE)
	AND quota_id = v_quota_id
	AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);
	RETURN v_actual_size + v_virtual_size;
END; ';


ALTER FUNCTION public.calculatestorageusage(v_quota_id uuid, v_storage_id uuid) OWNER TO engine;

--
-- Name: calculatevdsgroupusage(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION calculatevdsgroupusage(v_quota_id uuid, v_vds_group_id uuid) RETURNS SETOF vds_group_usage_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT cast(COALESCE(sum(num_of_sockets * cpu_per_socket), 0) as INTEGER) as virtual_cpu_usage,
    COALESCE(sum(mem_size_mb), 0) as mem_size_mb_usage
    FROM vm_static,vm_dynamic
    WHERE quota_id = v_quota_id
      AND vm_dynamic.vm_guid = vm_static.vm_guid
      AND vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses())
      AND (v_vds_group_id = vm_static.vds_group_id or v_vds_group_id IS NULL);
END; ';


ALTER FUNCTION public.calculatevdsgroupusage(v_quota_id uuid, v_vds_group_id uuid) OWNER TO engine;

--
-- Name: checkdbconnection(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION checkdbconnection() RETURNS SETOF integer
    LANGUAGE plpgsql IMMUTABLE
    AS '
BEGIN
    RETURN QUERY SELECT 1;
END; ';


ALTER FUNCTION public.checkdbconnection() OWNER TO engine;

--
-- Name: checkifjobhastasks(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION checkifjobhastasks(v_job_id uuid) RETURNS SETOF booleanresulttype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   step
        WHERE  job_id = v_job_id
        AND    external_id is not null
        AND    external_system_type in (''VDSM'',''GLUSTER''));
END; ';


ALTER FUNCTION public.checkifjobhastasks(v_job_id uuid) OWNER TO engine;

--
-- Name: checkifsnapshotexistsbyvmidandsnapshotid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION checkifsnapshotexistsbyvmidandsnapshotid(v_vm_id uuid, v_snapshot_id uuid) RETURNS SETOF booleanresulttype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    snapshot_id = v_snapshot_id);
END; ';


ALTER FUNCTION public.checkifsnapshotexistsbyvmidandsnapshotid(v_vm_id uuid, v_snapshot_id uuid) OWNER TO engine;

--
-- Name: checkifsnapshotexistsbyvmidandstatus(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION checkifsnapshotexistsbyvmidandstatus(v_vm_id uuid, v_status character varying) RETURNS SETOF booleanresulttype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    status = v_status);
END; ';


ALTER FUNCTION public.checkifsnapshotexistsbyvmidandstatus(v_vm_id uuid, v_status character varying) OWNER TO engine;

--
-- Name: checkifsnapshotexistsbyvmidandtype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION checkifsnapshotexistsbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) RETURNS SETOF booleanresulttype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    snapshot_type = v_snapshot_type);
END; ';


ALTER FUNCTION public.checkifsnapshotexistsbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) OWNER TO engine;

--
-- Name: clear_osinfo(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION clear_osinfo() RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      TRUNCATE dwh_osinfo;
END; ';


ALTER FUNCTION public.clear_osinfo() OWNER TO engine;

--
-- Name: clearvmdeviceaddress(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION clearvmdeviceaddress(v_device_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    update vm_device set address = '''' where device_id = v_device_id;
end;
';


ALTER FUNCTION public.clearvmdeviceaddress(v_device_id uuid) OWNER TO engine;

--
-- Name: createallmaterializedviewsiindexes(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION createallmaterializedviewsiindexes() RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
    v_create_index_sp NAME;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and create indexes(if defined)
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           v_create_index_sp := ''MtCreate'' || v_record.mv_name || ''Indexes'';
           -- Check if SP that creates the indexes exists
           IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
               v_create_index_sp := NULL;
           END IF;
           IF (v_create_index_sp IS NOT NULL) THEN
               EXECUTE ''select '' || v_create_index_sp || ''()'';
           END IF;
       END LOOP;
       CLOSE v_cur;
END; ';


ALTER FUNCTION public.createallmaterializedviewsiindexes() OWNER TO engine;

--
-- Name: createcustommaterializedview(name, name, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION createcustommaterializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_min_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true,  v_min_refresh_rate_in_sec);
     RETURN;
 END; ';


ALTER FUNCTION public.createcustommaterializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_min_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: createcustommaterializedview(name, name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION createcustommaterializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true, 0);
END; ';


ALTER FUNCTION public.createcustommaterializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: createcustommaterializedviewas(name, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION createcustommaterializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_min_refesh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, v_min_refesh_rate_in_sec);
     RETURN;
 END; ';


ALTER FUNCTION public.createcustommaterializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_min_refesh_rate_in_sec integer) OWNER TO engine;

--
-- Name: createcustommaterializedviewas(name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION createcustommaterializedviewas(v_view_name name, v_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, 0);
END; ';


ALTER FUNCTION public.createcustommaterializedviewas(v_view_name name, v_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedview(name, name, integer, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_custom boolean, v_min_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF FOUND THEN
         RAISE EXCEPTION ''Materialized view % already exists.'',
           v_matview;
     END IF;
     IF current_user != usename from pg_database , pg_user where datdba=usesysid and datname=current_database THEN
         RAISE EXCEPTION ''Materialized view % should be created with user ''''engine''''.'',
           v_matview;
     END IF;

     EXECUTE ''REVOKE ALL ON '' || v_view_name || '' FROM PUBLIC'';

     EXECUTE ''GRANT SELECT ON '' || v_view_name || '' TO PUBLIC'';

     EXECUTE ''CREATE TABLE '' || v_matview || '' AS SELECT * FROM '' || v_view_name;

     EXECUTE ''REVOKE ALL ON '' || v_matview || '' FROM PUBLIC'';

     EXECUTE ''GRANT SELECT ON '' || v_matview || '' TO PUBLIC'';

     INSERT INTO materialized_views (mv_name, v_name, refresh_rate_in_sec, last_refresh, custom, min_refresh_rate_in_sec)
       VALUES (v_matview, v_view_name, v_refresh_rate_in_sec, CURRENT_TIMESTAMP, v_custom, v_min_refresh_rate_in_sec);

     RETURN;
 END; ';


ALTER FUNCTION public.creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_custom boolean, v_min_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedview(name, name, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_min_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false,  v_min_refresh_rate_in_sec);
     RETURN;
 END; ';


ALTER FUNCTION public.creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer, v_min_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedview(name, name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false, 0);
END; ';


ALTER FUNCTION public.creatematerializedview(v_matview name, v_view_name name, v_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedviewas(name, integer, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_custom boolean, v_min_refesh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_renamed_view NAME;
 BEGIN
     IF FOUND THEN
         RAISE EXCEPTION ''Materialized view % already exists.'',
           v_view_name;
     END IF;

     v_renamed_view := v_view_name || ''_mt_base'';
     EXECUTE  ''ALTER VIEW '' ||  v_view_name || '' RENAME TO '' || v_renamed_view;
     perform CreateMaterializedView(v_view_name, v_renamed_view, v_refresh_rate_in_sec, v_custom, v_min_refesh_rate_in_sec);

     RETURN;
 END; ';


ALTER FUNCTION public.creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_custom boolean, v_min_refesh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedviewas(name, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_min_refesh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, v_min_refesh_rate_in_sec);
     RETURN;
 END; ';


ALTER FUNCTION public.creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer, v_min_refesh_rate_in_sec integer) OWNER TO engine;

--
-- Name: creatematerializedviewas(name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, 0);
END; ';


ALTER FUNCTION public.creatematerializedviewas(v_view_name name, v_refresh_rate_in_sec integer) OWNER TO engine;

--
-- Name: delete_entity_snapshot_by_command_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION delete_entity_snapshot_by_command_id(v_command_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
	BEGIN
		delete from business_entity_snapshot where command_id = v_command_id;
	END;
	RETURN;
END; ';


ALTER FUNCTION public.delete_entity_snapshot_by_command_id(v_command_id uuid) OWNER TO engine;

--
-- Name: delete_roles_groups(integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION delete_roles_groups(v_action_group_id integer, v_role_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM roles_groups
   WHERE action_group_id = v_action_group_id AND role_id = v_role_id;

END; ';


ALTER FUNCTION public.delete_roles_groups(v_action_group_id integer, v_role_id uuid) OWNER TO engine;

--
-- Name: deleteaction_version_map(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteaction_version_map(v_action_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM action_version_map
   WHERE action_type = v_action_type;

END; ';


ALTER FUNCTION public.deleteaction_version_map(v_action_type integer) OWNER TO engine;

--
-- Name: deleteaffinitygroup(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteaffinitygroup(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM affinity_groups
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.deleteaffinitygroup(v_id uuid) OWNER TO engine;

--
-- Name: deleteallglusterhooks(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteallglusterhooks(v_cluster_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_hooks
    WHERE cluster_id = v_cluster_id;
END; ';


ALTER FUNCTION public.deleteallglusterhooks(v_cluster_id uuid) OWNER TO engine;

--
-- Name: deleteasync_tasks(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteasync_tasks(v_task_id uuid) RETURNS integer
    LANGUAGE plpgsql
    AS '
DECLARE
deleted_rows int;
BEGIN
   DELETE FROM async_tasks
   WHERE task_id = v_task_id;
   GET DIAGNOSTICS deleted_rows = ROW_COUNT;
   RETURN deleted_rows;

END; ';


ALTER FUNCTION public.deleteasync_tasks(v_task_id uuid) OWNER TO engine;

--
-- Name: deleteasynctasksbyvdsmtaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteasynctasksbyvdsmtaskid(v_vdsm_task_id uuid) RETURNS integer
    LANGUAGE plpgsql
    AS '
DECLARE
deleted_rows int;
BEGIN
   DELETE FROM async_tasks
   WHERE vdsm_task_id = v_vdsm_task_id;
   GET DIAGNOSTICS deleted_rows = ROW_COUNT;
   RETURN deleted_rows;

END; ';


ALTER FUNCTION public.deleteasynctasksbyvdsmtaskid(v_vdsm_task_id uuid) OWNER TO engine;

--
-- Name: deleteauditalertlogbyvdsidandtype(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteauditalertlogbyvdsidandtype(v_vds_id uuid, v_log_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE audit_log set deleted = true
      where vds_id = v_vds_id and log_type = v_log_type;
END; ';


ALTER FUNCTION public.deleteauditalertlogbyvdsidandtype(v_vds_id uuid, v_log_type integer) OWNER TO engine;

--
-- Name: deleteauditlog(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteauditlog(v_audit_log_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE audit_log SET deleted = true
      WHERE audit_log_id = v_audit_log_id;
END; ';


ALTER FUNCTION public.deleteauditlog(v_audit_log_id integer) OWNER TO engine;

--
-- Name: deleteauditlogalertsbyvdsid(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteauditlogalertsbyvdsid(v_vds_id uuid, v_delete_config_alerts boolean DEFAULT true) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_min_alret_severity  INTEGER;
   v_no_config_alret_type  INTEGER;
   v_no_max_alret_type  INTEGER;
BEGIN
      v_min_alret_severity := 10;
      v_no_config_alret_type := 9000;
      v_no_max_alret_type := 9005;
      if (v_delete_config_alerts = true) then
         UPDATE audit_log set deleted = true
         where vds_id = v_vds_id and severity >= v_min_alret_severity and
         log_type  between v_no_config_alret_type and v_no_max_alret_type;
      else
         UPDATE audit_log set deleted = true
         where vds_id = v_vds_id and severity >= v_min_alret_severity and
         log_type  between v_no_config_alret_type + 1 and v_no_max_alret_type;
      end if;
END; ';


ALTER FUNCTION public.deleteauditlogalertsbyvdsid(v_vds_id uuid, v_delete_config_alerts boolean) OWNER TO engine;

--
-- Name: deleteauditlogolderthendate(timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteauditlogolderthendate(v_date timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_id  INTEGER;
   SWV_RowCount INTEGER;
BEGIN
        -- get first the id from which to remove in order to use index
      select   audit_log_id INTO v_id FROM audit_log WHERE LOG_TIME < v_date   order by audit_log_id desc LIMIT 1;
        -- check if there are candidates to remove
      GET DIAGNOSTICS SWV_RowCount = ROW_COUNT;
      if (SWV_RowCount > 0) then
         DELETE FROM audit_log
         WHERE audit_log_id <= v_id and
         audit_log_id not in(select audit_log_id from event_notification_hist);
      end if;
END; ';


ALTER FUNCTION public.deleteauditlogolderthendate(v_date timestamp with time zone) OWNER TO engine;

--
-- Name: deletebasedisk(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletebasedisk(v_disk_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_val  UUID;
BEGIN
    DELETE
    FROM   base_disks
    WHERE  disk_id = v_disk_id;

    -- Delete the disk''s permissions
   DELETE FROM permissions WHERE object_id = v_disk_id;
END; ';


ALTER FUNCTION public.deletebasedisk(v_disk_id uuid) OWNER TO engine;

--
-- Name: deletebookmark(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletebookmark(v_bookmark_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM bookmarks
      WHERE bookmark_Id = v_bookmark_id;
END; ';


ALTER FUNCTION public.deletebookmark(v_bookmark_id uuid) OWNER TO engine;

--
-- Name: deletebypoolvds_spm_id_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletebypoolvds_spm_id_map(v_vds_id uuid, v_storage_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM vds_spm_id_map
   WHERE vds_id = v_vds_id AND storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.deletebypoolvds_spm_id_map(v_vds_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: deleteclusterpolicy(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteclusterpolicy(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   cluster_policies
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.deleteclusterpolicy(v_id uuid) OWNER TO engine;

--
-- Name: deleteclusterpolicyunitsbyclusterpolicyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteclusterpolicyunitsbyclusterpolicyid(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   cluster_policy_units
    WHERE  cluster_policy_id = v_id;
END; ';


ALTER FUNCTION public.deleteclusterpolicyunitsbyclusterpolicyid(v_id uuid) OWNER TO engine;

--
-- Name: deletecompletedjobsolderthandate(timestamp with time zone, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletecompletedjobsolderthandate(v_succeeded_end_time timestamp with time zone, v_failed_end_time timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM job
    WHERE (is_auto_cleared
    AND ((end_time < v_succeeded_end_time
    AND    status = ''FINISHED'')
    OR    (end_time < v_failed_end_time
    AND    status IN (''FAILED'', ''ABORTED'', ''UNKNOWN''))));

    DELETE FROM job
    WHERE job_id IN
        (SELECT job_id
         FROM job
         WHERE NOT is_external
               AND NOT EXISTS
                (SELECT step.step_id
                 FROM step, async_tasks
                 WHERE step.job_id = job_id AND async_tasks.step_id = step.step_id));

END; ';


ALTER FUNCTION public.deletecompletedjobsolderthandate(v_succeeded_end_time timestamp with time zone, v_failed_end_time timestamp with time zone) OWNER TO engine;

--
-- Name: deletecustom_actions(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletecustom_actions(v_action_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM custom_actions
      WHERE action_id = v_action_id;
END; ';


ALTER FUNCTION public.deletecustom_actions(v_action_id integer) OWNER TO engine;

--
-- Name: deletedisk_image_dynamic(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletedisk_image_dynamic(v_image_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM disk_image_dynamic
   WHERE image_id = v_image_id;

END; ';


ALTER FUNCTION public.deletedisk_image_dynamic(v_image_id uuid) OWNER TO engine;

--
-- Name: deletedisklunmap(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletedisklunmap(v_disk_id uuid, v_lun_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   disk_lun_map
    WHERE  disk_id = v_disk_id
    AND    lun_id = v_lun_id;
END; ';


ALTER FUNCTION public.deletedisklunmap(v_disk_id uuid, v_lun_id character varying) OWNER TO engine;

--
-- Name: deleteevent_notification_hist(timestamp without time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteevent_notification_hist(v_sent_at timestamp without time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM event_notification_hist WHERE sent_at < v_sent_at;
END; ';


ALTER FUNCTION public.deleteevent_notification_hist(v_sent_at timestamp without time zone) OWNER TO engine;

--
-- Name: deleteevent_subscriber(character varying, integer, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteevent_subscriber(v_event_up_name character varying, v_method_id integer, v_subscriber_id uuid, v_tag_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      if (v_tag_name IS NULL) then
         delete from event_subscriber
         where event_up_name = v_event_up_name
         and method_id = v_method_id
         and subscriber_id = v_subscriber_id;
      else
         delete from event_subscriber
         where event_up_name = v_event_up_name
         and method_id = v_method_id
         and subscriber_id = v_subscriber_id
         and tag_name = v_tag_name;
      end if;
END; ';


ALTER FUNCTION public.deleteevent_subscriber(v_event_up_name character varying, v_method_id integer, v_subscriber_id uuid, v_tag_name character varying) OWNER TO engine;

--
-- Name: deleteglusterhook(uuid, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterhook(v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_hooks
    WHERE cluster_id = v_cluster_id AND gluster_command = v_gluster_command
    AND stage = v_stage AND name = v_name;
END; ';


ALTER FUNCTION public.deleteglusterhook(v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying) OWNER TO engine;

--
-- Name: deleteglusterhookbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterhookbyid(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_hooks
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.deleteglusterhookbyid(v_id uuid) OWNER TO engine;

--
-- Name: deleteglusterhooksbyids(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterhooksbyids(v_ids text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_hooks
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; ';


ALTER FUNCTION public.deleteglusterhooksbyids(v_ids text) OWNER TO engine;

--
-- Name: deleteglusterserver(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserver(v_server_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server
    WHERE server_id = v_server_id;
END; ';


ALTER FUNCTION public.deleteglusterserver(v_server_id uuid) OWNER TO engine;

--
-- Name: deleteglusterserverbyglusterserveruuid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserverbyglusterserveruuid(v_gluster_server_uuid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server
    WHERE gluster_server_uuid = v_gluster_server_uuid;
END; ';


ALTER FUNCTION public.deleteglusterserverbyglusterserveruuid(v_gluster_server_uuid uuid) OWNER TO engine;

--
-- Name: deleteglusterserverhook(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserverhook(v_hook_id uuid, v_server_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; ';


ALTER FUNCTION public.deleteglusterserverhook(v_hook_id uuid, v_server_id uuid) OWNER TO engine;

--
-- Name: deleteglusterserverhookbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserverhookbyid(v_hook_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id = v_hook_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; ';


ALTER FUNCTION public.deleteglusterserverhookbyid(v_hook_id uuid) OWNER TO engine;

--
-- Name: deleteglusterserverhooksbyids(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserverhooksbyids(v_ids text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id in (select * from fnSplitterUuid(v_ids));
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; ';


ALTER FUNCTION public.deleteglusterserverhooksbyids(v_ids text) OWNER TO engine;

--
-- Name: deleteglusterserverservice(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglusterserverservice(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_server_services
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.deleteglusterserverservice(v_id uuid) OWNER TO engine;

--
-- Name: deleteglustervolumeaccessprotocol(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumeaccessprotocol(v_volume_id uuid, v_access_protocol character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_access_protocols
    WHERE volume_id = v_volume_id
    AND   access_protocol = v_access_protocol;
END; ';


ALTER FUNCTION public.deleteglustervolumeaccessprotocol(v_volume_id uuid, v_access_protocol character varying) OWNER TO engine;

--
-- Name: deleteglustervolumebrick(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumebrick(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_bricks
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.deleteglustervolumebrick(v_id uuid) OWNER TO engine;

--
-- Name: deleteglustervolumebricks(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumebricks(v_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_bricks
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; ';


ALTER FUNCTION public.deleteglustervolumebricks(v_ids character varying) OWNER TO engine;

--
-- Name: deleteglustervolumebyguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumebyguid(v_volume_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volumes
    WHERE id = v_volume_id;
END; ';


ALTER FUNCTION public.deleteglustervolumebyguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: deleteglustervolumebyname(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumebyname(v_cluster_id uuid, v_vol_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volumes
    WHERE cluster_id = v_cluster_id
    AND   vol_name = v_vol_name;
END; ';


ALTER FUNCTION public.deleteglustervolumebyname(v_cluster_id uuid, v_vol_name character varying) OWNER TO engine;

--
-- Name: deleteglustervolumeoption(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumeoption(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_options
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.deleteglustervolumeoption(v_id uuid) OWNER TO engine;

--
-- Name: deleteglustervolumeoptions(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumeoptions(v_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_options
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; ';


ALTER FUNCTION public.deleteglustervolumeoptions(v_ids character varying) OWNER TO engine;

--
-- Name: deleteglustervolumesbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumesbyclusterid(v_cluster_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
DELETE FROM gluster_volumes
WHERE cluster_id = v_cluster_id;
END; ';


ALTER FUNCTION public.deleteglustervolumesbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: deleteglustervolumesbyguids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumesbyguids(v_volume_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volumes
    WHERE id in (select * from fnSplitterUuid(v_volume_ids));
END; ';


ALTER FUNCTION public.deleteglustervolumesbyguids(v_volume_ids character varying) OWNER TO engine;

--
-- Name: deleteglustervolumetransporttype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteglustervolumetransporttype(v_volume_id uuid, v_transport_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM gluster_volume_transport_types
    WHERE volume_id = v_volume_id
    AND   transport_type = v_transport_type;
END; ';


ALTER FUNCTION public.deleteglustervolumetransporttype(v_volume_id uuid, v_transport_type character varying) OWNER TO engine;

--
-- Name: deletegroup(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletegroup(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM tags_user_group_map
      WHERE group_id = v_id;
      DELETE FROM ad_groups
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.deletegroup(v_id uuid) OWNER TO engine;

--
-- Name: deleteimage(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteimage(v_image_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_val  UUID;
BEGIN
    DELETE
    FROM   images
    WHERE  image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.deleteimage(v_image_guid uuid) OWNER TO engine;

--
-- Name: deleteimage_storage_domain_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteimage_storage_domain_map(v_image_id uuid, v_storage_domain_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM image_storage_domain_map
   WHERE image_id = v_image_id AND storage_domain_id = v_storage_domain_id;

END; ';


ALTER FUNCTION public.deleteimage_storage_domain_map(v_image_id uuid, v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: deleteimage_storage_domain_map_by_image_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteimage_storage_domain_map_by_image_id(v_image_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM image_storage_domain_map
   WHERE image_id = v_image_id;

END; ';


ALTER FUNCTION public.deleteimage_storage_domain_map_by_image_id(v_image_id uuid) OWNER TO engine;

--
-- Name: deleteiscsibond(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteiscsibond(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val UUID;
BEGIN
      DELETE FROM iscsi_bonds WHERE id = v_id;
END; ';


ALTER FUNCTION public.deleteiscsibond(v_id uuid) OWNER TO engine;

--
-- Name: deletejob(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletejob(v_job_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM job
    WHERE job_id = v_job_id;
END; ';


ALTER FUNCTION public.deletejob(v_job_id uuid) OWNER TO engine;

--
-- Name: deletejobolderthandatewithstatus(timestamp with time zone, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletejobolderthandatewithstatus(v_end_time timestamp with time zone, v_status text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM job
    WHERE is_auto_cleared
    AND end_time < v_end_time
    AND status = any (string_to_array(v_status,'','')::VARCHAR[] );
END; ';


ALTER FUNCTION public.deletejobolderthandatewithstatus(v_end_time timestamp with time zone, v_status text) OWNER TO engine;

--
-- Name: deletelun(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletelun(v_lun_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  VARCHAR(50);
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   LUN_id INTO v_val FROM LUNs  WHERE LUN_id = v_LUN_id     FOR UPDATE;

   DELETE FROM LUNs
   WHERE LUN_id = v_LUN_id;

END; ';


ALTER FUNCTION public.deletelun(v_lun_id character varying) OWNER TO engine;

--
-- Name: deletelun_storage_server_connection_map(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletelun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM LUN_storage_server_connection_map
   WHERE LUN_id = v_LUN_id AND storage_server_connection = v_storage_server_connection;

END; ';


ALTER FUNCTION public.deletelun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) OWNER TO engine;

--
-- Name: deletenetwork(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletenetwork(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM network  WHERE id = v_id     FOR UPDATE;

   DELETE FROM network
   WHERE id = v_id;

   -- Delete the network''s permissions
   DELETE FROM permissions WHERE object_id = v_id;

END; ';


ALTER FUNCTION public.deletenetwork(v_id uuid) OWNER TO engine;

--
-- Name: deletenetwork_cluster(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletenetwork_cluster(v_cluster_id uuid, v_network_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM network_cluster
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

END; ';


ALTER FUNCTION public.deletenetwork_cluster(v_cluster_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: deletenetworkqos(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletenetworkqos(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM network_qos
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.deletenetworkqos(v_id uuid) OWNER TO engine;

--
-- Name: deleteovfgenerations(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteovfgenerations(v_vms_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM vm_ovf_generations WHERE vm_guid IN (SELECT * FROM fnSplitterUuid(v_vms_ids))
    -- needed here to ensure that vm with the same id hasn''t been added by import vm/template command
    AND vm_guid NOT IN (SELECT vm_guid FROM vm_static);
END; ';


ALTER FUNCTION public.deleteovfgenerations(v_vms_ids character varying) OWNER TO engine;

--
-- Name: deletepermission(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletepermission(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM permissions  WHERE id = v_id     FOR UPDATE;

   DELETE FROM permissions
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletepermission(v_id uuid) OWNER TO engine;

--
-- Name: deletepermissionsbyentityid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletepermissionsbyentityid(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM permissions
   WHERE object_id = v_id;
END; ';


ALTER FUNCTION public.deletepermissionsbyentityid(v_id uuid) OWNER TO engine;

--
-- Name: deletepolicyunit(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletepolicyunit(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM policy_units
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.deletepolicyunit(v_id uuid) OWNER TO engine;

--
-- Name: deleteprovider(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteprovider(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   providers
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.deleteprovider(v_id uuid) OWNER TO engine;

--
-- Name: deletequotabyquotaguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletequotabyquotaguid(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM quota
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.deletequotabyquotaguid(v_id uuid) OWNER TO engine;

--
-- Name: deletequotalimitationbyquotaguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletequotalimitationbyquotaguid(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM quota_limitation
   WHERE quota_id = v_id;
END; ';


ALTER FUNCTION public.deletequotalimitationbyquotaguid(v_id uuid) OWNER TO engine;

--
-- Name: deleterepo_domain_file_list(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleterepo_domain_file_list(v_storage_domain_id uuid, v_file_type integer DEFAULT NULL::integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM repo_file_meta_data
   WHERE repo_domain_id = v_storage_domain_id
     AND (v_file_type IS NULL OR file_type = v_file_type);

   RETURN;
END; ';


ALTER FUNCTION public.deleterepo_domain_file_list(v_storage_domain_id uuid, v_file_type integer) OWNER TO engine;

--
-- Name: deleterole(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleterole(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
    -- in order to force locking parent before children
   select   id INTO v_val FROM roles  WHERE id = v_id     FOR UPDATE;

   DELETE FROM roles
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deleterole(v_id uuid) OWNER TO engine;

--
-- Name: deletesnapshot(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletesnapshot(v_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   snapshots
    WHERE  snapshot_id = v_snapshot_id;
END; ';


ALTER FUNCTION public.deletesnapshot(v_snapshot_id uuid) OWNER TO engine;

--
-- Name: deletestep(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestep(v_step_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE FROM step
    WHERE step_id = v_step_id;
END; ';


ALTER FUNCTION public.deletestep(v_step_id uuid) OWNER TO engine;

--
-- Name: deletestorage_domain_dynamic(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestorage_domain_dynamic(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM storage_domain_dynamic
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletestorage_domain_dynamic(v_id uuid) OWNER TO engine;

--
-- Name: deletestorage_domain_static(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestorage_domain_static(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_domain_static  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_domain_static
   WHERE id = v_id;

	-- delete Storage permissions --
   DELETE FROM permissions where object_id = v_id;

END; ';


ALTER FUNCTION public.deletestorage_domain_static(v_id uuid) OWNER TO engine;

--
-- Name: deletestorage_pool(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestorage_pool(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

         -- Get (and keep) a shared lock with "right to upgrade to exclusive"
    select vm_guid INTO v_val FROM vm_static where vm_guid in (select vm_guid from vms where storage_pool_id = v_id) FOR UPDATE;
    DELETE
    FROM   snapshots
    WHERE  vm_id IN (
        SELECT vm_guid
        FROM   vms
        WHERE  storage_pool_id = v_id);
    delete FROM vm_static where vm_guid in (select vm_guid from vms where storage_pool_id = v_id);

    -- Delete vm pools as empty pools are not supported
    -- Get (and keep) a shared lock with "right to upgrade to exclusive"
    select vm_pool_id INTO v_val FROM vm_pools where vm_pool_id in (select vm_pool_id from vm_pools_view where storage_pool_id = v_id) FOR UPDATE;
    DELETE
    FROM   vm_pools
    WHERE  vm_pool_id IN (
        SELECT vm_pool_id
        FROM   vm_pools_view
        WHERE  storage_pool_id = v_id);

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_pool  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_pool
   WHERE id = v_id;

	-- delete StoragePool permissions --
   DELETE FROM permissions where object_id = v_id;

END; ';


ALTER FUNCTION public.deletestorage_pool(v_id uuid) OWNER TO engine;

--
-- Name: deletestorage_pool_iso_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestorage_pool_iso_map(v_storage_id uuid, v_storage_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id AND storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.deletestorage_pool_iso_map(v_storage_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: deletestorage_server_connections(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletestorage_server_connections(v_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  VARCHAR(50);
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_server_connections  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_server_connections
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletestorage_server_connections(v_id character varying) OWNER TO engine;

--
-- Name: deletetags(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags(v_tag_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
			-- in order to force locking parent before children
      select   tag_id INTO v_val FROM tags  WHERE tag_id = v_tag_id     FOR UPDATE;
      DELETE FROM tags_user_group_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_user_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vm_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vds_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vm_pool_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags
      WHERE tag_id = v_tag_id;
END; ';


ALTER FUNCTION public.deletetags(v_tag_id uuid) OWNER TO engine;

--
-- Name: deletetags_user_group_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags_user_group_map(v_group_id uuid, v_tag_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM tags_user_group_map
      WHERE group_id = v_group_id AND tag_id = v_tag_id;
END; ';


ALTER FUNCTION public.deletetags_user_group_map(v_group_id uuid, v_tag_id uuid) OWNER TO engine;

--
-- Name: deletetags_user_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags_user_map(v_tag_id uuid, v_user_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM tags_user_map
      WHERE tag_id = v_tag_id AND user_id = v_user_id;
END; ';


ALTER FUNCTION public.deletetags_user_map(v_tag_id uuid, v_user_id uuid) OWNER TO engine;

--
-- Name: deletetags_vds_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags_vds_map(v_tag_id uuid, v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM tags_vds_map
      WHERE tag_id = v_tag_id AND vds_id = v_vds_id;
END; ';


ALTER FUNCTION public.deletetags_vds_map(v_tag_id uuid, v_vds_id uuid) OWNER TO engine;

--
-- Name: deletetags_vm_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags_vm_map(v_tag_id uuid, v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM tags_vm_map
      WHERE tag_id = v_tag_id AND vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.deletetags_vm_map(v_tag_id uuid, v_vm_id uuid) OWNER TO engine;

--
-- Name: deletetags_vm_pool_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletetags_vm_pool_map(v_tag_id uuid, v_vm_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM tags_vm_pool_map
   WHERE tag_id = v_tag_id AND vm_pool_id = v_vm_pool_id;

END; ';


ALTER FUNCTION public.deletetags_vm_pool_map(v_tag_id uuid, v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: deleteuser(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deleteuser(v_user_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
			-- in order to force locking parent before children
      select   user_id INTO v_val FROM users  WHERE user_id = v_user_id     FOR UPDATE;
      DELETE FROM tags_user_map
      WHERE user_id = v_user_id;
      DELETE FROM users
      WHERE user_id = v_user_id;
END; ';


ALTER FUNCTION public.deleteuser(v_user_id uuid) OWNER TO engine;

--
-- Name: deletevdcoption(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevdcoption(v_option_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM vdc_options
      WHERE option_id = v_option_id;
END; ';


ALTER FUNCTION public.deletevdcoption(v_option_id integer) OWNER TO engine;

--
-- Name: deletevds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevds(v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   BEGIN
      UPDATE vm_static
      SET dedicated_vm_for_vds = null
      WHERE dedicated_vm_for_vds = v_vds_id;
      DELETE FROM tags_vds_map
      WHERE vds_id = v_vds_id;
   -- Delete all Vds Alerts from the database
      PERFORM DeleteAuditLogAlertsByVdsID(v_vds_id);
      DELETE FROM vds_statistics WHERE vds_id = v_vds_id;
      DELETE FROM vds_dynamic WHERE vds_id = v_vds_id;
      DELETE FROM vds_static WHERE vds_id = v_vds_id;
      DELETE FROM permissions where object_id = v_vds_id;
   END;
   RETURN;
END; ';


ALTER FUNCTION public.deletevds(v_vds_id uuid) OWNER TO engine;

--
-- Name: deletevds_interface(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevds_interface(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM vds_interface
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletevds_interface(v_id uuid) OWNER TO engine;

--
-- Name: deletevds_interface_statistics(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevds_interface_statistics(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM vds_interface_statistics  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vds_interface_statistics
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletevds_interface_statistics(v_id uuid) OWNER TO engine;

--
-- Name: deletevds_spm_id_map(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevds_spm_id_map(v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   DELETE FROM vds_spm_id_map
   WHERE vds_id = v_vds_id;

END; ';


ALTER FUNCTION public.deletevds_spm_id_map(v_vds_id uuid) OWNER TO engine;

--
-- Name: deletevdsdynamic(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevdsdynamic(v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   BEGIN
      DELETE FROM vds_dynamic
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.deletevdsdynamic(v_vds_id uuid) OWNER TO engine;

--
-- Name: deletevdsgroup(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevdsgroup(v_vds_group_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vds_group_id INTO v_val FROM vds_groups  WHERE vds_group_id = v_vds_group_id     FOR UPDATE;
      DELETE FROM vds_groups
      WHERE vds_group_id = v_vds_group_id;
		-- delete VDS group permissions --
      DELETE FROM permissions where object_id = v_vds_group_id;
END; ';


ALTER FUNCTION public.deletevdsgroup(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: deletevdsstatic(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevdsstatic(v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   BEGIN
      UPDATE vm_static
      SET dedicated_vm_for_vds = null,
          migration_support = 0
      WHERE dedicated_vm_for_vds = v_vds_id;
      DELETE FROM tags_vds_map
      WHERE vds_id = v_vds_id;
   -- Delete all Vds Alerts from the database
      PERFORM DeleteAuditLogAlertsByVdsID(v_vds_id);
      DELETE FROM vds_static
      WHERE vds_id = v_vds_id;
	-- delete VDS permissions --
      DELETE FROM permissions where object_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.deletevdsstatic(v_vds_id uuid) OWNER TO engine;

--
-- Name: deletevdsstatistics(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevdsstatistics(v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   BEGIN
      DELETE FROM vds_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.deletevdsstatistics(v_vds_id uuid) OWNER TO engine;

--
-- Name: deletevm(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevm(v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_vmt_guid  UUID;
BEGIN
      select   vm_static.vmt_guid INTO v_vmt_guid FROM vm_static WHERE vm_guid = v_vm_guid;
      UPDATE vm_static
      SET child_count =(SELECT COUNT(*) FROM vm_static WHERE vmt_guid = v_vmt_guid) -1
      WHERE vm_guid = v_vmt_guid;
      DELETE FROM tags_vm_map
      WHERE vm_id = v_vm_guid;
      DELETE
      FROM   snapshots
      WHERE  vm_id = v_vm_guid;
      DELETE FROM vm_statistics WHERE vm_guid = v_vm_guid;
      DELETE FROM vm_dynamic WHERE vm_guid = v_vm_guid;
      DELETE FROM vm_static WHERE vm_guid = v_vm_guid;
      DELETE FROM permissions where object_id = v_vm_guid;
END; ';


ALTER FUNCTION public.deletevm(v_vm_guid uuid) OWNER TO engine;

--
-- Name: deletevm_interface_statistics(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevm_interface_statistics(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM vm_interface_statistics  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vm_interface_statistics
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletevm_interface_statistics(v_id uuid) OWNER TO engine;

--
-- Name: deletevm_pool_map(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevm_pool_map(v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  VARCHAR(50);
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_pool_map  WHERE vm_guid = v_vm_guid     FOR UPDATE;
      DELETE FROM vm_pool_map
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.deletevm_pool_map(v_vm_guid uuid) OWNER TO engine;

--
-- Name: deletevm_pools(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevm_pools(v_vm_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_pool_id INTO v_val FROM vm_pools  WHERE vm_pool_id = v_vm_pool_id     FOR UPDATE;
      DELETE FROM vm_pools
      WHERE vm_pool_id = v_vm_pool_id;

		-- delete VmPool permissions --
      DELETE FROM permissions where object_id = v_vm_pool_id;
END; ';


ALTER FUNCTION public.deletevm_pools(v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: deletevmdevice(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmdevice(v_device_id uuid, v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM   vm_device
    WHERE  device_id = v_device_id
    AND (v_vm_id IS NULL or vm_id = v_vm_id);
END; ';


ALTER FUNCTION public.deletevmdevice(v_device_id uuid, v_vm_id uuid) OWNER TO engine;

--
-- Name: deletevmdynamic(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmdynamic(v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM vm_dynamic
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.deletevmdynamic(v_vm_guid uuid) OWNER TO engine;

--
-- Name: deletevmguestagentinterfacesbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmguestagentinterfacesbyvmid(v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE FROM vm_guest_agent_interfaces
   WHERE vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.deletevmguestagentinterfacesbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: deletevminit(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevminit(v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM vm_init
      WHERE vm_id = v_vm_id;

END; ';


ALTER FUNCTION public.deletevminit(v_vm_id uuid) OWNER TO engine;

--
-- Name: deletevminterface(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevminterface(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN

   -- Get (and keep) a shared lock with "right to upgrade to exclusive"
   -- in order to force locking parent before children
   select   id INTO v_val FROM vm_interface  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vm_interface
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.deletevminterface(v_id uuid) OWNER TO engine;

--
-- Name: deletevmstatic(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmstatic(v_vm_guid uuid, v_remove_permissions boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
            -- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_static  WHERE vm_guid = v_vm_guid     FOR UPDATE;
      DELETE FROM vm_static
      WHERE vm_guid = v_vm_guid
      AND   entity_type = ''VM'';

			-- delete VM permissions --
      if v_remove_permissions then
        DELETE FROM permissions where object_id = v_vm_guid;
      end if;
END; ';


ALTER FUNCTION public.deletevmstatic(v_vm_guid uuid, v_remove_permissions boolean) OWNER TO engine;

--
-- Name: deletevmstatistics(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmstatistics(v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM vm_statistics
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.deletevmstatistics(v_vm_guid uuid) OWNER TO engine;

--
-- Name: deletevmtemplates(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevmtemplates(v_vmt_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val  UUID;
BEGIN
        -- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_static  WHERE vm_guid = v_vmt_guid FOR UPDATE;
      DELETE FROM vm_static
      WHERE vm_guid = v_vmt_guid;
		-- delete Template permissions --
      DELETE FROM permissions where object_id = v_vmt_guid;
END; ';


ALTER FUNCTION public.deletevmtemplates(v_vmt_guid uuid) OWNER TO engine;

--
-- Name: deletevnicprofile(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION deletevnicprofile(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_val UUID;
BEGIN

    DELETE FROM vnic_profiles
    WHERE id = v_id;

    -- Delete the vnic profiles permissions
    DELETE FROM permissions WHERE object_id = v_id;

END; ';


ALTER FUNCTION public.deletevnicprofile(v_id uuid) OWNER TO engine;

--
-- Name: dropallcustommaterializedviews(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION dropallcustommaterializedviews() RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views where custom;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; ';


ALTER FUNCTION public.dropallcustommaterializedviews() OWNER TO engine;

--
-- Name: dropallmaterializedviews(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION dropallmaterializedviews() RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; ';


ALTER FUNCTION public.dropallmaterializedviews() OWNER TO engine;

--
-- Name: dropmaterializedview(name); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION dropmaterializedview(v_matview name) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN

     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
     END IF;

     EXECUTE ''DROP TABLE '' || v_matview || '' CASCADE'';
     DELETE FROM materialized_views WHERE mv_name=v_matview;

     RETURN;
 END; ';


ALTER FUNCTION public.dropmaterializedview(v_matview name) OWNER TO engine;

--
-- Name: fn_db_add_action_group_to_role(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_add_action_group_to_role(v_role_id uuid, v_action_group_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; ';


ALTER FUNCTION public.fn_db_add_action_group_to_role(v_role_id uuid, v_action_group_id integer) OWNER TO engine;

--
-- Name: fn_db_add_column(character varying, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_add_column(v_table character varying, v_column character varying, v_column_def text) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := ''ALTER TABLE '' || v_table || '' ADD COLUMN '' || v_column || '' '' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; ';


ALTER FUNCTION public.fn_db_add_column(v_table character varying, v_column character varying, v_column_def text) OWNER TO engine;

--
-- Name: fn_db_add_column_to_object_white_list(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_add_column_to_object_white_list(v_object_name character varying, v_column_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_add_column_to_object_white_list(v_object_name character varying, v_column_name character varying) OWNER TO engine;

--
-- Name: fn_db_add_config_value(character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_add_config_value(v_option_name character varying, v_option_value character varying, v_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_add_config_value(v_option_name character varying, v_option_value character varying, v_version character varying) OWNER TO engine;

--
-- Name: fn_db_change_column_type(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_change_column_type(v_table character varying, v_column character varying, v_type character varying, v_new_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := ''ALTER TABLE '' || v_table || '' ALTER COLUMN '' || v_column || '' TYPE '' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; ';


ALTER FUNCTION public.fn_db_change_column_type(v_table character varying, v_column character varying, v_type character varying, v_new_type character varying) OWNER TO engine;

--
-- Name: fn_db_create_constraint(character varying, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_create_constraint(v_table character varying, v_constraint character varying, v_constraint_sql text) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute ''ALTER TABLE '' || v_table ||  '' ADD CONSTRAINT '' || v_constraint || '' '' || v_constraint_sql;
    end if;
END; ';


ALTER FUNCTION public.fn_db_create_constraint(v_table character varying, v_constraint character varying, v_constraint_sql text) OWNER TO engine;

--
-- Name: fn_db_delete_config_for_version(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_delete_config_for_version(v_version text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; ';


ALTER FUNCTION public.fn_db_delete_config_for_version(v_version text) OWNER TO engine;

--
-- Name: fn_db_delete_config_value(character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_delete_config_value(v_option_name character varying, v_version text) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_delete_config_value(v_option_name character varying, v_version text) OWNER TO engine;

--
-- Name: fn_db_delete_config_value_all_versions(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_delete_config_value_all_versions(v_option_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_delete_config_value_all_versions(v_option_name character varying) OWNER TO engine;

--
-- Name: fn_db_delete_version_map(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_delete_version_map(v_cluster_version character varying, v_sp_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   DELETE
   FROM action_version_map
   WHERE cluster_minimal_version = v_cluster_version
     AND storage_pool_minimal_version = v_sp_version;
END; ';


ALTER FUNCTION public.fn_db_delete_version_map(v_cluster_version character varying, v_sp_version character varying) OWNER TO engine;

--
-- Name: fn_db_drop_column(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_drop_column(v_table character varying, v_column character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := ''ALTER TABLE '' || v_table || '' DROP COLUMN '' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;';


ALTER FUNCTION public.fn_db_drop_column(v_table character varying, v_column character varying) OWNER TO engine;

--
-- Name: fn_db_drop_constraint(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_drop_constraint(v_table character varying, v_constraint character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute ''ALTER TABLE '' || v_table ||  '' DROP CONSTRAINT '' || v_constraint || '' CASCADE'';
    end if;
END; ';


ALTER FUNCTION public.fn_db_drop_constraint(v_table character varying, v_constraint character varying) OWNER TO engine;

--
-- Name: fn_db_get_async_tasks(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_get_async_tasks() RETURNS SETOF async_tasks_info_rs
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='''';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; ';


ALTER FUNCTION public.fn_db_get_async_tasks() OWNER TO engine;

--
-- Name: fn_db_grant_action_group_to_all_roles_filter(integer, uuid[]); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[]) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; ';


ALTER FUNCTION public.fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[]) OWNER TO engine;

--
-- Name: fn_db_mask_object(regclass); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_mask_object(v_object regclass) RETURNS SETOF record
    LANGUAGE plpgsql
    AS '
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || ''.'' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || '', '', ''SELECT '' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || ''NULL::'' || quote_ident( temprec.typname ) || '' as '' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || '' FROM '' || v_table_name;
        v_sql := ''SELECT x::'' || v_table_name || '' as rec FROM ('' || v_sql || '') as x'';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; ';


ALTER FUNCTION public.fn_db_mask_object(v_object regclass) OWNER TO engine;

--
-- Name: fn_db_rename_column(character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_rename_column(v_table character varying, v_column character varying, v_new_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := ''ALTER TABLE '' || v_table || '' RENAME COLUMN '' || v_column || '' TO '' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; ';


ALTER FUNCTION public.fn_db_rename_column(v_table character varying, v_column character varying, v_new_name character varying) OWNER TO engine;

--
-- Name: fn_db_rename_config_key(character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_rename_config_key(v_old_option_name character varying, v_new_option_name character varying, v_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; ';


ALTER FUNCTION public.fn_db_rename_config_key(v_old_option_name character varying, v_new_option_name character varying, v_version character varying) OWNER TO engine;

--
-- Name: fn_db_split_config_value(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> ''general'' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = ''general'';
    v_version_count := count(distinct version) from vdc_options where version <> ''general'';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> ''general'';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn''t update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don''t have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = ''general'';
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying) OWNER TO engine;

--
-- Name: fn_db_unlock_disk(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_unlock_disk(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; ';


ALTER FUNCTION public.fn_db_unlock_disk(v_id uuid) OWNER TO engine;

--
-- Name: fn_db_unlock_entity(character varying, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_unlock_entity(v_object_type character varying, v_name character varying, v_recursive boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:=''OK'';
    SNAPSHOT_LOCKED:=''LOCKED'';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = ''vm'') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = ''template'') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; ';


ALTER FUNCTION public.fn_db_unlock_entity(v_object_type character varying, v_name character varying, v_recursive boolean) OWNER TO engine;

--
-- Name: fn_db_unlock_snapshot(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_unlock_snapshot(v_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:=''OK'';
    LOCKED:=''LOCKED'';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; ';


ALTER FUNCTION public.fn_db_unlock_snapshot(v_id uuid) OWNER TO engine;

--
-- Name: fn_db_update_config_value(character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_update_config_value(v_option_name character varying, v_option_value character varying, v_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_update_config_value(v_option_name character varying, v_option_value character varying, v_version character varying) OWNER TO engine;

--
-- Name: fn_db_update_default_config_value(character varying, character varying, character varying, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_db_update_default_config_value(v_option_name character varying, v_default_option_value character varying, v_option_value character varying, v_version character varying, v_ignore_default_value_case boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; ';


ALTER FUNCTION public.fn_db_update_default_config_value(v_option_name character varying, v_default_option_value character varying, v_option_value character varying, v_version character varying, v_ignore_default_value_case boolean) OWNER TO engine;

--
-- Name: fn_get_actual_images_size_by_storage(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_actual_images_size_by_storage(v_storage_domain_id uuid) RETURNS integer
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(disk_image_dynamic.actual_size),0)
				FROM images_storage_domain_view JOIN
	    			disk_image_dynamic ON ( images_storage_domain_view.image_guid = disk_image_dynamic.image_id )
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;';


ALTER FUNCTION public.fn_get_actual_images_size_by_storage(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: fn_get_ad_element_name(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_ad_element_name(v_ad_element_id uuid) RETURNS text
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
    result text;

BEGIN
   if (v_ad_element_id = getGlobalIds(''everyone'')) then
      result := ''Everyone'';
   else
      select(COALESCE(name,'''') || '' '' || COALESCE(surname,'''') || '' ('' || COALESCE(username,'''') || '')'') INTO result from users where user_id = v_ad_element_id;
      if (result is null) then
         select   name INTO result from ad_groups where ID = v_ad_element_id;
      end if;
   end if;
   return result;
END; ';


ALTER FUNCTION public.fn_get_ad_element_name(v_ad_element_id uuid) OWNER TO engine;

--
-- Name: fn_get_column_size(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_column_size(v_table character varying, v_column character varying) RETURNS integer
    LANGUAGE plpgsql STABLE
    AS '
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = ''public'' and udt_name in (''char'',''varchar'');
   return retvalue;
END; ';


ALTER FUNCTION public.fn_get_column_size(v_table character varying, v_column character varying) OWNER TO engine;

--
-- Name: fn_get_comparable_ip_list(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_comparable_ip_list(text) RETURNS inet[]
    LANGUAGE plpgsql IMMUTABLE STRICT
    AS '
BEGIN
CASE
    WHEN ($1 IS NULL) OR ($1 ~ E''^\\s*$'') THEN
        RETURN NULL;
    ELSE
        RETURN regexp_split_to_array(trim(both from $1), E''\\s+'')::inet[];
END CASE;
END; ';


ALTER FUNCTION public.fn_get_comparable_ip_list(text) OWNER TO engine;

--
-- Name: fn_get_disk_commited_value_by_storage(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_disk_commited_value_by_storage(v_storage_domain_id uuid) RETURNS integer
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(images_storage_domain_view.size),0)
				FROM images_storage_domain_view
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;';


ALTER FUNCTION public.fn_get_disk_commited_value_by_storage(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: fn_get_entity_name(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_entity_name(v_entity_id uuid, v_object_type integer) RETURNS text
    LANGUAGE plpgsql STABLE
    AS '
/*    Gets object name by its id and type

    Object Types (compatible with VdcObjectType, XXX entries are unused currently)
        Unknown XXX,
        System XXX,
        VM = 2,
        VDS = 3,
        VmTemplate = 4,
        VmPool = 5,
        AdElements XXX,
        Tags XXX,
        Bookmarks XXX,
        VdsGroups = 9,
        MultiLevelAdministration XXX,
        Storage = 11,
        EventNotification XXX,
        ImportExport XXX,
        StoragePool = 14,
        User = 15,
        Role = 16,
        Quota = 17,
        GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27
*/
DECLARE
    v_entity_type int4 := v_object_type;
    result text;

BEGIN

    CASE
    WHEN v_entity_type = 1 THEN
        result := ''System'';
    WHEN v_entity_type = 2 OR v_entity_type = 4 THEN
        result := ( SELECT vm_name FROM vm_static WHERE vm_guid = v_entity_id );
    WHEN v_entity_type = 3 THEN
        result := ( SELECT vds_name FROM vds_static WHERE vds_id = v_entity_id );
    WHEN v_entity_type = 5 THEN
        result := ( SELECT vm_pool_name FROM vm_pools WHERE vm_pool_id = v_entity_id );
    WHEN v_entity_type = 7 THEN
        result := ( SELECT tag_name FROM tags WHERE tag_id = v_entity_id );
    WHEN v_entity_type = 8 THEN
        result := ( SELECT bookmark_name FROM bookmarks WHERE bookmark_id = v_entity_id );
    WHEN v_entity_type = 9 THEN
        result := ( SELECT name FROM vds_groups WHERE vds_group_id = v_entity_id );
    WHEN v_entity_type = 11 THEN
        result := ( SELECT storage_name FROM storage_domain_static WHERE id = v_entity_id );
    WHEN v_entity_type = 14 THEN
        result := ( SELECT name FROM storage_pool WHERE id = v_entity_id );
    WHEN v_entity_type = 15 THEN
        result := ( SELECT username FROM users WHERE user_id = v_entity_id );
    WHEN v_entity_type = 16 THEN
        result := ( SELECT name FROM roles WHERE id = v_entity_id );
    WHEN v_entity_type = 17 THEN
        result := ( SELECT quota_name FROM quota WHERE id = v_entity_id );
   WHEN v_entity_type = 18 THEN
        result := ( SELECT vol_name FROM gluster_volumes WHERE id = v_entity_id );
    WHEN v_entity_type = 19 THEN
        result := ( SELECT disk_alias FROM base_disks WHERE disk_id = v_entity_id );
    WHEN v_entity_type = 20 THEN
        result := ( SELECT name FROM network WHERE id = v_entity_id );
    WHEN v_entity_type = 23 THEN
        result := ( SELECT concat(gluster_command,''-'',stage,''-'',name) FROM gluster_hooks where id = v_entity_id );
    WHEN v_entity_type = 25 THEN
        result := ( SELECT service_name FROM gluster_services where id = v_entity_id );
    WHEN v_entity_type = 27 THEN
        result := ( SELECT name FROM vnic_profiles where id = v_entity_id );
    ELSE
        result := ''Unknown type '' ||  v_entity_type;
    END CASE;

--      -- This should be written to an error var or include object_id that is missing
--    IF result IS NULL THEN
--        result := v_entity_id || '''' NOT FOUND'''';
--    END IF;
    RETURN result;
END;';


ALTER FUNCTION public.fn_get_entity_name(v_entity_id uuid, v_object_type integer) OWNER TO engine;

--
-- Name: fn_get_entity_parents(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_entity_parents(v_entity_id uuid, v_object_type integer) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
/*	Gets a list of all parent GUID to the system root (including)

	Object Types (compatible with VdcObjectType, XXX entries are unused currently)
		Unknown XXX,
		System XXX,
        Bottom = 0,
		VM = 2,
		VDS = 3,
		VmTemplate = 4,
		VmPool = 5,
		AdElements XXX,
		Tags XXX,
		Bookmarks XXX,
		VdsGroups = 9,
		MultiLevelAdministration XXX,
		Storage = 11,
		EventNotification XXX,
		ImportExport XXX,
		StoragePool = 14,
		User = 15,
		Role = 16,
		Quota = 17,
		GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27
*/
DECLARE
	v_entity_type int4 := v_object_type;
	system_root_id uuid;
	cluster_id uuid;
	ds_id uuid;
	v_image_id uuid;
	v_storage_id uuid;
    v_vm_id uuid;
    v_storage_pool_id uuid;
    v_profile_network_id uuid;

BEGIN

	system_root_id := ( SELECT getGlobalIds(''system'') ); -- hardcoded also in MLA Handler
	CASE
	WHEN v_entity_type = 0 THEN -- Bottom
		RETURN QUERY
			SELECT object_id
			FROM permissions;
	WHEN v_entity_type = 2 THEN -- VM
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 3 THEN -- VDS
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 4 THEN -- Template
		-- get image id first
		v_image_id := ( SELECT image_guid FROM images i JOIN vm_device vd ON i.image_group_id = vd.device_id WHERE vm_id = v_entity_id limit 1);
		-- get the storage id from images
		v_storage_id := ( SELECT storage_domain_id FROM image_storage_domain_map WHERE image_id = v_image_id limit 1);
		-- finally get data center id
		ds_id := ( SELECT storage_pool_id FROM storage_pool_iso_map WHERE storage_id = v_storage_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 5 THEN -- VM Pool
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_pools WHERE vm_pool_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 9 THEN -- Cluster
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 11 THEN -- Storage Domain

		RETURN QUERY
			SELECT system_root_id AS id
			UNION ALL
			SELECT storage_pool_id as id FROM storage_pool_iso_map WHERE storage_id = v_entity_id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 17 THEN -- Quota
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM quota WHERE id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 18 THEN -- GlusterVolume
        -- get cluster id
		cluster_id := ( SELECT v.cluster_id FROM gluster_volumes v WHERE id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;

	WHEN v_entity_type = 19 THEN -- Disk

        -- get data center, storage domain and vm
        SELECT INTO ds_id, v_storage_id, v_vm_id
                    storage_pool_id, storage_id, vm_id
        FROM images_storage_domain_view
        LEFT OUTER JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
        WHERE image_group_id = v_entity_id;

        -- get cluster
        cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_vm_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT v_storage_id AS id
            UNION
            SELECT v_vm_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 20 THEN -- Network

        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_entity_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 27 THEN -- VNICProfile

        SELECT INTO v_profile_network_id
                    vnic_profiles.network_id
        FROM vnic_profiles
        WHERE vnic_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_profile_network_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_profile_network_id AS id
            UNION
            SELECT v_entity_id AS id;

    WHEN v_entity_type = 23 THEN -- Gluster Hook

        -- get cluster id
        cluster_id := ( SELECT cluster_id FROM gluster_hooks WHERE id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 25 THEN -- Gluster Service

        -- get cluster id
        cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;
	ELSE
		IF v_entity_type IN ( 1,14,15,16 ) THEN -- Data Center, users and roles are under system
			RETURN QUERY
				SELECT system_root_id AS id
				UNION
				SELECT v_entity_id AS id;
		END IF;
	END CASE;
END;';


ALTER FUNCTION public.fn_get_entity_parents(v_entity_id uuid, v_object_type integer) OWNER TO engine;

--
-- Name: fn_get_storage_domain_shared_status_by_domain_id(uuid, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_get_storage_domain_shared_status_by_domain_id(v_storage_domain_id uuid, v_storage_status integer, v_storage_domain_type integer) RETURNS integer
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_result  INTEGER;
   v_rowsCount  INTEGER;
   v_status  INTEGER;
BEGIN
    if (v_storage_domain_type != 2) then
      if (v_storage_status is null) then
         v_result := 0;
      else
         -- if 1 row and status active (3) then domain is active (1)
         if v_storage_status = 3 then
            v_result := 1;
		 -- if 1 row and status not active then domain is inactive (2)
         else
            v_result := 2;
         end if;
      end if;
    else
      BEGIN
         CREATE GLOBAL TEMPORARY TABLE tt_TEMP22
         (
            status INTEGER,
            count INTEGER
         ) WITH OIDS;
         exception when others then
         truncate table tt_TEMP22;
      END;
      delete from tt_TEMP22;
      Insert INTO tt_TEMP22
      select status, count(storage_id) from storage_pool_iso_map
      where storage_id = v_storage_domain_id
      group by status;

      select count(*) INTO v_rowsCount from tt_TEMP22;

      -- if return 0 rows then the domain is unattached
      if (v_rowsCount = 0) then
         v_result := 0;
      else
         if (v_rowsCount = 1) then
	        -- if 1 row and status active (3) then domain is active (1)
            if v_storage_status = 3 then
               v_result := 1;
		    -- if 1 row and status not active then domain is inactive (2)
            else
               v_result := 2;
            end if;
	      -- else (if return more then 1 row)
          else
            select   count(*) INTO v_rowsCount from tt_TEMP22 where status = 3;
            if (v_rowsCount > 0) then
               v_result := 3;
			   -- non of the statuses is active
            else
               v_result := 2;
          end if;
         end if;
      end if;
    end if;
   return v_result;
END; ';


ALTER FUNCTION public.fn_get_storage_domain_shared_status_by_domain_id(v_storage_domain_id uuid, v_storage_status integer, v_storage_domain_type integer) OWNER TO engine;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: storage_pool; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE storage_pool (
    id uuid NOT NULL,
    name character varying(40) NOT NULL,
    description character varying(4000) NOT NULL,
    storage_pool_type integer,
    storage_pool_format_type character varying(50),
    status integer NOT NULL,
    master_domain_version integer NOT NULL,
    spm_vds_id uuid,
    compatibility_version character varying(40) DEFAULT '2.2'::character varying NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    quota_enforcement_type integer,
    free_text_comment text,
    is_local boolean
);


ALTER TABLE public.storage_pool OWNER TO engine;

--
-- Name: fn_perms_get_storage_pools_with_permitted_action_on_vds_groups(uuid, integer, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_perms_get_storage_pools_with_permitted_action_on_vds_groups(v_user_id uuid, v_action_group_id integer, v_supports_virt_service boolean, v_supports_gluster_service boolean) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT sp.*
      FROM storage_pool sp
      WHERE sp.id in
        (SELECT vg.storage_pool_id
         FROM vds_groups vg
         WHERE (SELECT get_entity_permissions(v_user_id, v_action_group_id, vg.vds_group_id, 9)) IS NOT NULL
         AND ((v_supports_virt_service = TRUE AND vg.virt_service = TRUE) OR (v_supports_gluster_service = TRUE AND vg.gluster_service = TRUE))
        );
END; ';


ALTER FUNCTION public.fn_perms_get_storage_pools_with_permitted_action_on_vds_groups(v_user_id uuid, v_action_group_id integer, v_supports_virt_service boolean, v_supports_gluster_service boolean) OWNER TO engine;

--
-- Name: quota; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE quota (
    id uuid NOT NULL,
    storage_pool_id uuid NOT NULL,
    quota_name character varying(65) NOT NULL,
    description character varying(250),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    threshold_vds_group_percentage integer DEFAULT 80,
    threshold_storage_percentage integer DEFAULT 80,
    grace_vds_group_percentage integer DEFAULT 20,
    grace_storage_percentage integer DEFAULT 20
);


ALTER TABLE public.quota OWNER TO engine;

--
-- Name: vds_groups; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_groups (
    vds_group_id uuid NOT NULL,
    name character varying(40) NOT NULL,
    description character varying(4000),
    cpu_name character varying(255),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    storage_pool_id uuid,
    max_vds_memory_over_commit integer DEFAULT 100 NOT NULL,
    compatibility_version character varying(40) DEFAULT '2.2'::character varying NOT NULL,
    transparent_hugepages boolean DEFAULT false NOT NULL,
    migrate_on_error integer DEFAULT 1 NOT NULL,
    virt_service boolean DEFAULT true NOT NULL,
    gluster_service boolean DEFAULT false NOT NULL,
    count_threads_as_cores boolean DEFAULT false NOT NULL,
    emulated_machine character varying(40),
    trusted_service boolean DEFAULT false NOT NULL,
    tunnel_migration boolean DEFAULT false NOT NULL,
    cluster_policy_id uuid,
    cluster_policy_custom_properties text,
    enable_balloon boolean DEFAULT false NOT NULL,
    free_text_comment text,
    detect_emulated_machine boolean DEFAULT false,
    architecture integer DEFAULT 0 NOT NULL,
    optimization_type smallint DEFAULT 0,
    spice_proxy character varying(255),
    ha_reservation boolean DEFAULT false NOT NULL,
    enable_ksm boolean DEFAULT true NOT NULL
);


ALTER TABLE public.vds_groups OWNER TO engine;

--
-- Name: vm_static; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_static (
    vm_guid uuid NOT NULL,
    vm_name character varying(255) NOT NULL,
    mem_size_mb integer NOT NULL,
    vmt_guid uuid NOT NULL,
    os integer DEFAULT 0 NOT NULL,
    description character varying(4000),
    vds_group_id uuid NOT NULL,
    creation_date timestamp with time zone,
    num_of_monitors integer NOT NULL,
    is_initialized boolean,
    is_auto_suspend boolean DEFAULT false,
    num_of_sockets integer DEFAULT 1 NOT NULL,
    cpu_per_socket integer DEFAULT 1 NOT NULL,
    usb_policy integer,
    time_zone character varying(40),
    is_stateless boolean,
    fail_back boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    dedicated_vm_for_vds uuid,
    auto_startup boolean,
    vm_type integer DEFAULT 0 NOT NULL,
    nice_level integer DEFAULT 0 NOT NULL,
    default_boot_sequence integer DEFAULT 0 NOT NULL,
    default_display_type integer DEFAULT 0 NOT NULL,
    priority integer DEFAULT 0 NOT NULL,
    iso_path character varying(4000) DEFAULT ''::character varying,
    origin integer DEFAULT 0,
    initrd_url character varying(4000),
    kernel_url character varying(4000),
    kernel_params character varying(4000),
    migration_support integer DEFAULT 0 NOT NULL,
    userdefined_properties character varying(4000),
    predefined_properties character varying(4000),
    min_allocated_mem integer DEFAULT 0 NOT NULL,
    entity_type character varying(32) NOT NULL,
    child_count integer DEFAULT 0,
    template_status integer,
    quota_id uuid,
    allow_console_reconnect boolean DEFAULT false NOT NULL,
    cpu_pinning character varying(4000) DEFAULT NULL::character varying,
    is_smartcard_enabled boolean DEFAULT false,
    host_cpu_flags boolean DEFAULT false,
    db_generation bigint DEFAULT 1,
    is_delete_protected boolean DEFAULT false,
    is_disabled boolean DEFAULT false,
    is_run_and_pause boolean DEFAULT false NOT NULL,
    created_by_user_id uuid,
    tunnel_migration boolean,
    free_text_comment text,
    single_qxl_pci boolean DEFAULT false NOT NULL,
    cpu_shares integer DEFAULT 0 NOT NULL,
    vnc_keyboard_layout character varying(16) DEFAULT NULL::character varying,
    instance_type_id uuid,
    image_type_id uuid,
    sso_method character varying(32) DEFAULT 'guest_agent'::character varying NOT NULL,
    original_template_id uuid,
    original_template_name character varying(255) DEFAULT NULL::character varying,
    migration_downtime integer,
    template_version_number integer,
    template_version_name character varying(40) DEFAULT NULL::character varying
);


ALTER TABLE public.vm_static OWNER TO engine;

--
-- Name: vm_templates_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_templates_view AS
    SELECT vm_templates.vm_guid AS vmt_guid, vm_templates.vm_name AS name, vm_templates.mem_size_mb, vm_templates.os, vm_templates.creation_date, vm_templates.child_count, vm_templates.num_of_sockets, vm_templates.cpu_per_socket, (vm_templates.num_of_sockets * vm_templates.cpu_per_socket) AS num_of_cpus, vm_templates.description, vm_templates.free_text_comment, vm_templates.vds_group_id, vm_templates.num_of_monitors, vm_templates.single_qxl_pci, vm_templates.allow_console_reconnect, vm_templates.template_status AS status, vm_templates.usb_policy, vm_templates.time_zone, vm_templates.fail_back, vds_groups.name AS vds_group_name, vds_groups.trusted_service, vm_templates.vm_type, vm_templates.nice_level, vm_templates.cpu_shares, storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, storage_pool.quota_enforcement_type, vm_templates.default_boot_sequence, vm_templates.default_display_type, vm_templates.priority, vm_templates.auto_startup, vm_templates.is_stateless, vm_templates.is_smartcard_enabled, vm_templates.is_delete_protected, vm_templates.sso_method, vm_templates.iso_path, vm_templates.origin, vm_templates.initrd_url, vm_templates.kernel_url, vm_templates.kernel_params, vm_templates.quota_id, quota.quota_name, vm_templates.db_generation, vm_templates.migration_support, vm_templates.dedicated_vm_for_vds, vm_templates.is_disabled, vm_templates.tunnel_migration, vm_templates.vnc_keyboard_layout, vm_templates.min_allocated_mem, vm_templates.is_run_and_pause, vm_templates.created_by_user_id, vm_templates.entity_type, vm_templates.migration_downtime, vds_groups.architecture, vm_templates.template_version_number, vm_templates.vmt_guid AS base_template_id, vm_templates.template_version_name FROM (((vm_static vm_templates JOIN vds_groups ON ((vm_templates.vds_group_id = vds_groups.vds_group_id))) LEFT JOIN storage_pool ON ((storage_pool.id = vds_groups.storage_pool_id))) LEFT JOIN quota ON ((vm_templates.quota_id = quota.id))) WHERE ((((vm_templates.entity_type)::text = 'TEMPLATE'::text) OR ((vm_templates.entity_type)::text = 'INSTANCE_TYPE'::text)) OR ((vm_templates.entity_type)::text = 'IMAGE_TYPE'::text));


ALTER TABLE public.vm_templates_view OWNER TO engine;

--
-- Name: fn_perms_get_templates_with_permitted_action(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_perms_get_templates_with_permitted_action(v_user_id uuid, v_action_group_id integer) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_templates_view.*
      FROM vm_templates_view, user_vm_template_permissions_view
      WHERE vm_templates_view.vmt_guid = user_vm_template_permissions_view.entity_id AND
            user_vm_template_permissions_view.user_id = v_user_id AND
            (SELECT get_entity_permissions(v_user_id, v_action_group_id, vm_templates_view.vmt_guid, 4) IS NOT NULL);
END; ';


ALTER FUNCTION public.fn_perms_get_templates_with_permitted_action(v_user_id uuid, v_action_group_id integer) OWNER TO engine;

--
-- Name: cluster_policies; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE cluster_policies (
    id uuid NOT NULL,
    name character varying(128) NOT NULL,
    description character varying(4000),
    is_locked boolean NOT NULL,
    is_default boolean NOT NULL,
    custom_properties text
);


ALTER TABLE public.cluster_policies OWNER TO engine;

--
-- Name: vds_groups_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vds_groups_view AS
    SELECT vds_groups.vds_group_id, vds_groups.name, vds_groups.description, vds_groups.cpu_name, vds_groups._create_date, vds_groups._update_date, vds_groups.storage_pool_id, vds_groups.max_vds_memory_over_commit, vds_groups.compatibility_version, vds_groups.transparent_hugepages, vds_groups.migrate_on_error, vds_groups.virt_service, vds_groups.gluster_service, vds_groups.count_threads_as_cores, vds_groups.emulated_machine, vds_groups.trusted_service, vds_groups.tunnel_migration, vds_groups.cluster_policy_id, vds_groups.cluster_policy_custom_properties, vds_groups.enable_balloon, vds_groups.free_text_comment, vds_groups.detect_emulated_machine, vds_groups.architecture, vds_groups.optimization_type, vds_groups.spice_proxy, vds_groups.ha_reservation, vds_groups.enable_ksm, storage_pool.name AS storage_pool_name, cluster_policies.name AS cluster_policy_name FROM ((vds_groups LEFT JOIN storage_pool ON ((vds_groups.storage_pool_id = storage_pool.id))) LEFT JOIN cluster_policies ON ((vds_groups.cluster_policy_id = cluster_policies.id)));


ALTER TABLE public.vds_groups_view OWNER TO engine;

--
-- Name: fn_perms_get_vds_groups_with_permitted_action(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_perms_get_vds_groups_with_permitted_action(v_user_id uuid, v_action_group_id integer) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE (SELECT 1 from get_entity_permissions(v_user_id, v_action_group_id, vds_groups_view.vds_group_id, 9)) IS NOT NULL;
END; ';


ALTER FUNCTION public.fn_perms_get_vds_groups_with_permitted_action(v_user_id uuid, v_action_group_id integer) OWNER TO engine;

--
-- Name: fn_user_permissions(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fn_user_permissions(v_userid uuid) RETURNS SETOF user_permissions
    LANGUAGE plpgsql STABLE
    AS '
DECLARE

BEGIN
	RETURN QUERY
	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    permissions.ad_element_id AS user_id
	    FROM permissions
		INNER JOIN users ON permissions.ad_element_id = users.user_id
	    WHERE users.user_id = v_userId

	    UNION

	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    temp.user_id AS user_id
	    FROM permissions INNER JOIN
	    (
		    -- get all groups of admin users
		    SELECT ad_groups.id group_id, users.user_id
		    FROM ad_groups, users
		    WHERE ad_groups.id IN
		    (SELECT * FROM fnsplitteruuid(users.group_ids))
			AND users.user_id = v_userId ) temp
		ON permissions.ad_element_id = temp.group_id;

END; ';


ALTER FUNCTION public.fn_user_permissions(v_userid uuid) OWNER TO engine;

--
-- Name: fnsplitter(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fnsplitter(ids text) RETURNS SETOF idtexttype
    LANGUAGE plpgsql IMMUTABLE
    AS '
BEGIN
	RETURN QUERY
		SELECT regexp_split_to_table(ids, '','') AS id;
END; ';


ALTER FUNCTION public.fnsplitter(ids text) OWNER TO engine;

--
-- Name: fnsplitteruuid(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION fnsplitteruuid(ids text) RETURNS SETOF uuid
    LANGUAGE plpgsql IMMUTABLE
    AS '
BEGIN
 IF ids != '''' THEN
	RETURN QUERY
		SELECT CAST(regexp_split_to_table(ids, '','') AS UUID);
 END IF;
END; ';


ALTER FUNCTION public.fnsplitteruuid(ids text) OWNER TO engine;

--
-- Name: force_delete_storage_domain(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION force_delete_storage_domain(v_storage_domain_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
      -- Creating a temporary table which will give all the images and the disks which resids on only the specified storage domain. (copied template disks on multiple storage domains will not be part of this table)
      CREATE GLOBAL TEMPORARY TABLE STORAGE_DOMAIN_MAP_TABLE AS select image_guid as image_id,disk_id
         from images_storage_domain_view where storage_id = v_storage_domain_id
         except select image_guid as image_id, disk_id from images_storage_domain_view where storage_id != v_storage_domain_id;
      exception when others then
         truncate table STORAGE_DOMAIN_MAP_TABLE;
         insert into STORAGE_DOMAIN_MAP_TABLE select image_guid as image_id,disk_id
         from images_storage_domain_view where storage_id = v_storage_domain_id
         except select image_guid as image_id, disk_id from images_storage_domain_view where storage_id != v_storage_domain_id;
   END;

   BEGIN
      -- Templates with any images residing on only the specified storage domain
      CREATE GLOBAL TEMPORARY TABLE TEMPLATES_IDS_TEMPORARY_TABLE AS select vm_device.vm_id as vm_guid
         from images_storage_domain_view
         JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
         JOIN STORAGE_DOMAIN_MAP_TABLE ON STORAGE_DOMAIN_MAP_TABLE.image_id = images_storage_domain_view.image_guid
         where entity_type = ''TEMPLATE'' and storage_id = v_storage_domain_id;
      exception when others then
         truncate table TEMPLATES_IDS_TEMPORARY_TABLE;
         insert into TEMPLATES_IDS_TEMPORARY_TABLE select vm_device.vm_id as vm_guid
         from images_storage_domain_view
         JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
         JOIN STORAGE_DOMAIN_MAP_TABLE ON STORAGE_DOMAIN_MAP_TABLE.image_id = images_storage_domain_view.image_guid
         where entity_type = ''TEMPLATE'' and storage_id = v_storage_domain_id;
   END;

   -- Add also Template Versions based on the selected templates
   insert into TEMPLATES_IDS_TEMPORARY_TABLE
     select vm_guid from vm_static
     where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE)
     and entity_type = ''TEMPLATE'';

   BEGIN
     -- Vms which resides on the storage domain
     CREATE GLOBAL TEMPORARY TABLE VM_IDS_TEMPORARY_TABLE AS select vm_id,vm_images_view.entity_type as entity_type from vm_images_view
            JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
            WHERE v_storage_domain_id in (SELECT * FROM fnsplitteruuid(storage_id));
     exception when others then
     truncate table VM_IDS_TEMPORARY_TABLE;
     insert into VM_IDS_TEMPORARY_TABLE select vm_id,vm_images_view.entity_type as entity_type from vm_images_view
            JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
            WHERE v_storage_domain_id in (SELECT * FROM fnsplitteruuid(storage_id));
   END;

   delete FROM permissions where object_id in (select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE where entity_type <> ''TEMPLATE'');
   delete FROM snapshots WHERE vm_id in (select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE);

   delete FROM image_storage_domain_map where storage_domain_id = v_storage_domain_id;
   delete FROM images where image_guid in (select image_id from STORAGE_DOMAIN_MAP_TABLE);
   delete FROM vm_interface where vmt_guid in(select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM permissions where object_id in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM permissions where object_id = v_storage_domain_id;
   delete FROM vm_static where vm_guid in(select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE where entity_type <> ''TEMPLATE'');

   -- Delete pools and snapshots of pools based on templates from the storage domain to be removed
   delete FROM snapshots where vm_id in (select vm_guid FROM vm_static where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE));
   delete FROM vm_static where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);

   delete FROM vm_static where vm_guid in(select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM storage_domain_dynamic where id  = v_storage_domain_id;
   delete FROM storage_domain_static where id  = v_storage_domain_id;

   -- Deletes the disks which the only storage domain they are reside on, is the storage domain.
   DELETE FROM base_disks WHERE  disk_id IN (SELECT disk_id FROM STORAGE_DOMAIN_MAP_TABLE);

   -- Deletes the disks''s permissions which the only storage domain they are reside on, is the storage domain.
   DELETE FROM permissions WHERE object_id IN (SELECT disk_id FROM STORAGE_DOMAIN_MAP_TABLE);

END; ';


ALTER FUNCTION public.force_delete_storage_domain(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: generate_drop_all_functions_syntax(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select ''drop function if exists '' || ns.nspname || ''.'' || proname || ''('' || oidvectortypes(proargtypes) || '') cascade;'' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = ''public'' order by proname;
END; ';


ALTER FUNCTION public.generate_drop_all_functions_syntax() OWNER TO engine;

--
-- Name: generate_drop_all_seq_syntax(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select ''DROP SEQUENCE if exists '' || sequence_name || '' CASCADE;'' from information_schema.sequences  where sequence_schema = ''public'' order by sequence_name;
END; ';


ALTER FUNCTION public.generate_drop_all_seq_syntax() OWNER TO engine;

--
-- Name: generate_drop_all_tables_syntax(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select ''DROP TABLE if exists '' || table_name || '' CASCADE;'' from information_schema.tables where table_schema = ''public'' and table_type = ''BASE TABLE'' order by table_name;
END; ';


ALTER FUNCTION public.generate_drop_all_tables_syntax() OWNER TO engine;

--
-- Name: generate_drop_all_user_types_syntax(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT ''DROP TYPE if exists '' || c.relname::information_schema.sql_identifier || '' CASCADE;''
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = ''c''::"char" and
   n.nspname = ''public''
   ORDER BY  c.relname::information_schema.sql_identifier;
END; ';


ALTER FUNCTION public.generate_drop_all_user_types_syntax() OWNER TO engine;

--
-- Name: generate_drop_all_views_syntax(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select ''DROP VIEW if exists '' || table_name || '' CASCADE;'' from information_schema.views where table_schema = ''public'' order by table_name;
END; ';


ALTER FUNCTION public.generate_drop_all_views_syntax() OWNER TO engine;

--
-- Name: get_all_commands(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_all_commands() RETURNS SETOF get_all_commands_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT distinct business_entity_snapshot.command_id, business_entity_snapshot.command_type
      FROM business_entity_snapshot;

END; ';


ALTER FUNCTION public.get_all_commands() OWNER TO engine;

--
-- Name: get_entity_permissions(uuid, integer, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_entity_permissions(v_user_id uuid, v_action_group_id integer, v_object_id uuid, v_object_type_id integer) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_everyone_object_id  UUID;
BEGIN
   v_everyone_object_id := getGlobalIds(''everyone''); -- hardcoded also in MLA Handler
   RETURN QUERY
   select   id from permissions where
		-- get all roles of action
   role_id in(select role_id from roles_groups where action_group_id = v_action_group_id)
		-- get allparents of object
   and (object_id in(select id from  fn_get_entity_parents(v_object_id,v_object_type_id)))
		-- get user and his groups
   and (ad_element_id = v_everyone_object_id or
   ad_element_id = v_user_id or ad_element_id in(select * from getUserAndGroupsById(v_user_id)))   LIMIT 1;
END; ';


ALTER FUNCTION public.get_entity_permissions(v_user_id uuid, v_action_group_id integer, v_object_id uuid, v_object_type_id integer) OWNER TO engine;

--
-- Name: get_entity_permissions_for_user_and_groups(uuid, text, integer, uuid, integer, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_entity_permissions_for_user_and_groups(v_user_id uuid, v_group_ids text, v_action_group_id integer, v_object_id uuid, v_object_type_id integer, v_ignore_everyone boolean) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_everyone_object_id  UUID;
BEGIN
   v_everyone_object_id := getGlobalIds(''everyone''); -- hardcoded also in MLA Handler
   RETURN QUERY
   select   id from permissions where
		-- get all roles of action
   role_id in(select role_id from roles_groups where action_group_id = v_action_group_id)
		-- get allparents of object
   and (object_id in(select id from  fn_get_entity_parents(v_object_id,v_object_type_id)))
		-- get user and his groups
   and ((NOT v_ignore_everyone and ad_element_id = v_everyone_object_id) or
   ad_element_id = v_user_id or ad_element_id in(select * from fnsplitteruuid(v_group_ids)))   LIMIT 1;
END; ';


ALTER FUNCTION public.get_entity_permissions_for_user_and_groups(v_user_id uuid, v_group_ids text, v_action_group_id integer, v_object_id uuid, v_object_type_id integer, v_ignore_everyone boolean) OWNER TO engine;

--
-- Name: business_entity_snapshot; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE business_entity_snapshot (
    id uuid NOT NULL,
    command_id uuid NOT NULL,
    command_type character varying(256) NOT NULL,
    entity_id character varying(128),
    entity_type character varying(128),
    entity_snapshot text,
    snapshot_class character varying(128),
    snapshot_type integer,
    insertion_order integer,
    started_at timestamp with time zone DEFAULT now()
);


ALTER TABLE public.business_entity_snapshot OWNER TO engine;

--
-- Name: get_entity_snapshot_by_command_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_entity_snapshot_by_command_id(v_command_id uuid) RETURNS SETOF business_entity_snapshot
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT business_entity_snapshot.*
      FROM business_entity_snapshot
      WHERE command_id = v_command_id order by insertion_order desc;
END; ';


ALTER FUNCTION public.get_entity_snapshot_by_command_id(v_command_id uuid) OWNER TO engine;

--
-- Name: get_entity_snapshot_by_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_entity_snapshot_by_id(v_id uuid) RETURNS SETOF business_entity_snapshot
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT business_entity_snapshot.*
      FROM business_entity_snapshot
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.get_entity_snapshot_by_id(v_id uuid) OWNER TO engine;

--
-- Name: roles_groups; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE roles_groups (
    role_id uuid NOT NULL,
    action_group_id integer NOT NULL
);


ALTER TABLE public.roles_groups OWNER TO engine;

--
-- Name: get_role_groups_by_role_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_role_groups_by_role_id(v_role_id uuid) RETURNS SETOF roles_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   where
   role_id = v_role_id;

END; ';


ALTER FUNCTION public.get_role_groups_by_role_id(v_role_id uuid) OWNER TO engine;

--
-- Name: get_roles_groups_by_action_group_id_and_by_role_id(integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_roles_groups_by_action_group_id_and_by_role_id(v_action_group_id integer, v_role_id uuid) RETURNS SETOF roles_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   where
   action_group_id = v_action_group_id AND
   role_id = v_role_id;

END; ';


ALTER FUNCTION public.get_roles_groups_by_action_group_id_and_by_role_id(v_action_group_id integer, v_role_id uuid) OWNER TO engine;

--
-- Name: get_seconds_to_wait_before_pm_operation(character varying, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_seconds_to_wait_before_pm_operation(v_vds_name character varying, v_event character varying, v_wait_for_sec integer) RETURNS integer
    LANGUAGE plpgsql STABLE
    AS '
declare v_last_event_dt timestamp with time zone;
declare v_now_dt timestamp with time zone;
BEGIN
      if exists(select 1 from audit_log where vds_name = v_vds_name and log_type_name = v_event) then
       begin
          v_last_event_dt := log_time
          from audit_log
          where vds_name = v_vds_name and log_type_name = v_event
          order by audit_log_id desc limit 1;
          v_now_dt :=  CURRENT_TIMESTAMP;
          RETURN cast((extract(epoch from v_last_event_dt) + v_wait_for_sec) - extract(epoch from v_now_dt) as int);
       end;
     else
          RETURN 0;
     end if;
END; ';


ALTER FUNCTION public.get_seconds_to_wait_before_pm_operation(v_vds_name character varying, v_event character varying, v_wait_for_sec integer) OWNER TO engine;

--
-- Name: permissions; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE permissions (
    id uuid NOT NULL,
    role_id uuid NOT NULL,
    ad_element_id uuid NOT NULL,
    object_id uuid NOT NULL,
    object_type_id integer NOT NULL
);


ALTER TABLE public.permissions OWNER TO engine;

--
-- Name: roles; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE roles (
    id uuid NOT NULL,
    name character varying(126) NOT NULL,
    description character varying(4000),
    is_readonly boolean NOT NULL,
    role_type integer NOT NULL,
    allows_viewing_children boolean DEFAULT false NOT NULL,
    app_mode integer NOT NULL
);


ALTER TABLE public.roles OWNER TO engine;

--
-- Name: permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW permissions_view AS
    SELECT permissions.id, permissions.role_id, permissions.ad_element_id, permissions.object_id, permissions.object_type_id, roles.name AS role_name, roles.role_type, roles.allows_viewing_children, roles.app_mode, fn_get_entity_name(permissions.object_id, permissions.object_type_id) AS object_name, fn_get_ad_element_name(permissions.ad_element_id) AS owner_name FROM (permissions JOIN roles ON ((permissions.role_id = roles.id)));


ALTER TABLE public.permissions_view OWNER TO engine;

--
-- Name: get_user_permissions_for_domain(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION get_user_permissions_for_domain(v_name character varying, v_domain character varying) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_user_name VARCHAR(255);
   v_index  INTEGER;
BEGIN
-- find if name already includes domain (@)
   v_index := POSITION(''@'' IN v_name);

   if (v_index > 0) then
      v_user_name := substr(v_name, 0, v_index);
   else
      v_user_name := v_name;
   end if;
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE permissions_view.ad_element_id in (
                SELECT users.user_id
                FROM users
                WHERE users.domain = v_domain
                AND (users.name = v_user_name OR
                     users.name = v_user_name || ''@'' || upper(v_domain)
                    ));

END; ';


ALTER FUNCTION public.get_user_permissions_for_domain(v_name character varying, v_domain character varying) OWNER TO engine;

--
-- Name: gluster_volume_access_protocols; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_volume_access_protocols (
    volume_id uuid NOT NULL,
    access_protocol character varying(32) NOT NULL
);


ALTER TABLE public.gluster_volume_access_protocols OWNER TO engine;

--
-- Name: getaccessprotocolsbyglustervolumeguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getaccessprotocolsbyglustervolumeguid(v_volume_id uuid) RETURNS SETOF gluster_volume_access_protocols
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
       RETURN QUERY SELECT *
       FROM  gluster_volume_access_protocols
       WHERE volume_id = v_volume_id;
END; ';


ALTER FUNCTION public.getaccessprotocolsbyglustervolumeguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: action_version_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE action_version_map (
    action_type integer NOT NULL,
    cluster_minimal_version character varying(40) NOT NULL,
    storage_pool_minimal_version character varying(40) NOT NULL
);


ALTER TABLE public.action_version_map OWNER TO engine;

--
-- Name: getaction_version_mapbyaction_type(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getaction_version_mapbyaction_type(v_action_type integer) RETURNS SETOF action_version_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM action_version_map
   WHERE action_type = v_action_type;

END; ';


ALTER FUNCTION public.getaction_version_mapbyaction_type(v_action_type integer) OWNER TO engine;

--
-- Name: vds_static; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_static (
    vds_id uuid NOT NULL,
    vds_name character varying(255) NOT NULL,
    ip character varying(255),
    vds_unique_id character varying(128),
    host_name character varying(255) NOT NULL,
    port integer NOT NULL,
    vds_group_id uuid NOT NULL,
    server_ssl_enabled boolean,
    vds_type integer DEFAULT 0 NOT NULL,
    vds_strength integer DEFAULT 100 NOT NULL,
    pm_type character varying(20),
    pm_user character varying(50),
    pm_password text,
    pm_port integer,
    pm_options character varying(4000) DEFAULT ''::character varying NOT NULL,
    pm_enabled boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    otp_validity bigint,
    vds_spm_priority smallint DEFAULT 5,
    recoverable boolean DEFAULT true NOT NULL,
    sshkeyfingerprint character varying(128),
    pm_proxy_preferences character varying(255) DEFAULT ''::character varying,
    pm_secondary_ip character varying(255),
    pm_secondary_type character varying(20),
    pm_secondary_user character varying(50),
    pm_secondary_password text,
    pm_secondary_port integer,
    pm_secondary_options character varying(4000),
    pm_secondary_concurrent boolean DEFAULT false,
    console_address character varying(255) DEFAULT NULL::character varying,
    ssh_username character varying(255),
    ssh_port integer,
    free_text_comment text,
    disable_auto_pm boolean DEFAULT false,
    CONSTRAINT vds_static_vds_spm_priority_check CHECK (((vds_spm_priority >= (-1)) AND (vds_spm_priority <= 10)))
);


ALTER TABLE public.vds_static OWNER TO engine;

--
-- Name: vm_dynamic; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_dynamic (
    vm_guid uuid NOT NULL,
    status integer NOT NULL,
    vm_ip text,
    vm_host character varying(255),
    vm_pid integer,
    last_start_time timestamp with time zone,
    guest_cur_user_name character varying(255),
    guest_last_login_time timestamp with time zone,
    guest_last_logout_time timestamp with time zone,
    guest_os character varying(255),
    run_on_vds uuid,
    migrating_to_vds uuid,
    app_list text,
    display integer,
    acpi_enable boolean,
    session integer,
    display_ip character varying(255),
    display_type integer,
    kvm_enable boolean,
    display_secure_port integer,
    utc_diff integer,
    last_vds_run_on uuid,
    client_ip character varying(255),
    guest_requested_memory integer,
    hibernation_vol_handle character varying(255),
    boot_sequence integer,
    exit_status integer DEFAULT 0 NOT NULL,
    pause_status integer DEFAULT 0 NOT NULL,
    exit_message character varying(4000),
    hash character varying(30),
    console_user_id uuid,
    guest_agent_nics_hash integer,
    console_cur_user_name character varying(255),
    last_watchdog_event bigint,
    last_watchdog_action character varying(8),
    is_run_once boolean DEFAULT false NOT NULL,
    vm_fqdn text DEFAULT ''::text,
    cpu_name character varying(255),
    last_stop_time timestamp with time zone,
    current_cd character varying(4000) DEFAULT NULL::character varying
);


ALTER TABLE public.vm_dynamic OWNER TO engine;

--
-- Name: vm_pool_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_pool_map (
    vm_pool_id uuid,
    vm_guid uuid NOT NULL
);


ALTER TABLE public.vm_pool_map OWNER TO engine;

--
-- Name: vm_pools; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_pools (
    vm_pool_id uuid NOT NULL,
    vm_pool_name character varying(255) NOT NULL,
    vm_pool_description character varying(4000) NOT NULL,
    vm_pool_type integer,
    parameters character varying(200),
    vds_group_id uuid,
    prestarted_vms smallint DEFAULT 0,
    max_assigned_vms_per_user smallint DEFAULT 1,
    vm_pool_comment text,
    spice_proxy character varying(255)
);


ALTER TABLE public.vm_pools OWNER TO engine;

--
-- Name: vm_pool_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_pool_map_view AS
    SELECT vm_pool_map.vm_guid, vm_pool_map.vm_pool_id, vm_pools.vm_pool_name, vm_pools.spice_proxy AS vm_pool_spice_proxy FROM (vm_pool_map JOIN vm_pools ON ((vm_pool_map.vm_pool_id = vm_pools.vm_pool_id)));


ALTER TABLE public.vm_pool_map_view OWNER TO engine;

--
-- Name: vm_statistics; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_statistics (
    vm_guid uuid NOT NULL,
    cpu_user numeric(18,0) DEFAULT 0,
    cpu_sys numeric(18,0) DEFAULT 0,
    elapsed_time numeric(18,0) DEFAULT 0,
    usage_network_percent integer DEFAULT 0,
    usage_mem_percent integer DEFAULT 0,
    usage_cpu_percent integer DEFAULT 0,
    disks_usage text,
    _update_date timestamp with time zone
);


ALTER TABLE public.vm_statistics OWNER TO engine;

--
-- Name: vms; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vms AS
    SELECT vm_static.vm_name, vm_static.mem_size_mb AS vm_mem_size_mb, vm_static.nice_level, vm_static.cpu_shares, vm_static.vmt_guid, vm_static.os AS vm_os, vm_static.description AS vm_description, vm_static.free_text_comment AS vm_comment, vm_static.vds_group_id, vm_static.creation_date AS vm_creation_date, vm_static.auto_startup, vm_static.is_stateless, vm_static.is_smartcard_enabled, vm_static.is_delete_protected, vm_static.sso_method, vm_static.dedicated_vm_for_vds, vm_static.fail_back, vm_static.default_boot_sequence, vm_static.vm_type, vm_pool_map_view.vm_pool_spice_proxy, vds_groups.name AS vds_group_name, vds_groups.transparent_hugepages, vds_groups.trusted_service, storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, vds_groups.description AS vds_group_description, vds_groups.spice_proxy AS vds_group_spice_proxy, vm_templates.vm_name AS vmt_name, vm_templates.mem_size_mb AS vmt_mem_size_mb, vm_templates.os AS vmt_os, vm_templates.creation_date AS vmt_creation_date, vm_templates.child_count AS vmt_child_count, vm_templates.num_of_sockets AS vmt_num_of_sockets, vm_templates.cpu_per_socket AS vmt_cpu_per_socket, (vm_templates.num_of_sockets * vm_templates.cpu_per_socket) AS vmt_num_of_cpus, vm_templates.description AS vmt_description, vm_dynamic.status, vm_dynamic.vm_ip, vm_dynamic.vm_host, vm_dynamic.vm_pid, vm_dynamic.last_start_time, vm_dynamic.guest_cur_user_name, vm_dynamic.console_cur_user_name, vm_dynamic.guest_last_login_time, vm_dynamic.guest_last_logout_time, vm_dynamic.guest_os, vm_dynamic.console_user_id, vm_dynamic.guest_agent_nics_hash, vm_dynamic.run_on_vds, vm_dynamic.migrating_to_vds, vm_dynamic.app_list, vm_dynamic.display, vm_dynamic.hibernation_vol_handle, vm_pool_map_view.vm_pool_name, vm_pool_map_view.vm_pool_id, vm_static.vm_guid, vm_static.num_of_monitors, vm_static.single_qxl_pci, vm_static.allow_console_reconnect, vm_static.is_initialized, vm_static.num_of_sockets, vm_static.cpu_per_socket, vm_static.usb_policy, vm_dynamic.acpi_enable, vm_dynamic.session, (vm_static.num_of_sockets * vm_static.cpu_per_socket) AS num_of_cpus, vm_static.quota_id, quota.quota_name, storage_pool.quota_enforcement_type, vm_dynamic.display_ip, vm_dynamic.display_type, vm_dynamic.kvm_enable, vm_dynamic.boot_sequence, vm_dynamic.display_secure_port, vm_dynamic.utc_diff, vm_dynamic.last_vds_run_on, vm_dynamic.client_ip, vm_dynamic.guest_requested_memory, vm_static.time_zone, vm_statistics.cpu_user, vm_statistics.cpu_sys, vm_statistics.elapsed_time, vm_statistics.usage_network_percent, vm_statistics.usage_mem_percent, vm_statistics.usage_cpu_percent, vds_static.vds_name AS run_on_vds_name, vds_groups.cpu_name AS vds_group_cpu_name, vm_static.default_display_type, vm_static.priority, vm_static.iso_path, vm_static.origin, vds_groups.compatibility_version AS vds_group_compatibility_version, vm_static.initrd_url, vm_static.kernel_url, vm_static.kernel_params, vm_dynamic.pause_status, vm_dynamic.exit_message, vm_dynamic.exit_status, vm_static.migration_support, vm_static.predefined_properties, vm_static.userdefined_properties, vm_static.min_allocated_mem, vm_dynamic.hash, vm_static.cpu_pinning, vm_static.db_generation, vm_static.host_cpu_flags, vm_static.tunnel_migration, vm_static.vnc_keyboard_layout, vm_static.is_run_and_pause, vm_static.created_by_user_id, vm_dynamic.last_watchdog_event, vm_dynamic.last_watchdog_action, vm_dynamic.is_run_once, vm_dynamic.vm_fqdn, vm_dynamic.cpu_name, vm_dynamic.current_cd, vm_static.instance_type_id, vm_static.image_type_id, vds_groups.architecture, vm_static.original_template_id, vm_static.original_template_name, vm_dynamic.last_stop_time, vm_static.migration_downtime, vm_static.template_version_number FROM ((((((((vm_static JOIN vm_dynamic ON ((vm_static.vm_guid = vm_dynamic.vm_guid))) JOIN vm_static vm_templates ON ((vm_static.vmt_guid = vm_templates.vm_guid))) JOIN vm_statistics ON ((vm_static.vm_guid = vm_statistics.vm_guid))) JOIN vds_groups ON ((vm_static.vds_group_id = vds_groups.vds_group_id))) LEFT JOIN storage_pool ON (((vm_static.vds_group_id = vds_groups.vds_group_id) AND (vds_groups.storage_pool_id = storage_pool.id)))) LEFT JOIN quota ON ((vm_static.quota_id = quota.id))) LEFT JOIN vds_static ON ((vm_dynamic.run_on_vds = vds_static.vds_id))) LEFT JOIN vm_pool_map_view ON ((vm_static.vm_guid = vm_pool_map_view.vm_guid))) WHERE ((vm_static.entity_type)::text = 'VM'::text);


ALTER TABLE public.vms OWNER TO engine;

--
-- Name: getactivevmsbystoragedomainid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getactivevmsbystoragedomainid(v_storage_domain_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id AND i.active = TRUE
      inner join image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
      WHERE status <> 0 and image_storage_domain_map.storage_domain_id = v_storage_domain_id;
END; ';


ALTER FUNCTION public.getactivevmsbystoragedomainid(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: affinity_group_members; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE affinity_group_members (
    affinity_group_id uuid NOT NULL,
    vm_id uuid NOT NULL
);


ALTER TABLE public.affinity_group_members OWNER TO engine;

SET default_with_oids = true;

--
-- Name: affinity_groups; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE affinity_groups (
    id uuid NOT NULL,
    name character varying(128) NOT NULL,
    description character varying(4000),
    cluster_id uuid NOT NULL,
    positive boolean DEFAULT true NOT NULL,
    enforcing boolean DEFAULT true NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone
);


ALTER TABLE public.affinity_groups OWNER TO engine;

--
-- Name: affinity_groups_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW affinity_groups_view AS
    SELECT affinity_groups.id, affinity_groups.name, affinity_groups.description, affinity_groups.cluster_id, affinity_groups.positive, affinity_groups.enforcing, affinity_groups._create_date, affinity_groups._update_date, array_to_string(array_agg(affinity_group_members.vm_id), ','::text) AS vm_ids, array_to_string(array_agg(vm_static.vm_name), ','::text) AS vm_names FROM ((affinity_groups LEFT JOIN affinity_group_members ON ((affinity_group_members.affinity_group_id = affinity_groups.id))) LEFT JOIN vm_static ON ((vm_static.vm_guid = affinity_group_members.vm_id))) GROUP BY affinity_groups.id, affinity_groups.name, affinity_groups.description, affinity_groups.cluster_id, affinity_groups.positive, affinity_groups.enforcing, affinity_groups._create_date, affinity_groups._update_date;


ALTER TABLE public.affinity_groups_view OWNER TO engine;

--
-- Name: getaffinitygroupbyaffinitygroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getaffinitygroupbyaffinitygroupid(v_id uuid) RETURNS SETOF affinity_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getaffinitygroupbyaffinitygroupid(v_id uuid) OWNER TO engine;

--
-- Name: getaffinitygroupbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getaffinitygroupbyname(v_name character varying) RETURNS SETOF affinity_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE name = v_name;
END; ';


ALTER FUNCTION public.getaffinitygroupbyname(v_name character varying) OWNER TO engine;

--
-- Name: getallaffinitygroupsbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallaffinitygroupsbyclusterid(v_cluster_id uuid) RETURNS SETOF affinity_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE cluster_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getallaffinitygroupsbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getallaffinitygroupsbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallaffinitygroupsbyvmid(v_vm_id uuid) RETURNS SETOF affinity_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
    SELECT affinity_groups_view.*
    FROM affinity_groups_view
    JOIN affinity_group_members ON v_vm_id = affinity_group_members.vm_id
    AND affinity_group_members.affinity_group_id = affinity_groups_view.id;
END; ';


ALTER FUNCTION public.getallaffinitygroupsbyvmid(v_vm_id uuid) OWNER TO engine;

SET default_with_oids = false;

--
-- Name: base_disks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE base_disks (
    disk_id uuid NOT NULL,
    disk_interface character varying(32) NOT NULL,
    wipe_after_delete boolean DEFAULT false NOT NULL,
    propagate_errors character varying(32) DEFAULT 'Off'::character varying NOT NULL,
    disk_alias character varying(255),
    disk_description character varying(500),
    shareable boolean DEFAULT false,
    boot boolean DEFAULT false NOT NULL,
    sgio smallint,
    alignment smallint DEFAULT 0 NOT NULL,
    last_alignment_scan timestamp with time zone
);


ALTER TABLE public.base_disks OWNER TO engine;

--
-- Name: disk_image_dynamic; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE disk_image_dynamic (
    image_id uuid NOT NULL,
    read_rate integer,
    write_rate integer,
    actual_size bigint NOT NULL,
    read_latency_seconds numeric(18,9),
    write_latency_seconds numeric(18,9),
    flush_latency_seconds numeric(18,9),
    _update_date timestamp with time zone
);


ALTER TABLE public.disk_image_dynamic OWNER TO engine;

--
-- Name: disk_lun_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE disk_lun_map (
    disk_id uuid NOT NULL,
    lun_id character varying NOT NULL
);


ALTER TABLE public.disk_lun_map OWNER TO engine;

--
-- Name: image_storage_domain_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE image_storage_domain_map (
    image_id uuid NOT NULL,
    storage_domain_id uuid NOT NULL,
    quota_id uuid
);


ALTER TABLE public.image_storage_domain_map OWNER TO engine;

--
-- Name: images; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE images (
    image_guid uuid NOT NULL,
    creation_date timestamp with time zone NOT NULL,
    size bigint NOT NULL,
    it_guid uuid NOT NULL,
    parentid uuid,
    imagestatus integer DEFAULT 0,
    lastmodified timestamp with time zone,
    vm_snapshot_id uuid,
    volume_type integer DEFAULT 2 NOT NULL,
    volume_format integer DEFAULT 4 NOT NULL,
    image_group_id uuid,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    active boolean DEFAULT false NOT NULL
);


ALTER TABLE public.images OWNER TO engine;

--
-- Name: snapshots; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE snapshots (
    snapshot_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    snapshot_type character varying(32) NOT NULL,
    status character varying(32) NOT NULL,
    description character varying(4000),
    creation_date timestamp with time zone NOT NULL,
    app_list text,
    vm_configuration text,
    _create_date timestamp with time zone DEFAULT now(),
    _update_date timestamp with time zone,
    memory_volume character varying(255)
);


ALTER TABLE public.snapshots OWNER TO engine;

--
-- Name: storage_domain_static; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE storage_domain_static (
    id uuid NOT NULL,
    storage character varying(250) NOT NULL,
    storage_name character varying(250) NOT NULL,
    storage_domain_type integer NOT NULL,
    storage_type integer NOT NULL,
    storage_domain_format_type character varying(50) DEFAULT '0'::character varying NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    recoverable boolean DEFAULT true NOT NULL,
    last_time_used_as_master bigint,
    storage_description character varying(4000),
    storage_comment text
);


ALTER TABLE public.storage_domain_static OWNER TO engine;

--
-- Name: storage_pool_iso_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE storage_pool_iso_map (
    storage_id uuid NOT NULL,
    storage_pool_id uuid NOT NULL,
    status integer
);


ALTER TABLE public.storage_pool_iso_map OWNER TO engine;

--
-- Name: storage_domain_static_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domain_static_view AS
    SELECT storage_domain_static.id, storage_domain_static.storage, storage_domain_static.storage_name, storage_domain_static.storage_description, storage_domain_static.storage_comment, storage_pool_iso_map.storage_pool_id, storage_pool_iso_map.status, storage_domain_static.storage_domain_type, storage_domain_static.storage_type, storage_domain_static.storage_domain_format_type, storage_domain_static.last_time_used_as_master, storage_pool.name AS storage_pool_name FROM ((storage_domain_static LEFT JOIN storage_pool_iso_map ON ((storage_pool_iso_map.storage_id = storage_domain_static.id))) LEFT JOIN storage_pool ON ((storage_pool.id = storage_pool_iso_map.storage_pool_id)));


ALTER TABLE public.storage_domain_static_view OWNER TO engine;

--
-- Name: vm_device; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_device (
    device_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    type character varying(30) NOT NULL,
    device character varying(30) NOT NULL,
    address character varying(255) NOT NULL,
    boot_order integer DEFAULT 0,
    spec_params text,
    is_managed boolean DEFAULT false NOT NULL,
    is_plugged boolean,
    is_readonly boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT now(),
    _update_date timestamp with time zone,
    alias character varying(255) DEFAULT ''::character varying,
    custom_properties text,
    snapshot_id uuid
);


ALTER TABLE public.vm_device OWNER TO engine;

--
-- Name: vms_for_disk_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vms_for_disk_view AS
    SELECT array_agg(vm_static.vm_name) AS array_vm_names, vm_device.device_id, vm_static.entity_type FROM (vm_static JOIN vm_device ON ((vm_static.vm_guid = vm_device.vm_id))) WHERE ((vm_device.device)::text = 'disk'::text) GROUP BY vm_device.device_id, vm_static.entity_type;


ALTER TABLE public.vms_for_disk_view OWNER TO engine;

--
-- Name: images_storage_domain_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW images_storage_domain_view AS
    SELECT images.image_guid, storage_domain_static_view.storage_name, storage_domain_static_view.storage AS storage_path, storage_domain_static_view.storage_pool_id, storage_domain_static_view.storage_type, images.creation_date, images.size, images.it_guid, snapshots.description, images.parentid, images.lastmodified, snapshots.app_list, image_storage_domain_map.storage_domain_id AS storage_id, images.vm_snapshot_id, images.volume_type, images.volume_format, images.imagestatus, images.image_group_id, images.active, vms_for_disk_view.entity_type, array_to_string(vms_for_disk_view.array_vm_names, ','::text) AS vm_names, COALESCE(array_upper(vms_for_disk_view.array_vm_names, 1), 0) AS number_of_vms, base_disks.disk_id, base_disks.disk_alias, base_disks.disk_description, base_disks.shareable, base_disks.disk_interface, base_disks.wipe_after_delete, base_disks.propagate_errors, base_disks.boot, base_disks.sgio, image_storage_domain_map.quota_id, quota.quota_name, storage_pool.quota_enforcement_type, disk_image_dynamic.actual_size, disk_image_dynamic.read_rate, disk_image_dynamic.write_rate, disk_image_dynamic.read_latency_seconds, disk_image_dynamic.write_latency_seconds, disk_image_dynamic.flush_latency_seconds, base_disks.alignment, base_disks.last_alignment_scan FROM ((((((((images LEFT JOIN disk_image_dynamic ON ((images.image_guid = disk_image_dynamic.image_id))) LEFT JOIN base_disks ON ((images.image_group_id = base_disks.disk_id))) LEFT JOIN vms_for_disk_view ON ((vms_for_disk_view.device_id = images.image_group_id))) LEFT JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = images.image_guid))) LEFT JOIN storage_domain_static_view ON ((image_storage_domain_map.storage_domain_id = storage_domain_static_view.id))) LEFT JOIN snapshots ON ((images.vm_snapshot_id = snapshots.snapshot_id))) LEFT JOIN quota ON ((image_storage_domain_map.quota_id = quota.id))) LEFT JOIN storage_pool ON ((storage_pool.id = storage_domain_static_view.storage_pool_id))) WHERE (images.image_guid <> '00000000-0000-0000-0000-000000000000'::uuid);


ALTER TABLE public.images_storage_domain_view OWNER TO engine;

--
-- Name: luns; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE luns (
    physical_volume_id character varying(50),
    lun_id character varying(255) NOT NULL,
    volume_group_id character varying(50) NOT NULL,
    serial character varying(4000),
    lun_mapping integer,
    vendor_id character varying(50),
    product_id character varying(50),
    device_size integer DEFAULT 0
);


ALTER TABLE public.luns OWNER TO engine;

--
-- Name: storage_for_image_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_for_image_view AS
    SELECT images.image_guid AS image_id, array_to_string(array_agg(storage_domain_static.storage), ','::text) AS storage_path, array_to_string(array_agg(storage_domain_static.id), ','::text) AS storage_id, array_to_string(array_agg(storage_domain_static.storage_type), ','::text) AS storage_type, array_to_string(array_agg(storage_domain_static.storage_name), ','::text) AS storage_name, array_to_string(array_agg(COALESCE((quota.id)::character varying, ''::character varying)), ','::text) AS quota_id, array_to_string(array_agg(COALESCE(quota.quota_name, ''::character varying)), ','::text) AS quota_name FROM (((images LEFT JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = images.image_guid))) LEFT JOIN storage_domain_static ON ((image_storage_domain_map.storage_domain_id = storage_domain_static.id))) LEFT JOIN quota ON ((image_storage_domain_map.quota_id = quota.id))) GROUP BY images.image_guid;


ALTER TABLE public.storage_for_image_view OWNER TO engine;

--
-- Name: all_disks_including_snapshots; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW all_disks_including_snapshots AS
    SELECT storage_impl.disk_storage_type, storage_impl.storage_id, storage_impl.storage_path, storage_impl.storage_name, storage_impl.storage_type, storage_impl.storage_pool_id, storage_impl.image_guid, storage_impl.creation_date, storage_impl.actual_size, storage_impl.read_rate, storage_impl.write_rate, storage_impl.read_latency_seconds, storage_impl.write_latency_seconds, storage_impl.flush_latency_seconds, storage_impl.size, storage_impl.it_guid, storage_impl.imagestatus, storage_impl.lastmodified, storage_impl.volume_type, storage_impl.volume_format, storage_impl.image_group_id, storage_impl.description, storage_impl.parentid, storage_impl.app_list, storage_impl.vm_snapshot_id, storage_impl.active, storage_impl.entity_type, storage_impl.number_of_vms, storage_impl.vm_names, storage_impl.quota_id, storage_impl.quota_name, storage_impl.quota_enforcement_type, storage_impl.lun_id, storage_impl.physical_volume_id, storage_impl.volume_group_id, storage_impl.serial, storage_impl.lun_mapping, storage_impl.vendor_id, storage_impl.product_id, storage_impl.device_size, bd.disk_id, bd.disk_interface, bd.wipe_after_delete, bd.propagate_errors, bd.disk_alias, bd.disk_description, bd.shareable, bd.boot, bd.sgio, bd.alignment, bd.last_alignment_scan FROM ((SELECT 0 AS disk_storage_type, storage_for_image_view.storage_id, storage_for_image_view.storage_path, storage_for_image_view.storage_name, storage_for_image_view.storage_type, images_storage_domain_view.storage_pool_id, images_storage_domain_view.image_guid, images_storage_domain_view.creation_date, images_storage_domain_view.actual_size, images_storage_domain_view.read_rate, images_storage_domain_view.write_rate, images_storage_domain_view.read_latency_seconds, images_storage_domain_view.write_latency_seconds, images_storage_domain_view.flush_latency_seconds, images_storage_domain_view.size, images_storage_domain_view.it_guid, images_storage_domain_view.imagestatus, images_storage_domain_view.lastmodified, images_storage_domain_view.volume_type, images_storage_domain_view.volume_format, images_storage_domain_view.image_group_id, images_storage_domain_view.description, images_storage_domain_view.parentid, images_storage_domain_view.app_list, images_storage_domain_view.vm_snapshot_id, images_storage_domain_view.active, images_storage_domain_view.entity_type, images_storage_domain_view.number_of_vms, images_storage_domain_view.vm_names, storage_for_image_view.quota_id, storage_for_image_view.quota_name, images_storage_domain_view.quota_enforcement_type, NULL::unknown AS lun_id, NULL::unknown AS physical_volume_id, NULL::unknown AS volume_group_id, NULL::unknown AS serial, NULL::unknown AS lun_mapping, NULL::unknown AS vendor_id, NULL::unknown AS product_id, NULL::unknown AS device_size FROM (images_storage_domain_view JOIN storage_for_image_view ON ((images_storage_domain_view.image_guid = storage_for_image_view.image_id))) UNION SELECT 1 AS disk_storage_type, NULL::unknown AS storage_id, NULL::unknown AS storage_path, NULL::unknown AS storage_name, NULL::unknown AS storage_type, NULL::unknown AS storage_pool_id, NULL::unknown AS image_guid, NULL::unknown AS creation_date, NULL::unknown AS actual_size, NULL::unknown AS read_rate, NULL::unknown AS write_rate, NULL::unknown AS read_latency_seconds, NULL::unknown AS write_latency_seconds, NULL::unknown AS flush_latency_seconds, NULL::unknown AS size, NULL::unknown AS it_guid, NULL::unknown AS imagestatus, NULL::unknown AS lastmodified, NULL::unknown AS volume_type, NULL::unknown AS volume_format, dlm.disk_id AS image_group_id, NULL::unknown AS description, NULL::unknown AS parentid, NULL::unknown AS app_list, NULL::unknown AS vm_snapshot_id, NULL::unknown AS active, vms_for_disk_view.entity_type, COALESCE(array_upper(vms_for_disk_view.array_vm_names, 1), 0) AS number_of_vms, array_to_string(vms_for_disk_view.array_vm_names, ','::text) AS vm_names, NULL::unknown AS quota_id, NULL::unknown AS quota_name, NULL::unknown AS quota_enforcement_type, l.lun_id, l.physical_volume_id, l.volume_group_id, l.serial, l.lun_mapping, l.vendor_id, l.product_id, l.device_size FROM ((disk_lun_map dlm JOIN luns l ON (((l.lun_id)::text = (dlm.lun_id)::text))) LEFT JOIN vms_for_disk_view ON ((vms_for_disk_view.device_id = dlm.disk_id)))) storage_impl JOIN base_disks bd ON ((bd.disk_id = storage_impl.image_group_id)));


ALTER TABLE public.all_disks_including_snapshots OWNER TO engine;

--
-- Name: all_disks; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW all_disks AS
    SELECT all_disks_including_snapshots.disk_storage_type, all_disks_including_snapshots.storage_id, all_disks_including_snapshots.storage_path, all_disks_including_snapshots.storage_name, all_disks_including_snapshots.storage_type, all_disks_including_snapshots.storage_pool_id, all_disks_including_snapshots.image_guid, all_disks_including_snapshots.creation_date, all_disks_including_snapshots.actual_size, all_disks_including_snapshots.read_rate, all_disks_including_snapshots.write_rate, all_disks_including_snapshots.read_latency_seconds, all_disks_including_snapshots.write_latency_seconds, all_disks_including_snapshots.flush_latency_seconds, all_disks_including_snapshots.size, all_disks_including_snapshots.it_guid, all_disks_including_snapshots.imagestatus, all_disks_including_snapshots.lastmodified, all_disks_including_snapshots.volume_type, all_disks_including_snapshots.volume_format, all_disks_including_snapshots.image_group_id, all_disks_including_snapshots.description, all_disks_including_snapshots.parentid, all_disks_including_snapshots.app_list, all_disks_including_snapshots.vm_snapshot_id, all_disks_including_snapshots.active, all_disks_including_snapshots.entity_type, all_disks_including_snapshots.number_of_vms, all_disks_including_snapshots.vm_names, all_disks_including_snapshots.quota_id, all_disks_including_snapshots.quota_name, all_disks_including_snapshots.quota_enforcement_type, all_disks_including_snapshots.lun_id, all_disks_including_snapshots.physical_volume_id, all_disks_including_snapshots.volume_group_id, all_disks_including_snapshots.serial, all_disks_including_snapshots.lun_mapping, all_disks_including_snapshots.vendor_id, all_disks_including_snapshots.product_id, all_disks_including_snapshots.device_size, all_disks_including_snapshots.disk_id, all_disks_including_snapshots.disk_interface, all_disks_including_snapshots.wipe_after_delete, all_disks_including_snapshots.propagate_errors, all_disks_including_snapshots.disk_alias, all_disks_including_snapshots.disk_description, all_disks_including_snapshots.shareable, all_disks_including_snapshots.boot, all_disks_including_snapshots.sgio, all_disks_including_snapshots.alignment, all_disks_including_snapshots.last_alignment_scan FROM all_disks_including_snapshots WHERE ((all_disks_including_snapshots.active IS NULL) OR (all_disks_including_snapshots.active = true));


ALTER TABLE public.all_disks OWNER TO engine;

--
-- Name: getallattachabledisksbypoolid(uuid, uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallattachabledisksbypoolid(v_storage_pool_id uuid, v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF all_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT distinct all_disks.*
    FROM all_disks
    WHERE (v_storage_pool_id IS NULL OR all_disks.storage_pool_id = v_storage_pool_id)
    AND (all_disks.number_of_vms = 0 OR all_disks.shareable)
        -- ImageStatus.ILLEGAL=4 / imagestatus IS NULL -> LunDiski / ImageStatus.Locked=2
        AND (all_disks.imagestatus IS NULL OR (all_disks.imagestatus != 4 AND all_disks.imagestatus != 2))
        AND (v_vm_id IS NULL OR v_vm_id NOT IN (SELECT vm_id FROM vm_device WHERE vm_device.device_id = all_disks.image_group_id))
    AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = disk_id));
END; ';


ALTER FUNCTION public.getallattachabledisksbypoolid(v_storage_pool_id uuid, v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallbystatus(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallbystatus(v_status integer) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE status = v_status;
END; ';


ALTER FUNCTION public.getallbystatus(v_status integer) OWNER TO engine;

--
-- Name: storage_server_connections; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE storage_server_connections (
    id character varying(50) NOT NULL,
    connection character varying(250) NOT NULL,
    user_name character varying(50),
    password character varying(50),
    iqn character varying(128),
    port character varying(50),
    portal character varying(50),
    storage_type integer NOT NULL,
    mount_options character varying(500),
    vfs_type character varying(128),
    nfs_version character varying(4),
    nfs_timeo smallint,
    nfs_retrans smallint
);


ALTER TABLE public.storage_server_connections OWNER TO engine;

--
-- Name: getallconnectablestorageseverconnection(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallconnectablestorageseverconnection(v_storage_pool_id uuid) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT distinct storage_server_connections.*
   FROM
   LUN_storage_server_connection_map LUN_storage_server_connection_map
   INNER JOIN  LUNs ON LUN_storage_server_connection_map.LUN_id = LUNs.LUN_id
   INNER JOIN  storage_domains ON LUNs.volume_group_id = storage_domains.storage
   INNER JOIN  storage_server_connections ON LUN_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (storage_domains.storage_pool_id = v_storage_pool_id  and storage_domains.status in(0,3,4))
   UNION
   SELECT distinct storage_server_connections.*
   FROM         storage_server_connections
   INNER JOIN  storage_domains ON storage_server_connections.id = storage_domains.storage
   WHERE     (storage_domains.storage_pool_id = v_storage_pool_id and storage_domains.status in(0,3,4));
END; ';


ALTER FUNCTION public.getallconnectablestorageseverconnection(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getallfromaction_version_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromaction_version_map() RETURNS SETOF action_version_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM action_version_map;

END; ';


ALTER FUNCTION public.getallfromaction_version_map() OWNER TO engine;

--
-- Name: async_tasks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE async_tasks (
    task_id uuid NOT NULL,
    action_type integer NOT NULL,
    status integer NOT NULL,
    result integer NOT NULL,
    action_parameters text,
    action_params_class character varying(256),
    step_id uuid,
    command_id uuid NOT NULL,
    started_at timestamp with time zone,
    storage_pool_id uuid,
    task_type integer DEFAULT 0 NOT NULL,
    task_parameters text,
    task_params_class character varying(256),
    vdsm_task_id uuid,
    root_command_id uuid
);


ALTER TABLE public.async_tasks OWNER TO engine;

--
-- Name: getallfromasync_tasks(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromasync_tasks() RETURNS SETOF async_tasks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks;

END; ';


ALTER FUNCTION public.getallfromasync_tasks() OWNER TO engine;

--
-- Name: audit_log_seq; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE audit_log_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.audit_log_seq OWNER TO engine;

--
-- Name: audit_log_seq; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('audit_log_seq', 1315, true);


--
-- Name: audit_log; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE audit_log (
    audit_log_id bigint DEFAULT nextval('audit_log_seq'::regclass) NOT NULL,
    user_id uuid,
    user_name character varying(255),
    vm_id uuid,
    vm_name character varying(255),
    vm_template_id uuid,
    vm_template_name character varying(40),
    vds_id uuid,
    vds_name character varying(255),
    log_time timestamp with time zone NOT NULL,
    log_type_name character varying(100) DEFAULT ''::character varying,
    log_type integer NOT NULL,
    severity integer NOT NULL,
    message text NOT NULL,
    processed boolean DEFAULT false NOT NULL,
    storage_pool_id uuid,
    storage_pool_name character varying(40),
    storage_domain_id uuid,
    storage_domain_name character varying(250),
    vds_group_id uuid,
    vds_group_name character varying(255),
    correlation_id character varying(50),
    job_id uuid,
    quota_id uuid,
    quota_name character varying(60),
    gluster_volume_id uuid,
    gluster_volume_name character varying(1000),
    origin character varying(255) DEFAULT 'oVirt'::character varying,
    custom_event_id integer DEFAULT (-1),
    event_flood_in_sec integer DEFAULT 30,
    custom_data text DEFAULT ''::text,
    deleted boolean DEFAULT false,
    call_stack text DEFAULT ''::text
);


ALTER TABLE public.audit_log OWNER TO engine;

--
-- Name: getallfromauditlog(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromauditlog(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log a
      WHERE NOT deleted AND
     (NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   user_vm_permissions_view pv, user_object_permissions_view dpv
                                   WHERE  pv.user_id = v_user_id AND pv.entity_id = a.vm_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vm_template_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vm_template_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vds_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vds_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_storage_pool_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.storage_pool_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_storage_domain_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.storage_domain_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vds_groups_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vds_group_id AND pv.entity_id = dpv.entity_id)
     );
END; ';


ALTER FUNCTION public.getallfromauditlog(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfrombasedisks(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfrombasedisks() RETURNS SETOF base_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   base_disks;
END; ';


ALTER FUNCTION public.getallfrombasedisks() OWNER TO engine;

--
-- Name: bookmarks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE bookmarks (
    bookmark_id uuid NOT NULL,
    bookmark_name character varying(40),
    bookmark_value character varying(300) NOT NULL
);


ALTER TABLE public.bookmarks OWNER TO engine;

--
-- Name: getallfrombookmarks(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfrombookmarks() RETURNS SETOF bookmarks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks;
END; ';


ALTER FUNCTION public.getallfrombookmarks() OWNER TO engine;

--
-- Name: getallfromclusterpolicys(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromclusterpolicys() RETURNS SETOF cluster_policies
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policies;
END; ';


ALTER FUNCTION public.getallfromclusterpolicys() OWNER TO engine;

--
-- Name: cluster_policy_units; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE cluster_policy_units (
    cluster_policy_id uuid,
    policy_unit_id uuid,
    filter_sequence integer DEFAULT 0,
    factor integer DEFAULT 1
);


ALTER TABLE public.cluster_policy_units OWNER TO engine;

--
-- Name: getallfromclusterpolicyunits(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromclusterpolicyunits() RETURNS SETOF cluster_policy_units
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policy_units;
END; ';


ALTER FUNCTION public.getallfromclusterpolicyunits() OWNER TO engine;

--
-- Name: custom_actions_seq; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE custom_actions_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.custom_actions_seq OWNER TO engine;

--
-- Name: custom_actions_seq; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('custom_actions_seq', 1, false);


--
-- Name: custom_actions; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE custom_actions (
    action_id integer DEFAULT nextval('custom_actions_seq'::regclass) NOT NULL,
    action_name character varying(50) NOT NULL,
    path character varying(300) NOT NULL,
    tab integer NOT NULL,
    description character varying(4000)
);


ALTER TABLE public.custom_actions OWNER TO engine;

--
-- Name: getallfromcustom_actions(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromcustom_actions() RETURNS SETOF custom_actions
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions;
END; ';


ALTER FUNCTION public.getallfromcustom_actions() OWNER TO engine;

--
-- Name: getallfromdisk_image_dynamic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromdisk_image_dynamic() RETURNS SETOF disk_image_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM disk_image_dynamic;

END; ';


ALTER FUNCTION public.getallfromdisk_image_dynamic() OWNER TO engine;

--
-- Name: getallfromdisklunmaps(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromdisklunmaps() RETURNS SETOF disk_lun_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   disk_lun_map;
END; ';


ALTER FUNCTION public.getallfromdisklunmaps() OWNER TO engine;

--
-- Name: getallfromdisks(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromdisks(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF all_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   all_disks
    WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM user_disk_permissions_view
                                        WHERE user_id = v_user_id AND entity_id = disk_id));
END; ';


ALTER FUNCTION public.getallfromdisks(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: event_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE event_map (
    event_up_name character varying(100) NOT NULL,
    event_down_name character varying(100) NOT NULL
);


ALTER TABLE public.event_map OWNER TO engine;

--
-- Name: event_subscriber; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE event_subscriber (
    subscriber_id uuid NOT NULL,
    event_up_name character varying(100) NOT NULL,
    method_id integer NOT NULL,
    method_address character varying(255),
    tag_name character varying(50) DEFAULT ''::character varying NOT NULL
);


ALTER TABLE public.event_subscriber OWNER TO engine;

--
-- Name: event_audit_log_subscriber_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW event_audit_log_subscriber_view AS
    SELECT 1 AS event_type, event_subscriber_1.subscriber_id, event_subscriber_1.event_up_name, event_subscriber_1.method_id, event_subscriber_1.method_address, event_subscriber_1.tag_name, audit_log_1.audit_log_id, audit_log_1.user_id, audit_log_1.user_name, audit_log_1.vm_id, audit_log_1.vm_name, audit_log_1.vm_template_id, audit_log_1.vm_template_name, audit_log_1.vds_id, audit_log_1.vds_name, audit_log_1.storage_pool_id, audit_log_1.storage_pool_name, audit_log_1.storage_domain_id, audit_log_1.storage_domain_name, audit_log_1.log_time, audit_log_1.severity, audit_log_1.message FROM (audit_log audit_log_1 JOIN event_subscriber event_subscriber_1 ON (((audit_log_1.log_type_name)::text = (event_subscriber_1.event_up_name)::text))) WHERE (audit_log_1.processed = false) UNION SELECT DISTINCT 0 AS event_type, event_subscriber.subscriber_id, audit_log.log_type_name AS event_up_name, event_subscriber.method_id, event_subscriber.method_address, event_subscriber.tag_name, audit_log.audit_log_id, audit_log.user_id, audit_log.user_name, audit_log.vm_id, audit_log.vm_name, audit_log.vm_template_id, audit_log.vm_template_name, audit_log.vds_id, audit_log.vds_name, audit_log.storage_pool_id, audit_log.storage_pool_name, audit_log.storage_domain_id, audit_log.storage_domain_name, audit_log.log_time, audit_log.severity, audit_log.message FROM ((audit_log audit_log JOIN event_map ON (((audit_log.log_type_name)::text = (event_map.event_down_name)::text))) JOIN event_subscriber event_subscriber ON (((event_subscriber.event_up_name)::text = (event_map.event_up_name)::text))) WHERE (audit_log.processed = false);


ALTER TABLE public.event_audit_log_subscriber_view OWNER TO engine;

--
-- Name: getallfromevent_audit_log_subscriber(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromevent_audit_log_subscriber() RETURNS SETOF event_audit_log_subscriber_view
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_last  BIGINT;
BEGIN
      -- begin tran


			-- get last event
			select   audit_log_id INTO v_last from audit_log    order by audit_log_id desc LIMIT 1;
			-- mark processed events
      update audit_log set processed = TRUE where audit_log_id <= v_last;
			-- get from view all events with id <= @last
      RETURN QUERY SELECT *
      from event_audit_log_subscriber_view  event_audit_log_subscriber_view
      where audit_log_id <= v_last;
END; ';


ALTER FUNCTION public.getallfromevent_audit_log_subscriber() OWNER TO engine;

--
-- Name: getallfromevent_audit_log_subscriber_only(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromevent_audit_log_subscriber_only() RETURNS SETOF event_audit_log_subscriber_view
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_last  BIGINT;
BEGIN
        -- get last event
        select   audit_log_id INTO v_last from audit_log order by audit_log_id desc LIMIT 1;
        -- get from view all events with id <= @last
        RETURN QUERY select *
                   from event_audit_log_subscriber_view  where audit_log_id <= v_last;
END; ';


ALTER FUNCTION public.getallfromevent_audit_log_subscriber_only() OWNER TO engine;

--
-- Name: event_notification_hist; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE event_notification_hist (
    subscriber_id uuid NOT NULL,
    event_name character varying(100) NOT NULL,
    audit_log_id bigint NOT NULL,
    method_type character(10) NOT NULL,
    sent_at timestamp with time zone NOT NULL,
    status boolean NOT NULL,
    reason character(255)
);


ALTER TABLE public.event_notification_hist OWNER TO engine;

--
-- Name: getallfromevent_notification_hist(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromevent_notification_hist() RETURNS SETOF event_notification_hist
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM event_notification_hist;

END; ';


ALTER FUNCTION public.getallfromevent_notification_hist() OWNER TO engine;

SET default_with_oids = true;

--
-- Name: gluster_server_services; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_server_services (
    id uuid NOT NULL,
    server_id uuid NOT NULL,
    service_id uuid NOT NULL,
    pid integer,
    status character varying(32) NOT NULL,
    message character varying(1000),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);


ALTER TABLE public.gluster_server_services OWNER TO engine;

--
-- Name: gluster_services; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_services (
    id uuid NOT NULL,
    service_type character varying(100) NOT NULL,
    service_name character varying(100) NOT NULL
);


ALTER TABLE public.gluster_services OWNER TO engine;

--
-- Name: gluster_server_services_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW gluster_server_services_view AS
    SELECT gluster_server_services.id, gluster_server_services.server_id, gluster_server_services.service_id, gluster_server_services.pid, gluster_server_services.status, gluster_server_services.message, gluster_server_services._create_date, gluster_server_services._update_date, gluster_services.service_name, gluster_services.service_type, vds_static.vds_name FROM ((gluster_server_services JOIN gluster_services ON ((gluster_server_services.service_id = gluster_services.id))) JOIN vds_static ON ((gluster_server_services.server_id = vds_static.vds_id)));


ALTER TABLE public.gluster_server_services_view OWNER TO engine;

--
-- Name: getallfromglusterserverservices(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromglusterserverservices() RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view;
END; ';


ALTER FUNCTION public.getallfromglusterserverservices() OWNER TO engine;

--
-- Name: getallfromglusterservices(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromglusterservices() RETURNS SETOF gluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT * FROM gluster_services;
END; ';


ALTER FUNCTION public.getallfromglusterservices() OWNER TO engine;

--
-- Name: getallfromimages(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromimages() RETURNS SETOF images
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   images;
END; ';


ALTER FUNCTION public.getallfromimages() OWNER TO engine;

--
-- Name: iscsi_bonds; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE iscsi_bonds (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    description character varying(4000),
    storage_pool_id uuid NOT NULL
);


ALTER TABLE public.iscsi_bonds OWNER TO engine;

--
-- Name: getallfromiscsibonds(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromiscsibonds() RETURNS SETOF iscsi_bonds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds;
END; ';


ALTER FUNCTION public.getallfromiscsibonds() OWNER TO engine;

SET default_with_oids = false;

--
-- Name: lun_storage_server_connection_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE lun_storage_server_connection_map (
    lun_id character varying(255) NOT NULL,
    storage_server_connection character varying(50) NOT NULL
);


ALTER TABLE public.lun_storage_server_connection_map OWNER TO engine;

--
-- Name: getallfromlun_storage_server_connection_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromlun_storage_server_connection_map() RETURNS SETOF lun_storage_server_connection_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT *
   FROM LUN_storage_server_connection_map lUN_storage_server_connection_map;

END; ';


ALTER FUNCTION public.getallfromlun_storage_server_connection_map() OWNER TO engine;

--
-- Name: luns_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW luns_view AS
    SELECT luns.physical_volume_id, luns.lun_id, luns.volume_group_id, luns.serial, luns.lun_mapping, luns.vendor_id, luns.product_id, luns.device_size, storage_domain_static.id AS storage_id, storage_domain_static.storage_name, disk_lun_map.disk_id, all_disks.disk_alias FROM (((luns LEFT JOIN storage_domain_static ON (((luns.volume_group_id)::text = (storage_domain_static.storage)::text))) LEFT JOIN disk_lun_map ON (((luns.lun_id)::text = (disk_lun_map.lun_id)::text))) LEFT JOIN all_disks ON ((disk_lun_map.disk_id = all_disks.disk_id)));


ALTER TABLE public.luns_view OWNER TO engine;

--
-- Name: getallfromluns(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromluns() RETURNS SETOF luns_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view;

END; ';


ALTER FUNCTION public.getallfromluns() OWNER TO engine;

--
-- Name: network; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE network (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    description character varying(4000),
    type integer,
    addr character varying(50),
    subnet character varying(20),
    gateway character varying(20),
    vlan_id integer,
    stp boolean DEFAULT false NOT NULL,
    storage_pool_id uuid,
    mtu integer,
    vm_network boolean DEFAULT true NOT NULL,
    provider_network_provider_id uuid,
    provider_network_external_id text,
    free_text_comment text,
    label text,
    qos_id uuid
);


ALTER TABLE public.network OWNER TO engine;

--
-- Name: getallfromnetwork(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromnetwork(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network
   WHERE NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_network_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = network.id);

END; ';


ALTER FUNCTION public.getallfromnetwork(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: network_cluster; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE network_cluster (
    network_id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    status integer DEFAULT 0 NOT NULL,
    is_display boolean DEFAULT false NOT NULL,
    required boolean DEFAULT true NOT NULL,
    migration boolean DEFAULT false NOT NULL
);


ALTER TABLE public.network_cluster OWNER TO engine;

--
-- Name: getallfromnetwork_cluster(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromnetwork_cluster() RETURNS SETOF network_cluster
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster;

END; ';


ALTER FUNCTION public.getallfromnetwork_cluster() OWNER TO engine;

--
-- Name: getallfromnetwork_clusterbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromnetwork_clusterbyclusterid(v_cluster_id uuid) RETURNS SETOF network_cluster
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE cluster_id = v_cluster_id;

END; ';


ALTER FUNCTION public.getallfromnetwork_clusterbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getallfromnetwork_clusterbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromnetwork_clusterbynetworkid(v_network_id uuid) RETURNS SETOF network_cluster
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE network_id = v_network_id;

END; ';


ALTER FUNCTION public.getallfromnetwork_clusterbynetworkid(v_network_id uuid) OWNER TO engine;

SET default_with_oids = true;

--
-- Name: network_qos; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE network_qos (
    id uuid NOT NULL,
    name character varying(50),
    storage_pool_id uuid,
    inbound_average integer,
    inbound_peak integer,
    inbound_burst integer,
    outbound_average integer,
    outbound_peak integer,
    outbound_burst integer,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone
);


ALTER TABLE public.network_qos OWNER TO engine;

--
-- Name: getallfromnetworkqoss(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromnetworkqoss() RETURNS SETOF network_qos
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network_qos;
END; ';


ALTER FUNCTION public.getallfromnetworkqoss() OWNER TO engine;

SET default_with_oids = false;

--
-- Name: policy_units; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE policy_units (
    id uuid NOT NULL,
    name character varying(128) NOT NULL,
    is_internal boolean NOT NULL,
    custom_properties_regex text,
    type smallint DEFAULT 0,
    enabled boolean DEFAULT true NOT NULL,
    description text
);


ALTER TABLE public.policy_units OWNER TO engine;

--
-- Name: getallfrompolicyunits(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfrompolicyunits() RETURNS SETOF policy_units
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   policy_units;
END; ';


ALTER FUNCTION public.getallfrompolicyunits() OWNER TO engine;

--
-- Name: providers; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE providers (
    id uuid NOT NULL,
    name character varying(128) NOT NULL,
    description character varying(4000),
    url character varying(512) NOT NULL,
    provider_type character varying(32) NOT NULL,
    auth_required boolean NOT NULL,
    auth_username character varying(64),
    auth_password text,
    _create_date timestamp with time zone DEFAULT now(),
    _update_date timestamp with time zone,
    custom_properties text,
    tenant_name character varying(128),
    plugin_type character varying(64),
    agent_configuration text
);


ALTER TABLE public.providers OWNER TO engine;

--
-- Name: getallfromproviders(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromproviders() RETURNS SETOF providers
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers;
END; ';


ALTER FUNCTION public.getallfromproviders() OWNER TO engine;

--
-- Name: getallfromprovidersbytype(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromprovidersbytype(v_provider_type character varying) RETURNS SETOF providers
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE provider_type = v_provider_type;
END; ';


ALTER FUNCTION public.getallfromprovidersbytype(v_provider_type character varying) OWNER TO engine;

--
-- Name: getallfromrole(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromrole(v_app_mode integer) RETURNS SETOF roles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE (roles.app_mode & v_app_mode) > 0;

END; ';


ALTER FUNCTION public.getallfromrole(v_app_mode integer) OWNER TO engine;

--
-- Name: getallfromsnapshots(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromsnapshots() RETURNS SETOF snapshots
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots;
END; ';


ALTER FUNCTION public.getallfromsnapshots() OWNER TO engine;

--
-- Name: getallfromsnapshotsbyvmid(uuid, uuid, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromsnapshotsbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean, v_fill_configuration boolean) RETURNS SETOF getallfromsnapshotsbyvmid_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT snapshot_id,
           vm_id,
           snapshot_type,
           status,
           description,
           creation_date,
           app_list,
           memory_volume,
           CASE WHEN v_fill_configuration = TRUE THEN vm_configuration ELSE NULL END,
           vm_configuration IS NOT NULL AND LENGTH(vm_configuration) > 0
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = v_vm_id))
    ORDER BY creation_date ASC;
END; ';


ALTER FUNCTION public.getallfromsnapshotsbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean, v_fill_configuration boolean) OWNER TO engine;

--
-- Name: storage_domain_dynamic; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE storage_domain_dynamic (
    id uuid NOT NULL,
    available_disk_size integer,
    used_disk_size integer,
    _update_date timestamp with time zone
);


ALTER TABLE public.storage_domain_dynamic OWNER TO engine;

--
-- Name: getallfromstorage_domain_dynamic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstorage_domain_dynamic() RETURNS SETOF storage_domain_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_dynamic;

END; ';


ALTER FUNCTION public.getallfromstorage_domain_dynamic() OWNER TO engine;

--
-- Name: getallfromstorage_domain_static(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstorage_domain_static() RETURNS SETOF storage_domain_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static;
END; ';


ALTER FUNCTION public.getallfromstorage_domain_static() OWNER TO engine;

--
-- Name: storage_domains; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domains AS
    SELECT storage_domain_static.id, storage_domain_static.storage, storage_domain_static.storage_name, storage_domain_static.storage_description, storage_domain_static.storage_comment, storage_pool_iso_map.storage_pool_id, storage_domain_dynamic.available_disk_size, storage_domain_dynamic.used_disk_size, fn_get_disk_commited_value_by_storage(storage_domain_static.id) AS commited_disk_size, fn_get_actual_images_size_by_storage(storage_domain_static.id) AS actual_images_size, storage_pool_iso_map.status, storage_pool.name AS storage_pool_name, storage_domain_static.storage_type, storage_domain_static.storage_domain_type, storage_domain_static.storage_domain_format_type, storage_domain_static.last_time_used_as_master, fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, storage_pool_iso_map.status, storage_domain_static.storage_domain_type) AS storage_domain_shared_status, storage_domain_static.recoverable FROM (((storage_domain_static JOIN storage_domain_dynamic ON ((storage_domain_static.id = storage_domain_dynamic.id))) LEFT JOIN storage_pool_iso_map ON ((storage_domain_static.id = storage_pool_iso_map.storage_id))) LEFT JOIN storage_pool ON ((storage_pool_iso_map.storage_pool_id = storage_pool.id)));


ALTER TABLE public.storage_domains OWNER TO engine;

--
-- Name: getallfromstorage_domains(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstorage_domains(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM user_storage_domain_permissions_view
                                       WHERE user_id = v_user_id AND entity_id = id));
END; ';


ALTER FUNCTION public.getallfromstorage_domains(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromstorage_pool(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstorage_pool(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_storage_pool_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = id));
END; ';


ALTER FUNCTION public.getallfromstorage_pool(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromstorage_pool_iso_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstorage_pool_iso_map() RETURNS SETOF storage_pool_iso_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map;

END; ';


ALTER FUNCTION public.getallfromstorage_pool_iso_map() OWNER TO engine;

--
-- Name: getallfromstoragedomainsbyconnectionid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromstoragedomainsbyconnectionid(v_connection_id character varying) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage = v_connection_id;
END; ';


ALTER FUNCTION public.getallfromstoragedomainsbyconnectionid(v_connection_id character varying) OWNER TO engine;

--
-- Name: tags; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags (
    tag_id uuid NOT NULL,
    tag_name character varying(50) DEFAULT ''::character varying NOT NULL,
    description character varying(4000),
    parent_id uuid,
    readonly boolean,
    type integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone
);


ALTER TABLE public.tags OWNER TO engine;

--
-- Name: getallfromtags(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags() RETURNS SETOF tags
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags;
END; ';


ALTER FUNCTION public.getallfromtags() OWNER TO engine;

--
-- Name: tags_user_group_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags_user_group_map (
    tag_id uuid NOT NULL,
    group_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);


ALTER TABLE public.tags_user_group_map OWNER TO engine;

--
-- Name: getallfromtags_user_group_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags_user_group_map() RETURNS SETOF tags_user_group_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_user_group_map.*
      FROM tags_user_group_map;
END; ';


ALTER FUNCTION public.getallfromtags_user_group_map() OWNER TO engine;

--
-- Name: tags_user_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags_user_map (
    tag_id uuid NOT NULL,
    user_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);


ALTER TABLE public.tags_user_map OWNER TO engine;

--
-- Name: getallfromtags_user_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags_user_map() RETURNS SETOF tags_user_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_user_map.*
      FROM tags_user_map;
END; ';


ALTER FUNCTION public.getallfromtags_user_map() OWNER TO engine;

--
-- Name: tags_vds_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags_vds_map (
    tag_id uuid NOT NULL,
    vds_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);


ALTER TABLE public.tags_vds_map OWNER TO engine;

--
-- Name: getallfromtags_vds_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags_vds_map() RETURNS SETOF tags_vds_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_vds_map.*
      FROM tags_vds_map;
END; ';


ALTER FUNCTION public.getallfromtags_vds_map() OWNER TO engine;

--
-- Name: tags_vm_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags_vm_map (
    tag_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    defaultdisplaytype integer DEFAULT 0
);


ALTER TABLE public.tags_vm_map OWNER TO engine;

--
-- Name: getallfromtags_vm_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags_vm_map() RETURNS SETOF tags_vm_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_vm_map.*
      FROM tags_vm_map;
END; ';


ALTER FUNCTION public.getallfromtags_vm_map() OWNER TO engine;

--
-- Name: tags_vm_pool_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE tags_vm_pool_map (
    tag_id uuid NOT NULL,
    vm_pool_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);


ALTER TABLE public.tags_vm_pool_map OWNER TO engine;

--
-- Name: getallfromtags_vm_pool_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromtags_vm_pool_map() RETURNS SETOF tags_vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT tags_vm_pool_map.*
   FROM tags_vm_pool_map;

END; ';


ALTER FUNCTION public.getallfromtags_vm_pool_map() OWNER TO engine;

--
-- Name: users; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE users (
    user_id uuid NOT NULL,
    name character varying(255),
    surname character varying(255),
    domain character varying(255) NOT NULL,
    username character varying(255) NOT NULL,
    groups character varying NOT NULL,
    department character varying(255),
    role character varying(255),
    email character varying(255),
    note character varying(255),
    last_admin_check_status boolean DEFAULT false NOT NULL,
    group_ids text,
    external_id bytea DEFAULT ''::bytea NOT NULL,
    active boolean DEFAULT false NOT NULL
);


ALTER TABLE public.users OWNER TO engine;

--
-- Name: getallfromusers(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromusers(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF users
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   users u, user_db_users_permissions_view p
                                   WHERE  u.user_id = v_user_id AND u.user_id = p.ad_element_id));
END; ';


ALTER FUNCTION public.getallfromusers(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: vdc_options_seq; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE vdc_options_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.vdc_options_seq OWNER TO engine;

--
-- Name: vdc_options_seq; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('vdc_options_seq', 452, true);


--
-- Name: vdc_options; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vdc_options (
    option_id integer DEFAULT nextval('vdc_options_seq'::regclass) NOT NULL,
    option_name character varying(100) NOT NULL,
    option_value character varying(4000) NOT NULL,
    version character varying(40) DEFAULT 'general'::character varying NOT NULL
);


ALTER TABLE public.vdc_options OWNER TO engine;

--
-- Name: getallfromvdcoption(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvdcoption() RETURNS SETOF vdc_options
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options;
END; ';


ALTER FUNCTION public.getallfromvdcoption() OWNER TO engine;

--
-- Name: vds_dynamic; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_dynamic (
    vds_id uuid NOT NULL,
    status integer NOT NULL,
    cpu_cores integer,
    cpu_model character varying(255),
    cpu_speed_mh numeric(18,0),
    if_total_speed character varying(40),
    kvm_enabled boolean,
    physical_mem_mb integer,
    mem_commited integer DEFAULT 0,
    vm_active integer DEFAULT 0,
    vm_count integer DEFAULT 0 NOT NULL,
    vm_migrating integer DEFAULT 0,
    reserved_mem integer,
    guest_overhead integer,
    software_version character varying(40),
    version_name character varying(40),
    build_name character varying(40),
    previous_status integer,
    cpu_flags character varying(4000),
    cpu_over_commit_time_stamp timestamp with time zone,
    vms_cores_count integer,
    pending_vcpus_count integer,
    cpu_sockets integer,
    net_config_dirty boolean,
    supported_cluster_levels character varying(40),
    host_os character varying(4000),
    kvm_version character varying(4000),
    spice_version character varying(4000),
    kernel_version character varying(4000),
    iscsi_initiator_name character varying(4000),
    transparent_hugepages_state integer DEFAULT 0 NOT NULL,
    hooks character varying(4000) DEFAULT ''::character varying,
    _update_date timestamp with time zone,
    non_operational_reason integer DEFAULT 0 NOT NULL,
    pending_vmem_size integer DEFAULT 0 NOT NULL,
    rpm_version character varying(256) DEFAULT NULL::character varying,
    supported_engines character varying(40),
    libvirt_version character varying(256) DEFAULT NULL::character varying,
    cpu_threads integer,
    hw_manufacturer character varying(255),
    hw_product_name character varying(255),
    hw_version character varying(255),
    hw_serial_number character varying(255),
    hw_uuid character varying(255),
    hw_family character varying(255),
    hbas text,
    supported_emulated_machines character varying(255),
    gluster_version character varying(4000),
    controlled_by_pm_policy boolean DEFAULT false
);


ALTER TABLE public.vds_dynamic OWNER TO engine;

--
-- Name: vds_spm_id_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_spm_id_map (
    storage_pool_id uuid NOT NULL,
    vds_spm_id integer NOT NULL,
    vds_id uuid NOT NULL
);


ALTER TABLE public.vds_spm_id_map OWNER TO engine;

--
-- Name: vds_statistics; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_statistics (
    vds_id uuid NOT NULL,
    cpu_idle numeric(18,0) DEFAULT 0,
    cpu_load numeric(18,0) DEFAULT 0,
    cpu_sys numeric(18,0) DEFAULT 0,
    cpu_user numeric(18,0) DEFAULT 0,
    usage_mem_percent integer DEFAULT 0,
    usage_cpu_percent integer DEFAULT 0,
    usage_network_percent integer,
    mem_available bigint,
    mem_shared bigint,
    swap_free bigint,
    swap_total bigint,
    ksm_cpu_percent integer DEFAULT 0,
    ksm_pages bigint,
    ksm_state boolean,
    _update_date timestamp with time zone,
    mem_free bigint,
    ha_score integer DEFAULT 0 NOT NULL,
    anonymous_hugepages integer
);


ALTER TABLE public.vds_statistics OWNER TO engine;

--
-- Name: vds; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vds AS
    SELECT vds_groups.vds_group_id, vds_groups.name AS vds_group_name, vds_groups.description AS vds_group_description, vds_groups.architecture, vds_static.vds_id, vds_static.vds_name, vds_static.ip, vds_static.vds_unique_id, vds_static.host_name, vds_static.free_text_comment, vds_static.port, vds_static.vds_strength, vds_static.server_ssl_enabled, vds_static.vds_type, vds_static.pm_type, vds_static.pm_user, vds_static.pm_password, vds_static.pm_port, vds_static.pm_options, vds_static.pm_enabled, vds_static.pm_proxy_preferences, vds_static.pm_secondary_ip, vds_static.pm_secondary_options, vds_static.pm_secondary_port, vds_static.pm_secondary_password, vds_static.pm_secondary_user, vds_static.pm_secondary_type, vds_static.pm_secondary_concurrent, vds_static.vds_spm_priority, vds_dynamic.hooks, vds_dynamic.status, vds_dynamic.cpu_cores, vds_dynamic.cpu_threads, vds_dynamic.cpu_model, vds_dynamic.cpu_speed_mh, vds_dynamic.if_total_speed, vds_dynamic.kvm_enabled, vds_dynamic.physical_mem_mb, vds_dynamic.pending_vcpus_count, vds_dynamic.pending_vmem_size, vds_dynamic.mem_commited, vds_dynamic.vm_active, vds_dynamic.vm_count, vds_dynamic.vm_migrating, vds_dynamic.vms_cores_count, vds_dynamic.cpu_over_commit_time_stamp, vds_groups.max_vds_memory_over_commit, vds_dynamic.net_config_dirty, vds_groups.count_threads_as_cores, storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, vds_dynamic.reserved_mem, vds_dynamic.guest_overhead, vds_dynamic.rpm_version, vds_dynamic.software_version, vds_dynamic.version_name, vds_dynamic.build_name, vds_dynamic.previous_status, vds_statistics.cpu_idle, vds_statistics.cpu_load, vds_statistics.cpu_sys, vds_statistics.cpu_user, vds_statistics.usage_mem_percent, vds_statistics.usage_cpu_percent, vds_statistics.usage_network_percent, vds_statistics.mem_available, vds_statistics.mem_free, vds_statistics.mem_shared, vds_statistics.swap_free, vds_statistics.swap_total, vds_statistics.ksm_cpu_percent, vds_statistics.ksm_pages, vds_statistics.ksm_state, vds_dynamic.cpu_flags, vds_groups.cpu_name AS vds_group_cpu_name, vds_dynamic.cpu_sockets, vds_spm_id_map.vds_spm_id, vds_static.otp_validity, CASE WHEN (storage_pool.spm_vds_id = vds_static.vds_id) THEN CASE WHEN (storage_pool.status = 5) THEN 1 ELSE 2 END ELSE 0 END AS spm_status, vds_dynamic.supported_cluster_levels, vds_dynamic.supported_engines, vds_groups.compatibility_version AS vds_group_compatibility_version, vds_groups.virt_service AS vds_group_virt_service, vds_groups.gluster_service AS vds_group_gluster_service, vds_dynamic.host_os, vds_dynamic.kvm_version, vds_dynamic.libvirt_version, vds_dynamic.spice_version, vds_dynamic.gluster_version, vds_dynamic.kernel_version, vds_dynamic.iscsi_initiator_name, vds_dynamic.transparent_hugepages_state, vds_statistics.anonymous_hugepages, vds_dynamic.non_operational_reason, vds_static.recoverable, vds_static.sshkeyfingerprint, vds_dynamic.hw_manufacturer, vds_dynamic.hw_product_name, vds_dynamic.hw_version, vds_dynamic.hw_serial_number, vds_dynamic.hw_uuid, vds_dynamic.hw_family, vds_static.console_address, vds_dynamic.hbas, vds_dynamic.supported_emulated_machines, vds_static.ssh_port, vds_static.ssh_username, vds_statistics.ha_score, vds_static.disable_auto_pm, vds_dynamic.controlled_by_pm_policy FROM (((((vds_groups JOIN vds_static ON ((vds_groups.vds_group_id = vds_static.vds_group_id))) JOIN vds_dynamic ON ((vds_static.vds_id = vds_dynamic.vds_id))) JOIN vds_statistics ON ((vds_static.vds_id = vds_statistics.vds_id))) LEFT JOIN storage_pool ON ((vds_groups.storage_pool_id = storage_pool.id))) LEFT JOIN vds_spm_id_map ON ((vds_static.vds_id = vds_spm_id_map.vds_id)));


ALTER TABLE public.vds OWNER TO engine;

--
-- Name: getallfromvds(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvds(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM user_vds_permissions_view
                                          WHERE user_id = v_user_id AND entity_id = vds_id));
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getallfromvds(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromvds_spm_id_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvds_spm_id_map() RETURNS SETOF vds_spm_id_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map;

END; ';


ALTER FUNCTION public.getallfromvds_spm_id_map() OWNER TO engine;

--
-- Name: getallfromvdsdynamic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvdsdynamic() RETURNS SETOF vds_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_dynamic.*
      FROM vds_dynamic;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getallfromvdsdynamic() OWNER TO engine;

--
-- Name: getallfromvdsgroups(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvdsgroups(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM   user_vds_groups_permissions_view
                                          WHERE  user_id = v_user_id and entity_id = vds_group_id));

END; ';


ALTER FUNCTION public.getallfromvdsgroups(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromvdsstatic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvdsstatic() RETURNS SETOF vds_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_static.*
   FROM vds_static;

   RETURN;
END; ';


ALTER FUNCTION public.getallfromvdsstatic() OWNER TO engine;

--
-- Name: getallfromvdsstatistics(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvdsstatistics() RETURNS SETOF vds_statistics
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_statistics.*
      FROM vds_statistics;
   END;


   RETURN;
END; ';


ALTER FUNCTION public.getallfromvdsstatistics() OWNER TO engine;

--
-- Name: getallfromvm_pool_map(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvm_pool_map() RETURNS SETOF vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pool_map.*
      FROM vm_pool_map;
END; ';


ALTER FUNCTION public.getallfromvm_pool_map() OWNER TO engine;

--
-- Name: getallfromvm_pools(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvm_pools() RETURNS SETOF getallfromvm_pools_rs
    LANGUAGE plpgsql
    AS '
BEGIN
      -- BEGIN TRAN
BEGIN
         CREATE GLOBAL TEMPORARY TABLE tt_VM_POOL_GROUP
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_GROUP;
      END;
      insert INTO tt_VM_POOL_GROUP(vm_pool_id,
					assigned_vm_count)
      select
      vm_pools_view.vm_pool_id,
			  count(vm_pool_map.vm_pool_id)
      from vm_pools_view
      left join vm_pool_map on vm_pools_view.vm_pool_id = vm_pool_map.vm_pool_id
      group by vm_pools_view.vm_pool_id,vm_pool_map.vm_pool_id;
      BEGIN
         CREATE GLOBAL TEMPORARY TABLE tt_VM_POOL_RUNNING
         (
            vm_pool_id UUID,
            vm_running_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_RUNNING;
      END;
      insert INTO tt_VM_POOL_RUNNING(vm_pool_id,
					vm_running_count)
      select vm_pools_view.vm_pool_id, count(vm_pools_view.vm_pool_id)
      from vm_pools_view
      left join vm_pool_map on vm_pools_view.vm_pool_id = vm_pool_map.vm_pool_id
      left join vm_dynamic on vm_pool_map.vm_guid = vm_dynamic.vm_guid
      where vm_dynamic.status > 0
      group by vm_pools_view.vm_pool_id;
      BEGIN
         CREATE GLOBAL TEMPORARY TABLE tt_VM_POOL_PRERESULT
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER,
            vm_running_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_PRERESULT;
      END;
      insert INTO tt_VM_POOL_PRERESULT(vm_pool_id,
					assigned_vm_count,
					vm_running_count)
      select pg.vm_pool_id, pg.assigned_vm_count, pr.vm_running_count
      from tt_VM_POOL_GROUP pg
      left join tt_VM_POOL_RUNNING pr on pg.vm_pool_id = pr.vm_pool_id;
      update tt_VM_POOL_PRERESULT
      set vm_running_count = 0
      where vm_running_count is NULL;
      BEGIN
         CREATE GLOBAL TEMPORARY TABLE tt_VM_POOL_RESULT
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER,
            vm_running_count INTEGER,
            vm_pool_description VARCHAR(4000),
            vm_pool_comment text,
            vm_pool_name VARCHAR(255),
            vm_pool_type INTEGER,
            parameters VARCHAR(200),
            prestarted_vms INTEGER,
            vds_group_id UUID,
            vds_group_name VARCHAR(40),
            max_assigned_vms_per_user SMALLINT,
            spice_proxy VARCHAR(255)
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_RESULT;
      END;
      insert INTO tt_VM_POOL_RESULT(vm_pool_id,
            assigned_vm_count,
            vm_running_count,
            vm_pool_description,
            vm_pool_comment,
            vm_pool_name,
            vm_pool_type,
            parameters,
            prestarted_vms,
            vds_group_id,
            vds_group_name,
            max_assigned_vms_per_user,
            spice_proxy)
      select ppr.vm_pool_id, ppr.assigned_vm_count, ppr.vm_running_count,
  				 p.vm_pool_description, p.vm_pool_comment, p.vm_pool_name, p.vm_pool_type, p.parameters, p.prestarted_vms,
					 p.vds_group_id, p.vds_group_name, p.max_assigned_vms_per_user, p.spice_proxy
      from tt_VM_POOL_PRERESULT ppr
      inner join vm_pools_view p on ppr.vm_pool_id = p.vm_pool_id;
      RETURN QUERY select *
      from tt_VM_POOL_RESULT;
END; ';


ALTER FUNCTION public.getallfromvm_pools() OWNER TO engine;

--
-- Name: vm_device_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_device_view AS
    SELECT vm_device.device_id, vm_device.vm_id, vm_device.type, vm_device.device, vm_device.address, vm_device.boot_order, vm_device.spec_params, vm_device.is_managed, vm_device.is_plugged, vm_device.is_readonly, vm_device.alias, vm_device.custom_properties, vm_device.snapshot_id FROM vm_device;


ALTER TABLE public.vm_device_view OWNER TO engine;

--
-- Name: getallfromvmdevice(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmdevice() RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view;
END; ';


ALTER FUNCTION public.getallfromvmdevice() OWNER TO engine;

--
-- Name: getallfromvmdynamic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmdynamic() RETURNS SETOF vm_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic;
END; ';


ALTER FUNCTION public.getallfromvmdynamic() OWNER TO engine;

--
-- Name: vm_interface; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_interface (
    id uuid NOT NULL,
    vm_guid uuid,
    vmt_guid uuid,
    mac_addr character varying(20),
    name character varying(50) NOT NULL,
    speed integer,
    type integer DEFAULT 0,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    linked boolean DEFAULT true NOT NULL,
    vnic_profile_id uuid
);


ALTER TABLE public.vm_interface OWNER TO engine;

--
-- Name: getallfromvminterfaces(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvminterfaces() RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface;
END; ';


ALTER FUNCTION public.getallfromvminterfaces() OWNER TO engine;

--
-- Name: vm_interface_statistics; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_interface_statistics (
    id uuid NOT NULL,
    vm_id uuid,
    rx_rate numeric(18,0),
    tx_rate numeric(18,0),
    rx_drop numeric(18,0),
    tx_drop numeric(18,0),
    iface_status integer,
    _update_date timestamp with time zone
);


ALTER TABLE public.vm_interface_statistics OWNER TO engine;

SET default_with_oids = true;

--
-- Name: vnic_profiles; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vnic_profiles (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    network_id uuid NOT NULL,
    port_mirroring boolean NOT NULL,
    custom_properties text,
    description text,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    network_qos_id uuid
);


ALTER TABLE public.vnic_profiles OWNER TO engine;

--
-- Name: vm_interface_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_interface_view AS
    SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, vm_interface_statistics.rx_drop, vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, vm_interface.type, vm_interface.speed, vm_interface.mac_addr, network.name AS network_name, vm_interface.name, vm_interface.vnic_profile_id, vm_static.vm_guid, vm_interface.vmt_guid, vm_static.vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds, vm_device.is_plugged, vm_device.custom_properties, vnic_profiles.port_mirroring, vm_interface.linked, vm_static.vds_group_id, vm_static.entity_type AS vm_entity_type, vnic_profiles.name AS vnic_profile_name FROM ((((vm_interface_statistics JOIN vm_interface ON ((vm_interface_statistics.id = vm_interface.id))) JOIN vm_static ON ((vm_interface.vm_guid = vm_static.vm_guid))) JOIN vm_device ON (((vm_interface.vm_guid = vm_device.vm_id) AND (vm_interface.id = vm_device.device_id)))) LEFT JOIN (vnic_profiles JOIN network ON ((network.id = vnic_profiles.network_id))) ON ((vnic_profiles.id = vm_interface.vnic_profile_id))) UNION SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, vm_interface_statistics.rx_drop, vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, vm_interface.type, vm_interface.speed, vm_interface.mac_addr, network.name AS network_name, vm_interface.name, vm_interface.vnic_profile_id, NULL::uuid AS vm_guid, vm_interface.vmt_guid, vm_templates.vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds, vm_device.is_plugged, vm_device.custom_properties, vnic_profiles.port_mirroring, vm_interface.linked, vm_templates.vds_group_id, vm_templates.entity_type AS vm_entity_type, vnic_profiles.name AS vnic_profile_name FROM ((((vm_interface_statistics RIGHT JOIN vm_interface ON ((vm_interface_statistics.id = vm_interface.id))) JOIN vm_static vm_templates ON ((vm_interface.vmt_guid = vm_templates.vm_guid))) JOIN vm_device ON (((vm_interface.vmt_guid = vm_device.vm_id) AND (vm_interface.id = vm_device.device_id)))) LEFT JOIN (vnic_profiles JOIN network ON ((network.id = vnic_profiles.network_id))) ON ((vnic_profiles.id = vm_interface.vnic_profile_id)));


ALTER TABLE public.vm_interface_view OWNER TO engine;

--
-- Name: getallfromvmnetworkinterfaceviews(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmnetworkinterfaceviews() RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
FROM vm_interface_view;

END; ';


ALTER FUNCTION public.getallfromvmnetworkinterfaceviews() OWNER TO engine;

--
-- Name: getallfromvms(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvms(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM user_vm_permissions_view
                                       WHERE user_id = v_user_id AND entity_id = vm_guid))
   ORDER BY vm_guid;
END; ';


ALTER FUNCTION public.getallfromvms(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromvmstatic(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmstatic() RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getallfromvmstatic() OWNER TO engine;

--
-- Name: getallfromvmstaticbystoragepoolid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmstaticbystoragepoolid(v_sp_id uuid) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static INNER JOIN
        vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid INNER JOIN
        vds_groups ON vm_static.vds_group_id = vds_groups.vds_group_id LEFT OUTER JOIN
        storage_pool ON vm_static.vds_group_id = vds_groups.vds_group_id
        and vds_groups.storage_pool_id = storage_pool.id
   WHERE v_sp_id = storage_pool.id
   AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getallfromvmstaticbystoragepoolid(v_sp_id uuid) OWNER TO engine;

--
-- Name: getallfromvmstatistics(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmstatistics() RETURNS SETOF vm_statistics
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_statistics.*
      FROM vm_statistics;
END; ';


ALTER FUNCTION public.getallfromvmstatistics() OWNER TO engine;

--
-- Name: getallfromvmtemplates(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvmtemplates(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM   user_vm_template_permissions_view
                                          WHERE  user_id = v_user_id AND entity_id = vmt_guid))
      ORDER BY name;
END; ';


ALTER FUNCTION public.getallfromvmtemplates(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallfromvnicprofiles(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvnicprofiles() RETURNS SETOF vnic_profiles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles;

END; ';


ALTER FUNCTION public.getallfromvnicprofiles() OWNER TO engine;

--
-- Name: vnic_profiles_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vnic_profiles_view AS
    SELECT vnic_profiles.id, vnic_profiles.name, vnic_profiles.network_id, vnic_profiles.network_qos_id, vnic_profiles.port_mirroring, vnic_profiles.custom_properties, vnic_profiles.description, network.name AS network_name, network_qos.name AS network_qos_name, storage_pool.name AS data_center_name, storage_pool.compatibility_version, storage_pool.id AS data_center_id FROM (((vnic_profiles JOIN network ON ((vnic_profiles.network_id = network.id))) LEFT JOIN network_qos ON ((vnic_profiles.network_qos_id = network_qos.id))) JOIN storage_pool ON ((network.storage_pool_id = storage_pool.id)));


ALTER TABLE public.vnic_profiles_view OWNER TO engine;

--
-- Name: getallfromvnicprofileviews(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallfromvnicprofileviews(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vnic_profiles_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   user_vnic_profile_permissions_view
                                   WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id);

END; ';


ALTER FUNCTION public.getallfromvnicprofileviews(v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

SET default_with_oids = false;

--
-- Name: ad_groups; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE ad_groups (
    id uuid NOT NULL,
    name character varying(256) NOT NULL,
    domain character varying(100),
    distinguishedname character varying(4000) DEFAULT NULL::character varying,
    active boolean DEFAULT false NOT NULL,
    external_id bytea DEFAULT ''::bytea NOT NULL
);


ALTER TABLE public.ad_groups OWNER TO engine;

--
-- Name: getallgroups(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallgroups() RETURNS SETOF ad_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups;
END; ';


ALTER FUNCTION public.getallgroups() OWNER TO engine;

--
-- Name: getalljobidsbyentityid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getalljobidsbyentityid(v_entity_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT job_subject_entity.job_id
    FROM job_subject_entity
    WHERE entity_id = v_entity_id;
END; ';


ALTER FUNCTION public.getalljobidsbyentityid(v_entity_id uuid) OWNER TO engine;

--
-- Name: job; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE job (
    job_id uuid NOT NULL,
    action_type character varying(50) NOT NULL,
    description text NOT NULL,
    status character varying(32) NOT NULL,
    owner_id uuid,
    visible boolean DEFAULT true NOT NULL,
    start_time timestamp with time zone NOT NULL,
    end_time timestamp with time zone,
    last_update_time timestamp with time zone,
    correlation_id character varying(50) NOT NULL,
    is_external boolean DEFAULT false,
    is_auto_cleared boolean DEFAULT true
);


ALTER TABLE public.job OWNER TO engine;

--
-- Name: getalljobs(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getalljobs() RETURNS SETOF job
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    where status != ''UNKNOWN''
    order by start_time DESC;
END; ';


ALTER FUNCTION public.getalljobs() OWNER TO engine;

--
-- Name: getallnetworkbyclusterid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworkbyclusterid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF networkviewclustertype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT
    DISTINCT
    network.id,
    network.name,
    network.description,
    network.free_text_comment,
    network.type,
    network.addr,
    network.subnet,
    network.gateway,
    network.vlan_id,
    network.stp,
    network.storage_pool_id,
    network.mtu,
    network.vm_network,
    network.label,
    network.provider_network_provider_id,
    network.provider_network_external_id,
    network.qos_id,
    network_cluster.network_id,
    network_cluster.cluster_id,
    network_cluster.status,
    network_cluster.is_display,
    network_cluster.required,
    network_cluster.migration
   FROM network
   INNER JOIN network_cluster
   ON network.id = network_cluster.network_id
   WHERE network_cluster.cluster_id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_network_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = network.id))
   ORDER BY network.name;
END; ';


ALTER FUNCTION public.getallnetworkbyclusterid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallnetworkbystoragepoolid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworkbystoragepoolid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM network
   WHERE storage_pool_id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_network_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = network.id));

END; ';


ALTER FUNCTION public.getallnetworkbystoragepoolid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallnetworklabelsbydatacenterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworklabelsbydatacenterid(v_id uuid) RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT DISTINCT label
    FROM network
    WHERE network.storage_pool_id = v_id
    AND label IS NOT NULL;
END; ';


ALTER FUNCTION public.getallnetworklabelsbydatacenterid(v_id uuid) OWNER TO engine;

--
-- Name: getallnetworkqosforstoragepool(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworkqosforstoragepool(v_storage_pool_id uuid) RETURNS SETOF network_qos
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM network_qos
   WHERE storage_pool_id = v_storage_pool_id;
END; ';


ALTER FUNCTION public.getallnetworkqosforstoragepool(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getallnetworksbynetworkproviderid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworksbynetworkproviderid(v_id uuid) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   network
    WHERE  provider_network_provider_id = v_id;
END; ';


ALTER FUNCTION public.getallnetworksbynetworkproviderid(v_id uuid) OWNER TO engine;

--
-- Name: network_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW network_view AS
    SELECT network.id, network.name, network.description, network.free_text_comment, network.type, network.addr, network.subnet, network.gateway, network.vlan_id, network.stp, network.mtu, network.vm_network, network.storage_pool_id, network.provider_network_provider_id, network.provider_network_external_id, network.qos_id, network.label, storage_pool.name AS storage_pool_name, storage_pool.compatibility_version, providers.name AS provider_name FROM ((network JOIN storage_pool ON ((network.storage_pool_id = storage_pool.id))) LEFT JOIN providers ON ((network.provider_network_provider_id = providers.id)));


ALTER TABLE public.network_view OWNER TO engine;

--
-- Name: getallnetworkviewsbynetworkproviderid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallnetworkviewsbynetworkproviderid(v_id uuid) RETURNS SETOF network_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   network_view
    WHERE  provider_network_provider_id = v_id;
END; ';


ALTER FUNCTION public.getallnetworkviewsbynetworkproviderid(v_id uuid) OWNER TO engine;

--
-- Name: getallrolesbyuseridandgroupids(uuid, text, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallrolesbyuseridandgroupids(v_user_id uuid, v_group_ids text, v_app_mode integer) RETURNS SETOF roles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT roles.*
   FROM roles INNER JOIN
   permissions ON permissions.role_id = roles.id
   WHERE (roles.app_mode & v_app_mode) > 0
   AND (permissions.ad_element_id = v_user_id
   or permissions.ad_element_id in(select id from getElementIdsByIdAndGroups(v_user_id, v_group_ids)));

END; ';


ALTER FUNCTION public.getallrolesbyuseridandgroupids(v_user_id uuid, v_group_ids text, v_app_mode integer) OWNER TO engine;

--
-- Name: step; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE step (
    step_id uuid NOT NULL,
    parent_step_id uuid,
    job_id uuid NOT NULL,
    step_type character varying(32) NOT NULL,
    description text NOT NULL,
    step_number integer NOT NULL,
    status character varying(32) NOT NULL,
    start_time timestamp with time zone NOT NULL,
    end_time timestamp with time zone,
    correlation_id character varying(50) NOT NULL,
    external_id uuid,
    external_system_type character varying(32),
    is_external boolean DEFAULT false
);


ALTER TABLE public.step OWNER TO engine;

--
-- Name: getallsteps(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallsteps() RETURNS SETOF step
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.*
    FROM step;
END; ';


ALTER FUNCTION public.getallsteps() OWNER TO engine;

--
-- Name: getallstorage_server_connections(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallstorage_server_connections() RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections;
END; ';


ALTER FUNCTION public.getallstorage_server_connections() OWNER TO engine;

--
-- Name: quota_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW quota_view AS
    SELECT q.id AS quota_id, q.storage_pool_id, storage_pool.name AS storage_pool_name, q.quota_name, q.description, q.threshold_vds_group_percentage, q.threshold_storage_percentage, q.grace_vds_group_percentage, q.grace_storage_percentage, storage_pool.quota_enforcement_type FROM storage_pool, quota q WHERE (storage_pool.id = q.storage_pool_id);


ALTER TABLE public.quota_view OWNER TO engine;

--
-- Name: getallthinquota(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallthinquota() RETURNS SETOF quota_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM quota_view;
END; ';


ALTER FUNCTION public.getallthinquota() OWNER TO engine;

--
-- Name: getallthinquotasbystorageid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallthinquotasbystorageid(v_storage_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF quota_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT DISTINCT
    quota_id,
    storage_pool_id,
    storage_pool_name,
    quota_name,
    description,
    threshold_vds_group_percentage,
    threshold_storage_percentage,
    grace_vds_group_percentage,
    grace_storage_percentage,
    quota_enforcement_type
   FROM   quota_limitations_view
   WHERE  (storage_id = v_storage_id
   OR     (is_global AND
           NOT is_empty AND
           storage_size_gb IS NOT null AND
           storage_pool_id IN (SELECT storage_pool_id FROM storage_pool_iso_map
               WHERE  storage_id = v_storage_id)))
   AND (NOT v_is_filtered OR
          EXISTS (SELECT 1 FROM permissions p
                  JOIN user_flat_groups u ON
                  u.granted_id = p.ad_element_id WHERE
                  u.user_id = v_user_id AND
                  p.object_type_id = 17 AND -- quota object
                  p.role_id = ''def0000a-0000-0000-0000-def00000000a'' AND -- consume quota
                  quota_id = p.object_id));
END; ';


ALTER FUNCTION public.getallthinquotasbystorageid(v_storage_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getallthinquotasbyvdsgroupid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallthinquotasbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF quota_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT DISTINCT
    quota_id,
    storage_pool_id,
    storage_pool_name,
    quota_name,
    description,
    threshold_vds_group_percentage,
    threshold_storage_percentage,
    grace_vds_group_percentage,
    grace_storage_percentage,
    quota_enforcement_type
   FROM   quota_limitations_view
   WHERE  (vds_group_id = v_vds_group_id
   OR     (is_global AND
           NOT is_empty AND
           virtual_cpu IS NOT null AND
           storage_pool_id IN (SELECT storage_pool_id FROM vds_groups
               WHERE  vds_group_id = v_vds_group_id)))
   AND (NOT v_is_filtered OR
          EXISTS (SELECT 1 FROM permissions p
                  JOIN user_flat_groups u ON
                  u.granted_id = p.ad_element_id WHERE
                  u.user_id = v_user_id AND
                  p.object_type_id = 17 AND -- quota object
                  p.role_id = ''def0000a-0000-0000-0000-def00000000a'' AND -- consume quota
                  quota_id = p.object_id));
END; ';


ALTER FUNCTION public.getallthinquotasbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getalluserswithpermissionsbyentityid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getalluserswithpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view p
   WHERE object_id in (select id from fn_get_entity_parents(v_id,
                                                            (SELECT DISTINCT role_type
                                                               FROM permissions_view p
                                                              WHERE object_id = v_id)))
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_flat_groups u
                                       WHERE  p.ad_element_id = u.granted_id
                                       AND    u.user_id       = v_user_id));
END; ';


ALTER FUNCTION public.getalluserswithpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getalluserswithpermissionsonentitybyentityid(uuid, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getalluserswithpermissionsonentitybyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE (permissions_view.app_mode & v_app_mode) > 0
   AND object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   GetAllUsersWithPermissionsByEntityId(v_id, v_user_id, v_is_filtered)));
END; ';


ALTER FUNCTION public.getalluserswithpermissionsonentitybyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) OWNER TO engine;

--
-- Name: vm_pools_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_pools_view AS
    SELECT vm_pools.vm_pool_id, vm_pools.vm_pool_name, vm_pools.vm_pool_description, vm_pools.vm_pool_comment, vm_pools.vm_pool_type, vm_pools.parameters, vm_pools.prestarted_vms, vm_pools.vds_group_id, vds_groups.name AS vds_group_name, vds_groups.architecture, storage_pool.name AS storage_pool_name, storage_pool.id AS storage_pool_id, vm_pools.max_assigned_vms_per_user, vm_pools.spice_proxy FROM ((vm_pools JOIN vds_groups ON ((vm_pools.vds_group_id = vds_groups.vds_group_id))) LEFT JOIN storage_pool ON ((storage_pool.id = vds_groups.storage_pool_id)));


ALTER TABLE public.vm_pools_view OWNER TO engine;

--
-- Name: getallvm_poolsbyuser_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallvm_poolsbyuser_id(v_user_id uuid) RETURNS SETOF vm_pools_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT  DISTINCT vm_pools_view.*
      FROM         users_and_groups_to_vm_pool_map_view INNER JOIN
      vm_pools_view ON
      users_and_groups_to_vm_pool_map_view.vm_pool_id = vm_pools_view.vm_pool_id
      WHERE     (users_and_groups_to_vm_pool_map_view.user_id = v_user_id);
END; ';


ALTER FUNCTION public.getallvm_poolsbyuser_id(v_user_id uuid) OWNER TO engine;

--
-- Name: getallvm_poolsbyuser_id_with_groups_and_userroles(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallvm_poolsbyuser_id_with_groups_and_userroles(v_user_id uuid) RETURNS SETOF vm_pools_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT pools.*
	FROM vm_pools_view pools
    INNER JOIN user_vm_pool_permissions_view ON user_id = v_user_id AND entity_id = pools.vm_pool_id;
END; ';


ALTER FUNCTION public.getallvm_poolsbyuser_id_with_groups_and_userroles(v_user_id uuid) OWNER TO engine;

--
-- Name: getallvmsrelatedtoquotaid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallvmsrelatedtoquotaid(v_quota_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE quota_id = v_quota_id
      UNION
      SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
      WHERE image_storage_domain_map.quota_id = v_quota_id;
END; ';


ALTER FUNCTION public.getallvmsrelatedtoquotaid(v_quota_id uuid) OWNER TO engine;

--
-- Name: getallvmtemplatesrelatedtoquotaid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getallvmtemplatesrelatedtoquotaid(v_quota_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
	RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE quota_id = v_quota_id
      UNION
      SELECT DISTINCT vm_templates.*
      FROM vm_templates_view vm_templates
      INNER JOIN vm_device vd ON vd.vm_id = vm_templates.vmt_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
      WHERE image_storage_domain_map.quota_id = v_quota_id;
END; ';


ALTER FUNCTION public.getallvmtemplatesrelatedtoquotaid(v_quota_id uuid) OWNER TO engine;

--
-- Name: getancestralimagebyimageguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getancestralimagebyimageguid(v_image_guid uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY WITH RECURSIVE ancestor_image(image_guid, parentid) AS (
         SELECT image_guid, parentid
         FROM images
         WHERE image_guid = v_image_guid
         UNION ALL
         SELECT i.image_guid, i.parentid
         FROM images i, ancestor_image ai
         WHERE i.image_guid = ai.parentid
      )
      SELECT i.*
      FROM ancestor_image ai, images_storage_domain_view i
      WHERE ai.parentid = ''00000000-0000-0000-0000-000000000000''
      AND ai.image_guid = i.image_guid;
END; ';


ALTER FUNCTION public.getancestralimagebyimageguid(v_image_guid uuid) OWNER TO engine;

--
-- Name: getasync_tasksbytask_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasync_tasksbytask_id(v_task_id uuid) RETURNS SETOF async_tasks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks
   WHERE task_id = v_task_id;

END; ';


ALTER FUNCTION public.getasync_tasksbytask_id(v_task_id uuid) OWNER TO engine;

--
-- Name: async_tasks_entities; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE async_tasks_entities (
    async_task_id uuid NOT NULL,
    entity_id uuid NOT NULL,
    entity_type character varying(128)
);


ALTER TABLE public.async_tasks_entities OWNER TO engine;

--
-- Name: getasynctaskentitiesbytaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasynctaskentitiesbytaskid(v_task_id uuid) RETURNS SETOF async_tasks_entities
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks_entities
   WHERE async_task_id = v_task_id;
END; ';


ALTER FUNCTION public.getasynctaskentitiesbytaskid(v_task_id uuid) OWNER TO engine;

--
-- Name: getasynctasksbyentityid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasynctasksbyentityid(v_entity_id uuid) RETURNS SETOF async_tasks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT async_tasks.*
   FROM async_tasks
   JOIN async_tasks_entities ON async_task_id = task_id
   WHERE entity_id = v_entity_id;

END; ';


ALTER FUNCTION public.getasynctasksbyentityid(v_entity_id uuid) OWNER TO engine;

--
-- Name: getasynctasksbystoragepoolid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasynctasksbystoragepoolid(v_storage_pool_id uuid) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT async_tasks.task_id
   FROM  async_tasks
   WHERE storage_pool_id = v_storage_pool_id;
END; ';


ALTER FUNCTION public.getasynctasksbystoragepoolid(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getasynctasksbyvdsmtaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasynctasksbyvdsmtaskid(v_vdsm_task_id uuid) RETURNS SETOF async_tasks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks
   WHERE vdsm_task_id = v_vdsm_task_id;

END; ';


ALTER FUNCTION public.getasynctasksbyvdsmtaskid(v_vdsm_task_id uuid) OWNER TO engine;

--
-- Name: getasynctasksidsbyentityid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getasynctasksidsbyentityid(v_entity_id uuid) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT async_task_id from async_tasks_entities where entity_id = v_entity_id;
END; ';


ALTER FUNCTION public.getasynctasksidsbyentityid(v_entity_id uuid) OWNER TO engine;

--
-- Name: getattacheddisksnapshotstovm(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getattacheddisksnapshotstovm(v_vm_guid uuid, v_is_plugged boolean) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql
    AS '
BEGIN
      RETURN QUERY SELECT images_storage_domain_view.*
      FROM images_storage_domain_view
      JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
      WHERE vm_device.vm_id = v_vm_guid AND (v_is_plugged IS NULL OR vm_device.is_plugged = v_is_plugged)
            AND vm_device.snapshot_id IS NOT NULL
            AND vm_device.snapshot_id = images_storage_domain_view.vm_snapshot_id;
END; ';


ALTER FUNCTION public.getattacheddisksnapshotstovm(v_vm_guid uuid, v_is_plugged boolean) OWNER TO engine;

--
-- Name: getauditlogbyauditlogid(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getauditlogbyauditlogid(v_audit_log_id integer) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE audit_log_id = v_audit_log_id;
END; ';


ALTER FUNCTION public.getauditlogbyauditlogid(v_audit_log_id integer) OWNER TO engine;

--
-- Name: getauditlogbyoriginandcustomeventid(character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getauditlogbyoriginandcustomeventid(v_origin character varying, v_custom_event_id integer) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE origin = v_origin and custom_event_id = v_custom_event_id;
END; ';


ALTER FUNCTION public.getauditlogbyoriginandcustomeventid(v_origin character varying, v_custom_event_id integer) OWNER TO engine;

--
-- Name: getauditlogbyvmid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getauditlogbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM   audit_log
      WHERE  not deleted and vm_id = v_vm_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vm_id));


END; ';


ALTER FUNCTION public.getauditlogbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getauditlogbyvmtemplateid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getauditlogbyvmtemplateid(v_vm_template_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM   audit_log
      WHERE  not deleted and vm_template_id = v_vm_template_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vm_template_id));


END; ';


ALTER FUNCTION public.getauditlogbyvmtemplateid(v_vm_template_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getauditloglaterthendate(timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getauditloglaterthendate(v_date timestamp with time zone) RETURNS SETOF audit_log
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE not deleted and LOG_TIME >= v_date;
END; ';


ALTER FUNCTION public.getauditloglaterthendate(v_date timestamp with time zone) OWNER TO engine;

--
-- Name: getbasediskbybasediskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbasediskbybasediskid(v_disk_id uuid) RETURNS SETOF base_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   base_disks
    WHERE  disk_id = v_disk_id;
END; ';


ALTER FUNCTION public.getbasediskbybasediskid(v_disk_id uuid) OWNER TO engine;

--
-- Name: getbookmarkbybookmark_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbookmarkbybookmark_id(v_bookmark_id uuid) RETURNS SETOF bookmarks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks
      WHERE bookmark_Id = v_bookmark_id;
END; ';


ALTER FUNCTION public.getbookmarkbybookmark_id(v_bookmark_id uuid) OWNER TO engine;

--
-- Name: getbookmarkbybookmark_name(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbookmarkbybookmark_name(v_bookmark_name character varying) RETURNS SETOF bookmarks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks
      WHERE bookmark_name = v_bookmark_name;
END; ';


ALTER FUNCTION public.getbookmarkbybookmark_name(v_bookmark_name character varying) OWNER TO engine;

--
-- Name: gluster_volume_bricks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_volume_bricks (
    volume_id uuid NOT NULL,
    server_id uuid NOT NULL,
    brick_dir character varying(4096) NOT NULL,
    status character varying(32) NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone,
    id uuid NOT NULL,
    brick_order integer DEFAULT 0,
    task_id uuid
);


ALTER TABLE public.gluster_volume_bricks OWNER TO engine;

--
-- Name: gluster_volumes; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_volumes (
    id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    vol_name character varying(1000) NOT NULL,
    vol_type character varying(32) NOT NULL,
    status character varying(32) NOT NULL,
    replica_count integer DEFAULT 0 NOT NULL,
    stripe_count integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone,
    task_id uuid
);


ALTER TABLE public.gluster_volumes OWNER TO engine;

--
-- Name: gluster_volume_bricks_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW gluster_volume_bricks_view AS
    SELECT gluster_volume_bricks.volume_id, gluster_volume_bricks.server_id, gluster_volume_bricks.brick_dir, gluster_volume_bricks.status, gluster_volume_bricks._create_date, gluster_volume_bricks._update_date, gluster_volume_bricks.id, gluster_volume_bricks.brick_order, gluster_volume_bricks.task_id, vds_static.host_name AS vds_name, gluster_volumes.vol_name AS volume_name FROM ((gluster_volume_bricks JOIN vds_static ON ((vds_static.vds_id = gluster_volume_bricks.server_id))) JOIN gluster_volumes ON ((gluster_volumes.id = gluster_volume_bricks.volume_id)));


ALTER TABLE public.gluster_volume_bricks_view OWNER TO engine;

--
-- Name: getbrickbyserveridanddirectory(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbrickbyserveridanddirectory(v_server_id uuid, v_brick_dir character varying) RETURNS SETOF gluster_volume_bricks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_bricks_view
    WHERE server_id = v_server_id
    AND brick_dir = v_brick_dir;
END; ';


ALTER FUNCTION public.getbrickbyserveridanddirectory(v_server_id uuid, v_brick_dir character varying) OWNER TO engine;

--
-- Name: getbricksbyglustervolumeguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbricksbyglustervolumeguid(v_volume_id uuid) RETURNS SETOF gluster_volume_bricks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_bricks_view
    WHERE volume_id = v_volume_id
    ORDER BY brick_order;
END; ';


ALTER FUNCTION public.getbricksbyglustervolumeguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: getbricksbytaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getbricksbytaskid(v_task_id uuid) RETURNS SETOF gluster_volume_bricks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
FROM  gluster_volume_bricks_view
WHERE task_id = v_task_id
ORDER BY brick_order;
END; ';


ALTER FUNCTION public.getbricksbytaskid(v_task_id uuid) OWNER TO engine;

--
-- Name: getclusterpolicybyclusterpolicyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getclusterpolicybyclusterpolicyid(v_id uuid) RETURNS SETOF cluster_policies
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policies
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getclusterpolicybyclusterpolicyid(v_id uuid) OWNER TO engine;

--
-- Name: getclusterpolicyunitsbyclusterpolicyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getclusterpolicyunitsbyclusterpolicyid(v_id uuid) RETURNS SETOF cluster_policy_units
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policy_units
    WHERE cluster_policy_id = v_id;
END; ';


ALTER FUNCTION public.getclusterpolicyunitsbyclusterpolicyid(v_id uuid) OWNER TO engine;

--
-- Name: getconnectionsbyiscsibondid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getconnectionsbyiscsibondid(v_iscsi_bond_id uuid) RETURNS SETOF character varying
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT iscsi_bonds_storage_connections_map.connection_id
      FROM iscsi_bonds_storage_connections_map
      WHERE iscsi_bond_id = v_iscsi_bond_id;
END; ';


ALTER FUNCTION public.getconnectionsbyiscsibondid(v_iscsi_bond_id uuid) OWNER TO engine;

--
-- Name: getconsumedpermissionsforquotaid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getconsumedpermissionsforquotaid(v_quota_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY    SELECT *
   FROM permissions_view
   WHERE role_id in (SELECT role_id FROM ROLES_groups where action_group_id = 901)
     AND object_id in(select id from  fn_get_entity_parents(v_quota_id,17));
END; ';


ALTER FUNCTION public.getconsumedpermissionsforquotaid(v_quota_id uuid) OWNER TO engine;

--
-- Name: getcustom_actionsbyaction_id(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getcustom_actionsbyaction_id(v_action_id integer) RETURNS SETOF custom_actions
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE action_id = v_action_id;
END; ';


ALTER FUNCTION public.getcustom_actionsbyaction_id(v_action_id integer) OWNER TO engine;

--
-- Name: getcustom_actionsbynameandtab(character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getcustom_actionsbynameandtab(v_action_name character varying, v_tab integer) RETURNS SETOF custom_actions
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE tab = v_tab and action_name = v_action_name;
END; ';


ALTER FUNCTION public.getcustom_actionsbynameandtab(v_action_name character varying, v_tab integer) OWNER TO engine;

--
-- Name: getcustom_actionsbytab_id(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getcustom_actionsbytab_id(v_tab integer) RETURNS SETOF custom_actions
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE tab = v_tab;
END; ';


ALTER FUNCTION public.getcustom_actionsbytab_id(v_tab integer) OWNER TO engine;

--
-- Name: getdbgeneration(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdbgeneration(v_vm_guid uuid) RETURNS SETOF bigint
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT db_generation
      FROM vm_static
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.getdbgeneration(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getdcidbyexternalnetworkid(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdcidbyexternalnetworkid(v_external_id text) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT storage_pool_id
    FROM network
    WHERE provider_network_external_id = v_external_id;
END; ';


ALTER FUNCTION public.getdcidbyexternalnetworkid(v_external_id text) OWNER TO engine;

--
-- Name: getdirectpermissionsbyadelementid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdirectpermissionsbyadelementid(v_ad_element_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE permissions_view.ad_element_id = v_ad_element_id;

END; ';


ALTER FUNCTION public.getdirectpermissionsbyadelementid(v_ad_element_id uuid) OWNER TO engine;

--
-- Name: getdisk_image_dynamicbyimage_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisk_image_dynamicbyimage_id(v_image_id uuid) RETURNS SETOF disk_image_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM disk_image_dynamic
   WHERE image_id = v_image_id;

END; ';


ALTER FUNCTION public.getdisk_image_dynamicbyimage_id(v_image_id uuid) OWNER TO engine;

--
-- Name: getdiskbydiskid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdiskbydiskid(v_disk_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF all_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   all_disks
    WHERE  image_group_id = v_disk_id
    AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                         FROM user_disk_permissions_view
                                         WHERE user_id = v_user_id AND entity_id = v_disk_id));
END; ';


ALTER FUNCTION public.getdiskbydiskid(v_disk_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getdisklunmapbydisklunmapid(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisklunmapbydisklunmapid(v_disk_id uuid, v_lun_id character varying) RETURNS SETOF disk_lun_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   disk_lun_map
    WHERE  disk_id = v_disk_id
    AND    lun_id = v_lun_id;
END; ';


ALTER FUNCTION public.getdisklunmapbydisklunmapid(v_disk_id uuid, v_lun_id character varying) OWNER TO engine;

--
-- Name: getdisklunmapbylunid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisklunmapbylunid(v_lun_id character varying) RETURNS SETOF disk_lun_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
	RETURN QUERY
    SELECT *
    FROM   disk_lun_map
    WHERE  lun_id = v_lun_id;
END; ';


ALTER FUNCTION public.getdisklunmapbylunid(v_lun_id character varying) OWNER TO engine;

--
-- Name: getdisksnapshotforvmsnapshot(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisksnapshotforvmsnapshot(v_image_group_id uuid, v_vm_snapshot_id uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view
      WHERE image_group_id = v_image_group_id
      AND vm_snapshot_id = v_vm_snapshot_id;
END; ';


ALTER FUNCTION public.getdisksnapshotforvmsnapshot(v_image_group_id uuid, v_vm_snapshot_id uuid) OWNER TO engine;

--
-- Name: getdisksvmguid(uuid, boolean, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisksvmguid(v_vm_guid uuid, v_only_plugged boolean, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF all_disks_including_snapshots
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT all_disks_including_snapshots.*
      FROM all_disks_including_snapshots
      LEFT JOIN vm_device ON vm_device.device_id = all_disks_including_snapshots.image_group_id AND (NOT v_only_plugged OR is_plugged)
      WHERE vm_device.vm_id = v_vm_guid
      AND ((vm_device.snapshot_id IS NULL AND all_disks_including_snapshots.active IS NOT FALSE)
          OR vm_device.snapshot_id = all_disks_including_snapshots.vm_snapshot_id)
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = all_disks_including_snapshots.disk_id));

END; ';


ALTER FUNCTION public.getdisksvmguid(v_vm_guid uuid, v_only_plugged boolean, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getdisksvmguidbasicview(uuid, boolean, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdisksvmguidbasicview(v_vm_guid uuid, v_only_plugged boolean, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF disks_basic_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT disk_id,disk_alias, size
      FROM images
      LEFT OUTER JOIN base_disks ON images.image_group_id = base_disks.disk_id
      LEFT JOIN vm_device ON vm_device.device_id = image_group_id AND (NOT v_only_plugged OR is_plugged)
      WHERE vm_device.vm_id = v_vm_guid
      AND images.active = true
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = disk_id));

END; ';


ALTER FUNCTION public.getdisksvmguidbasicview(v_vm_guid uuid, v_only_plugged boolean, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: dwh_history_timekeeping; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE dwh_history_timekeeping (
    var_name character varying(50) NOT NULL,
    var_value character varying(255),
    var_datetime timestamp with time zone
);


ALTER TABLE public.dwh_history_timekeeping OWNER TO engine;

--
-- Name: getdwhhistorytimekeepingbyvarname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getdwhhistorytimekeepingbyvarname(v_var_name character varying) RETURNS SETOF dwh_history_timekeeping
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM dwh_history_timekeeping
   WHERE var_name = v_var_name;
END; ';


ALTER FUNCTION public.getdwhhistorytimekeepingbyvarname(v_var_name character varying) OWNER TO engine;

--
-- Name: getelementidsbyidandgroups(uuid, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getelementidsbyidandgroups(v_id uuid, v_group_ids text) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
  RETURN QUERY
  select * from fnsplitteruuid(v_group_ids)
  UNION
  select v_id
  UNION
  -- user is also member of ''Everyone''
  select ''EEE00000-0000-0000-0000-123456789EEE'';
END; ';


ALTER FUNCTION public.getelementidsbyidandgroups(v_id uuid, v_group_ids text) OWNER TO engine;

--
-- Name: getevent_subscriberbysubscriber_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getevent_subscriberbysubscriber_id(v_subscriber_id uuid) RETURNS SETOF event_subscriber
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM event_subscriber
   WHERE subscriber_id = v_subscriber_id;

END; ';


ALTER FUNCTION public.getevent_subscriberbysubscriber_id(v_subscriber_id uuid) OWNER TO engine;

--
-- Name: geteventmapbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION geteventmapbyname(v_event_name character varying) RETURNS SETOF event_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      from event_map
      where event_up_name = v_event_name;
END; ';


ALTER FUNCTION public.geteventmapbyname(v_event_name character varying) OWNER TO engine;

--
-- Name: event_notification_methods; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE event_notification_methods (
    method_id integer NOT NULL,
    method_type character(10) NOT NULL
);


ALTER TABLE public.event_notification_methods OWNER TO engine;

--
-- Name: geteventnotificationmethodbyid(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION geteventnotificationmethodbyid(v_method_id integer) RETURNS SETOF event_notification_methods
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      from event_notification_methods
      where method_id = v_method_id;
END; ';


ALTER FUNCTION public.geteventnotificationmethodbyid(v_method_id integer) OWNER TO engine;

--
-- Name: getexternalidsfromsteps(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getexternalidsfromsteps(v_status character varying, v_external_system_type character varying) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.external_id
    FROM step
    INNER JOIN job ON step.job_id = job.job_id
    WHERE job.status = v_status
    AND step.external_system_type = v_external_system_type;
END; ';


ALTER FUNCTION public.getexternalidsfromsteps(v_status character varying, v_external_system_type character varying) OWNER TO engine;

--
-- Name: getfailedautostartvms(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getfailedautostartvms() RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE auto_startup = TRUE and status = 0 and exit_status = 1;
END; ';


ALTER FUNCTION public.getfailedautostartvms() OWNER TO engine;

--
-- Name: getfailingstorage_domains(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getfailingstorage_domains() RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
    SELECT * FROM storage_domains WHERE recoverable AND status = 4; --inactive
END; ';


ALTER FUNCTION public.getfailingstorage_domains() OWNER TO engine;

--
-- Name: getfailingvdss(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getfailingvdss() RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
    SELECT * FROM vds WHERE recoverable AND status = 10; --non operational
END; ';


ALTER FUNCTION public.getfailingvdss() OWNER TO engine;

--
-- Name: getforroleandadelementandobject_wgroupcheck(uuid, uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getforroleandadelementandobject_wgroupcheck(v_role_id uuid, v_ad_element_id uuid, v_object_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and object_id = v_object_id and ad_element_id in (
         select * from getUserAndGroupsById(v_ad_element_id));
END; ';


ALTER FUNCTION public.getforroleandadelementandobject_wgroupcheck(v_role_id uuid, v_ad_element_id uuid, v_object_id uuid) OWNER TO engine;

--
-- Name: getglobalids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglobalids(v_name character varying) RETURNS uuid
    LANGUAGE plpgsql IMMUTABLE STRICT
    AS '
   DECLARE
   v_id  UUID;
BEGIN
   if (v_name = ''system'') then
      v_id := ''AAA00000-0000-0000-0000-123456789AAA'';
   elsif (v_name = ''everyone'') then
      v_id := ''EEE00000-0000-0000-0000-123456789EEE'';
   -- bottom is an object which all the objects in the system are its parents
   -- useful to denote we want all objects when checking for permissions
   elsif (v_name = ''bottom'') then
      v_id := ''BBB00000-0000-0000-0000-123456789BBB'';
   end if;
   return  v_id;
END; ';


ALTER FUNCTION public.getglobalids(v_name character varying) OWNER TO engine;

--
-- Name: getglusterbrickbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterbrickbyid(v_id uuid) RETURNS SETOF gluster_volume_bricks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volume_bricks_view
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getglusterbrickbyid(v_id uuid) OWNER TO engine;

SET default_with_oids = true;

--
-- Name: gluster_cluster_services; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_cluster_services (
    cluster_id uuid NOT NULL,
    service_type character varying(100) NOT NULL,
    status character varying(32) NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);


ALTER TABLE public.gluster_cluster_services OWNER TO engine;

--
-- Name: getglusterclusterservicesbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterclusterservicesbyclusterid(v_cluster_id uuid) RETURNS SETOF gluster_cluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_cluster_services
    WHERE   cluster_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getglusterclusterservicesbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getglusterclusterservicesbyclusteridandservicetype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterclusterservicesbyclusteridandservicetype(v_cluster_id uuid, v_service_type character varying) RETURNS SETOF gluster_cluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_cluster_services
    WHERE   cluster_id = v_cluster_id
    AND     service_type = v_service_type;
END; ';


ALTER FUNCTION public.getglusterclusterservicesbyclusteridandservicetype(v_cluster_id uuid, v_service_type character varying) OWNER TO engine;

--
-- Name: gluster_hooks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_hooks (
    id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    gluster_command character varying(128) NOT NULL,
    stage character varying(50) NOT NULL,
    name character varying(256) NOT NULL,
    hook_status character varying(50),
    content_type character varying(50),
    checksum character varying(256),
    content text,
    conflict_status integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);


ALTER TABLE public.gluster_hooks OWNER TO engine;

--
-- Name: getglusterhook(uuid, character varying, character varying, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterhook(v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying, v_includecontent boolean DEFAULT false) RETURNS SETOF gluster_hooks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum,
    CASE v_includeContent WHEN true THEN content
                          ELSE null::text
    END as content,
    conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE cluster_id = v_cluster_id AND gluster_command = v_gluster_command
    AND stage = v_stage AND name = v_name;
END; ';


ALTER FUNCTION public.getglusterhook(v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying, v_includecontent boolean) OWNER TO engine;

--
-- Name: getglusterhookbyid(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterhookbyid(v_id uuid, v_includecontent boolean DEFAULT false) RETURNS SETOF gluster_hooks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum,
    CASE v_includeContent WHEN true THEN content
                          ELSE null::text
    END as content,
    conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getglusterhookbyid(v_id uuid, v_includecontent boolean) OWNER TO engine;

--
-- Name: getglusterhookcontentbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterhookcontentbyid(v_id uuid) RETURNS SETOF text
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT content
    FROM  gluster_hooks
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getglusterhookcontentbyid(v_id uuid) OWNER TO engine;

--
-- Name: getglusterhooksbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterhooksbyclusterid(v_cluster_id uuid) RETURNS SETOF gluster_hooks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum, null::text as content, conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE cluster_id = v_cluster_id order by gluster_command asc, stage asc;
END; ';


ALTER FUNCTION public.getglusterhooksbyclusterid(v_cluster_id uuid) OWNER TO engine;

SET default_with_oids = false;

--
-- Name: gluster_volume_options; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_volume_options (
    volume_id uuid NOT NULL,
    option_key character varying(8192) NOT NULL,
    option_val character varying(8192) NOT NULL,
    id uuid NOT NULL
);


ALTER TABLE public.gluster_volume_options OWNER TO engine;

--
-- Name: getglusteroptionbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusteroptionbyid(v_id uuid) RETURNS SETOF gluster_volume_options
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volume_options
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getglusteroptionbyid(v_id uuid) OWNER TO engine;

SET default_with_oids = true;

--
-- Name: gluster_server; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_server (
    server_id uuid NOT NULL,
    gluster_server_uuid uuid NOT NULL
);


ALTER TABLE public.gluster_server OWNER TO engine;

--
-- Name: getglusterserverbyglusterserveruuid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverbyglusterserveruuid(v_gluster_server_uuid uuid) RETURNS SETOF gluster_server
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT server_id, gluster_server_uuid
    FROM gluster_server
    WHERE gluster_server_uuid = v_gluster_server_uuid;
END; ';


ALTER FUNCTION public.getglusterserverbyglusterserveruuid(v_gluster_server_uuid uuid) OWNER TO engine;

--
-- Name: getglusterserverbyserverid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverbyserverid(v_server_id uuid) RETURNS SETOF gluster_server
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT server_id, gluster_server_uuid
    FROM gluster_server
    WHERE server_id = v_server_id;
END; ';


ALTER FUNCTION public.getglusterserverbyserverid(v_server_id uuid) OWNER TO engine;

--
-- Name: gluster_server_hooks; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_server_hooks (
    hook_id uuid NOT NULL,
    server_id uuid NOT NULL,
    hook_status character varying(50),
    content_type character varying(50),
    checksum character varying(256),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);


ALTER TABLE public.gluster_server_hooks OWNER TO engine;

--
-- Name: gluster_server_hooks_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW gluster_server_hooks_view AS
    SELECT gluster_server_hooks.hook_id, gluster_server_hooks.server_id, gluster_server_hooks.hook_status, gluster_server_hooks.content_type, gluster_server_hooks.checksum, gluster_server_hooks._create_date, gluster_server_hooks._update_date, vds_static.vds_name AS server_name FROM (gluster_server_hooks JOIN vds_static ON ((gluster_server_hooks.server_id = vds_static.vds_id)));


ALTER TABLE public.gluster_server_hooks_view OWNER TO engine;

--
-- Name: getglusterserverhook(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverhook(v_hook_id uuid, v_server_id uuid) RETURNS SETOF gluster_server_hooks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_server_hooks_view
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
END; ';


ALTER FUNCTION public.getglusterserverhook(v_hook_id uuid, v_server_id uuid) OWNER TO engine;

--
-- Name: getglusterserverhooksbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverhooksbyid(v_id uuid) RETURNS SETOF gluster_server_hooks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_server_hooks_view
    WHERE hook_id = v_id;
END; ';


ALTER FUNCTION public.getglusterserverhooksbyid(v_id uuid) OWNER TO engine;

--
-- Name: getglusterserverservicebyglusterserverserviceid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverservicebyglusterserverserviceid(v_id uuid) RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.getglusterserverservicebyglusterserverserviceid(v_id uuid) OWNER TO engine;

--
-- Name: getglusterserverservicesbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverservicesbyclusterid(v_cluster_id uuid) RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT s.*
    FROM    gluster_server_services_view s, vds_static v
    WHERE   s.server_id = v.vds_id
    AND     v.vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getglusterserverservicesbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getglusterserverservicesbyclusteridandservicetype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverservicesbyclusteridandservicetype(v_cluster_id uuid, v_service_type character varying) RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT s.*
    FROM    gluster_server_services_view s, vds_static v
    WHERE   s.server_id = v.vds_id
    AND     v.vds_group_id = v_cluster_id
    AND     s.service_type = v_service_type;
END; ';


ALTER FUNCTION public.getglusterserverservicesbyclusteridandservicetype(v_cluster_id uuid, v_service_type character varying) OWNER TO engine;

--
-- Name: getglusterserverservicesbyserverid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverservicesbyserverid(v_server_id uuid) RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   server_id = v_server_id;
END; ';


ALTER FUNCTION public.getglusterserverservicesbyserverid(v_server_id uuid) OWNER TO engine;

--
-- Name: getglusterserverservicesbyserveridandservicetype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterserverservicesbyserveridandservicetype(v_server_id uuid, v_service_type character varying) RETURNS SETOF gluster_server_services_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   server_id = v_server_id
    AND     service_type = v_service_type;
END; ';


ALTER FUNCTION public.getglusterserverservicesbyserveridandservicetype(v_server_id uuid, v_service_type character varying) OWNER TO engine;

--
-- Name: getglusterservicebyglusterserviceid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterservicebyglusterserviceid(v_id uuid) RETURNS SETOF gluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.getglusterservicebyglusterserviceid(v_id uuid) OWNER TO engine;

--
-- Name: getglusterservicebytypeandname(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterservicebytypeandname(v_service_type character varying, v_service_name character varying) RETURNS SETOF gluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   service_type = v_service_type
    AND     service_name = v_service_name;
END; ';


ALTER FUNCTION public.getglusterservicebytypeandname(v_service_type character varying, v_service_name character varying) OWNER TO engine;

--
-- Name: getglusterservicesbytype(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterservicesbytype(v_service_type character varying) RETURNS SETOF gluster_services
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   service_type = v_service_type;
END; ';


ALTER FUNCTION public.getglusterservicesbytype(v_service_type character varying) OWNER TO engine;

--
-- Name: gluster_service_types; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_service_types (
    service_type character varying(100) NOT NULL
);


ALTER TABLE public.gluster_service_types OWNER TO engine;

--
-- Name: getglusterservicetypes(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglusterservicetypes() RETURNS SETOF gluster_service_types
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_service_types;
END; ';


ALTER FUNCTION public.getglusterservicetypes() OWNER TO engine;

SET default_with_oids = false;

--
-- Name: job_subject_entity; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE job_subject_entity (
    job_id uuid NOT NULL,
    entity_id uuid NOT NULL,
    entity_type character varying(32) NOT NULL
);


ALTER TABLE public.job_subject_entity OWNER TO engine;

--
-- Name: gluster_volume_task_steps; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW gluster_volume_task_steps AS
    SELECT step.step_id, step.parent_step_id, step.job_id, step.step_type, step.description, step.step_number, step.status, step.start_time, step.end_time, step.correlation_id, step.external_id, step.external_system_type, step.is_external, gluster_volumes.id AS volume_id, job.job_id AS job_job_id, job.action_type, job.description AS job_description, job.status AS job_status, job.start_time AS job_start_time, job.end_time AS job_end_time FROM (((gluster_volumes JOIN job_subject_entity js ON ((js.entity_id = gluster_volumes.id))) JOIN job ON (((job.job_id = js.job_id) AND ((job.action_type)::text = ANY ((ARRAY['StartRebalanceGlusterVolume'::character varying, 'StartRemoveGlusterVolumeBricks'::character varying])::text[]))))) LEFT JOIN step ON ((((step.external_id = gluster_volumes.task_id) AND ((step.external_system_type)::text = 'GLUSTER'::text)) AND (step.job_id = js.job_id))));


ALTER TABLE public.gluster_volume_task_steps OWNER TO engine;

--
-- Name: getglustertaskbyglustervolumeguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustertaskbyglustervolumeguid(v_volume_id uuid) RETURNS SETOF gluster_volume_task_steps
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
       RETURN QUERY SELECT *
       FROM  gluster_volume_task_steps
       WHERE volume_id = v_volume_id
       ORDER BY job_start_time desc LIMIT 1;
END; ';


ALTER FUNCTION public.getglustertaskbyglustervolumeguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: getglustervolumebricksbyserverguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumebricksbyserverguid(v_server_id uuid) RETURNS SETOF gluster_volume_bricks_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
FROM  gluster_volume_bricks_view
WHERE server_id = v_server_id
ORDER BY brick_order;
END; ';


ALTER FUNCTION public.getglustervolumebricksbyserverguid(v_server_id uuid) OWNER TO engine;

--
-- Name: gluster_volumes_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW gluster_volumes_view AS
    SELECT gluster_volumes.id, gluster_volumes.cluster_id, gluster_volumes.vol_name, gluster_volumes.vol_type, gluster_volumes.status, gluster_volumes.replica_count, gluster_volumes.stripe_count, gluster_volumes._create_date, gluster_volumes._update_date, gluster_volumes.task_id, vds_groups.name AS vds_group_name FROM (gluster_volumes JOIN vds_groups ON ((gluster_volumes.cluster_id = vds_groups.vds_group_id)));


ALTER TABLE public.gluster_volumes_view OWNER TO engine;

--
-- Name: getglustervolumebyglustertaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumebyglustertaskid(v_task_id uuid) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE task_id = v_task_id;
END; ';


ALTER FUNCTION public.getglustervolumebyglustertaskid(v_task_id uuid) OWNER TO engine;

--
-- Name: getglustervolumebyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumebyid(v_volume_id uuid) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE id = v_volume_id;
END; ';


ALTER FUNCTION public.getglustervolumebyid(v_volume_id uuid) OWNER TO engine;

--
-- Name: getglustervolumebyname(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumebyname(v_cluster_id uuid, v_vol_name character varying) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE cluster_id = v_cluster_id and vol_name = v_vol_name;
END; ';


ALTER FUNCTION public.getglustervolumebyname(v_cluster_id uuid, v_vol_name character varying) OWNER TO engine;

--
-- Name: getglustervolumesbyclusterguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumesbyclusterguid(v_cluster_id uuid) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getglustervolumesbyclusterguid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getglustervolumesbyoption(uuid, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumesbyoption(v_cluster_id uuid, v_status character varying, v_option_key character varying, v_option_val character varying) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND id IN (SELECT volume_id FROM gluster_volume_options
    WHERE option_key=v_option_key AND option_val=v_option_val);
END; ';


ALTER FUNCTION public.getglustervolumesbyoption(v_cluster_id uuid, v_status character varying, v_option_key character varying, v_option_val character varying) OWNER TO engine;

--
-- Name: getglustervolumesbystatusandtypes(uuid, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumesbystatusandtypes(v_cluster_id uuid, v_status character varying, v_vol_types text) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND vol_type IN (SELECT ID FROM fnSplitter(v_vol_types));
END; ';


ALTER FUNCTION public.getglustervolumesbystatusandtypes(v_cluster_id uuid, v_status character varying, v_vol_types text) OWNER TO engine;

--
-- Name: getglustervolumesbystatustypesandoption(uuid, character varying, text, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getglustervolumesbystatustypesandoption(v_cluster_id uuid, v_status character varying, v_vol_types text, v_option_key character varying, v_option_val character varying) RETURNS SETOF gluster_volumes_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND vol_type IN (SELECT ID FROM fnSplitter(v_vol_types))
    AND id IN (SELECT volume_id FROM gluster_volume_options
    WHERE option_key=v_option_key AND option_val=v_option_val);
END; ';


ALTER FUNCTION public.getglustervolumesbystatustypesandoption(v_cluster_id uuid, v_status character varying, v_vol_types text, v_option_key character varying, v_option_val character varying) OWNER TO engine;

--
-- Name: getgroupbyexternalid(character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getgroupbyexternalid(v_domain character varying, v_external_id bytea) RETURNS SETOF ad_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE domain = v_domain AND external_id = v_external_id;
END; ';


ALTER FUNCTION public.getgroupbyexternalid(v_domain character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: getgroupbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getgroupbyid(v_id uuid) RETURNS SETOF ad_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.getgroupbyid(v_id uuid) OWNER TO engine;

--
-- Name: getgroupbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getgroupbyname(v_name character varying) RETURNS SETOF ad_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE name = v_name;
END; ';


ALTER FUNCTION public.getgroupbyname(v_name character varying) OWNER TO engine;

--
-- Name: gethostnetworksbycluster(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gethostnetworksbycluster(v_cluster_id uuid) RETURNS TABLE(vds_id uuid, network_name character varying)
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_static.vds_id, vds_interface.network_name
   FROM vds_static
   JOIN vds_interface ON vds_interface.vds_id = vds_static.vds_id
   AND vds_static.vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.gethostnetworksbycluster(v_cluster_id uuid) OWNER TO engine;

--
-- Name: gethostsforstorageoperation(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gethostsforstorageoperation(v_storage_pool_id uuid, v_local_fs_only boolean) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        LEFT JOIN vds_groups vg ON vds.vds_group_id = vg.vds_group_id
        LEFT JOIN storage_pool sp ON vds.storage_pool_id = sp.id
        WHERE (v_storage_pool_id IS NULL OR vds.storage_pool_id = v_storage_pool_id)
        AND (vg.virt_service = true)
        AND (NOT v_local_fs_only OR sp.is_local = true)
        AND (v_storage_pool_id IS NOT NULL OR vds.status = 3); -- if DC is unspecified return only hosts with status = UP
    END;
    RETURN;
END; ';


ALTER FUNCTION public.gethostsforstorageoperation(v_storage_pool_id uuid, v_local_fs_only boolean) OWNER TO engine;

--
-- Name: getidsforovfdeletion(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getidsforovfdeletion(v_storage_pool_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT ovf.vm_guid as vm_guid
   FROM vm_ovf_generations ovf
   WHERE ovf.storage_pool_id = v_storage_pool_id AND ovf.vm_guid NOT IN (SELECT vm_guid FROM vm_static);
END; ';


ALTER FUNCTION public.getidsforovfdeletion(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getimage_storage_domain_mapbyimage_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getimage_storage_domain_mapbyimage_id(v_image_id uuid) RETURNS SETOF image_storage_domain_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM image_storage_domain_map
   WHERE image_id = v_image_id;

END; ';


ALTER FUNCTION public.getimage_storage_domain_mapbyimage_id(v_image_id uuid) OWNER TO engine;

--
-- Name: getimage_storage_domain_mapbystorage_domain_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getimage_storage_domain_mapbystorage_domain_id(v_storage_domain_id uuid) RETURNS SETOF image_storage_domain_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM image_storage_domain_map
   WHERE storage_domain_id = v_storage_domain_id;

END; ';


ALTER FUNCTION public.getimage_storage_domain_mapbystorage_domain_id(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: vm_images_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_images_view AS
    SELECT storage_for_image_view.storage_id, storage_for_image_view.storage_path, storage_for_image_view.storage_name, storage_for_image_view.storage_type, images_storage_domain_view.storage_pool_id, images_storage_domain_view.image_guid, images_storage_domain_view.creation_date, disk_image_dynamic.actual_size, disk_image_dynamic.read_rate, disk_image_dynamic.read_latency_seconds, disk_image_dynamic.write_latency_seconds, disk_image_dynamic.flush_latency_seconds, disk_image_dynamic.write_rate, images_storage_domain_view.size, images_storage_domain_view.it_guid, images_storage_domain_view.description, images_storage_domain_view.parentid, images_storage_domain_view.imagestatus, images_storage_domain_view.lastmodified, images_storage_domain_view.app_list, images_storage_domain_view.vm_snapshot_id, images_storage_domain_view.volume_type, images_storage_domain_view.image_group_id, images_storage_domain_view.active, images_storage_domain_view.volume_format, images_storage_domain_view.disk_interface, images_storage_domain_view.boot, images_storage_domain_view.wipe_after_delete, images_storage_domain_view.propagate_errors, images_storage_domain_view.sgio, images_storage_domain_view.entity_type, images_storage_domain_view.number_of_vms, images_storage_domain_view.vm_names, storage_for_image_view.quota_id, storage_for_image_view.quota_name, images_storage_domain_view.quota_enforcement_type, images_storage_domain_view.disk_id, images_storage_domain_view.disk_alias, images_storage_domain_view.disk_description, images_storage_domain_view.shareable, images_storage_domain_view.alignment, images_storage_domain_view.last_alignment_scan FROM ((images_storage_domain_view JOIN disk_image_dynamic ON ((images_storage_domain_view.image_guid = disk_image_dynamic.image_id))) JOIN storage_for_image_view ON ((images_storage_domain_view.image_guid = storage_for_image_view.image_id))) WHERE (images_storage_domain_view.active = true);


ALTER TABLE public.vm_images_view OWNER TO engine;

--
-- Name: getimagebyimageguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getimagebyimageguid(v_image_guid uuid) RETURNS SETOF vm_images_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM vm_images_view
      WHERE image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.getimagebyimageguid(v_image_guid uuid) OWNER TO engine;

--
-- Name: getimagebyimageid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getimagebyimageid(v_image_guid uuid) RETURNS SETOF images
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   images
    WHERE  image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.getimagebyimageid(v_image_guid uuid) OWNER TO engine;

--
-- Name: getimageswhichhavenodisk(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getimageswhichhavenodisk(v_vm_id uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT i.*
      FROM   images_storage_domain_view i
      JOIN   snapshots s ON (i.vm_snapshot_id = s.snapshot_id)
      WHERE  s.vm_id = v_vm_id
      AND    NOT EXISTS (
          SELECT 1
          FROM   base_disks d
          WHERE  d.disk_id = i.image_group_id);
END; ';


ALTER FUNCTION public.getimageswhichhavenodisk(v_vm_id uuid) OWNER TO engine;

--
-- Name: vds_interface; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_interface (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    network_name character varying(50),
    vds_id uuid,
    mac_addr character varying(59),
    is_bond boolean DEFAULT false,
    bond_name character varying(50),
    bond_type integer,
    bond_opts character varying(4000),
    vlan_id integer,
    speed integer,
    addr character varying(20),
    subnet character varying(20),
    gateway character varying(20),
    boot_protocol integer,
    type integer DEFAULT 0,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    mtu integer,
    bridged boolean DEFAULT true NOT NULL,
    labels text,
    qos_overridden boolean DEFAULT false NOT NULL
);


ALTER TABLE public.vds_interface OWNER TO engine;

--
-- Name: vds_interface_statistics; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vds_interface_statistics (
    id uuid NOT NULL,
    vds_id uuid,
    rx_rate numeric(18,0),
    tx_rate numeric(18,0),
    rx_drop numeric(18,0),
    tx_drop numeric(18,0),
    iface_status integer,
    _update_date timestamp with time zone
);


ALTER TABLE public.vds_interface_statistics OWNER TO engine;

--
-- Name: vds_interface_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vds_interface_view AS
    SELECT vds_interface_statistics.rx_rate, vds_interface_statistics.tx_rate, vds_interface_statistics.rx_drop, vds_interface_statistics.tx_drop, vds_interface_statistics.iface_status, vds_interface.type, vds_interface.gateway, vds_interface.subnet, vds_interface.addr, vds_interface.speed, vds_interface.vlan_id, vds_interface.bond_type, vds_interface.bond_name, vds_interface.is_bond, vds_interface.bond_opts, vds_interface.mac_addr, vds_interface.network_name, vds_interface.name, vds_static.vds_id, vds_static.vds_name, vds_interface.id, vds_interface.boot_protocol, vds_interface.mtu, vds_interface.bridged, 1 AS is_vds, vds_interface.qos_overridden, vds_interface.labels, vds_static.vds_group_id FROM ((vds_interface_statistics JOIN vds_interface ON ((vds_interface_statistics.id = vds_interface.id))) JOIN vds_static ON ((vds_interface.vds_id = vds_static.vds_id)));


ALTER TABLE public.vds_interface_view OWNER TO engine;

--
-- Name: getinterface_viewbyaddr(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getinterface_viewbyaddr(v_cluster_id uuid, v_addr character varying) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   WHERE vds_interface_view.addr = v_addr
   AND vds_static.vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getinterface_viewbyaddr(v_cluster_id uuid, v_addr character varying) OWNER TO engine;

--
-- Name: getinterface_viewbyvds_id(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getinterface_viewbyvds_id(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   WHERE vds_id = v_vds_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_vds_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_vds_id));

END; ';


ALTER FUNCTION public.getinterface_viewbyvds_id(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getinterfacesbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getinterfacesbyclusterid(v_cluster_id uuid) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   WHERE vds_static.vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getinterfacesbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getinterfacesbydatacenterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getinterfacesbydatacenterid(v_data_center_id uuid) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   INNER JOIN vds_groups
   ON vds_static.vds_group_id = vds_groups.vds_group_id
   WHERE vds_groups.storage_pool_id = v_data_center_id;
END; ';


ALTER FUNCTION public.getinterfacesbydatacenterid(v_data_center_id uuid) OWNER TO engine;

--
-- Name: getiscsibondbyiscsibondid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getiscsibondbyiscsibondid(v_id uuid) RETURNS SETOF iscsi_bonds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.getiscsibondbyiscsibondid(v_id uuid) OWNER TO engine;

--
-- Name: getiscsibondsbystoragepoolid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getiscsibondsbystoragepoolid(v_storage_pool_id uuid) RETURNS SETOF iscsi_bonds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds
      WHERE storage_pool_id = v_storage_pool_id;
END; ';


ALTER FUNCTION public.getiscsibondsbystoragepoolid(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getiscsiifacesbyhostidandstoragetargetid(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getiscsiifacesbyhostidandstoragetargetid(v_host_id uuid, v_target_id character varying) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view,
        network_cluster,
        network,
        iscsi_bonds_networks_map,
        iscsi_bonds_storage_connections_map
   WHERE
       iscsi_bonds_storage_connections_map.connection_id = v_target_id AND
       iscsi_bonds_storage_connections_map.iscsi_bond_id = iscsi_bonds_networks_map.iscsi_bond_id AND
       iscsi_bonds_networks_map.network_id = network.id AND
       network.id = network_cluster.network_id AND
       network.name = vds_interface_view.network_name AND
       network_cluster.cluster_id = vds_interface_view.vds_group_id AND
       vds_interface_view.vds_id = v_host_id;
END; ';


ALTER FUNCTION public.getiscsiifacesbyhostidandstoragetargetid(v_host_id uuid, v_target_id character varying) OWNER TO engine;

--
-- Name: getisvdsgroupempty(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getisvdsgroupempty(v_vds_group_id uuid) RETURNS boolean
    LANGUAGE plpgsql
    AS '
BEGIN
      RETURN NOT EXISTS(SELECT 1 FROM vm_static WHERE vds_group_id = v_vds_group_id AND vm_guid != ''00000000-0000-0000-0000-000000000000'') AND NOT EXISTS(SELECT 1 FROM vds_static WHERE vds_group_id = v_vds_group_id);
END; ';


ALTER FUNCTION public.getisvdsgroupempty(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getjobbyjobid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getjobbyjobid(v_job_id uuid) RETURNS SETOF job
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE job_id = v_job_id;
END; ';


ALTER FUNCTION public.getjobbyjobid(v_job_id uuid) OWNER TO engine;

--
-- Name: getjobsbycorrelationid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getjobsbycorrelationid(v_correlation_id character varying) RETURNS SETOF job
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE correlation_id = v_correlation_id;
END; ';


ALTER FUNCTION public.getjobsbycorrelationid(v_correlation_id character varying) OWNER TO engine;

--
-- Name: getjobsbyoffsetandpagesize(integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getjobsbyoffsetandpagesize(v_position integer, v_page_size integer) RETURNS SETOF job
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    (SELECT job.*
    FROM JOB
    WHERE status = ''STARTED''
    ORDER BY last_update_time desc)
    UNION ALL
    (SELECT job.*
    FROM JOB
    WHERE status not in (''STARTED'',''UNKNOWN'')
    ORDER BY last_update_time desc)
    OFFSET v_position LIMIT v_page_size;
END; ';


ALTER FUNCTION public.getjobsbyoffsetandpagesize(v_position integer, v_page_size integer) OWNER TO engine;

--
-- Name: getjobsubjectentitybyjobid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getjobsubjectentitybyjobid(v_job_id uuid) RETURNS SETOF job_subject_entity
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT job_subject_entity.*
    FROM job_subject_entity
    WHERE job_id = v_job_id;
END; ';


ALTER FUNCTION public.getjobsubjectentitybyjobid(v_job_id uuid) OWNER TO engine;

--
-- Name: getlun_storage_server_connection_mapbylunbystorage_server_conn(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getlun_storage_server_connection_mapbylunbystorage_server_conn(v_lun_id character varying, v_storage_server_connection character varying) RETURNS SETOF lun_storage_server_connection_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT *
   FROM LUN_storage_server_connection_map lUN_storage_server_connection_map
   WHERE LUN_id = v_LUN_id AND storage_server_connection = v_storage_server_connection;

END; ';


ALTER FUNCTION public.getlun_storage_server_connection_mapbylunbystorage_server_conn(v_lun_id character varying, v_storage_server_connection character varying) OWNER TO engine;

--
-- Name: getlunbylunid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getlunbylunid(v_lun_id character varying) RETURNS SETOF luns_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view
   WHERE LUN_id = v_LUN_id;

END; ';


ALTER FUNCTION public.getlunbylunid(v_lun_id character varying) OWNER TO engine;

--
-- Name: getlunsbystorage_server_connection(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getlunsbystorage_server_connection(v_storage_server_connection character varying) RETURNS SETOF luns_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT luns_view.*
   FROM luns_view INNER JOIN
   LUN_storage_server_connection_map
   ON LUN_storage_server_connection_map.LUN_id = luns_view.LUN_id
   WHERE LUN_storage_server_connection_map.storage_server_connection = v_storage_server_connection;

END; ';


ALTER FUNCTION public.getlunsbystorage_server_connection(v_storage_server_connection character varying) OWNER TO engine;

--
-- Name: getlunsbyvolumegroupid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getlunsbyvolumegroupid(v_volume_group_id character varying) RETURNS SETOF luns_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view
   WHERE volume_group_id = v_volume_group_id;

END; ';


ALTER FUNCTION public.getlunsbyvolumegroupid(v_volume_group_id character varying) OWNER TO engine;

--
-- Name: getmacsbydatacenterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getmacsbydatacenterid(v_data_center_id uuid) RETURNS SETOF character varying
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT mac_addr
   FROM vm_interface
   WHERE EXISTS (SELECT 1
                 FROM vm_static
                 JOIN vds_groups ON vm_static.vds_group_id = vds_groups.vds_group_id
                 WHERE vds_groups.storage_pool_id = v_data_center_id
                 AND vm_static.vm_guid = vm_interface.vm_guid);
END; ';


ALTER FUNCTION public.getmacsbydatacenterid(v_data_center_id uuid) OWNER TO engine;

--
-- Name: getnamesofvmstaticdedicatedtovds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnamesofvmstaticdedicatedtovds(v_vds_id uuid) RETURNS SETOF getnamesofvmstaticdedicatedtovds_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
      SELECT vm_name
      FROM vm_static
      WHERE dedicated_vm_for_vds = v_vds_id
      AND   migration_support = 2
      AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getnamesofvmstaticdedicatedtovds(v_vds_id uuid) OWNER TO engine;

--
-- Name: getnetwork_clusterbycluster_idandbynetwork_id(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetwork_clusterbycluster_idandbynetwork_id(v_cluster_id uuid, v_network_id uuid) RETURNS SETOF network_cluster
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

END; ';


ALTER FUNCTION public.getnetwork_clusterbycluster_idandbynetwork_id(v_cluster_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: getnetworkbyid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworkbyid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM network
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                    FROM   user_network_permissions_view
                                    WHERE  user_id = v_user_id AND entity_id = v_id));

END; ';


ALTER FUNCTION public.getnetworkbyid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getnetworkbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworkbyname(v_networkname character varying) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM network
   WHERE name = v_networkName;

END; ';


ALTER FUNCTION public.getnetworkbyname(v_networkname character varying) OWNER TO engine;

--
-- Name: getnetworkbynameandcluster(character varying, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworkbynameandcluster(v_name character varying, v_cluster_id uuid) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT network.*
   FROM network
   WHERE network.name = v_name
   AND EXISTS (SELECT 1
               FROM network_cluster
               WHERE network.id = network_cluster.network_id
               AND   network_cluster.cluster_id = v_cluster_id);

END; ';


ALTER FUNCTION public.getnetworkbynameandcluster(v_name character varying, v_cluster_id uuid) OWNER TO engine;

--
-- Name: getnetworkbynameanddatacenter(character varying, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworkbynameanddatacenter(v_name character varying, v_storage_pool_id uuid) RETURNS SETOF network
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT network.*
   FROM network
   WHERE network.name = v_name
   AND   network.storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getnetworkbynameanddatacenter(v_name character varying, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getnetworkqosbynetworkqosid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworkqosbynetworkqosid(v_id uuid) RETURNS SETOF network_qos
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM network_qos
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.getnetworkqosbynetworkqosid(v_id uuid) OWNER TO engine;

--
-- Name: getnetworksbyiscsibondid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnetworksbyiscsibondid(v_iscsi_bond_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT iscsi_bonds_networks_map.network_id
      FROM iscsi_bonds_networks_map
      WHERE iscsi_bond_id = v_iscsi_bond_id;
END; ';


ALTER FUNCTION public.getnetworksbyiscsibondid(v_iscsi_bond_id uuid) OWNER TO engine;

--
-- Name: getnfsstorage_server_connectionsbystoragepoolid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnfsstorage_server_connectionsbystoragepoolid(v_storage_pool_id uuid) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT distinct storage_server_connections.*
   FROM    storage_server_connections storage_server_connections
   INNER JOIN
   storage_domain_static_view ON
   storage_server_connections.id = storage_domain_static_view.storage
   WHERE     (storage_domain_static_view.storage_pool_id = v_storage_pool_id);
END; ';


ALTER FUNCTION public.getnfsstorage_server_connectionsbystoragepoolid(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getnoncountablequtoavmstatuses(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnoncountablequtoavmstatuses() RETURNS SETOF integer
    LANGUAGE plpgsql IMMUTABLE
    AS '
BEGIN
    RETURN query select 0 union select 13 union select 14 union select 15;
--(Down(0), Suspended(13), ImageIllegal(14), ImageLocked(15))
END; ';


ALTER FUNCTION public.getnoncountablequtoavmstatuses() OWNER TO engine;

--
-- Name: getnumofsnapshotsbymemoryvolume(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnumofsnapshotsbymemoryvolume(v_memory_volume character varying) RETURNS SETOF bigint
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT COUNT(*)
    FROM   snapshots
    WHERE  memory_volume = v_memory_volume;
END; ';


ALTER FUNCTION public.getnumofsnapshotsbymemoryvolume(v_memory_volume character varying) OWNER TO engine;

--
-- Name: getnvmtagsbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnvmtagsbyvmid(v_vm_id uuid) RETURNS SETOF tags_vm_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY select * from tags_vm_map
      where tags_vm_map.vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.getnvmtagsbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: getnvmtagsbyvmidanddefaulttag(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getnvmtagsbyvmidanddefaulttag(v_vm_id uuid) RETURNS SETOF tags_vm_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY select tags_vm_map.* from tags_vm_map
      inner join tags on tags.tag_id = tags_vm_map.tag_id
      where tags_vm_map.vm_id = v_vm_id
      and tags.type = 1;
END; ';


ALTER FUNCTION public.getnvmtagsbyvmidanddefaulttag(v_vm_id uuid) OWNER TO engine;

--
-- Name: getoptionsbyglustervolumeguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getoptionsbyglustervolumeguid(v_volume_id uuid) RETURNS SETOF gluster_volume_options
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_options
    WHERE volume_id = v_volume_id;
END; ';


ALTER FUNCTION public.getoptionsbyglustervolumeguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: getorderedvmguidsforrunmultipleactions(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getorderedvmguidsforrunmultipleactions(v_vm_guids character varying) RETURNS SETOF getorderedvmguidsforrunmultipleactions_rs
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_ordered_guids GetOrderedVmGuidsForRunMultipleActions_rs;
BEGIN
   FOR v_ordered_guids IN EXECUTE ''SELECT vm_guid from vm_static where vm_guid in( '' || v_vm_guids || '' ) AND entity_type = ''''VM''''  order by auto_startup desc,priority desc, migration_support desc'' LOOP
      RETURN NEXT v_ordered_guids;
   END LOOP;

END; ';


ALTER FUNCTION public.getorderedvmguidsforrunmultipleactions(v_vm_guids character varying) OWNER TO engine;

--
-- Name: getovfgeneration(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getovfgeneration(v_vm_id uuid) RETURNS SETOF bigint
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm.ovf_generation
   FROM vm_ovf_generations vm
   WHERE vm.vm_guid = v_vm_id;
END; ';


ALTER FUNCTION public.getovfgeneration(v_vm_id uuid) OWNER TO engine;

--
-- Name: getpermissionbyroleid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionbyroleid(v_role_id uuid) RETURNS SETOF permissions
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   from permissions
   where role_id = v_role_id;
END; ';


ALTER FUNCTION public.getpermissionbyroleid(v_role_id uuid) OWNER TO engine;

--
-- Name: getpermissionsbyadelementid(uuid, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyadelementid(v_ad_element_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE (permissions_view.app_mode & v_app_mode) > 0
   AND (permissions_view.ad_element_id = v_ad_element_id
    OR    ad_element_id IN (SELECT * FROM getUserAndGroupsById(v_ad_element_id)))
   AND (NOT v_is_filtered OR EXISTS (SELECT 1 FROM user_permissions_permissions_view WHERE user_id = v_user_id));

END; ';


ALTER FUNCTION public.getpermissionsbyadelementid(v_ad_element_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) OWNER TO engine;

--
-- Name: getpermissionsbyentityid(uuid, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE  (permissions_view.app_mode & v_app_mode) > 0
   AND object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   GetUserPermissionsByEntityId(v_id, v_user_id, v_is_filtered)));
END; ';


ALTER FUNCTION public.getpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) OWNER TO engine;

--
-- Name: getpermissionsbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyid(v_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getpermissionsbyid(v_id uuid) OWNER TO engine;

--
-- Name: getpermissionsbyroleid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyroleid(v_role_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id;

END; ';


ALTER FUNCTION public.getpermissionsbyroleid(v_role_id uuid) OWNER TO engine;

--
-- Name: getpermissionsbyroleidandadelementid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyroleidandadelementid(v_role_id uuid, v_ad_element_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and ad_element_id = v_ad_element_id;

END; ';


ALTER FUNCTION public.getpermissionsbyroleidandadelementid(v_role_id uuid, v_ad_element_id uuid) OWNER TO engine;

--
-- Name: getpermissionsbyroleidandadelementidandobjectid(uuid, uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyroleidandadelementidandobjectid(v_role_id uuid, v_ad_element_id uuid, v_object_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and ad_element_id = v_ad_element_id and object_id = v_object_id;

END; ';


ALTER FUNCTION public.getpermissionsbyroleidandadelementidandobjectid(v_role_id uuid, v_ad_element_id uuid, v_object_id uuid) OWNER TO engine;

--
-- Name: getpermissionsbyroleidandobjectid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionsbyroleidandobjectid(v_role_id uuid, v_object_id uuid) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and object_id = v_object_id;

END; ';


ALTER FUNCTION public.getpermissionsbyroleidandobjectid(v_role_id uuid, v_object_id uuid) OWNER TO engine;

--
-- Name: getpermissionstreebyentityid(uuid, integer, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpermissionstreebyentityid(v_id uuid, v_object_type_id integer, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM   permissions_view p
   WHERE  (p.app_mode & v_app_mode) > 0
   AND  object_id in(select id from  fn_get_entity_parents(v_id,v_object_type_id))
   AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_flat_groups u
                                        WHERE  p.ad_element_id = u.granted_id
                                        AND    u.user_id       = v_user_id));

END; ';


ALTER FUNCTION public.getpermissionstreebyentityid(v_id uuid, v_object_type_id integer, v_user_id uuid, v_is_filtered boolean, v_app_mode integer) OWNER TO engine;

--
-- Name: getpluggedvminterfacesbymac(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpluggedvminterfacesbymac(v_mac_address character varying) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE mac_addr = v_mac_address
   AND is_plugged = true;
END; ';


ALTER FUNCTION public.getpluggedvminterfacesbymac(v_mac_address character varying) OWNER TO engine;

--
-- Name: getpolicyunitbypolicyunitid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getpolicyunitbypolicyunitid(v_id uuid) RETURNS SETOF policy_units
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   policy_units
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.getpolicyunitbypolicyunitid(v_id uuid) OWNER TO engine;

--
-- Name: getproviderbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getproviderbyname(v_name character varying) RETURNS SETOF providers
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE  name = v_name;
END; ';


ALTER FUNCTION public.getproviderbyname(v_name character varying) OWNER TO engine;

--
-- Name: getproviderbyproviderid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getproviderbyproviderid(v_id uuid) RETURNS SETOF providers
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.getproviderbyproviderid(v_id uuid) OWNER TO engine;

--
-- Name: getquotabyadelementid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotabyadelementid(v_ad_element_id uuid, v_storage_pool_id uuid, v_recursive boolean) RETURNS SETOF quota_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT * FROM quota_view WHERE quota_view.quota_id IN
   (SELECT object_id
    FROM PERMISSIONS
    WHERE object_type_id = 17
    AND role_id in (SELECT role_id FROM ROLES_groups where action_group_id = 901)
    AND ad_element_id = v_ad_element_id OR
        (v_recursive AND ad_element_id IN (SELECT * FROM getUserAndGroupsById(v_ad_element_id))))
    AND (v_storage_pool_id = quota_view.storage_pool_id or v_storage_pool_id IS NULL);
  END; ';


ALTER FUNCTION public.getquotabyadelementid(v_ad_element_id uuid, v_storage_pool_id uuid, v_recursive boolean) OWNER TO engine;

--
-- Name: quota_limitation; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE quota_limitation (
    id uuid NOT NULL,
    quota_id uuid NOT NULL,
    storage_id uuid,
    vds_group_id uuid,
    virtual_cpu integer,
    mem_size_mb bigint,
    storage_size_gb bigint
);


ALTER TABLE public.quota_limitation OWNER TO engine;

--
-- Name: quota_global_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW quota_global_view AS
    SELECT q_limit.quota_id, q.storage_pool_id, storage_pool.name AS storage_pool_name, q.quota_name, q.description, q.threshold_vds_group_percentage, q.threshold_storage_percentage, q.grace_vds_group_percentage, q.grace_storage_percentage, q_limit.virtual_cpu, (calculatevdsgroupusage(q_limit.quota_id, NULL::uuid)).virtual_cpu_usage AS virtual_cpu_usage, q_limit.mem_size_mb, (calculatevdsgroupusage(q_limit.quota_id, NULL::uuid)).mem_size_mb_usage AS mem_size_mb_usage, q_limit.storage_size_gb, calculatestorageusage(q_limit.quota_id, NULL::uuid) AS storage_size_gb_usage, storage_pool.quota_enforcement_type FROM storage_pool, (quota q LEFT JOIN quota_limitation q_limit ON ((q_limit.quota_id = q.id))) WHERE (((storage_pool.id = q.storage_pool_id) AND (q_limit.vds_group_id IS NULL)) AND (q_limit.storage_id IS NULL));


ALTER TABLE public.quota_global_view OWNER TO engine;

--
-- Name: getquotabyquotaguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotabyquotaguid(v_id uuid) RETURNS SETOF quota_global_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM quota_global_view
   WHERE quota_id = v_id;
END; ';


ALTER FUNCTION public.getquotabyquotaguid(v_id uuid) OWNER TO engine;

--
-- Name: getquotabyquotaname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotabyquotaname(v_quota_name character varying) RETURNS SETOF quota_global_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM quota_global_view
   WHERE quota_name = v_quota_name;
END; ';


ALTER FUNCTION public.getquotabyquotaname(v_quota_name character varying) OWNER TO engine;

--
-- Name: getquotabystoragepoolguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotabystoragepoolguid(v_storage_pool_id uuid) RETURNS SETOF quota_global_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM  quota_global_view
   WHERE (storage_pool_id = v_storage_pool_id or v_storage_pool_id IS NULL);
END; ';


ALTER FUNCTION public.getquotabystoragepoolguid(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getquotacount(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotacount() RETURNS SETOF bigint
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT count(*) as num_quota
    FROM quota;
END; ';


ALTER FUNCTION public.getquotacount() OWNER TO engine;

--
-- Name: quota_storage_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW quota_storage_view AS
    SELECT q_limit.id AS quota_storage_id, q_limit.quota_id, q_limit.storage_id, storage_domain_static.storage_name, q_limit.storage_size_gb, calculatestorageusage(q_limit.quota_id, q_limit.storage_id) AS storage_size_gb_usage FROM quota_limitation q_limit, quota q, storage_domain_static WHERE ((((q_limit.quota_id = q.id) AND (q_limit.vds_group_id IS NULL)) AND (q_limit.storage_id IS NOT NULL)) AND (storage_domain_static.id = q_limit.storage_id));


ALTER TABLE public.quota_storage_view OWNER TO engine;

--
-- Name: getquotastoragebyquotaguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotastoragebyquotaguid(v_id uuid) RETURNS SETOF quota_storage_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM  quota_storage_view
   WHERE quota_id = v_id;
END; ';


ALTER FUNCTION public.getquotastoragebyquotaguid(v_id uuid) OWNER TO engine;

--
-- Name: getquotastoragebystorageguid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotastoragebystorageguid(v_storage_id uuid, v_id uuid, v_allow_empty boolean) RETURNS SETOF quota_storage_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM
   (SELECT  COALESCE(q_storage_view.quota_storage_id, q_g_view.quota_id) as quota_storage_id,
            q_g_view.quota_id as quota_id,
            q_storage_view.storage_id,
            q_storage_view.storage_name,
            COALESCE(q_storage_view.storage_size_gb, q_g_view.storage_size_gb) as storage_size_gb,
            COALESCE(q_storage_view.storage_size_gb_usage, q_g_view.storage_size_gb_usage) as storage_size_gb_usage
    FROM  quota_global_view q_g_view
    LEFT OUTER JOIN quota_storage_view q_storage_view ON q_g_view.quota_id = q_storage_view.quota_id
    AND  (v_storage_id = q_storage_view.storage_id OR v_storage_id IS NULL)
   WHERE q_g_view.quota_id = v_id) sub
   WHERE (v_allow_empty OR storage_size_gb IS NOT NULL);
END; ';


ALTER FUNCTION public.getquotastoragebystorageguid(v_storage_id uuid, v_id uuid, v_allow_empty boolean) OWNER TO engine;

--
-- Name: quota_vds_group_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW quota_vds_group_view AS
    SELECT q_limit.id AS quota_vds_group_id, q_limit.quota_id, q_limit.vds_group_id, vds_groups.name AS vds_group_name, q_limit.virtual_cpu, (calculatevdsgroupusage(q_limit.quota_id, q_limit.vds_group_id)).virtual_cpu_usage AS virtual_cpu_usage, q_limit.mem_size_mb, (calculatevdsgroupusage(q_limit.quota_id, q_limit.vds_group_id)).mem_size_mb_usage AS mem_size_mb_usage FROM quota_limitation q_limit, quota q, vds_groups WHERE ((((q_limit.quota_id = q.id) AND (q_limit.vds_group_id IS NOT NULL)) AND (q_limit.storage_id IS NULL)) AND (vds_groups.vds_group_id = q_limit.vds_group_id));


ALTER TABLE public.quota_vds_group_view OWNER TO engine;

--
-- Name: getquotavdsgroupbyquotaguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotavdsgroupbyquotaguid(v_id uuid) RETURNS SETOF quota_vds_group_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT quota_vds_group_view.*
   FROM  quota_vds_group_view
   WHERE quota_id = v_id;
END; ';


ALTER FUNCTION public.getquotavdsgroupbyquotaguid(v_id uuid) OWNER TO engine;

--
-- Name: getquotavdsgroupbyvdsgroupguid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getquotavdsgroupbyvdsgroupguid(v_vds_group_id uuid, v_id uuid, v_allow_empty boolean) RETURNS SETOF quota_vds_group_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM (SELECT COALESCE(q_vds_view.quota_vds_group_id, q_g_view.quota_id) as quota_vds_group_id,
                q_g_view.quota_id as quota_id,
                q_vds_view.vds_group_id as vds_group_id,
                q_vds_view.vds_group_name as vds_group_name,
                COALESCE(q_vds_view.virtual_cpu,q_g_view.virtual_cpu) as virtual_cpu,
                COALESCE(q_vds_view.virtual_cpu_usage, q_g_view.virtual_cpu_usage) as virtual_cpu_usage,
                COALESCE(q_vds_view.mem_size_mb,q_g_view.mem_size_mb) as mem_size_mb,
                COALESCE(q_vds_view.mem_size_mb_usage, q_g_view.mem_size_mb_usage) as mem_size_mb_usage
         FROM   quota_global_view q_g_view
         LEFT OUTER JOIN quota_vds_group_view q_vds_view ON q_g_view.quota_id = q_vds_view.quota_id
         AND   (v_vds_group_id = q_vds_view.vds_group_id OR v_vds_group_id IS NULL)
         WHERE q_g_view.quota_id = v_id) sub
   WHERE v_allow_empty OR virtual_cpu IS NOT NULL OR mem_size_mb IS NOT NULL;
END; ';


ALTER FUNCTION public.getquotavdsgroupbyvdsgroupguid(v_vds_group_id uuid, v_id uuid, v_allow_empty boolean) OWNER TO engine;

--
-- Name: repo_file_meta_data; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE repo_file_meta_data (
    repo_domain_id uuid NOT NULL,
    repo_image_id character varying(256) NOT NULL,
    size bigint DEFAULT 0,
    date_created timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    last_refreshed bigint DEFAULT 0,
    file_type integer DEFAULT 0,
    repo_image_name character varying(256)
);


ALTER TABLE public.repo_file_meta_data OWNER TO engine;

--
-- Name: getrepo_files_by_storage_domain(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getrepo_files_by_storage_domain(v_storage_domain_id uuid, v_file_type integer DEFAULT NULL::integer) RETURNS SETOF repo_file_meta_data
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT repo_file_meta_data.*
   FROM repo_file_meta_data
   WHERE repo_domain_id = v_storage_domain_id
   AND (v_file_type IS NULL OR repo_file_meta_data.file_type = v_file_type)
   ORDER BY repo_file_meta_data.last_refreshed;
END; ';


ALTER FUNCTION public.getrepo_files_by_storage_domain(v_storage_domain_id uuid, v_file_type integer) OWNER TO engine;

--
-- Name: getrepo_files_in_all_storage_pools(integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getrepo_files_in_all_storage_pools(v_storage_domain_type integer, v_storage_pool_status integer, v_vds_status integer, v_storage_domain_status integer) RETURNS SETOF getrepo_files_in_all_storage_pools_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
 RETURN QUERY SELECT distinct b.storage_domain_id,c.last_refreshed,b.file_type
   FROM storage_domain_file_repos b
   LEFT OUTER JOIN
   (SELECT storage_domain_id,file_type,min(last_refreshed) as last_refreshed
      FROM storage_domain_file_repos a
   	  Group by storage_domain_id,file_type) as c ON b.storage_domain_id = c.storage_domain_id
                                                 AND b.file_type = c.file_type
   WHERE b.storage_domain_type = v_storage_domain_type
     and b.storage_pool_status = v_storage_pool_status
     and b.storage_domain_status = v_storage_domain_status
	 and b.vds_status = v_vds_status;
END; ';


ALTER FUNCTION public.getrepo_files_in_all_storage_pools(v_storage_domain_type integer, v_storage_pool_status integer, v_vds_status integer, v_storage_domain_status integer) OWNER TO engine;

--
-- Name: getroleactiongroupsbyroleid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getroleactiongroupsbyroleid(v_id uuid) RETURNS SETOF roles_groups
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   WHERE role_id = v_id;
END; ';


ALTER FUNCTION public.getroleactiongroupsbyroleid(v_id uuid) OWNER TO engine;

--
-- Name: getrolebyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getrolebyname(v_name character varying) RETURNS SETOF roles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE name = v_name;

END; ';


ALTER FUNCTION public.getrolebyname(v_name character varying) OWNER TO engine;

--
-- Name: getrolsbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getrolsbyid(v_id uuid) RETURNS SETOF roles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getrolsbyid(v_id uuid) OWNER TO engine;

--
-- Name: getrunningvmsbyclusterid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getrunningvmsbyclusterid(v_cluster_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT DISTINCT vms.*
    FROM vms
    WHERE run_on_vds IS NOT NULL AND
        vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.getrunningvmsbyclusterid(v_cluster_id uuid) OWNER TO engine;

--
-- Name: getsnapshotbyguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotbyguid(v_image_guid uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.getsnapshotbyguid(v_image_guid uuid) OWNER TO engine;

--
-- Name: getsnapshotbyparentguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotbyparentguid(v_parent_guid uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE ParentId = v_parent_guid;
END; ';


ALTER FUNCTION public.getsnapshotbyparentguid(v_parent_guid uuid) OWNER TO engine;

--
-- Name: getsnapshotbysnapshotid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotbysnapshotid(v_snapshot_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF snapshots
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  snapshot_id = v_snapshot_id AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = (SELECT vm_id
                                        FROM snapshots where snapshot_id = v_snapshot_id)));
END; ';


ALTER FUNCTION public.getsnapshotbysnapshotid(v_snapshot_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getsnapshotbyvmidandtype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) RETURNS SETOF snapshots
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    ORDER BY creation_date ASC
    LIMIT 1;
END; ';


ALTER FUNCTION public.getsnapshotbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) OWNER TO engine;

--
-- Name: getsnapshotbyvmidandtypeandstatus(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotbyvmidandtypeandstatus(v_vm_id uuid, v_snapshot_type character varying, v_status character varying) RETURNS SETOF snapshots
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    AND    status = v_status
    ORDER BY creation_date ASC
    LIMIT 1;
END; ';


ALTER FUNCTION public.getsnapshotbyvmidandtypeandstatus(v_vm_id uuid, v_snapshot_type character varying, v_status character varying) OWNER TO engine;

--
-- Name: getsnapshotidsbyvmidandtype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotidsbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT snapshot_id
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    ORDER BY creation_date ASC;
END; ';


ALTER FUNCTION public.getsnapshotidsbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) OWNER TO engine;

--
-- Name: getsnapshotidsbyvmidandtypeandstatus(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotidsbyvmidandtypeandstatus(v_vm_id uuid, v_snapshot_type character varying, v_status character varying) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT snapshot_id
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    AND    status = v_status
    ORDER BY creation_date ASC;
END; ';


ALTER FUNCTION public.getsnapshotidsbyvmidandtypeandstatus(v_vm_id uuid, v_snapshot_type character varying, v_status character varying) OWNER TO engine;

--
-- Name: getsnapshotsbyimagegroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotsbyimagegroupid(v_image_group_id uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE image_group_id = v_image_group_id;
END; ';


ALTER FUNCTION public.getsnapshotsbyimagegroupid(v_image_group_id uuid) OWNER TO engine;

--
-- Name: getsnapshotsbystoragedomainid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotsbystoragedomainid(v_storage_domain_id uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE storage_id = v_storage_domain_id;
END; ';


ALTER FUNCTION public.getsnapshotsbystoragedomainid(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: getsnapshotsbyvmsnapshotid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsnapshotsbyvmsnapshotid(v_vm_snapshot_id uuid) RETURNS SETOF images_storage_domain_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE vm_snapshot_id = v_vm_snapshot_id;
END; ';


ALTER FUNCTION public.getsnapshotsbyvmsnapshotid(v_vm_snapshot_id uuid) OWNER TO engine;

--
-- Name: getstepbystepid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstepbystepid(v_step_id uuid) RETURNS SETOF step
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE step_id = v_step_id;
END; ';


ALTER FUNCTION public.getstepbystepid(v_step_id uuid) OWNER TO engine;

--
-- Name: getstepsbyexternaltaskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstepsbyexternaltaskid(v_external_id uuid) RETURNS SETOF step
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE external_id = v_external_id
    ORDER BY parent_step_id nulls first, step_number;
END; ';


ALTER FUNCTION public.getstepsbyexternaltaskid(v_external_id uuid) OWNER TO engine;

--
-- Name: getstepsbyjobid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstepsbyjobid(v_job_id uuid) RETURNS SETOF step
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE job_id = v_job_id
    ORDER BY parent_step_id nulls first, step_number;
END; ';


ALTER FUNCTION public.getstepsbyjobid(v_job_id uuid) OWNER TO engine;

--
-- Name: getstepsbyparentstepid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstepsbyparentstepid(v_parent_step_id uuid) RETURNS SETOF step
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE parent_step_id = v_parent_step_id
    ORDER BY step_number;
END; ';


ALTER FUNCTION public.getstepsbyparentstepid(v_parent_step_id uuid) OWNER TO engine;

--
-- Name: getstorage_domain_by_type_and_storagepoolid(integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domain_by_type_and_storagepoolid(v_storage_domain_type integer, v_storage_pool_id uuid) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND storage_domain_type = v_storage_domain_type;
END; ';


ALTER FUNCTION public.getstorage_domain_by_type_and_storagepoolid(v_storage_domain_type integer, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_domain_dynamicbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domain_dynamicbyid(v_id uuid) RETURNS SETOF storage_domain_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_dynamic
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getstorage_domain_dynamicbyid(v_id uuid) OWNER TO engine;

--
-- Name: getstorage_domain_staticbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domain_staticbyid(v_id uuid) RETURNS SETOF storage_domain_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getstorage_domain_staticbyid(v_id uuid) OWNER TO engine;

--
-- Name: getstorage_domain_staticbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domain_staticbyname(v_name character varying) RETURNS SETOF storage_domain_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static
   WHERE storage_name = v_name;

END; ';


ALTER FUNCTION public.getstorage_domain_staticbyname(v_name character varying) OWNER TO engine;

--
-- Name: getstorage_domain_staticbystorage_pool_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domain_staticbystorage_pool_id(v_storage_pool_id uuid) RETURNS SETOF storage_domain_static_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static_view
   WHERE storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getstorage_domain_staticbystorage_pool_id(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_domains_by_connection(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_connection(v_connection character varying) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage IN (
      SELECT id
      FROM storage_server_connections
      WHERE connection = v_connection);

END; ';


ALTER FUNCTION public.getstorage_domains_by_connection(v_connection character varying) OWNER TO engine;

--
-- Name: storage_domains_without_storage_pools; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domains_without_storage_pools AS
    SELECT DISTINCT storage_domain_static.id, storage_domain_static.storage, storage_domain_static.storage_name, storage_domain_static.storage_description, storage_domain_static.storage_comment, storage_domain_static.storage_type, storage_domain_static.storage_domain_type, storage_domain_static.storage_domain_format_type, storage_domain_static.last_time_used_as_master, NULL::text AS storage_pool_id, NULL::text AS storage_pool_name, storage_domain_dynamic.available_disk_size, storage_domain_dynamic.used_disk_size, fn_get_disk_commited_value_by_storage(storage_domain_static.id) AS commited_disk_size, fn_get_actual_images_size_by_storage(storage_domain_static.id) AS actual_images_size, NULL::text AS status, fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, storage_pool_iso_map.status, storage_domain_static.storage_domain_type) AS storage_domain_shared_status, storage_domain_static.recoverable FROM ((storage_domain_static JOIN storage_domain_dynamic ON ((storage_domain_static.id = storage_domain_dynamic.id))) LEFT JOIN storage_pool_iso_map ON ((storage_domain_static.id = storage_pool_iso_map.storage_id)));


ALTER TABLE public.storage_domains_without_storage_pools OWNER TO engine;

--
-- Name: getstorage_domains_by_id(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_id(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF storage_domains_without_storage_pools
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains_without_storage_pools
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_id));

END; ';


ALTER FUNCTION public.getstorage_domains_by_id(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getstorage_domains_by_id_and_by_storage_pool_id(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_id_and_by_storage_pool_id(v_id uuid, v_storage_pool_id uuid) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE id = v_id and storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getstorage_domains_by_id_and_by_storage_pool_id(v_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_domains_by_storage_pool_id_and_connection(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_storage_pool_id_and_connection(v_storage_pool_id uuid, v_connection character varying) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND storage IN (
      SELECT id
      FROM storage_server_connections
      WHERE connection = v_connection);
END; ';


ALTER FUNCTION public.getstorage_domains_by_storage_pool_id_and_connection(v_storage_pool_id uuid, v_connection character varying) OWNER TO engine;

--
-- Name: getstorage_domains_by_storage_pool_id_with_permitted_action(uuid, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_storage_pool_id_with_permitted_action(v_user_id uuid, v_action_group_id integer, v_storage_pool_id uuid) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND (SELECT get_entity_permissions(v_user_id, v_action_group_id, id, 11)) IS NOT NULL;

END; ';


ALTER FUNCTION public.getstorage_domains_by_storage_pool_id_with_permitted_action(v_user_id uuid, v_action_group_id integer, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_domains_by_storagepoolid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_by_storagepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = id));



END; ';


ALTER FUNCTION public.getstorage_domains_by_storagepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getstorage_domains_list_by_imageid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_list_by_imageid(v_image_id uuid) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY SELECT *
    FROM storage_domains
    WHERE id in (SELECT storage_domain_id
                 FROM image_storage_domain_map
                 WHERE image_id = v_image_id);
END; ';


ALTER FUNCTION public.getstorage_domains_list_by_imageid(v_image_id uuid) OWNER TO engine;

--
-- Name: getstorage_domains_list_by_storagedomainid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_domains_list_by_storagedomainid(v_storage_domain_id uuid) RETURNS SETOF storage_domains
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_domains.id = v_storage_domain_id;

END; ';


ALTER FUNCTION public.getstorage_domains_list_by_storagedomainid(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: getstorage_pool_iso_mapbystorage_idandbystorage_pool_id(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_pool_iso_mapbystorage_idandbystorage_pool_id(v_storage_id uuid, v_storage_pool_id uuid) RETURNS SETOF storage_pool_iso_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id AND storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getstorage_pool_iso_mapbystorage_idandbystorage_pool_id(v_storage_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_pool_iso_mapsbybystorage_pool_id(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_pool_iso_mapsbybystorage_pool_id(v_storage_id uuid, v_storage_pool_id uuid) RETURNS SETOF storage_pool_iso_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getstorage_pool_iso_mapsbybystorage_pool_id(v_storage_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getstorage_pool_iso_mapsbystorage_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_pool_iso_mapsbystorage_id(v_storage_id uuid) RETURNS SETOF storage_pool_iso_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id;

END; ';


ALTER FUNCTION public.getstorage_pool_iso_mapsbystorage_id(v_storage_id uuid) OWNER TO engine;

--
-- Name: getstorage_poolbyid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_poolbyid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_pool_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_id));



END; ';


ALTER FUNCTION public.getstorage_poolbyid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getstorage_poolbyname(character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_poolbyname(v_name character varying, v_is_case_sensitive boolean) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE name = v_name OR (NOT v_is_case_sensitive AND name ilike v_name);
END; ';


ALTER FUNCTION public.getstorage_poolbyname(v_name character varying, v_is_case_sensitive boolean) OWNER TO engine;

--
-- Name: getstorage_poolsbystoragedomainid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_poolsbystoragedomainid(v_storage_domain_id uuid) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT storage_pool.*
   FROM storage_pool
   inner join storage_pool_iso_map on storage_pool.id = storage_pool_iso_map.storage_pool_id
   WHERE storage_pool_iso_map.storage_id = v_storage_domain_id;

END; ';


ALTER FUNCTION public.getstorage_poolsbystoragedomainid(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: getstorage_poolsbyvdsgroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_poolsbyvdsgroupid(v_clusterid uuid) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE storage_pool.id in(select storage_pool_id
      FROM vds_groups
      WHERE vds_group_id = v_clusterId);

END; ';


ALTER FUNCTION public.getstorage_poolsbyvdsgroupid(v_clusterid uuid) OWNER TO engine;

--
-- Name: getstorage_poolsbyvdsid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_poolsbyvdsid(v_vdsid uuid) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_clusterId  UUID;
BEGIN
select   vds_group_id INTO v_clusterId FROM Vds_static WHERE vds_id = v_vdsId;
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE storage_pool.id in(select storage_pool_id
      FROM vds_groups
      WHERE vds_group_id = v_clusterId);

END; ';


ALTER FUNCTION public.getstorage_poolsbyvdsid(v_vdsid uuid) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbyconnection(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbyconnection(v_connection character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE connection = v_connection;

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbyconnection(v_connection character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbyid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbyid(v_id character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbyid(v_id character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbyiqn(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbyiqn(v_iqn character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE iqn = v_iqn;

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbyiqn(v_iqn character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbyiqnandconnection(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbyiqnandconnection(v_iqn character varying, v_connection character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE iqn = v_iqn and (connection = v_connection or connection is NULL);

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbyiqnandconnection(v_iqn character varying, v_connection character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbykey(character varying, character varying, character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbykey(v_iqn character varying, v_connection character varying, v_port character varying, v_portal character varying, v_username character varying, v_password character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE (iqn = v_iqn or iqn is NULL) and
			(connection = v_connection) and
			(port = v_port or port is NULL) and
			(portal = v_portal or portal is NULL) and
			(user_name = v_username or user_name is NULL) and
			(password = v_password or password is NULL);

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbykey(v_iqn character varying, v_connection character varying, v_port character varying, v_portal character varying, v_username character varying, v_password character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbylunid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbylunid(v_lunid character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT storage_server_connections.*
   FROM  storage_server_connections storage_server_connections
   INNER JOIN lun_storage_server_connection_map ON
   lun_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (lun_storage_server_connection_map.lun_id = v_lunId);
END; ';


ALTER FUNCTION public.getstorage_server_connectionsbylunid(v_lunid character varying) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbystoragetype(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbystoragetype(v_storage_type integer) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE storage_type = v_storage_type;

END; ';


ALTER FUNCTION public.getstorage_server_connectionsbystoragetype(v_storage_type integer) OWNER TO engine;

--
-- Name: getstorage_server_connectionsbyvolumegroupid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorage_server_connectionsbyvolumegroupid(v_volume_group_id character varying) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT storage_server_connections.*
   FROM
   LUN_storage_server_connection_map  LUN_storage_server_connection_map
   INNER JOIN
   LUNs ON LUN_storage_server_connection_map.LUN_id = LUNs.LUN_id INNER JOIN
   storage_domain_static ON LUNs.volume_group_id = storage_domain_static.storage INNER JOIN
   storage_server_connections ON
   LUN_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (storage_domain_static.storage = v_volume_group_id);
END; ';


ALTER FUNCTION public.getstorage_server_connectionsbyvolumegroupid(v_volume_group_id character varying) OWNER TO engine;

--
-- Name: getstoragedomainidsbystoragepoolidandstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstoragedomainidsbystoragepoolidandstatus(v_storage_pool_id uuid, v_status integer) RETURNS SETOF getstoragedomainidsbystoragepoolidandstatus_rs
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
   SELECT storage_id
   FROM   storage_pool_iso_map
   WHERE  storage_pool_id = v_storage_pool_id
   AND    status = v_status;

END; ';


ALTER FUNCTION public.getstoragedomainidsbystoragepoolidandstatus(v_storage_pool_id uuid, v_status integer) OWNER TO engine;

--
-- Name: getstoragepoolsbyclusterservice(boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstoragepoolsbyclusterservice(v_supports_virt_service boolean, v_supports_gluster_service boolean) RETURNS SETOF storage_pool
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT sp.* FROM storage_pool SP
   WHERE EXISTS (SELECT 1 FROM vds_groups vg
       WHERE ((v_supports_virt_service = TRUE AND vg.virt_service = TRUE) OR
              (v_supports_gluster_service = TRUE AND vg.gluster_service = TRUE)) AND vg.storage_pool_id = sp.id);
END; ';


ALTER FUNCTION public.getstoragepoolsbyclusterservice(v_supports_virt_service boolean, v_supports_gluster_service boolean) OWNER TO engine;

--
-- Name: getstorageserverconnectionsbyids(text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorageserverconnectionsbyids(v_ids text) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections WHERE id = any(string_to_array(v_ids,'','')::VARCHAR[]);
END; ';


ALTER FUNCTION public.getstorageserverconnectionsbyids(v_ids text) OWNER TO engine;

--
-- Name: getstorageserverconnectionsfordomain(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getstorageserverconnectionsfordomain(v_storage_domain_id uuid) RETURNS SETOF storage_server_connections
    LANGUAGE plpgsql STABLE
    AS '
 BEGIN
RETURN QUERY SELECT *
FROM storage_server_connections
WHERE EXISTS  ( SELECT 1
		FROM    storage_domain_static
		WHERE   storage_domain_static.id = v_storage_domain_id
		AND     storage_domain_static.storage_type in (1,4,6) -- file storage domains - nfs,posix,local
		AND     storage_server_connections.id  = storage_domain_static.storage
		UNION ALL
		SELECT 1
		FROM   storage_domain_static
		JOIN   luns ON storage_domain_static.storage  = luns.volume_group_id
		JOIN   lun_storage_server_connection_map ON  luns.lun_id = lun_storage_server_connection_map.lun_id
							 AND storage_server_connections.id  = lun_storage_server_connection_map.storage_server_connection
		WHERE  storage_domain_static.id = v_storage_domain_id
		AND    storage_domain_static.storage_type = 3  -- storage type = iscsi
		);
END; ';


ALTER FUNCTION public.getstorageserverconnectionsfordomain(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: getsystem_statistics(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getsystem_statistics(v_entity character varying, v_status character varying) RETURNS getsystem_statistics_rs
    LANGUAGE plpgsql STABLE
    AS '
   DECLARE
   v_i Getsystem_statistics_rs;
   v_sql  VARCHAR(4000);
   v_sys_entity VARCHAR(10);
BEGIN
   v_sql := NULL;

   v_sys_entity := upper(v_entity);
   if v_sys_entity = ''VM'' then
      v_sql := ''select count(vm_guid) from vm_dynamic'';
   elsif v_sys_entity = ''HOST'' then
      v_sql := ''select count(vds_id) from vds_dynamic'';
   elsif v_sys_entity = ''USER'' then
      v_sql := ''select count(user_id) from users'';
   elsif v_sys_entity = ''TSD'' then
      v_sql := ''select count(id) from storage_domain_static'';
   elsif v_sys_entity = ''ASD'' then
      v_sql := ''select count(storage_id) from storage_pool_iso_map'';
   else
      raise ''Unknown entity type "%"'', v_entity;
   end if;

   if v_status != '''' then
      if v_sys_entity = ''USER'' then
          v_sql := coalesce(v_sql, '''') || '' where active::integer in ('' || coalesce(v_status, '''') || '')'';
      elsif v_sys_entity != ''TSD'' then
          v_sql := coalesce(v_sql, '''') || '' where status in ('' || coalesce(v_status, '''') || '')'';
      end if;
   end if;
   EXECUTE v_sql INTO v_i;
   RETURN v_i;
END; ';


ALTER FUNCTION public.getsystem_statistics(v_entity character varying, v_status character varying) OWNER TO engine;

--
-- Name: gettags_vm_pool_mapbytag_idandbyvm_pool_id(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettags_vm_pool_mapbytag_idandbyvm_pool_id(v_tag_id uuid, v_vm_pool_id uuid) RETURNS SETOF tags_vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT tags_vm_pool_map.*
   FROM tags_vm_pool_map
   WHERE tag_id = v_tag_id AND vm_pool_id = v_vm_pool_id;

END; ';


ALTER FUNCTION public.gettags_vm_pool_mapbytag_idandbyvm_pool_id(v_tag_id uuid, v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: gettagsbyparent_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyparent_id(v_parent_id uuid) RETURNS SETOF tags
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE parent_id = v_parent_id;
END; ';


ALTER FUNCTION public.gettagsbyparent_id(v_parent_id uuid) OWNER TO engine;

--
-- Name: gettagsbytag_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbytag_id(v_tag_id uuid) RETURNS SETOF tags
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE tag_id = v_tag_id;
END; ';


ALTER FUNCTION public.gettagsbytag_id(v_tag_id uuid) OWNER TO engine;

--
-- Name: gettagsbytag_name(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbytag_name(v_tag_name character varying) RETURNS SETOF tags
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE tag_name = v_tag_name;
END; ';


ALTER FUNCTION public.gettagsbytag_name(v_tag_name character varying) OWNER TO engine;

--
-- Name: tags_user_group_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW tags_user_group_map_view AS
    SELECT tags.tag_id, tags.tag_name, tags.parent_id, tags.readonly, tags.type, tags_user_group_map.group_id FROM (tags_user_group_map JOIN tags ON ((tags_user_group_map.tag_id = tags.tag_id)));


ALTER TABLE public.tags_user_group_map_view OWNER TO engine;

--
-- Name: gettagsbyusergroupid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyusergroupid(v_group_ids character varying) RETURNS SETOF tags_user_group_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_group_map_view.*
      FROM tags_user_group_map_view
      WHERE group_id in(select * from fnSplitterUuid(v_group_ids));
END; ';


ALTER FUNCTION public.gettagsbyusergroupid(v_group_ids character varying) OWNER TO engine;

--
-- Name: tags_user_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW tags_user_map_view AS
    SELECT tags.tag_id, tags.tag_name, tags.parent_id, tags.readonly, tags.type, tags_user_map.user_id FROM (tags JOIN tags_user_map ON ((tags.tag_id = tags_user_map.tag_id)));


ALTER TABLE public.tags_user_map_view OWNER TO engine;

--
-- Name: gettagsbyuserid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyuserid(v_user_ids character varying) RETURNS SETOF tags_user_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_map_view.*
      FROM tags_user_map_view
      WHERE user_id in(select * from fnSplitterUuid(v_user_ids));
END; ';


ALTER FUNCTION public.gettagsbyuserid(v_user_ids character varying) OWNER TO engine;

--
-- Name: tags_vds_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW tags_vds_map_view AS
    SELECT tags.tag_id, tags.tag_name, tags.parent_id, tags.readonly, tags.type, tags_vds_map.vds_id FROM (tags JOIN tags_vds_map ON ((tags.tag_id = tags_vds_map.tag_id)));


ALTER TABLE public.tags_vds_map_view OWNER TO engine;

--
-- Name: gettagsbyvdsid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyvdsid(v_vds_ids character varying) RETURNS SETOF tags_vds_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vds_map_view.*
      FROM tags_vds_map_view
      WHERE vds_id in(select * from fnSplitterUuid(v_vds_ids));
END; ';


ALTER FUNCTION public.gettagsbyvdsid(v_vds_ids character varying) OWNER TO engine;

--
-- Name: tags_vm_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW tags_vm_map_view AS
    SELECT tags.tag_id, tags.tag_name, tags.parent_id, tags.readonly, tags.type, tags_vm_map.vm_id FROM (tags JOIN tags_vm_map ON ((tags.tag_id = tags_vm_map.tag_id)));


ALTER TABLE public.tags_vm_map_view OWNER TO engine;

--
-- Name: gettagsbyvmid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyvmid(v_vm_ids character varying) RETURNS SETOF tags_vm_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_map_view.*
      FROM tags_vm_map_view
      WHERE vm_id in(select * from fnSplitterUuid(v_vm_ids));
END; ';


ALTER FUNCTION public.gettagsbyvmid(v_vm_ids character varying) OWNER TO engine;

--
-- Name: tags_vm_pool_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW tags_vm_pool_map_view AS
    SELECT tags.tag_id, tags.tag_name, tags.parent_id, tags.readonly, tags.type, tags_vm_pool_map.vm_pool_id FROM (tags JOIN tags_vm_pool_map ON ((tags.tag_id = tags_vm_pool_map.tag_id)));


ALTER TABLE public.tags_vm_pool_map_view OWNER TO engine;

--
-- Name: gettagsbyvmpoolid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagsbyvmpoolid(v_vm_pool_ids character varying) RETURNS SETOF tags_vm_pool_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_pool_map_view.*
      FROM tags_vm_pool_map_view
      WHERE vm_pool_id in(select * from fnSplitterUuid(v_vm_pool_ids));
END; ';


ALTER FUNCTION public.gettagsbyvmpoolid(v_vm_pool_ids character varying) OWNER TO engine;

--
-- Name: gettaguserbytagidandbyuserid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettaguserbytagidandbyuserid(v_tag_id uuid, v_user_id uuid) RETURNS SETOF tags_user_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_user_map.*
      FROM tags_user_map
      WHERE tag_id = v_tag_id AND user_id = v_user_id;
END; ';


ALTER FUNCTION public.gettaguserbytagidandbyuserid(v_tag_id uuid, v_user_id uuid) OWNER TO engine;

--
-- Name: gettagusergroupbygroupidandbytagid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagusergroupbygroupidandbytagid(v_group_id uuid, v_tag_id uuid) RETURNS SETOF tags_user_group_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_user_group_map.*
      FROM tags_user_group_map
      WHERE group_id = v_group_id AND tag_id = v_tag_id;
END; ';


ALTER FUNCTION public.gettagusergroupbygroupidandbytagid(v_group_id uuid, v_tag_id uuid) OWNER TO engine;

--
-- Name: gettagvdsbytagidandbyvdsid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagvdsbytagidandbyvdsid(v_tag_id uuid, v_vds_id uuid) RETURNS SETOF tags_vds_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_vds_map.*
      FROM tags_vds_map
      WHERE tag_id = v_tag_id AND vds_id = v_vds_id;
END; ';


ALTER FUNCTION public.gettagvdsbytagidandbyvdsid(v_tag_id uuid, v_vds_id uuid) OWNER TO engine;

--
-- Name: gettagvmbytagidandbyvmid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettagvmbytagidandbyvmid(v_tag_id uuid, v_vm_id uuid) RETURNS SETOF tags_vm_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT tags_vm_map.*
      FROM tags_vm_map
      WHERE tag_id = v_tag_id AND vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.gettagvmbytagidandbyvmid(v_tag_id uuid, v_vm_id uuid) OWNER TO engine;

--
-- Name: gettemplatecount(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettemplatecount() RETURNS SETOF bigint
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT count (vm_templates.*)
      FROM vm_templates_view vm_templates;
END; ';


ALTER FUNCTION public.gettemplatecount() OWNER TO engine;

--
-- Name: gettemplateversionsforbasetemplate(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettemplateversionsforbasetemplate(v_base_template_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   from vm_templates_view
   where base_template_id = v_base_template_id and vmt_guid != v_base_template_id;
END; ';


ALTER FUNCTION public.gettemplateversionsforbasetemplate(v_base_template_id uuid) OWNER TO engine;

--
-- Name: gettemplatewithlatestversioninchain(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettemplatewithlatestversioninchain(v_template_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   from vm_templates_view
   where base_template_id =
      (select vmt_guid from vm_static where vm_guid = v_template_id)
   order by template_version_number desc
   limit 1;
END; ';


ALTER FUNCTION public.gettemplatewithlatestversioninchain(v_template_id uuid) OWNER TO engine;

--
-- Name: gluster_volume_transport_types; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE gluster_volume_transport_types (
    volume_id uuid NOT NULL,
    transport_type character varying(32) NOT NULL
);


ALTER TABLE public.gluster_volume_transport_types OWNER TO engine;

--
-- Name: gettransporttypesbyglustervolumeguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettransporttypesbyglustervolumeguid(v_volume_id uuid) RETURNS SETOF gluster_volume_transport_types
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
       RETURN QUERY SELECT *
       FROM  gluster_volume_transport_types
       WHERE volume_id = v_volume_id;
END; ';


ALTER FUNCTION public.gettransporttypesbyglustervolumeguid(v_volume_id uuid) OWNER TO engine;

--
-- Name: gettrustedvdsgroups(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION gettrustedvdsgroups() RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE trusted_service;
END; ';


ALTER FUNCTION public.gettrustedvdsgroups() OWNER TO engine;

--
-- Name: getupandprioritizedvds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getupandprioritizedvds(v_storage_pool_id uuid) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds.*
      FROM vds vds, vds_groups vdsgroup
      WHERE (vds.status = 3) AND (vds.storage_pool_id = v_storage_pool_id) AND (vds_spm_priority IS NULL OR vds_spm_priority > -1)
      AND vds.vds_group_id = vdsgroup.vds_group_id AND vdsgroup.virt_service = true
      ORDER BY vds_spm_priority DESC, RANDOM();
   END;
   RETURN;
END; ';


ALTER FUNCTION public.getupandprioritizedvds(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getuserandgroupsbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getuserandgroupsbyid(v_id uuid) RETURNS SETOF iduuidtype
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY
   select ID from ad_groups,users where users.user_id = v_id
   and ad_groups.id in(select * from fnsplitteruuid(users.group_ids))
   UNION
   select v_id
   UNION
   -- user is also member of ''Everyone''
   select ''EEE00000-0000-0000-0000-123456789EEE'';
END; ';


ALTER FUNCTION public.getuserandgroupsbyid(v_id uuid) OWNER TO engine;

--
-- Name: getuserbyexternalid(character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getuserbyexternalid(v_domain character varying, v_external_id bytea) RETURNS SETOF users
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE domain = v_domain AND external_id = v_external_id;
END; ';


ALTER FUNCTION public.getuserbyexternalid(v_domain character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: getuserbyuserid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getuserbyuserid(v_user_id uuid) RETURNS SETOF users
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE user_id = v_user_id;
END; ';


ALTER FUNCTION public.getuserbyuserid(v_user_id uuid) OWNER TO engine;

--
-- Name: getuserbyusername(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getuserbyusername(v_username character varying) RETURNS SETOF users
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE username = v_username;
END; ';


ALTER FUNCTION public.getuserbyusername(v_username character varying) OWNER TO engine;

--
-- Name: getusergrouptagsbytagids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getusergrouptagsbytagids(v_tag_ids character varying) RETURNS SETOF tags_user_group_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_group_map_view.*
      FROM tags_user_group_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; ';


ALTER FUNCTION public.getusergrouptagsbytagids(v_tag_ids character varying) OWNER TO engine;

--
-- Name: getuserpermissionsbyentityid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getuserpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF permissions_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view p
   WHERE object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_flat_groups u
                                       WHERE  p.ad_element_id = u.granted_id
                                       AND    u.user_id       = v_user_id));
END; ';


ALTER FUNCTION public.getuserpermissionsbyentityid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getusersbyvmguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getusersbyvmguid(v_vm_guid uuid) RETURNS SETOF users
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      inner join permissions
      on users.user_id = permissions.ad_element_id
      WHERE permissions.object_type_id = 2
      and	permissions.object_id = v_vm_guid;
END; ';


ALTER FUNCTION public.getusersbyvmguid(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getusertagsbytagids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getusertagsbytagids(v_tag_ids character varying) RETURNS SETOF tags_user_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_map_view.*
      FROM tags_user_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; ';


ALTER FUNCTION public.getusertagsbytagids(v_tag_ids character varying) OWNER TO engine;

--
-- Name: getvdcoptionbyid(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdcoptionbyid(v_option_id integer) RETURNS SETOF vdc_options
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options
      WHERE option_id = v_option_id;
END; ';


ALTER FUNCTION public.getvdcoptionbyid(v_option_id integer) OWNER TO engine;

--
-- Name: getvdcoptionbyname(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdcoptionbyname(v_option_name character varying, v_version character varying) RETURNS SETOF vdc_options
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options
      WHERE OPTION_NAME = v_option_name and version = v_version;
END; ';


ALTER FUNCTION public.getvdcoptionbyname(v_option_name character varying, v_version character varying) OWNER TO engine;

--
-- Name: getvds_spm_id_mapbystorage_pool_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvds_spm_id_mapbystorage_pool_id(v_storage_pool_id uuid) RETURNS SETOF vds_spm_id_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE storage_pool_id = v_storage_pool_id;

END; ';


ALTER FUNCTION public.getvds_spm_id_mapbystorage_pool_id(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getvds_spm_id_mapbystorage_pool_idandbyvds_spm_id(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvds_spm_id_mapbystorage_pool_idandbyvds_spm_id(v_storage_pool_id uuid, v_vds_spm_id integer) RETURNS SETOF vds_spm_id_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE storage_pool_id = v_storage_pool_id AND vds_spm_id = v_vds_spm_id;

END; ';


ALTER FUNCTION public.getvds_spm_id_mapbystorage_pool_idandbyvds_spm_id(v_storage_pool_id uuid, v_vds_spm_id integer) OWNER TO engine;

--
-- Name: getvds_spm_id_mapbyvds_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvds_spm_id_mapbyvds_id(v_vds_id uuid) RETURNS SETOF vds_spm_id_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE vds_id = v_vds_id;

END; ';


ALTER FUNCTION public.getvds_spm_id_mapbyvds_id(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvdsbyhostname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyhostname(v_host_name character varying) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE host_name = v_host_name;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbyhostname(v_host_name character varying) OWNER TO engine;

--
-- Name: getvdsbyip(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyip(v_ip character varying) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE ip = v_ip;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbyip(v_ip character varying) OWNER TO engine;

--
-- Name: getvdsbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyname(v_vds_name character varying) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_name = v_vds_name;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbyname(v_vds_name character varying) OWNER TO engine;

--
-- Name: getvdsbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbynetworkid(v_network_id uuid) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vds
   WHERE EXISTS (
      SELECT 1
      FROM vds_interface
      INNER JOIN network
      ON network.name = vds_interface.network_name
      INNER JOIN network_cluster
      ON network.id = network_cluster.network_id
      WHERE network_id = v_network_id
      AND vds.vds_group_id = network_cluster.cluster_id
      AND vds_interface.vds_id = vds.vds_id);
END; ';


ALTER FUNCTION public.getvdsbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvdsbystoragepoolid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbystoragepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM   vds
      WHERE  storage_pool_id = v_storage_pool_id
      AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                           FROM   user_vds_permissions_view
                                           WHERE  user_id = v_user_id AND entity_id = vds_id));
   END;
   RETURN;
END; ';


ALTER FUNCTION public.getvdsbystoragepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsbystoragepoolidwithstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbystoragepoolidwithstatus(v_storage_pool_id uuid, v_status integer) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        WHERE (status = v_status) AND (storage_pool_id = v_storage_pool_id);
    END;
    RETURN;
END; ';


ALTER FUNCTION public.getvdsbystoragepoolidwithstatus(v_storage_pool_id uuid, v_status integer) OWNER TO engine;

--
-- Name: getvdsbytype(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbytype(v_vds_type integer) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_type = v_vds_type;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbytype(v_vds_type integer) OWNER TO engine;

--
-- Name: getvdsbyuniqueid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyuniqueid(v_vds_unique_id character varying) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_unique_id = v_vds_unique_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbyuniqueid(v_vds_unique_id character varying) OWNER TO engine;

--
-- Name: getvdsbyvdsgroupid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
	-- this sp returns all vds for a given cluster
   BEGIN
      if (v_is_filtered) then
          RETURN QUERY SELECT DISTINCT (rec).*
          FROM fn_db_mask_object(''vds'') as q (rec vds)
          WHERE (rec).vds_group_id = v_vds_group_id
          AND EXISTS (SELECT 1
              FROM   user_vds_permissions_view
              WHERE  user_id = v_user_id AND entity_id = (rec).vds_id);
      else
          RETURN QUERY SELECT DISTINCT vds.*
          FROM vds
          WHERE vds_group_id = v_vds_group_id;
      end if;
    END;
    RETURN;
END; ';


ALTER FUNCTION public.getvdsbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsbyvdsid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsbyvdsid(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
v_columns text[];
BEGIN
    BEGIN
      if (v_is_filtered) then
          RETURN QUERY SELECT DISTINCT (rec).*
          FROM fn_db_mask_object(''vds'') as q (rec vds)
          WHERE (rec).vds_id = v_vds_id
          AND EXISTS (SELECT 1
              FROM   user_vds_permissions_view
              WHERE  user_id = v_user_id AND entity_id = v_vds_id);
      else
          RETURN QUERY SELECT DISTINCT vds.*
          FROM vds
          WHERE vds_id = v_vds_id;
      end if;
    END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsbyvdsid(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsdynamicbyvdsid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsdynamicbyvdsid(v_vds_id uuid) RETURNS SETOF vds_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_dynamic.*
      FROM vds_dynamic
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsdynamicbyvdsid(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvdsforvdsgroupwithstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsforvdsgroupwithstatus(v_vds_group_id uuid, v_status integer) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        WHERE (status = v_status) AND (vds_group_id = v_vds_group_id)
        ORDER BY vds.vds_id ASC;
    END;
    RETURN;
END; ';


ALTER FUNCTION public.getvdsforvdsgroupwithstatus(v_vds_group_id uuid, v_status integer) OWNER TO engine;

--
-- Name: getvdsgroupbyvdsgroupid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE vds_group_id = v_vds_group_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vds_group_id));

END; ';


ALTER FUNCTION public.getvdsgroupbyvdsgroupid(v_vds_group_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsgroupbyvdsgroupname(character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupbyvdsgroupname(v_vds_group_name character varying, v_is_case_sensitive boolean) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE name = v_vds_group_name OR (NOT v_is_case_sensitive AND name ilike v_vds_group_name);
END; ';


ALTER FUNCTION public.getvdsgroupbyvdsgroupname(v_vds_group_name character varying, v_is_case_sensitive boolean) OWNER TO engine;

--
-- Name: getvdsgroupforuserbyvdsgroupname(character varying, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupforuserbyvdsgroupname(v_vds_group_name character varying, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE name = v_vds_group_name
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vds_group_id));
END; ';


ALTER FUNCTION public.getvdsgroupforuserbyvdsgroupname(v_vds_group_name character varying, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsgroupsbyclusterpolicyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupsbyclusterpolicyid(v_cluster_policy_id uuid) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE cluster_policy_id = v_cluster_policy_id;
END; ';


ALTER FUNCTION public.getvdsgroupsbyclusterpolicyid(v_cluster_policy_id uuid) OWNER TO engine;

--
-- Name: getvdsgroupsbystoragepoolid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupsbystoragepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE storage_pool_id = v_storage_pool_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vds_group_id));
END; ';


ALTER FUNCTION public.getvdsgroupsbystoragepoolid(v_storage_pool_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsgroupwithrunningvms(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsgroupwithrunningvms(v_vds_group_id uuid) RETURNS SETOF vds_groups_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE vds_group_id = v_vds_group_id and vds_group_id in(select vds_group_id from vms where vms.status NOT IN(0,13,14));
END; ';


ALTER FUNCTION public.getvdsgroupwithrunningvms(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvdsinterfacebyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsinterfacebyid(v_vds_interface_id uuid) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   WHERE id = v_vds_interface_id;
END; ';


ALTER FUNCTION public.getvdsinterfacebyid(v_vds_interface_id uuid) OWNER TO engine;

--
-- Name: getvdsinterfacesbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsinterfacesbynetworkid(v_network_id uuid) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds
   ON vds.vds_id = vds_interface_view.vds_id
   INNER JOIN network_cluster
   ON network_cluster.cluster_id = vds.vds_group_id
   INNER JOIN network
   ON network.id = network_cluster.network_id
   AND network.name = vds_interface_view.network_name
   WHERE network.id = v_network_id;
END; ';


ALTER FUNCTION public.getvdsinterfacesbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvdsmanagedinterfacebyvdsid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsmanagedinterfacebyvdsid(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vds_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   -- Checking if the 2nd bit in the type column is set, meaning that the interface is managed
   WHERE vds_id = v_vds_id AND (type & 2) = 2
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_vds_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_vds_id));

END; ';


ALTER FUNCTION public.getvdsmanagedinterfacebyvdsid(v_vds_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvdsstaticbyhostname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsstaticbyhostname(v_host_name character varying) RETURNS SETOF vds_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vds_static.*
   FROM vds_static
   WHERE host_name = v_host_name;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsstaticbyhostname(v_host_name character varying) OWNER TO engine;

--
-- Name: getvdsstaticbyip(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsstaticbyip(v_ip character varying) RETURNS SETOF vds_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static
      WHERE ip = v_ip;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsstaticbyip(v_ip character varying) OWNER TO engine;

--
-- Name: getvdsstaticbyvdsgroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsstaticbyvdsgroupid(v_vds_group_id uuid) RETURNS SETOF vds_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static vds_static
      WHERE vds_group_id = v_vds_group_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsstaticbyvdsgroupid(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvdsstaticbyvdsid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsstaticbyvdsid(v_vds_id uuid) RETURNS SETOF vds_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsstaticbyvdsid(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvdsstatisticsbyvdsid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdsstatisticsbyvdsid(v_vds_id uuid) RETURNS SETOF vds_statistics
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
BEGIN
      RETURN QUERY SELECT vds_statistics.*
      FROM vds_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdsstatisticsbyvdsid(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvdstagsbytagids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdstagsbytagids(v_tag_ids character varying) RETURNS SETOF tags_vds_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vds_map_view.*
      FROM tags_vds_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; ';


ALTER FUNCTION public.getvdstagsbytagids(v_tag_ids character varying) OWNER TO engine;

--
-- Name: getvdswithoutmigratingvmsbyvdsgroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdswithoutmigratingvmsbyvdsgroupid(v_vds_group_id uuid) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN


	-- this sp returns all vds in given cluster that have no pending vms and no vms in migration states
	BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_group_id = v_vds_group_id and
      pending_vcpus_count = 0
      and	vds.status = 3
      and	vds_id not in(select distinct RUN_ON_VDS from vm_dynamic
         where status in(5,6,11,12));
   END;

   RETURN;
END; ';


ALTER FUNCTION public.getvdswithoutmigratingvmsbyvdsgroupid(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvdswithoutnetwork(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvdswithoutnetwork(v_network_id uuid) RETURNS SETOF vds
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vds.*
   FROM vds
   INNER JOIN network_cluster
   ON vds.vds_group_id = network_cluster.cluster_id
   WHERE network_cluster.network_id = v_network_id
   AND NOT EXISTS (
      SELECT 1
      FROM vds_interface
      INNER JOIN network
      ON network.name = vds_interface.network_name
      INNER JOIN network_cluster
      ON network.id = network_cluster.network_id
      WHERE network_cluster.network_id = v_network_id
      AND vds.vds_group_id = network_cluster.cluster_id
      AND vds_interface.vds_id = vds.vds_id);
END; ';


ALTER FUNCTION public.getvdswithoutnetwork(v_network_id uuid) OWNER TO engine;

--
-- Name: getvm_interface_statisticsbyid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_interface_statisticsbyid(v_id uuid) RETURNS SETOF vm_interface_statistics
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM vm_interface_statistics
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getvm_interface_statisticsbyid(v_id uuid) OWNER TO engine;

--
-- Name: getvm_pool_mapbyvm_guid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_pool_mapbyvm_guid(v_vm_guid uuid) RETURNS SETOF vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pool_map.*
      FROM vm_pool_map
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.getvm_pool_mapbyvm_guid(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getvm_pool_mapbyvm_pool_id(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_pool_mapbyvm_pool_id(v_vm_pool_id uuid) RETURNS SETOF vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pool_map.*
      FROM vm_pool_map INNER JOIN vm_static
      ON vm_pool_map.vm_guid = vm_static.vm_guid
      WHERE vm_pool_id = v_vm_pool_id
      ORDER BY vm_static.VM_NAME;
END; ';


ALTER FUNCTION public.getvm_pool_mapbyvm_pool_id(v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: getvm_poolsbyadgroup_names(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_poolsbyadgroup_names(v_ad_group_names character varying) RETURNS SETOF vm_pools_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vm_pools_view.*
      FROM         ad_groups INNER JOIN
      users_and_groups_to_vm_pool_map_view ON
      ad_groups.id = users_and_groups_to_vm_pool_map_view.user_id INNER JOIN
      vm_pools_view ON users_and_groups_to_vm_pool_map_view.vm_pool_id = vm_pools_view.vm_pool_id
      WHERE     (ad_groups.name in(select Id from fnSplitter(v_ad_group_names)));
END; ';


ALTER FUNCTION public.getvm_poolsbyadgroup_names(v_ad_group_names character varying) OWNER TO engine;

--
-- Name: vm_pools_full_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_pools_full_view AS
    SELECT vmp.vm_pool_id, vmp.vm_pool_name, vmp.vm_pool_description, vmp.vm_pool_comment, vmp.vm_pool_type, vmp.parameters, vmp.prestarted_vms, vmp.vds_group_id, vmp.vds_group_name, vmp.architecture, vmp.max_assigned_vms_per_user, vmp.spice_proxy, (SELECT count(vm_pool_map.vm_pool_id) AS expr1 FROM (vm_pools_view v1 LEFT JOIN vm_pool_map ON (((v1.vm_pool_id = vm_pool_map.vm_pool_id) AND (v1.vm_pool_id = vmp.vm_pool_id))))) AS assigned_vm_count, (SELECT count(v2.vm_pool_id) AS expr1 FROM ((vm_pools v2 LEFT JOIN vm_pool_map vm_pool_map_1 ON (((v2.vm_pool_id = vm_pool_map_1.vm_pool_id) AND (v2.vm_pool_id = vmp.vm_pool_id)))) LEFT JOIN vm_dynamic ON ((vm_pool_map_1.vm_guid = vm_dynamic.vm_guid))) WHERE (vm_dynamic.status <> ALL (ARRAY[0, 15])) GROUP BY v2.vm_pool_id) AS vm_running_count, vmp.storage_pool_name, vmp.storage_pool_id FROM vm_pools_view vmp;


ALTER TABLE public.vm_pools_full_view OWNER TO engine;

--
-- Name: getvm_poolsbyvm_pool_id(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_poolsbyvm_pool_id(v_vm_pool_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_pools_full_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pools_full_view.*
      FROM vm_pools_full_view
      WHERE vm_pool_id = v_vm_pool_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_pool_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vm_pool_id));
END; ';


ALTER FUNCTION public.getvm_poolsbyvm_pool_id(v_vm_pool_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvm_poolsbyvm_pool_name(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvm_poolsbyvm_pool_name(v_vm_pool_name character varying) RETURNS SETOF vm_pools_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pools_view.*
      FROM vm_pools_view
      WHERE vm_pool_name = v_vm_pool_name;
END; ';


ALTER FUNCTION public.getvm_poolsbyvm_pool_name(v_vm_pool_name character varying) OWNER TO engine;

--
-- Name: getvmbootactivedisk(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmbootactivedisk(v_vm_guid uuid) RETURNS SETOF all_disks
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT all_disks.*
      FROM all_disks
      JOIN vm_device ON vm_device.device_id = all_disks.image_group_id
      WHERE vm_device.vm_id = v_vm_guid AND boot = TRUE AND vm_device.snapshot_id IS NULL;
END; ';


ALTER FUNCTION public.getvmbootactivedisk(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getvmbyhibernationimageid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmbyhibernationimageid(v_image_id character varying) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      WHERE hibernation_vol_handle like ''%'' || coalesce(v_image_id,'''') || ''%'';
END; ';


ALTER FUNCTION public.getvmbyhibernationimageid(v_image_id character varying) OWNER TO engine;

--
-- Name: getvmbyvmguid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmbyvmguid(v_vm_guid uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vm_guid = v_vm_guid
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = v_vm_guid));
END; ';


ALTER FUNCTION public.getvmbyvmguid(v_vm_guid uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmbyvmnamefordatacenter(uuid, character varying, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmbyvmnamefordatacenter(v_data_center_id uuid, v_vm_name character varying, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vm_name = v_vm_name
   AND   (v_data_center_id is null OR storage_pool_id = v_data_center_id)
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = vms.vm_guid));
END; ';


ALTER FUNCTION public.getvmbyvmnamefordatacenter(v_data_center_id uuid, v_vm_name character varying, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmdatafrompoolbypoolid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdatafrompoolbypoolid(v_pool_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
     RETURN QUERY SELECT vms.*
     FROM vms WHERE vm_pool_id = v_pool_id
     AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_pool_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = v_pool_id))
     -- Limiting results to 1 since we only need a single VM from the pool to retrieve the pool data
     LIMIT 1;
END; ';


ALTER FUNCTION public.getvmdatafrompoolbypoolid(v_pool_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmdevicebydeviceid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdevicebydeviceid(v_device_id uuid, v_vm_id uuid) RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  device_id = v_device_id
    AND (v_vm_id IS NULL OR vm_id = v_vm_id);
END; ';


ALTER FUNCTION public.getvmdevicebydeviceid(v_device_id uuid, v_vm_id uuid) OWNER TO engine;

--
-- Name: getvmdevicebyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdevicebyvmid(v_vm_id uuid) RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id order by device_id;
END; ';


ALTER FUNCTION public.getvmdevicebyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: getvmdevicebyvmidandtype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdevicebyvmidandtype(v_vm_id uuid, v_type character varying) RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id and type = v_type
    ORDER BY NULLIF(alias,'''') NULLS LAST;
END; ';


ALTER FUNCTION public.getvmdevicebyvmidandtype(v_vm_id uuid, v_type character varying) OWNER TO engine;

--
-- Name: getvmdevicebyvmidtypeanddevice(uuid, character varying, character varying, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdevicebyvmidtypeanddevice(v_vm_id uuid, v_type character varying, v_device character varying, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id and type = v_type and device = v_device
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = v_vm_id))
    ORDER BY NULLIF(alias,'''') NULLS LAST;

END; ';


ALTER FUNCTION public.getvmdevicebyvmidtypeanddevice(v_vm_id uuid, v_type character varying, v_device character varying, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmdynamicbyvmguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmdynamicbyvmguid(v_vm_guid uuid) RETURNS SETOF vm_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.getvmdynamicbyvmguid(v_vm_guid uuid) OWNER TO engine;

SET default_with_oids = true;

--
-- Name: vm_guest_agent_interfaces; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_guest_agent_interfaces (
    vm_id uuid NOT NULL,
    interface_name text,
    mac_address character varying(59),
    ipv4_addresses text,
    ipv6_addresses text
);


ALTER TABLE public.vm_guest_agent_interfaces OWNER TO engine;

--
-- Name: getvmguestagentinterfacesbyvmid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmguestagentinterfacesbyvmid(v_vm_id uuid, v_user_id uuid, v_filtered boolean) RETURNS SETOF vm_guest_agent_interfaces
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM vm_guest_agent_interfaces
   WHERE vm_id = v_vm_id
   AND (NOT v_filtered OR EXISTS (SELECT 1
                                  FROM   user_vm_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = v_vm_id));
END; ';


ALTER FUNCTION public.getvmguestagentinterfacesbyvmid(v_vm_id uuid, v_user_id uuid, v_filtered boolean) OWNER TO engine;

--
-- Name: getvmidsforversionupdate(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmidsforversionupdate(v_base_template_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select vs.vm_guid
             from vm_static vs
               natural join vm_dynamic
             where (vmt_guid = v_base_template_id or vmt_guid in
                          (select vm_guid from vm_static where vmt_guid = v_base_template_id))
               and template_version_number is null and entity_type=''VM'' and status=0
                   and (is_stateless = TRUE or
                        (exists (select * from vm_pool_map where vm_guid = vs.vm_guid)
                         and not exists
                        (SELECT *
                         FROM   snapshots
                         WHERE  vm_id = vs.vm_guid
                                AND    snapshot_type = ''STATELESS'')));
END; ';


ALTER FUNCTION public.getvmidsforversionupdate(v_base_template_id uuid) OWNER TO engine;

--
-- Name: getvmimagebyimageguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmimagebyimageguid(v_image_guid uuid) RETURNS SETOF vm_images_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM vm_images_view
      WHERE image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.getvmimagebyimageguid(v_image_guid uuid) OWNER TO engine;

--
-- Name: vm_init; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_init (
    vm_id uuid NOT NULL,
    host_name text,
    domain text,
    authorized_keys text,
    regenerate_keys boolean DEFAULT false,
    time_zone character varying(40) DEFAULT NULL::character varying,
    dns_servers text,
    dns_search_domains text,
    networks text,
    password text,
    winkey character varying(30) DEFAULT NULL::character varying,
    custom_script text
);


ALTER TABLE public.vm_init OWNER TO engine;

--
-- Name: getvminitbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminitbyvmid(v_vm_id uuid) RETURNS SETOF vm_init
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_init.*
   FROM vm_init
   WHERE vm_id = v_vm_id;

END; ';


ALTER FUNCTION public.getvminitbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: getvminterfacebytemplateid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminterfacebytemplateid(v_template_id uuid) RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE vmt_guid = v_template_id;

END; ';


ALTER FUNCTION public.getvminterfacebytemplateid(v_template_id uuid) OWNER TO engine;

--
-- Name: getvminterfacebyvminterfaceid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminterfacebyvminterfaceid(v_id uuid) RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.getvminterfacebyvminterfaceid(v_id uuid) OWNER TO engine;

--
-- Name: getvminterfacesbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminterfacesbynetworkid(v_network_id uuid) RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vm_interface.*
   FROM vm_interface
   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
   INNER JOIN vm_static on vm_interface.vm_guid = vm_static.vm_guid
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_static.entity_type = ''VM'';
END; ';


ALTER FUNCTION public.getvminterfacesbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvminterfacesbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminterfacesbyvmid(v_vm_id uuid) RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE vm_guid = v_vm_id;
END; ';


ALTER FUNCTION public.getvminterfacesbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: getvminterfaceviewsbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvminterfaceviewsbynetworkid(v_network_id uuid) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vm_interface_view.*
   FROM vm_interface_view
   INNER JOIN vnic_profiles ON vnic_profiles.id = vm_interface_view.vnic_profile_id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_interface_view.vm_entity_type = ''VM'';
END; ';


ALTER FUNCTION public.getvminterfaceviewsbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvmmapsinvmpoolbyvmpoolidandstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmmapsinvmpoolbyvmpoolidandstatus(v_vm_pool_id uuid, v_status integer) RETURNS SETOF vm_pool_map
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_pool_id, vm_pool_map.vm_guid
      FROM vm_pool_map, vm_dynamic
      WHERE vm_pool_map.vm_guid = vm_dynamic.vm_guid
      AND vm_pool_id = v_vm_pool_id
      AND vm_dynamic.status = v_status;
END; ';


ALTER FUNCTION public.getvmmapsinvmpoolbyvmpoolidandstatus(v_vm_pool_id uuid, v_status integer) OWNER TO engine;

--
-- Name: getvmnetworkinterfaceviewbytemplateid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmnetworkinterfaceviewbytemplateid(v_template_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE vmt_guid = v_template_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
   FROM   user_vm_template_permissions_view
   WHERE  user_id = v_user_id AND entity_id = v_template_id));
END; ';


ALTER FUNCTION public.getvmnetworkinterfaceviewbytemplateid(v_template_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmnetworkinterfaceviewbyvmid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmnetworkinterfaceviewbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE vm_guid = v_vm_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
   FROM   user_vm_permissions_view
   WHERE  user_id = v_user_id AND entity_id = v_vm_id));
END; ';


ALTER FUNCTION public.getvmnetworkinterfaceviewbyvmid(v_vm_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmnetworkinterfaceviewbyvmnetworkinterfaceviewid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmnetworkinterfaceviewbyvmnetworkinterfaceviewid(v_id uuid) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getvmnetworkinterfaceviewbyvmnetworkinterfaceviewid(v_id uuid) OWNER TO engine;

--
-- Name: getvmsbyadgroupnames(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyadgroupnames(v_ad_group_names character varying) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select distinct vms.* from vms
   inner join permissions on vms.vm_guid = permissions.object_id
   inner join ad_groups on ad_groups.id = permissions.ad_element_id
   WHERE     (ad_groups.name in(select Id from fnSplitter(v_ad_group_names)));
END; ';


ALTER FUNCTION public.getvmsbyadgroupnames(v_ad_group_names character varying) OWNER TO engine;

--
-- Name: vms_with_plug_info; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vms_with_plug_info AS
    SELECT vms.vm_name, vms.vm_mem_size_mb, vms.nice_level, vms.cpu_shares, vms.vmt_guid, vms.vm_os, vms.vm_description, vms.vm_comment, vms.vds_group_id, vms.vm_creation_date, vms.auto_startup, vms.is_stateless, vms.is_smartcard_enabled, vms.is_delete_protected, vms.sso_method, vms.dedicated_vm_for_vds, vms.fail_back, vms.default_boot_sequence, vms.vm_type, vms.vm_pool_spice_proxy, vms.vds_group_name, vms.transparent_hugepages, vms.trusted_service, vms.storage_pool_id, vms.storage_pool_name, vms.vds_group_description, vms.vds_group_spice_proxy, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date, vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_num_of_cpus, vms.vmt_description, vms.status, vms.vm_ip, vms.vm_host, vms.vm_pid, vms.last_start_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.guest_last_logout_time, vms.guest_os, vms.console_user_id, vms.guest_agent_nics_hash, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display, vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci, vms.allow_console_reconnect, vms.is_initialized, vms.num_of_sockets, vms.cpu_per_socket, vms.usb_policy, vms.acpi_enable, vms.session, vms.num_of_cpus, vms.quota_id, vms.quota_name, vms.quota_enforcement_type, vms.display_ip, vms.display_type, vms.kvm_enable, vms.boot_sequence, vms.display_secure_port, vms.utc_diff, vms.last_vds_run_on, vms.client_ip, vms.guest_requested_memory, vms.time_zone, vms.cpu_user, vms.cpu_sys, vms.elapsed_time, vms.usage_network_percent, vms.usage_mem_percent, vms.usage_cpu_percent, vms.run_on_vds_name, vms.vds_group_cpu_name, vms.default_display_type, vms.priority, vms.iso_path, vms.origin, vms.vds_group_compatibility_version, vms.initrd_url, vms.kernel_url, vms.kernel_params, vms.pause_status, vms.exit_message, vms.exit_status, vms.migration_support, vms.predefined_properties, vms.userdefined_properties, vms.min_allocated_mem, vms.hash, vms.cpu_pinning, vms.db_generation, vms.host_cpu_flags, vms.tunnel_migration, vms.vnc_keyboard_layout, vms.is_run_and_pause, vms.created_by_user_id, vms.last_watchdog_event, vms.last_watchdog_action, vms.is_run_once, vms.vm_fqdn, vms.cpu_name, vms.current_cd, vms.instance_type_id, vms.image_type_id, vms.architecture, vms.original_template_id, vms.original_template_name, vms.last_stop_time, vms.migration_downtime, vms.template_version_number, vd.device_id, vd.vm_id, vd.type, vd.device, vd.address, vd.boot_order, vd.spec_params, vd.is_managed, vd.is_plugged, vd.is_readonly, vd._create_date, vd._update_date, vd.alias, vd.custom_properties, vd.snapshot_id FROM (vms JOIN vm_device vd ON ((vd.vm_id = vms.vm_guid)));


ALTER TABLE public.vms_with_plug_info OWNER TO engine;

--
-- Name: getvmsbydiskid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbydiskid(v_disk_guid uuid) RETURNS SETOF vms_with_plug_info
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vms_with_plug_info.*
      FROM vms_with_plug_info
      WHERE device_id = v_disk_guid;
END; ';


ALTER FUNCTION public.getvmsbydiskid(v_disk_guid uuid) OWNER TO engine;

--
-- Name: getvmsbyids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyids(v_vms_ids character varying) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm.*
             FROM vms vm
             WHERE vm.vm_guid IN (SELECT * from fnSplitterUuid(v_vms_ids));
END; ';


ALTER FUNCTION public.getvmsbyids(v_vms_ids character varying) OWNER TO engine;

--
-- Name: getvmsbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbynetworkid(v_network_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vms
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      INNER JOIN vnic_profiles
      ON vnic_profiles.id = vm_interface.vnic_profile_id
      WHERE vnic_profiles.network_id = v_network_id
      AND vm_interface.vm_guid = vms.vm_guid);
END; ';


ALTER FUNCTION public.getvmsbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvmsbystoragedomainid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbystoragedomainid(v_storage_domain_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      inner join image_storage_domain_map on images.image_guid = image_storage_domain_map.image_id
      where image_storage_domain_map.storage_domain_id = v_storage_domain_id;
END; ';


ALTER FUNCTION public.getvmsbystoragedomainid(v_storage_domain_id uuid) OWNER TO engine;

--
-- Name: getvmsbyuserid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyuserid(v_user_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY select vms.* from vms
   inner join permissions on vms.vm_guid = permissions.object_id
   WHERE permissions.ad_element_id = v_user_id;
END; ';


ALTER FUNCTION public.getvmsbyuserid(v_user_id uuid) OWNER TO engine;

--
-- Name: getvmsbyuseridwithgroupsanduserroles(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyuseridwithgroupsanduserroles(v_user_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   from vms
   inner join permissions_view as perms on vms.vm_guid = perms.object_id
   WHERE (perms.ad_element_id = v_user_id
   or perms.ad_element_id in(select id from getUserAndGroupsById(v_user_id)))
   and perms.role_type = 2;

END; ';


ALTER FUNCTION public.getvmsbyuseridwithgroupsanduserroles(v_user_id uuid) OWNER TO engine;

--
-- Name: getvmsbyvdsgroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyvdsgroupid(v_vds_group_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE vds_group_id = v_vds_group_id;
END; ';


ALTER FUNCTION public.getvmsbyvdsgroupid(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvmsbyvmpoolid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyvmpoolid(v_vm_pool_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE vm_pool_id = v_vm_pool_id;
END; ';


ALTER FUNCTION public.getvmsbyvmpoolid(v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: getvmsbyvmtguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyvmtguid(v_vmt_guid uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vmt_guid = v_vmt_guid;
END; ';


ALTER FUNCTION public.getvmsbyvmtguid(v_vmt_guid uuid) OWNER TO engine;

--
-- Name: getvmsbyvnicprofileid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsbyvnicprofileid(v_vnic_profile_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vms
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      WHERE vm_interface.vnic_profile_id = v_vnic_profile_id
      AND vm_interface.vm_guid = vms.vm_guid);
END; ';


ALTER FUNCTION public.getvmsbyvnicprofileid(v_vnic_profile_id uuid) OWNER TO engine;

--
-- Name: getvmsdynamicrunningonvds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsdynamicrunningonvds(v_vds_id uuid) RETURNS SETOF vm_dynamic
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic
      WHERE RUN_ON_VDS = v_vds_id;
END; ';


ALTER FUNCTION public.getvmsdynamicrunningonvds(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvmsidsforovfupdate(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsidsforovfupdate(v_storage_pool_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm.vm_guid as vm_guid
   FROM vms vm, vm_ovf_generations ovf_gen
   WHERE vm.vm_guid = ovf_gen.vm_guid
         AND vm.db_generation >  ovf_gen.ovf_generation
         AND vm.storage_pool_id = v_storage_pool_id;
END; ';


ALTER FUNCTION public.getvmsidsforovfupdate(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getvmsmigratingtovds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsmigratingtovds(v_vds_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE migrating_to_vds = v_vds_id;

END; ';


ALTER FUNCTION public.getvmsmigratingtovds(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvmsrunningonormigratingtovds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsrunningonormigratingtovds(v_vds_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    -- use migrating_to_vds column when the VM is in status Migrating From
    RETURN QUERY SELECT DISTINCT V.* FROM VMS V
    WHERE V.RUN_ON_VDS=V_VDS_ID OR (V.STATUS = 5 AND V.MIGRATING_TO_VDS=V_VDS_ID)
    ORDER BY V.VM_NAME;
END; ';


ALTER FUNCTION public.getvmsrunningonormigratingtovds(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvmsrunningonvds(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmsrunningonvds(v_vds_id uuid) RETURNS SETOF vms
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE run_on_vds = v_vds_id;

END; ';


ALTER FUNCTION public.getvmsrunningonvds(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvmstaticbygroupidandnetwork(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstaticbygroupidandnetwork(v_groupid uuid, v_networkname character varying) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT
   vm_static.* from vm_static
   inner join vm_interface_view
   on vm_static.vm_guid = vm_interface_view.vm_guid
   and network_name = v_networkName
   and vm_static.vds_group_id = v_groupId;


END; ';


ALTER FUNCTION public.getvmstaticbygroupidandnetwork(v_groupid uuid, v_networkname character varying) OWNER TO engine;

--
-- Name: getvmstaticbyname(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstaticbyname(v_vm_name character varying) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE VM_NAME = v_vm_name
   AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getvmstaticbyname(v_vm_name character varying) OWNER TO engine;

--
-- Name: getvmstaticbyvdsgroup(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstaticbyvdsgroup(v_vds_group_id uuid) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE vds_group_id = v_vds_group_id
   AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getvmstaticbyvdsgroup(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvmstaticbyvmguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstaticbyvmguid(v_vm_guid uuid) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE vm_guid = v_vm_guid
   AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getvmstaticbyvmguid(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getvmstaticwithfailbackbyvdsid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstaticwithfailbackbyvdsid(v_vds_id uuid) RETURNS SETOF vm_static
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE dedicated_vm_for_vds = v_vds_id and fail_back = TRUE
   AND   entity_type = ''VM'';

END; ';


ALTER FUNCTION public.getvmstaticwithfailbackbyvdsid(v_vds_id uuid) OWNER TO engine;

--
-- Name: getvmstatisticsbyvmguid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmstatisticsbyvmguid(v_vm_guid uuid) RETURNS SETOF vm_statistics
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_statistics.*
      FROM vm_statistics
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.getvmstatisticsbyvmguid(v_vm_guid uuid) OWNER TO engine;

--
-- Name: getvmtagsbytagid(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtagsbytagid(v_tag_ids character varying) RETURNS SETOF tags_vm_map_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_map_view.*
      FROM tags_vm_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; ';


ALTER FUNCTION public.getvmtagsbytagid(v_tag_ids character varying) OWNER TO engine;

--
-- Name: getvmtemplatebyvdsgroupid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatebyvdsgroupid(v_vds_group_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE vds_group_id = v_vds_group_id;
END; ';


ALTER FUNCTION public.getvmtemplatebyvdsgroupid(v_vds_group_id uuid) OWNER TO engine;

--
-- Name: getvmtemplatebyvmtguid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatebyvmtguid(v_vmt_guid uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE vmt_guid = v_vmt_guid
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vmt_guid));
END; ';


ALTER FUNCTION public.getvmtemplatebyvmtguid(v_vmt_guid uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmtemplatebyvmtname(character varying, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatebyvmtname(v_vmt_name character varying, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE name = v_vmt_name
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vmt_guid));
END; ';


ALTER FUNCTION public.getvmtemplatebyvmtname(v_vmt_name character varying, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmtemplateinterfacesbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplateinterfacesbynetworkid(v_network_id uuid) RETURNS SETOF vm_interface
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vm_interface.*
   FROM vm_interface
   INNER JOIN vm_static on vm_interface.vmt_guid = vm_static.vm_guid
   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_static.entity_type  = ''TEMPLATE'';
END; ';


ALTER FUNCTION public.getvmtemplateinterfacesbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvmtemplateinterfaceviewsbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplateinterfaceviewsbynetworkid(v_network_id uuid) RETURNS SETOF vm_interface_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT vm_interface_view.*
   FROM vm_interface_view
   INNER JOIN vnic_profiles ON vnic_profiles.id = vm_interface_view.vnic_profile_id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_interface_view.vm_entity_type = ''TEMPLATE'';
END; ';


ALTER FUNCTION public.getvmtemplateinterfaceviewsbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvmtemplatesbyids(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesbyids(v_vm_templates_ids character varying) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT vm_templates.*
   FROM vm_templates_view vm_templates
   WHERE vm_templates.vmt_guid IN (SELECT * FROM fnSplitterUuid(v_vm_templates_ids));
END; ';


ALTER FUNCTION public.getvmtemplatesbyids(v_vm_templates_ids character varying) OWNER TO engine;

--
-- Name: vm_templates_with_plug_info; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_templates_with_plug_info AS
    SELECT vm_templates_view.vmt_guid, vm_templates_view.name, vm_templates_view.mem_size_mb, vm_templates_view.os, vm_templates_view.creation_date, vm_templates_view.child_count, vm_templates_view.num_of_sockets, vm_templates_view.cpu_per_socket, vm_templates_view.num_of_cpus, vm_templates_view.description, vm_templates_view.free_text_comment, vm_templates_view.vds_group_id, vm_templates_view.num_of_monitors, vm_templates_view.single_qxl_pci, vm_templates_view.allow_console_reconnect, vm_templates_view.status, vm_templates_view.usb_policy, vm_templates_view.time_zone, vm_templates_view.fail_back, vm_templates_view.vds_group_name, vm_templates_view.trusted_service, vm_templates_view.vm_type, vm_templates_view.nice_level, vm_templates_view.cpu_shares, vm_templates_view.storage_pool_id, vm_templates_view.storage_pool_name, vm_templates_view.quota_enforcement_type, vm_templates_view.default_boot_sequence, vm_templates_view.default_display_type, vm_templates_view.priority, vm_templates_view.auto_startup, vm_templates_view.is_stateless, vm_templates_view.is_smartcard_enabled, vm_templates_view.is_delete_protected, vm_templates_view.sso_method, vm_templates_view.iso_path, vm_templates_view.origin, vm_templates_view.initrd_url, vm_templates_view.kernel_url, vm_templates_view.kernel_params, vm_templates_view.quota_id, vm_templates_view.quota_name, vm_templates_view.db_generation, vm_templates_view.migration_support, vm_templates_view.dedicated_vm_for_vds, vm_templates_view.is_disabled, vm_templates_view.tunnel_migration, vm_templates_view.vnc_keyboard_layout, vm_templates_view.min_allocated_mem, vm_templates_view.is_run_and_pause, vm_templates_view.created_by_user_id, vm_templates_view.entity_type, vm_templates_view.migration_downtime, vm_templates_view.architecture, vm_templates_view.template_version_number, vm_templates_view.base_template_id, vm_templates_view.template_version_name, images.image_guid, images.image_group_id, vd.is_plugged FROM ((vm_templates_view JOIN vm_device vd ON ((vd.vm_id = vm_templates_view.vmt_guid))) JOIN images ON (((images.image_group_id = vd.device_id) AND (images.active = true))));


ALTER TABLE public.vm_templates_with_plug_info OWNER TO engine;

--
-- Name: getvmtemplatesbyimageid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesbyimageid(v_image_guid uuid) RETURNS SETOF vm_templates_with_plug_info
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT *
      FROM vm_templates_with_plug_info t
      WHERE t.image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.getvmtemplatesbyimageid(v_image_guid uuid) OWNER TO engine;

--
-- Name: getvmtemplatesbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesbynetworkid(v_network_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_templates_view
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      INNER JOIN vnic_profiles
      ON vnic_profiles.id = vm_interface.vnic_profile_id
      WHERE vnic_profiles.network_id = v_network_id
      AND vm_interface.vmt_guid = vm_templates_view.vmt_guid);
END; ';


ALTER FUNCTION public.getvmtemplatesbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvmtemplatesbystoragedomainid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesbystoragedomainid(v_storage_domain_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
      RETURN QUERY SELECT DISTINCT vm_templates.*
      FROM vm_templates_view vm_templates
      INNER JOIN vm_device vd ON vd.vm_id = vm_templates.vmt_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id AND i.active = TRUE
      where i.image_guid in(select image_id from image_storage_domain_map where storage_domain_id = v_storage_domain_id)
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_template_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = vm_templates.vmt_guid));
END; ';


ALTER FUNCTION public.getvmtemplatesbystoragedomainid(v_storage_domain_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvmtemplatesbyvnicprofileid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesbyvnicprofileid(v_vnic_profile_id uuid) RETURNS SETOF vm_templates_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
   RETURN QUERY SELECT *
   FROM vm_templates_view
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      WHERE vm_interface.vnic_profile_id = v_vnic_profile_id
      AND vm_interface.vmt_guid = vm_templates_view.vmt_guid);
END; ';


ALTER FUNCTION public.getvmtemplatesbyvnicprofileid(v_vnic_profile_id uuid) OWNER TO engine;

--
-- Name: getvmtemplatesidsforovfupdate(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmtemplatesidsforovfupdate(v_storage_pool_id uuid) RETURNS SETOF uuid
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT templates.vmt_guid as vm_guid
   FROM vm_templates_view templates, vm_ovf_generations generations
   WHERE generations.vm_guid = templates.vmt_guid
   AND templates.db_generation > generations.ovf_generation
   AND templates.storage_pool_id = v_storage_pool_id;
END; ';


ALTER FUNCTION public.getvmtemplatesidsforovfupdate(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: getvmunmanageddevicesbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvmunmanageddevicesbyvmid(v_vm_id uuid) RETURNS SETOF vm_device_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    select vm_device_view.* from vm_device_view
    where vm_id = v_vm_id and
          is_managed = false;
END; ';


ALTER FUNCTION public.getvmunmanageddevicesbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: getvnicprofilebyvnicprofileid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofilebyvnicprofileid(v_id uuid) RETURNS SETOF vnic_profiles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.getvnicprofilebyvnicprofileid(v_id uuid) OWNER TO engine;

--
-- Name: getvnicprofilesbynetworkid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofilesbynetworkid(v_network_id uuid) RETURNS SETOF vnic_profiles
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles
   WHERE network_id = v_network_id;

END; ';


ALTER FUNCTION public.getvnicprofilesbynetworkid(v_network_id uuid) OWNER TO engine;

--
-- Name: getvnicprofileviewbyvnicprofileviewid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofileviewbyvnicprofileviewid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vnic_profiles_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE id = v_id
AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                  FROM   user_vnic_profile_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));

END; ';


ALTER FUNCTION public.getvnicprofileviewbyvnicprofileviewid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvnicprofileviewsbydatacenterid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofileviewsbydatacenterid(v_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vnic_profiles_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vnic_profiles_view
    WHERE  data_center_id = v_id
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vnic_profile_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));
END; ';


ALTER FUNCTION public.getvnicprofileviewsbydatacenterid(v_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvnicprofileviewsbynetworkid(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofileviewsbynetworkid(v_network_id uuid, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF vnic_profiles_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE network_id = v_network_id
AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                  FROM   user_vnic_profile_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));

END; ';


ALTER FUNCTION public.getvnicprofileviewsbynetworkid(v_network_id uuid, v_user_id uuid, v_is_filtered boolean) OWNER TO engine;

--
-- Name: getvnicprofileviewsbynetworkqosid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION getvnicprofileviewsbynetworkqosid(v_network_qos_id uuid) RETURNS SETOF vnic_profiles_view
    LANGUAGE plpgsql STABLE
    AS '
BEGIN
RETURN QUERY SELECT *
   FROM vnic_profiles_view
   WHERE network_qos_id = v_network_qos_id;
END; ';


ALTER FUNCTION public.getvnicprofileviewsbynetworkqosid(v_network_qos_id uuid) OWNER TO engine;

--
-- Name: increasestoragepoolmasterversion(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION increasestoragepoolmasterversion(v_id uuid) RETURNS integer
    LANGUAGE plpgsql
    AS '
DECLARE v_master_domain_version INTEGER;
BEGIN
      UPDATE storage_pool
      SET
      master_domain_version = master_domain_version + 1
      WHERE id = v_id
      RETURNING master_domain_version into v_master_domain_version;

      RETURN v_master_domain_version;
END; ';


ALTER FUNCTION public.increasestoragepoolmasterversion(v_id uuid) OWNER TO engine;

--
-- Name: incrementdbgeneration(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION incrementdbgeneration(v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET db_generation  = db_generation + 1
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.incrementdbgeneration(v_vm_guid uuid) OWNER TO engine;

--
-- Name: incrementdbgenerationforallinstoragepool(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION incrementdbgenerationforallinstoragepool(v_storage_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     curs CURSOR FOR SELECT vms.vm_guid FROM vm_static vms
                     WHERE vms.vds_group_id IN (SELECT vgs.vds_group_id FROM vds_groups vgs
                                                WHERE vgs.storage_pool_id=v_storage_pool_id)
                     ORDER BY vm_guid;
     id UUID;
BEGIN
      OPEN curs;
      LOOP
         FETCH curs INTO id;
         IF NOT FOUND THEN
            EXIT;
         END IF;
         UPDATE vm_static SET db_generation  = db_generation + 1 WHERE vm_guid = id;
      END LOOP;
END; ';


ALTER FUNCTION public.incrementdbgenerationforallinstoragepool(v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: insert_entity_snapshot(uuid, uuid, character varying, character varying, character varying, text, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insert_entity_snapshot(v_id uuid, v_command_id uuid, v_command_type character varying, v_entity_id character varying, v_entity_type character varying, v_entity_snapshot text, v_snapshot_class character varying, v_snapshot_type integer, v_insertion_order integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
	BEGIN
		INSERT INTO business_entity_snapshot(id, command_id, command_type, entity_id,entity_type,entity_snapshot, snapshot_class, snapshot_type,insertion_order)
				VALUES(v_id, v_command_id, v_command_type, v_entity_id,v_entity_type,v_entity_snapshot, v_snapshot_class, v_snapshot_type,v_insertion_order);
	END;

   RETURN;
END; ';


ALTER FUNCTION public.insert_entity_snapshot(v_id uuid, v_command_id uuid, v_command_type character varying, v_entity_id character varying, v_entity_type character varying, v_entity_snapshot text, v_snapshot_class character varying, v_snapshot_type integer, v_insertion_order integer) OWNER TO engine;

--
-- Name: insert_osinfo(integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insert_osinfo(v_os_id integer, v_os_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT into dwh_osinfo (os_id, os_name) VALUES (v_os_id, v_os_name);
      UPDATE dwh_history_timekeeping SET var_datetime = now() where var_name = ''lastOsinfoUpdate'';
END; ';


ALTER FUNCTION public.insert_osinfo(v_os_id integer, v_os_name character varying) OWNER TO engine;

--
-- Name: insert_roles_groups(integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insert_roles_groups(v_action_group_id integer, v_role_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO roles_groups(action_group_id, role_id)
	VALUES(v_action_group_id, v_role_id);
END; ';


ALTER FUNCTION public.insert_roles_groups(v_action_group_id integer, v_role_id uuid) OWNER TO engine;

--
-- Name: insertaction_version_map(integer, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertaction_version_map(v_action_type integer, v_cluster_minimal_version character varying, v_storage_pool_minimal_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO action_version_map(action_type, cluster_minimal_version, storage_pool_minimal_version)
	VALUES(v_action_type, v_cluster_minimal_version, v_storage_pool_minimal_version);
END; ';


ALTER FUNCTION public.insertaction_version_map(v_action_type integer, v_cluster_minimal_version character varying, v_storage_pool_minimal_version character varying) OWNER TO engine;

--
-- Name: insertaffinitygroupwithmembers(uuid, character varying, character varying, uuid, boolean, boolean, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertaffinitygroupwithmembers(v_id uuid, v_name character varying, v_description character varying, v_cluster_id uuid, v_positive boolean, v_enforcing boolean, v_vm_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    iter_id UUID;
BEGIN
    INSERT INTO affinity_groups(
        id,
        name,
        description,
        cluster_id,
        positive,
        enforcing)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_cluster_id,
        v_positive,
        v_enforcing);
    FOR iter_id IN (SELECT * FROM fnsplitteruuid(v_vm_ids))
    LOOP
        INSERT INTO affinity_group_members(
            affinity_group_id,
            vm_id)
        VALUES(
            v_id,
            iter_id);
    END LOOP;
END; ';


ALTER FUNCTION public.insertaffinitygroupwithmembers(v_id uuid, v_name character varying, v_description character varying, v_cluster_id uuid, v_positive boolean, v_enforcing boolean, v_vm_ids character varying) OWNER TO engine;

--
-- Name: insertasync_tasks(integer, integer, integer, uuid, uuid, text, character varying, text, character varying, uuid, uuid, uuid, timestamp with time zone, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertasync_tasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_started_at timestamp with time zone, v_storage_pool_id uuid, v_async_task_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO async_tasks(action_type, result, status, vdsm_task_id, task_id, action_parameters,action_params_class, task_parameters, task_params_class, step_id, command_id, root_command_id, started_at,storage_pool_id, task_type)
	VALUES(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_action_parameters,v_action_params_class, v_task_parameters, v_task_params_class, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type);
END; ';


ALTER FUNCTION public.insertasync_tasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_started_at timestamp with time zone, v_storage_pool_id uuid, v_async_task_type integer) OWNER TO engine;

--
-- Name: insertasynctaskentities(uuid, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertasynctaskentities(v_task_id uuid, v_entity_id uuid, v_entity_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      IF NOT EXISTS (SELECT 1 from async_tasks_entities where async_task_id = v_task_id and entity_id = v_entity_id) THEN
            INSERT INTO async_tasks_entities (async_task_id,entity_id,entity_type) VALUES (v_task_id, v_entity_id, v_entity_type);
      END IF;
END; ';


ALTER FUNCTION public.insertasynctaskentities(v_task_id uuid, v_entity_id uuid, v_entity_type character varying) OWNER TO engine;

--
-- Name: insertauditlog(integer, timestamp with time zone, integer, character varying, integer, text, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, character varying, uuid, uuid, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertauditlog(INOUT v_audit_log_id integer, v_log_time timestamp with time zone, v_log_type integer, v_log_type_name character varying, v_severity integer, v_message text, v_user_id uuid, v_user_name character varying, v_vds_id uuid, v_vds_name character varying, v_vm_id uuid, v_vm_name character varying, v_vm_template_id uuid, v_vm_template_name character varying, v_storage_pool_id uuid, v_storage_pool_name character varying, v_storage_domain_id uuid, v_storage_domain_name character varying, v_vds_group_id uuid, v_vds_group_name character varying, v_quota_id uuid, v_quota_name character varying, v_correlation_id character varying, v_job_id uuid, v_gluster_volume_id uuid, v_gluster_volume_name character varying, v_call_stack text) RETURNS integer
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_min_alret_severity  INTEGER;
BEGIN
      v_min_alret_severity := 10;
	-- insert regular log messages (non alerts)
      if (v_severity < v_min_alret_severity) then

INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack)
		VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack);

         v_audit_log_id := CURRVAL(''audit_log_seq'');
      else
         if (not exists(select audit_log_id from audit_log where vds_name = v_vds_name and log_type = v_log_type)) then

INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack)
			VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack);

            v_audit_log_id := CURRVAL(''audit_log_seq'');
         else
            select   audit_log_id INTO v_audit_log_id from audit_log where vds_name = v_vds_name and log_type = v_log_type;
         end if;
      end if;
END; ';


ALTER FUNCTION public.insertauditlog(INOUT v_audit_log_id integer, v_log_time timestamp with time zone, v_log_type integer, v_log_type_name character varying, v_severity integer, v_message text, v_user_id uuid, v_user_name character varying, v_vds_id uuid, v_vds_name character varying, v_vm_id uuid, v_vm_name character varying, v_vm_template_id uuid, v_vm_template_name character varying, v_storage_pool_id uuid, v_storage_pool_name character varying, v_storage_domain_id uuid, v_storage_domain_name character varying, v_vds_group_id uuid, v_vds_group_name character varying, v_quota_id uuid, v_quota_name character varying, v_correlation_id character varying, v_job_id uuid, v_gluster_volume_id uuid, v_gluster_volume_name character varying, v_call_stack text) OWNER TO engine;

--
-- Name: insertbasedisk(uuid, character varying, boolean, character varying, character varying, character varying, boolean, boolean, integer, smallint, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertbasedisk(v_disk_id uuid, v_disk_interface character varying, v_wipe_after_delete boolean, v_propagate_errors character varying, v_disk_alias character varying, v_disk_description character varying, v_shareable boolean, v_boot boolean, v_sgio integer, v_alignment smallint, v_last_alignment_scan timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO base_disks(
        disk_id,
        disk_interface,
        wipe_after_delete,
        propagate_errors,
        disk_alias,
        disk_description,
        shareable,
        boot,
        sgio,
        alignment,
        last_alignment_scan)
    VALUES(
        v_disk_id,
        v_disk_interface,
        v_wipe_after_delete,
        v_propagate_errors,
        v_disk_alias,
        v_disk_description,
        v_shareable,
        v_boot,
        v_sgio,
        v_alignment,
        v_last_alignment_scan);
END; ';


ALTER FUNCTION public.insertbasedisk(v_disk_id uuid, v_disk_interface character varying, v_wipe_after_delete boolean, v_propagate_errors character varying, v_disk_alias character varying, v_disk_description character varying, v_shareable boolean, v_boot boolean, v_sgio integer, v_alignment smallint, v_last_alignment_scan timestamp with time zone) OWNER TO engine;

--
-- Name: insertbookmark(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertbookmark(v_bookmark_id uuid, v_bookmark_name character varying, v_bookmark_value character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO bookmarks(bookmark_Id,bookmark_name, bookmark_value)
	VALUES(v_bookmark_id, v_bookmark_name, v_bookmark_value);
END; ';


ALTER FUNCTION public.insertbookmark(v_bookmark_id uuid, v_bookmark_name character varying, v_bookmark_value character varying) OWNER TO engine;

--
-- Name: insertclusterpolicy(uuid, character varying, character varying, boolean, boolean, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertclusterpolicy(v_id uuid, v_name character varying, v_description character varying, v_is_locked boolean, v_is_default boolean, v_custom_properties text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO cluster_policies(
        id,
        name,
        description,
        is_locked,
        is_default,
        custom_properties)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_is_locked,
        v_is_default,
        v_custom_properties);
END; ';


ALTER FUNCTION public.insertclusterpolicy(v_id uuid, v_name character varying, v_description character varying, v_is_locked boolean, v_is_default boolean, v_custom_properties text) OWNER TO engine;

--
-- Name: insertclusterpolicyunit(uuid, uuid, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertclusterpolicyunit(v_cluster_policy_id uuid, v_policy_unit_id uuid, v_filter_sequence integer, v_factor integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO cluster_policy_units(
        cluster_policy_id,
        policy_unit_id,
        filter_sequence,
        factor)
    VALUES(
        v_cluster_policy_id,
        v_policy_unit_id,
        v_filter_sequence,
        v_factor);
END; ';


ALTER FUNCTION public.insertclusterpolicyunit(v_cluster_policy_id uuid, v_policy_unit_id uuid, v_filter_sequence integer, v_factor integer) OWNER TO engine;

--
-- Name: insertcustom_actions(integer, character varying, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertcustom_actions(INOUT v_action_id integer, v_action_name character varying, v_path character varying, v_tab integer, v_description character varying) RETURNS integer
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO custom_actions(action_name, path, tab, description)
	VALUES(v_action_name, v_path, v_tab, v_description);

      v_action_id := CURRVAL(''custom_actions_seq'');
END; ';


ALTER FUNCTION public.insertcustom_actions(INOUT v_action_id integer, v_action_name character varying, v_path character varying, v_tab integer, v_description character varying) OWNER TO engine;

--
-- Name: insertdisk_image_dynamic(uuid, integer, integer, bigint, numeric, numeric, numeric); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertdisk_image_dynamic(v_image_id uuid, v_read_rate integer, v_write_rate integer, v_actual_size bigint, v_read_latency_seconds numeric, v_write_latency_seconds numeric, v_flush_latency_seconds numeric) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO disk_image_dynamic(image_id, read_rate, write_rate, actual_size, read_latency_seconds, write_latency_seconds, flush_latency_seconds)
	VALUES(v_image_id, v_read_rate, v_write_rate, v_actual_size, v_read_latency_seconds, v_write_latency_seconds, v_flush_latency_seconds);
END; ';


ALTER FUNCTION public.insertdisk_image_dynamic(v_image_id uuid, v_read_rate integer, v_write_rate integer, v_actual_size bigint, v_read_latency_seconds numeric, v_write_latency_seconds numeric, v_flush_latency_seconds numeric) OWNER TO engine;

--
-- Name: insertdisklunmap(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertdisklunmap(v_disk_id uuid, v_lun_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO disk_lun_map(
        disk_id,
        lun_id)
    VALUES(
        v_disk_id,
        v_lun_id);
END; ';


ALTER FUNCTION public.insertdisklunmap(v_disk_id uuid, v_lun_id character varying) OWNER TO engine;

--
-- Name: insertevent_notification_hist(bigint, character varying, character, character, timestamp with time zone, boolean, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertevent_notification_hist(v_audit_log_id bigint, v_event_name character varying, v_method_type character, v_reason character, v_sent_at timestamp with time zone, v_status boolean, v_subscriber_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO event_notification_hist(audit_log_id, event_name, method_type, reason, sent_at, status, subscriber_id)
	VALUES(v_audit_log_id, v_event_name, v_method_type, v_reason, v_sent_at, v_status, v_subscriber_id::uuid);
END; ';


ALTER FUNCTION public.insertevent_notification_hist(v_audit_log_id bigint, v_event_name character varying, v_method_type character, v_reason character, v_sent_at timestamp with time zone, v_status boolean, v_subscriber_id character varying) OWNER TO engine;

--
-- Name: insertevent_subscriber(character varying, integer, character varying, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertevent_subscriber(v_event_up_name character varying, v_method_id integer, v_method_address character varying, v_subscriber_id uuid, v_tag_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      if not exists(select * from  event_subscriber where
      subscriber_id = v_subscriber_id and
      event_up_name = v_event_up_name and
      method_id = v_method_id and
      tag_name = v_tag_name) then

INSERT INTO event_subscriber(event_up_name, method_id, method_address, subscriber_id, tag_name)
			VALUES(v_event_up_name, v_method_id, v_method_address, v_subscriber_id,v_tag_name);
      end if;
END; ';


ALTER FUNCTION public.insertevent_subscriber(v_event_up_name character varying, v_method_id integer, v_method_address character varying, v_subscriber_id uuid, v_tag_name character varying) OWNER TO engine;

--
-- Name: insertexternalauditlog(integer, timestamp with time zone, integer, character varying, integer, text, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, uuid, character varying, character varying, uuid, uuid, character varying, text, character varying, integer, integer, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertexternalauditlog(INOUT v_audit_log_id integer, v_log_time timestamp with time zone, v_log_type integer, v_log_type_name character varying, v_severity integer, v_message text, v_user_id uuid, v_user_name character varying, v_vds_id uuid, v_vds_name character varying, v_vm_id uuid, v_vm_name character varying, v_vm_template_id uuid, v_vm_template_name character varying, v_storage_pool_id uuid, v_storage_pool_name character varying, v_storage_domain_id uuid, v_storage_domain_name character varying, v_vds_group_id uuid, v_vds_group_name character varying, v_quota_id uuid, v_quota_name character varying, v_correlation_id character varying, v_job_id uuid, v_gluster_volume_id uuid, v_gluster_volume_name character varying, v_call_stack text, v_origin character varying, v_custom_event_id integer, v_event_flood_in_sec integer, v_custom_data text) RETURNS integer
    LANGUAGE plpgsql
    AS '
DECLARE
    v_max_message_length INTEGER;
    v_truncated_message text;
BEGIN

   -- truncate message if exceeds configured max length. truncated messages will be ended
   -- with "..." to indicate that message is incomplete due to size limits.

   v_truncated_message := v_message;
   v_max_message_length := cast(option_value as int) FROM vdc_options WHERE option_name = ''MaxAuditLogMessageLength'' and version = ''general'';
   IF (v_max_message_length IS NOT NULL and length(v_message) > v_max_message_length) THEN
      v_truncated_message := substr(v_message, 1, v_max_message_length -3) || ''...'';
   END IF;
   INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack, origin, custom_event_id, event_flood_in_sec, custom_data )
		VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_truncated_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack, v_origin, v_custom_event_id, v_event_flood_in_sec, v_custom_data);

   v_audit_log_id := CURRVAL(''audit_log_seq'');
END; ';


ALTER FUNCTION public.insertexternalauditlog(INOUT v_audit_log_id integer, v_log_time timestamp with time zone, v_log_type integer, v_log_type_name character varying, v_severity integer, v_message text, v_user_id uuid, v_user_name character varying, v_vds_id uuid, v_vds_name character varying, v_vm_id uuid, v_vm_name character varying, v_vm_template_id uuid, v_vm_template_name character varying, v_storage_pool_id uuid, v_storage_pool_name character varying, v_storage_domain_id uuid, v_storage_domain_name character varying, v_vds_group_id uuid, v_vds_group_name character varying, v_quota_id uuid, v_quota_name character varying, v_correlation_id character varying, v_job_id uuid, v_gluster_volume_id uuid, v_gluster_volume_name character varying, v_call_stack text, v_origin character varying, v_custom_event_id integer, v_event_flood_in_sec integer, v_custom_data text) OWNER TO engine;

--
-- Name: insertglusterclusterservice(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglusterclusterservice(v_cluster_id uuid, v_service_type character varying, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_cluster_services(cluster_id, service_type, status)
    VALUES (v_cluster_id, v_service_type, v_status);
END; ';


ALTER FUNCTION public.insertglusterclusterservice(v_cluster_id uuid, v_service_type character varying, v_status character varying) OWNER TO engine;

--
-- Name: insertglusterhook(uuid, uuid, character varying, character varying, character varying, character varying, character varying, character varying, text, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglusterhook(v_id uuid, v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying, v_hook_status character varying, v_content_type character varying, v_checksum character varying, v_content text, v_conflict_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_hooks(id, cluster_id, gluster_command, stage, name, hook_status,
    content_type, checksum, content, conflict_status)
    VALUES (v_id, v_cluster_id, v_gluster_command, v_stage, v_name,v_hook_status,
    v_content_type, v_checksum, v_content, v_conflict_status);
END; ';


ALTER FUNCTION public.insertglusterhook(v_id uuid, v_cluster_id uuid, v_gluster_command character varying, v_stage character varying, v_name character varying, v_hook_status character varying, v_content_type character varying, v_checksum character varying, v_content text, v_conflict_status integer) OWNER TO engine;

--
-- Name: insertglusterserver(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglusterserver(v_server_id uuid, v_gluster_server_uuid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_server(server_id, gluster_server_uuid)
    VALUES (v_server_id, v_gluster_server_uuid);
END; ';


ALTER FUNCTION public.insertglusterserver(v_server_id uuid, v_gluster_server_uuid uuid) OWNER TO engine;

--
-- Name: insertglusterserverhook(uuid, uuid, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglusterserverhook(v_hook_id uuid, v_server_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_server_hooks(hook_id, server_id, hook_status, content_type, checksum)
    VALUES(v_hook_id, v_server_id, v_hook_status, v_content_type, v_checksum);
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; ';


ALTER FUNCTION public.insertglusterserverhook(v_hook_id uuid, v_server_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying) OWNER TO engine;

--
-- Name: insertglusterserverservice(uuid, uuid, uuid, integer, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglusterserverservice(v_id uuid, v_server_id uuid, v_service_id uuid, v_pid integer, v_status character varying, v_message character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_server_services(id, server_id, service_id, pid, status, message)
    VALUES (v_id, v_server_id, v_service_id, v_pid, v_status, v_message);
END; ';


ALTER FUNCTION public.insertglusterserverservice(v_id uuid, v_server_id uuid, v_service_id uuid, v_pid integer, v_status character varying, v_message character varying) OWNER TO engine;

--
-- Name: insertglustervolume(uuid, uuid, character varying, character varying, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglustervolume(v_id uuid, v_cluster_id uuid, v_vol_name character varying, v_vol_type character varying, v_status character varying, v_replica_count integer, v_stripe_count integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_volumes (id, cluster_id, vol_name, vol_type,
        status, replica_count, stripe_count)
    VALUES (v_id,  v_cluster_id, v_vol_name, v_vol_type,
        v_status, v_replica_count,  v_stripe_count);
END; ';


ALTER FUNCTION public.insertglustervolume(v_id uuid, v_cluster_id uuid, v_vol_name character varying, v_vol_type character varying, v_status character varying, v_replica_count integer, v_stripe_count integer) OWNER TO engine;

--
-- Name: insertglustervolumeaccessprotocol(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglustervolumeaccessprotocol(v_volume_id uuid, v_access_protocol character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_volume_access_protocols (volume_id, access_protocol)
    VALUES (v_volume_id, v_access_protocol);
END; ';


ALTER FUNCTION public.insertglustervolumeaccessprotocol(v_volume_id uuid, v_access_protocol character varying) OWNER TO engine;

--
-- Name: insertglustervolumebrick(uuid, uuid, uuid, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglustervolumebrick(v_id uuid, v_volume_id uuid, v_server_id uuid, v_brick_dir character varying, v_brick_order integer, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_volume_bricks (id, volume_id, server_id, brick_dir, brick_order, status)
    VALUES (v_id, v_volume_id, v_server_id, v_brick_dir, v_brick_order, v_status);
END; ';


ALTER FUNCTION public.insertglustervolumebrick(v_id uuid, v_volume_id uuid, v_server_id uuid, v_brick_dir character varying, v_brick_order integer, v_status character varying) OWNER TO engine;

--
-- Name: insertglustervolumeoption(uuid, uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglustervolumeoption(v_id uuid, v_volume_id uuid, v_option_key character varying, v_option_val character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_volume_options (id, volume_id, option_key, option_val)
    VALUES (v_id, v_volume_id, v_option_key, v_option_val);
END; ';


ALTER FUNCTION public.insertglustervolumeoption(v_id uuid, v_volume_id uuid, v_option_key character varying, v_option_val character varying) OWNER TO engine;

--
-- Name: insertglustervolumetransporttype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertglustervolumetransporttype(v_volume_id uuid, v_transport_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO gluster_volume_transport_types (volume_id, transport_type)
    VALUES (v_volume_id, v_transport_type);
END; ';


ALTER FUNCTION public.insertglustervolumetransporttype(v_volume_id uuid, v_transport_type character varying) OWNER TO engine;

--
-- Name: insertgroup(uuid, character varying, boolean, character varying, character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertgroup(v_id uuid, v_name character varying, v_active boolean, v_domain character varying, v_distinguishedname character varying, v_external_id bytea) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO ad_groups(id, name,active,domain,distinguishedname,external_id)
	VALUES(v_id, v_name,v_active,v_domain,v_distinguishedname,v_external_id);
END; ';


ALTER FUNCTION public.insertgroup(v_id uuid, v_name character varying, v_active boolean, v_domain character varying, v_distinguishedname character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: insertimage(timestamp with time zone, uuid, uuid, bigint, uuid, integer, timestamp with time zone, uuid, integer, integer, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertimage(v_creation_date timestamp with time zone, v_image_guid uuid, v_it_guid uuid, v_size bigint, v_parentid uuid, v_imagestatus integer, v_lastmodified timestamp with time zone, v_vm_snapshot_id uuid, v_volume_type integer, v_volume_format integer, v_image_group_id uuid, v_active boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO images(
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active)
    VALUES(
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active);
END; ';


ALTER FUNCTION public.insertimage(v_creation_date timestamp with time zone, v_image_guid uuid, v_it_guid uuid, v_size bigint, v_parentid uuid, v_imagestatus integer, v_lastmodified timestamp with time zone, v_vm_snapshot_id uuid, v_volume_type integer, v_volume_format integer, v_image_group_id uuid, v_active boolean) OWNER TO engine;

--
-- Name: insertimage_storage_domain_map(uuid, uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertimage_storage_domain_map(v_image_id uuid, v_storage_domain_id uuid, v_quota_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO image_storage_domain_map(image_id, storage_domain_id, quota_id)
	VALUES(v_image_id, v_storage_domain_id, v_quota_id);
END; ';


ALTER FUNCTION public.insertimage_storage_domain_map(v_image_id uuid, v_storage_domain_id uuid, v_quota_id uuid) OWNER TO engine;

--
-- Name: insertiscsibond(uuid, character varying, character varying, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertiscsibond(v_id uuid, v_name character varying, v_description character varying, v_storage_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO iscsi_bonds(id, name, description, storage_pool_id)
      VALUES(v_id, v_name, v_description, v_storage_pool_id);
END; ';


ALTER FUNCTION public.insertiscsibond(v_id uuid, v_name character varying, v_description character varying, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: insertjob(uuid, character varying, text, character varying, uuid, boolean, timestamp with time zone, timestamp with time zone, timestamp with time zone, character varying, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertjob(v_job_id uuid, v_action_type character varying, v_description text, v_status character varying, v_owner_id uuid, v_visible boolean, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_last_update_time timestamp with time zone, v_correlation_id character varying, v_is_external boolean, v_is_auto_cleared boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO job(
        job_id,
        action_type,
        description,
        status,
        owner_id,
        visible,
        start_time,
        end_time,
        last_update_time,
        correlation_id,
        is_external,
        is_auto_cleared)
    VALUES (
        v_job_id,
        v_action_type,
        v_description,
        v_status,
        v_owner_id,
        v_visible,
        v_start_time,
        v_end_time,
        v_last_update_time,
        v_correlation_id,
        v_is_external,
        v_is_auto_cleared);
END; ';


ALTER FUNCTION public.insertjob(v_job_id uuid, v_action_type character varying, v_description text, v_status character varying, v_owner_id uuid, v_visible boolean, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_last_update_time timestamp with time zone, v_correlation_id character varying, v_is_external boolean, v_is_auto_cleared boolean) OWNER TO engine;

--
-- Name: insertjobsubjectentity(uuid, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertjobsubjectentity(v_job_id uuid, v_entity_id uuid, v_entity_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO job_subject_entity(
        job_id,
        entity_id,
        entity_type)
    VALUES (
        v_job_id,
        v_entity_id,
        v_entity_type);
END; ';


ALTER FUNCTION public.insertjobsubjectentity(v_job_id uuid, v_entity_id uuid, v_entity_type character varying) OWNER TO engine;

--
-- Name: insertlun_storage_server_connection_map(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertlun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO LUN_storage_server_connection_map(LUN_id, storage_server_connection)
	VALUES(v_LUN_id, v_storage_server_connection);
END; ';


ALTER FUNCTION public.insertlun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) OWNER TO engine;

--
-- Name: insertluns(character varying, character varying, character varying, character varying, integer, character varying, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertluns(v_lun_id character varying, v_physical_volume_id character varying, v_volume_group_id character varying, v_serial character varying, v_lun_mapping integer, v_vendor_id character varying, v_product_id character varying, v_device_size integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO LUNs(LUN_id, physical_volume_id, volume_group_id, serial, lun_mapping, vendor_id, product_id, device_size)
	VALUES(v_LUN_id, v_physical_volume_id, v_volume_group_id, v_serial, v_lun_mapping, v_vendor_id, v_product_id, v_device_size);
END; ';


ALTER FUNCTION public.insertluns(v_lun_id character varying, v_physical_volume_id character varying, v_volume_group_id character varying, v_serial character varying, v_lun_mapping integer, v_vendor_id character varying, v_product_id character varying, v_device_size integer) OWNER TO engine;

--
-- Name: insertnetwork(character varying, character varying, text, uuid, character varying, character varying, character varying, integer, integer, boolean, uuid, integer, boolean, uuid, text, uuid, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertnetwork(v_addr character varying, v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_subnet character varying, v_gateway character varying, v_type integer, v_vlan_id integer, v_stp boolean, v_storage_pool_id uuid, v_mtu integer, v_vm_network boolean, v_provider_network_provider_id uuid, v_provider_network_external_id text, v_qos_id uuid, v_label text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO network(addr, description, free_text_comment, id, name, subnet, gateway, type, vlan_id, stp, storage_pool_id, mtu, vm_network, provider_network_provider_id, provider_network_external_id, qos_id, label)
	VALUES(v_addr, v_description, v_free_text_comment, v_id, v_name, v_subnet, v_gateway, v_type, v_vlan_id, v_stp, v_storage_pool_id, v_mtu, v_vm_network, v_provider_network_provider_id, v_provider_network_external_id, v_qos_id, v_label);
END; ';


ALTER FUNCTION public.insertnetwork(v_addr character varying, v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_subnet character varying, v_gateway character varying, v_type integer, v_vlan_id integer, v_stp boolean, v_storage_pool_id uuid, v_mtu integer, v_vm_network boolean, v_provider_network_provider_id uuid, v_provider_network_external_id text, v_qos_id uuid, v_label text) OWNER TO engine;

--
-- Name: insertnetwork_cluster(uuid, uuid, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertnetwork_cluster(v_cluster_id uuid, v_network_id uuid, v_status integer, v_is_display boolean, v_required boolean, v_migration boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO network_cluster(cluster_id, network_id, status, is_display, required, migration)
	VALUES(v_cluster_id, v_network_id, v_status, v_is_display, v_required, v_migration);
END; ';


ALTER FUNCTION public.insertnetwork_cluster(v_cluster_id uuid, v_network_id uuid, v_status integer, v_is_display boolean, v_required boolean, v_migration boolean) OWNER TO engine;

--
-- Name: insertnetworkqos(uuid, character varying, uuid, integer, integer, integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertnetworkqos(v_id uuid, v_name character varying, v_storage_pool_id uuid, v_inbound_average integer, v_inbound_peak integer, v_inbound_burst integer, v_outbound_average integer, v_outbound_peak integer, v_outbound_burst integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO network_qos(id, name, storage_pool_id, inbound_average, inbound_peak, inbound_burst, outbound_average, outbound_peak, outbound_burst)
  VALUES(v_id, v_name, v_storage_pool_id, v_inbound_average, v_inbound_peak, v_inbound_burst, v_outbound_average, v_outbound_peak, v_outbound_burst);
END; ';


ALTER FUNCTION public.insertnetworkqos(v_id uuid, v_name character varying, v_storage_pool_id uuid, v_inbound_average integer, v_inbound_peak integer, v_inbound_burst integer, v_outbound_average integer, v_outbound_peak integer, v_outbound_burst integer) OWNER TO engine;

--
-- Name: insertorupdateasynctasks(integer, integer, integer, uuid, uuid, text, character varying, text, character varying, uuid, uuid, uuid, timestamp with time zone, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertorupdateasynctasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_started_at timestamp with time zone, v_storage_pool_id uuid, v_async_task_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      IF NOT EXISTS (SELECT 1 from async_tasks where async_tasks.task_id = v_task_id) THEN
            PERFORM Insertasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_action_parameters,
            v_action_params_class, v_task_parameters, v_task_params_class, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type);
      ELSE
            PERFORM Updateasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_action_parameters,  v_action_params_class, v_task_parameters, v_task_params_class, v_step_id, v_command_id, v_root_command_id,v_storage_pool_id);
      END IF;
END; ';


ALTER FUNCTION public.insertorupdateasynctasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_started_at timestamp with time zone, v_storage_pool_id uuid, v_async_task_type integer) OWNER TO engine;

--
-- Name: insertpermission(uuid, uuid, uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertpermission(v_ad_element_id uuid, v_id uuid, v_role_id uuid, v_object_id uuid, v_object_type_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO permissions(ad_element_id, id, role_id, object_id, object_type_id)
	VALUES(v_ad_element_id, v_id, v_role_id, v_object_id, v_object_type_id);
END; ';


ALTER FUNCTION public.insertpermission(v_ad_element_id uuid, v_id uuid, v_role_id uuid, v_object_id uuid, v_object_type_id integer) OWNER TO engine;

--
-- Name: insertpolicyunit(uuid, character varying, text, boolean, smallint, text, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertpolicyunit(v_id uuid, v_name character varying, v_description text, v_is_internal boolean, v_type smallint, v_custom_properties_regex text, v_enabled boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO policy_units(
        id,
        name,
        description,
        is_internal,
        type,
        custom_properties_regex,
        enabled)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_is_internal,
        v_type,
        v_custom_properties_regex,
        v_enabled);
END; ';


ALTER FUNCTION public.insertpolicyunit(v_id uuid, v_name character varying, v_description text, v_is_internal boolean, v_type smallint, v_custom_properties_regex text, v_enabled boolean) OWNER TO engine;

--
-- Name: insertprovider(uuid, character varying, character varying, character varying, character varying, boolean, character varying, text, text, character varying, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertprovider(v_id uuid, v_name character varying, v_description character varying, v_url character varying, v_provider_type character varying, v_auth_required boolean, v_auth_username character varying, v_auth_password text, v_custom_properties text, v_tenant_name character varying DEFAULT NULL::character varying, v_plugin_type character varying DEFAULT NULL::character varying, v_agent_configuration text DEFAULT NULL::text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO providers(
        id,
        name,
        description,
        url,
        provider_type,
        auth_required,
        auth_username,
        auth_password,
        custom_properties,
        tenant_name,
        plugin_type,
        agent_configuration)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_url,
        v_provider_type,
        v_auth_required,
        v_auth_username,
        v_auth_password,
        v_custom_properties,
        v_tenant_name,
        v_plugin_type,
        v_agent_configuration);
END; ';


ALTER FUNCTION public.insertprovider(v_id uuid, v_name character varying, v_description character varying, v_url character varying, v_provider_type character varying, v_auth_required boolean, v_auth_username character varying, v_auth_password text, v_custom_properties text, v_tenant_name character varying, v_plugin_type character varying, v_agent_configuration text) OWNER TO engine;

--
-- Name: insertquota(uuid, uuid, character varying, character varying, integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertquota(v_id uuid, v_storage_pool_id uuid, v_quota_name character varying, v_description character varying, v_threshold_vds_group_percentage integer, v_threshold_storage_percentage integer, v_grace_vds_group_percentage integer, v_grace_storage_percentage integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO quota(id, storage_pool_id, quota_name, description, threshold_vds_group_percentage, threshold_storage_percentage, grace_vds_group_percentage, grace_storage_percentage)
   VALUES(v_id,  v_storage_pool_id, v_quota_name,  v_description,  v_threshold_vds_group_percentage ,  v_threshold_storage_percentage,  v_grace_vds_group_percentage,  v_grace_storage_percentage);
END; ';


ALTER FUNCTION public.insertquota(v_id uuid, v_storage_pool_id uuid, v_quota_name character varying, v_description character varying, v_threshold_vds_group_percentage integer, v_threshold_storage_percentage integer, v_grace_vds_group_percentage integer, v_grace_storage_percentage integer) OWNER TO engine;

--
-- Name: insertquotalimitation(uuid, uuid, uuid, uuid, integer, bigint, bigint); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertquotalimitation(v_id uuid, v_quota_id uuid, v_storage_id uuid, v_vds_group_id uuid, v_virtual_cpu integer, v_mem_size_mb bigint, v_storage_size_gb bigint) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO quota_limitation(id, quota_id, storage_id, vds_group_id, virtual_cpu, mem_size_mb, storage_size_gb)
   VALUES(v_id, v_quota_id, v_storage_id, v_vds_group_id, v_virtual_cpu, v_mem_size_mb, v_storage_size_gb);

END; ';


ALTER FUNCTION public.insertquotalimitation(v_id uuid, v_quota_id uuid, v_storage_id uuid, v_vds_group_id uuid, v_virtual_cpu integer, v_mem_size_mb bigint, v_storage_size_gb bigint) OWNER TO engine;

--
-- Name: insertrepo_domain_file_meta_data(uuid, character varying, character varying, bigint, timestamp with time zone, bigint, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertrepo_domain_file_meta_data(v_repo_domain_id uuid, v_repo_image_id character varying, v_repo_image_name character varying, v_size bigint, v_date_created timestamp with time zone, v_last_refreshed bigint, v_file_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

INSERT INTO repo_file_meta_data(repo_domain_id, repo_image_id, repo_image_name, size, date_created,
        last_refreshed, file_type)
    VALUES(v_repo_domain_id, v_repo_image_id, v_repo_image_name, v_size, v_date_created,
        v_last_refreshed, v_file_type);

END; ';


ALTER FUNCTION public.insertrepo_domain_file_meta_data(v_repo_domain_id uuid, v_repo_image_id character varying, v_repo_image_name character varying, v_size bigint, v_date_created timestamp with time zone, v_last_refreshed bigint, v_file_type integer) OWNER TO engine;

--
-- Name: insertrole(character varying, uuid, character varying, boolean, integer, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertrole(v_description character varying, v_id uuid, v_name character varying, v_is_readonly boolean, v_role_type integer, v_allows_viewing_children boolean, v_app_mode integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO roles(description, id, name, is_readonly, role_type, allows_viewing_children, app_mode)
	VALUES(v_description, v_id, v_name, v_is_readonly, v_role_type, v_allows_viewing_children, v_app_mode);
END; ';


ALTER FUNCTION public.insertrole(v_description character varying, v_id uuid, v_name character varying, v_is_readonly boolean, v_role_type integer, v_allows_viewing_children boolean, v_app_mode integer) OWNER TO engine;

--
-- Name: insertsnapshot(uuid, uuid, character varying, character varying, character varying, timestamp with time zone, text, text, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertsnapshot(v_snapshot_id uuid, v_vm_id uuid, v_snapshot_type character varying, v_status character varying, v_description character varying, v_creation_date timestamp with time zone, v_app_list text, v_vm_configuration text, v_memory_volume character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO snapshots(
        snapshot_id,
        status,
        vm_id,
        snapshot_type,
        description,
        creation_date,
        app_list,
        vm_configuration,
        memory_volume)
    VALUES(
        v_snapshot_id,
        v_status,
        v_vm_id,
        v_snapshot_type,
        v_description,
        v_creation_date,
        v_app_list,
        v_vm_configuration,
        v_memory_volume);
END; ';


ALTER FUNCTION public.insertsnapshot(v_snapshot_id uuid, v_vm_id uuid, v_snapshot_type character varying, v_status character varying, v_description character varying, v_creation_date timestamp with time zone, v_app_list text, v_vm_configuration text, v_memory_volume character varying) OWNER TO engine;

--
-- Name: insertstep(uuid, uuid, uuid, character varying, text, integer, character varying, timestamp with time zone, timestamp with time zone, character varying, uuid, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstep(v_step_id uuid, v_parent_step_id uuid, v_job_id uuid, v_step_type character varying, v_description text, v_step_number integer, v_status character varying, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_correlation_id character varying, v_external_id uuid, v_external_system_type character varying, v_is_external boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO step(
        step_id,
        parent_step_id,
        job_id,
        step_type,
        description,
        step_number,
        status,
        start_time,
        end_time,
        correlation_id,
        external_id,
        external_system_type,
        is_external)
    VALUES (
        v_step_id,
        v_parent_step_id,
        v_job_id,
        v_step_type,
        v_description,
        v_step_number,
        v_status,
        v_start_time,
        v_end_time,
        v_correlation_id,
        v_external_id,
        v_external_system_type,
        v_is_external);
END; ';


ALTER FUNCTION public.insertstep(v_step_id uuid, v_parent_step_id uuid, v_job_id uuid, v_step_type character varying, v_description text, v_step_number integer, v_status character varying, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_correlation_id character varying, v_external_id uuid, v_external_system_type character varying, v_is_external boolean) OWNER TO engine;

--
-- Name: insertstorage_domain_dynamic(integer, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstorage_domain_dynamic(v_available_disk_size integer, v_id uuid, v_used_disk_size integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO storage_domain_dynamic(available_disk_size, id, used_disk_size)
	VALUES(v_available_disk_size, v_id, v_used_disk_size);
END; ';


ALTER FUNCTION public.insertstorage_domain_dynamic(v_available_disk_size integer, v_id uuid, v_used_disk_size integer) OWNER TO engine;

--
-- Name: insertstorage_domain_static(uuid, character varying, character varying, character varying, text, integer, integer, character varying, bigint); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstorage_domain_static(v_id uuid, v_storage character varying, v_storage_name character varying, v_storage_description character varying, v_storage_comment text, v_storage_type integer, v_storage_domain_type integer, v_storage_domain_format_type character varying, v_last_time_used_as_master bigint) RETURNS void
    LANGUAGE plpgsql
    AS '
   BEGIN
INSERT INTO storage_domain_static(id, storage,storage_name, storage_description, storage_comment, storage_type, storage_domain_type, storage_domain_format_type, last_time_used_as_master)
	VALUES(v_id, v_storage, v_storage_name, v_storage_description, v_storage_comment, v_storage_type, v_storage_domain_type, v_storage_domain_format_type, v_last_time_used_as_master);
END; ';


ALTER FUNCTION public.insertstorage_domain_static(v_id uuid, v_storage character varying, v_storage_name character varying, v_storage_description character varying, v_storage_comment text, v_storage_type integer, v_storage_domain_type integer, v_storage_domain_format_type character varying, v_last_time_used_as_master bigint) OWNER TO engine;

--
-- Name: insertstorage_pool(character varying, text, uuid, character varying, integer, boolean, integer, uuid, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstorage_pool(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_status integer, v_is_local boolean, v_master_domain_version integer, v_spm_vds_id uuid, v_compatibility_version character varying, v_quota_enforcement_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO storage_pool(description, free_text_comment, id, name, status, is_local, master_domain_version,spm_vds_id,compatibility_version,quota_enforcement_type)
	VALUES(v_description, v_free_text_comment, v_id, v_name, v_status, v_is_local, v_master_domain_version,v_spm_vds_id,v_compatibility_version,v_quota_enforcement_type);
END; ';


ALTER FUNCTION public.insertstorage_pool(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_status integer, v_is_local boolean, v_master_domain_version integer, v_spm_vds_id uuid, v_compatibility_version character varying, v_quota_enforcement_type integer) OWNER TO engine;

--
-- Name: insertstorage_pool_iso_map(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstorage_pool_iso_map(v_storage_id uuid, v_storage_pool_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO storage_pool_iso_map(storage_id, storage_pool_id, status)
	VALUES(v_storage_id, v_storage_pool_id, v_status);
END; ';


ALTER FUNCTION public.insertstorage_pool_iso_map(v_storage_id uuid, v_storage_pool_id uuid, v_status integer) OWNER TO engine;

--
-- Name: insertstorage_server_connections(character varying, character varying, character varying, character varying, character varying, text, integer, character varying, character varying, character varying, character varying, smallint, smallint); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertstorage_server_connections(v_connection character varying, v_id character varying, v_iqn character varying, v_port character varying, v_portal character varying, v_password text, v_storage_type integer, v_user_name character varying, v_mount_options character varying, v_vfs_type character varying, v_nfs_version character varying, v_nfs_timeo smallint, v_nfs_retrans smallint) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO storage_server_connections(connection, id, iqn, port,portal,
	password, storage_type, user_name,mount_options,vfs_type,nfs_version,nfs_timeo,nfs_retrans)
	VALUES(v_connection, v_id, v_iqn,v_port,v_portal, v_password, v_storage_type, v_user_name,v_mount_options,v_vfs_type,v_nfs_version,v_nfs_timeo,v_nfs_retrans);
END; ';


ALTER FUNCTION public.insertstorage_server_connections(v_connection character varying, v_id character varying, v_iqn character varying, v_port character varying, v_portal character varying, v_password text, v_storage_type integer, v_user_name character varying, v_mount_options character varying, v_vfs_type character varying, v_nfs_version character varying, v_nfs_timeo smallint, v_nfs_retrans smallint) OWNER TO engine;

--
-- Name: inserttags(character varying, uuid, character varying, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags(v_description character varying, v_tag_id uuid, v_tag_name character varying, v_parent_id uuid, v_readonly boolean, v_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO tags(tag_id,description, tag_name,parent_id,readonly,type)
	VALUES(v_tag_id,v_description, v_tag_name,v_parent_id,v_readonly,v_type);
END; ';


ALTER FUNCTION public.inserttags(v_description character varying, v_tag_id uuid, v_tag_name character varying, v_parent_id uuid, v_readonly boolean, v_type integer) OWNER TO engine;

--
-- Name: inserttags_user_group_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags_user_group_map(v_group_id uuid, v_tag_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO tags_user_group_map(group_id, tag_id)
	VALUES(v_group_id, v_tag_id);
END; ';


ALTER FUNCTION public.inserttags_user_group_map(v_group_id uuid, v_tag_id uuid) OWNER TO engine;

--
-- Name: inserttags_user_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags_user_map(v_tag_id uuid, v_user_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO tags_user_map(tag_id, user_id)
	VALUES(v_tag_id, v_user_id);
END; ';


ALTER FUNCTION public.inserttags_user_map(v_tag_id uuid, v_user_id uuid) OWNER TO engine;

--
-- Name: inserttags_vds_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags_vds_map(v_tag_id uuid, v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO tags_vds_map(tag_id, vds_id)
	VALUES(v_tag_id, v_vds_id);
END; ';


ALTER FUNCTION public.inserttags_vds_map(v_tag_id uuid, v_vds_id uuid) OWNER TO engine;

--
-- Name: inserttags_vm_map(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags_vm_map(v_tag_id uuid, v_vm_id uuid, v_defaultdisplaytype integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO tags_vm_map(tag_id, vm_id, DefaultDisplayType)
	VALUES(v_tag_id, v_vm_id, v_DefaultDisplayType);
END; ';


ALTER FUNCTION public.inserttags_vm_map(v_tag_id uuid, v_vm_id uuid, v_defaultdisplaytype integer) OWNER TO engine;

--
-- Name: inserttags_vm_pool_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inserttags_vm_pool_map(v_tag_id uuid, v_vm_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO tags_vm_pool_map(tag_id, vm_pool_id)
	VALUES(v_tag_id, v_vm_pool_id);
END; ';


ALTER FUNCTION public.inserttags_vm_pool_map(v_tag_id uuid, v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: insertuser(character varying, character varying, character varying, character varying, character varying, character varying, character varying, boolean, character varying, uuid, character varying, character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertuser(v_department character varying, v_domain character varying, v_email character varying, v_groups character varying, v_name character varying, v_note character varying, v_role character varying, v_active boolean, v_surname character varying, v_user_id uuid, v_username character varying, v_group_ids character varying, v_external_id bytea) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO users(department, domain, email, groups, name, note, role, active, surname, user_id, username, group_ids, external_id)
	VALUES(v_department, v_domain, v_email, v_groups, v_name, v_note, v_role, v_active, v_surname, v_user_id, v_username, v_group_ids, v_external_id);
END; ';


ALTER FUNCTION public.insertuser(v_department character varying, v_domain character varying, v_email character varying, v_groups character varying, v_name character varying, v_note character varying, v_role character varying, v_active boolean, v_surname character varying, v_user_id uuid, v_username character varying, v_group_ids character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: insertvdcoption(character varying, character varying, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvdcoption(v_option_name character varying, v_option_value character varying, v_version character varying, INOUT v_option_id integer) RETURNS integer
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vdc_options(OPTION_NAME, option_value, version)
	VALUES(v_option_name, v_option_value, v_version);

      v_option_id := CURRVAL(''vdc_options_seq'');
END; ';


ALTER FUNCTION public.insertvdcoption(v_option_name character varying, v_option_value character varying, v_version character varying, INOUT v_option_id integer) OWNER TO engine;

--
-- Name: insertvds_interface(character varying, character varying, integer, character varying, uuid, boolean, character varying, character varying, character varying, character varying, integer, character varying, integer, integer, uuid, integer, integer, boolean, boolean, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvds_interface(v_addr character varying, v_bond_name character varying, v_bond_type integer, v_gateway character varying, v_id uuid, v_is_bond boolean, v_bond_opts character varying, v_mac_addr character varying, v_name character varying, v_network_name character varying, v_speed integer, v_subnet character varying, v_boot_protocol integer, v_type integer, v_vds_id uuid, v_vlan_id integer, v_mtu integer, v_bridged boolean, v_qos_overridden boolean, v_labels text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vds_interface(addr, bond_name, bond_type, gateway, id, is_bond, bond_opts, mac_addr, name, network_name, speed, subnet, boot_protocol, type, VDS_ID, vlan_id, mtu, bridged, qos_overridden, labels)
	VALUES(v_addr, v_bond_name, v_bond_type, v_gateway, v_id, v_is_bond, v_bond_opts, v_mac_addr, v_name, v_network_name, v_speed, v_subnet, v_boot_protocol, v_type, v_vds_id, v_vlan_id, v_mtu, v_bridged, v_qos_overridden, v_labels);
END; ';


ALTER FUNCTION public.insertvds_interface(v_addr character varying, v_bond_name character varying, v_bond_type integer, v_gateway character varying, v_id uuid, v_is_bond boolean, v_bond_opts character varying, v_mac_addr character varying, v_name character varying, v_network_name character varying, v_speed integer, v_subnet character varying, v_boot_protocol integer, v_type integer, v_vds_id uuid, v_vlan_id integer, v_mtu integer, v_bridged boolean, v_qos_overridden boolean, v_labels text) OWNER TO engine;

--
-- Name: insertvds_interface_statistics(uuid, numeric, numeric, numeric, numeric, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvds_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vds_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, vds_id, iface_status)
	VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, v_vds_id,v_iface_status);
END; ';


ALTER FUNCTION public.insertvds_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vds_id uuid) OWNER TO engine;

--
-- Name: insertvds_spm_id_map(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvds_spm_id_map(v_storage_pool_id uuid, v_vds_id uuid, v_vds_spm_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vds_spm_id_map(storage_pool_id, vds_id, vds_spm_id)
	VALUES(v_storage_pool_id, v_vds_id, v_vds_spm_id);
END; ';


ALTER FUNCTION public.insertvds_spm_id_map(v_storage_pool_id uuid, v_vds_id uuid, v_vds_spm_id integer) OWNER TO engine;

--
-- Name: insertvdsdynamic(integer, integer, character varying, numeric, character varying, boolean, integer, integer, integer, uuid, integer, integer, integer, integer, integer, integer, character varying, character varying, character varying, character varying, integer, character varying, timestamp with time zone, integer, integer, integer, boolean, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, integer, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvdsdynamic(v_cpu_cores integer, v_cpu_threads integer, v_cpu_model character varying, v_cpu_speed_mh numeric, v_if_total_speed character varying, v_kvm_enabled boolean, v_mem_commited integer, v_physical_mem_mb integer, v_status integer, v_vds_id uuid, v_vm_active integer, v_vm_count integer, v_vms_cores_count integer, v_vm_migrating integer, v_reserved_mem integer, v_guest_overhead integer, v_rpm_version character varying, v_software_version character varying, v_version_name character varying, v_build_name character varying, v_previous_status integer, v_cpu_flags character varying, v_cpu_over_commit_time_stamp timestamp with time zone, v_pending_vcpus_count integer, v_pending_vmem_size integer, v_cpu_sockets integer, v_net_config_dirty boolean, v_supported_cluster_levels character varying, v_supported_engines character varying, v_host_os character varying, v_kvm_version character varying, v_libvirt_version character varying, v_spice_version character varying, v_gluster_version character varying, v_kernel_version character varying, v_iscsi_initiator_name character varying, v_transparent_hugepages_state integer, v_hooks character varying, v_hw_manufacturer character varying, v_hw_product_name character varying, v_hw_version character varying, v_hw_serial_number character varying, v_hw_uuid character varying, v_hw_family character varying, v_hbas character varying, v_supported_emulated_machines character varying, v_controlled_by_pm_policy boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
INSERT INTO vds_dynamic(cpu_cores, cpu_threads, cpu_model, cpu_speed_mh, if_total_speed, kvm_enabled, mem_commited, physical_mem_mb,	status, vds_id, vm_active, vm_count, vm_migrating, reserved_mem, guest_overhead, rpm_version, software_version, version_name, build_name, previous_status, cpu_flags, cpu_over_commit_time_stamp, vms_cores_count, pending_vcpus_count, pending_vmem_size, cpu_sockets,net_config_dirty, supported_cluster_levels, supported_engines, host_os, kvm_version, libvirt_version, spice_version, gluster_version, kernel_version, iscsi_initiator_name, transparent_hugepages_state, hooks, hw_manufacturer, hw_product_name, hw_version, hw_serial_number, hw_uuid, hw_family, hbas, supported_emulated_machines, controlled_by_pm_policy)
	VALUES(v_cpu_cores,	v_cpu_threads, v_cpu_model,	v_cpu_speed_mh,	v_if_total_speed, v_kvm_enabled, v_mem_commited, v_physical_mem_mb,	v_status, v_vds_id, v_vm_active, v_vm_count, v_vm_migrating,	v_reserved_mem, v_guest_overhead, v_rpm_version, v_software_version, v_version_name, v_build_name, v_previous_status, v_cpu_flags, v_cpu_over_commit_time_stamp, v_vms_cores_count,v_pending_vcpus_count, v_pending_vmem_size, v_cpu_sockets, v_net_config_dirty, v_supported_cluster_levels, v_supported_engines, v_host_os, v_kvm_version, v_libvirt_version, v_spice_version, v_gluster_version, v_kernel_version, v_iscsi_initiator_name, v_transparent_hugepages_state, v_hooks, v_hw_manufacturer, v_hw_product_name, v_hw_version, v_hw_serial_number, v_hw_uuid, v_hw_family, v_hbas, v_supported_emulated_machines, v_controlled_by_pm_policy);
   END;

   RETURN;
END; ';


ALTER FUNCTION public.insertvdsdynamic(v_cpu_cores integer, v_cpu_threads integer, v_cpu_model character varying, v_cpu_speed_mh numeric, v_if_total_speed character varying, v_kvm_enabled boolean, v_mem_commited integer, v_physical_mem_mb integer, v_status integer, v_vds_id uuid, v_vm_active integer, v_vm_count integer, v_vms_cores_count integer, v_vm_migrating integer, v_reserved_mem integer, v_guest_overhead integer, v_rpm_version character varying, v_software_version character varying, v_version_name character varying, v_build_name character varying, v_previous_status integer, v_cpu_flags character varying, v_cpu_over_commit_time_stamp timestamp with time zone, v_pending_vcpus_count integer, v_pending_vmem_size integer, v_cpu_sockets integer, v_net_config_dirty boolean, v_supported_cluster_levels character varying, v_supported_engines character varying, v_host_os character varying, v_kvm_version character varying, v_libvirt_version character varying, v_spice_version character varying, v_gluster_version character varying, v_kernel_version character varying, v_iscsi_initiator_name character varying, v_transparent_hugepages_state integer, v_hooks character varying, v_hw_manufacturer character varying, v_hw_product_name character varying, v_hw_version character varying, v_hw_serial_number character varying, v_hw_uuid character varying, v_hw_family character varying, v_hbas character varying, v_supported_emulated_machines character varying, v_controlled_by_pm_policy boolean) OWNER TO engine;

--
-- Name: insertvdsgroups(uuid, character varying, text, character varying, character varying, uuid, integer, boolean, character varying, boolean, integer, boolean, boolean, boolean, character varying, boolean, boolean, boolean, uuid, text, boolean, integer, smallint, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvdsgroups(v_vds_group_id uuid, v_description character varying, v_free_text_comment text, v_name character varying, v_cpu_name character varying, v_storage_pool_id uuid, v_max_vds_memory_over_commit integer, v_count_threads_as_cores boolean, v_compatibility_version character varying, v_transparent_hugepages boolean, v_migrate_on_error integer, v_virt_service boolean, v_gluster_service boolean, v_tunnel_migration boolean, v_emulated_machine character varying, v_detect_emulated_machine boolean, v_trusted_service boolean, v_ha_reservation boolean, v_cluster_policy_id uuid, v_cluster_policy_custom_properties text, v_enable_balloon boolean, v_architecture integer, v_optimization_type smallint, v_spice_proxy character varying, v_enable_ksm boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO vds_groups(vds_group_id,description, name, free_text_comment, cpu_name, storage_pool_id,  max_vds_memory_over_commit, count_threads_as_cores, compatibility_version,
        transparent_hugepages, migrate_on_error, virt_service, gluster_service, tunnel_migration, emulated_machine, detect_emulated_machine, trusted_service, ha_reservation, cluster_policy_id,
        cluster_policy_custom_properties, enable_balloon, architecture, optimization_type, spice_proxy, enable_ksm)
	VALUES(v_vds_group_id,v_description, v_name, v_free_text_comment, v_cpu_name, v_storage_pool_id,  v_max_vds_memory_over_commit, v_count_threads_as_cores, v_compatibility_version,
    v_transparent_hugepages, v_migrate_on_error, v_virt_service, v_gluster_service, v_tunnel_migration, v_emulated_machine, v_detect_emulated_machine, v_trusted_service, v_ha_reservation, v_cluster_policy_id, v_cluster_policy_custom_properties, v_enable_balloon,
    v_architecture, v_optimization_type, v_spice_proxy, v_enable_ksm);
END; ';


ALTER FUNCTION public.insertvdsgroups(v_vds_group_id uuid, v_description character varying, v_free_text_comment text, v_name character varying, v_cpu_name character varying, v_storage_pool_id uuid, v_max_vds_memory_over_commit integer, v_count_threads_as_cores boolean, v_compatibility_version character varying, v_transparent_hugepages boolean, v_migrate_on_error integer, v_virt_service boolean, v_gluster_service boolean, v_tunnel_migration boolean, v_emulated_machine character varying, v_detect_emulated_machine boolean, v_trusted_service boolean, v_ha_reservation boolean, v_cluster_policy_id uuid, v_cluster_policy_custom_properties text, v_enable_balloon boolean, v_architecture integer, v_optimization_type smallint, v_spice_proxy character varying, v_enable_ksm boolean) OWNER TO engine;

--
-- Name: insertvdsstatic(text, uuid, character varying, character varying, character varying, integer, uuid, character varying, boolean, integer, integer, character varying, character varying, character varying, integer, character varying, boolean, character varying, character varying, character varying, character varying, text, integer, character varying, boolean, integer, character varying, character varying, integer, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvdsstatic(v_free_text_comment text, v_vds_id uuid, v_host_name character varying, v_ip character varying, v_vds_unique_id character varying, v_port integer, v_vds_group_id uuid, v_vds_name character varying, v_server_ssl_enabled boolean, v_vds_type integer, v_vds_strength integer, v_pm_type character varying, v_pm_user character varying, v_pm_password character varying, v_pm_port integer, v_pm_options character varying, v_pm_enabled boolean, v_pm_proxy_preferences character varying, v_pm_secondary_ip character varying, v_pm_secondary_type character varying, v_pm_secondary_user character varying, v_pm_secondary_password text, v_pm_secondary_port integer, v_pm_secondary_options character varying, v_pm_secondary_concurrent boolean, v_vds_spm_priority integer, v_sshkeyfingerprint character varying, v_console_address character varying, v_ssh_port integer, v_ssh_username character varying, v_disable_auto_pm boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   IF v_vds_unique_id IS NULL OR NOT EXISTS(SELECT vds_name FROM vds_static WHERE vds_unique_id = v_vds_unique_id) then
      BEGIN
         INSERT INTO vds_static(vds_id,host_name, free_text_comment, ip, vds_unique_id, port, vds_group_id, vds_name, server_SSL_enabled,
                               vds_type,vds_strength,pm_type,pm_user,pm_password,pm_port,pm_options,pm_enabled,
                               pm_proxy_preferences, pm_secondary_ip, pm_secondary_type, pm_secondary_user,
                               pm_secondary_password, pm_secondary_port, pm_secondary_options, pm_secondary_concurrent,
                               vds_spm_priority, sshKeyFingerprint, console_address, ssh_port, ssh_username, disable_auto_pm)
			VALUES(v_vds_id,v_host_name, v_free_text_comment, v_ip, v_vds_unique_id, v_port, v_vds_group_id, v_vds_name, v_server_SSL_enabled,
                               v_vds_type,v_vds_strength,v_pm_type,v_pm_user,v_pm_password,v_pm_port,v_pm_options,v_pm_enabled,
                               v_pm_proxy_preferences, v_pm_secondary_ip, v_pm_secondary_type, v_pm_secondary_user,
                               v_pm_secondary_password, v_pm_secondary_port, v_pm_secondary_options, v_pm_secondary_concurrent,
                               v_vds_spm_priority, v_sshKeyFingerprint, v_console_address, v_ssh_port, v_ssh_username, v_disable_auto_pm);
      END;
   end if;
   RETURN;
END; ';


ALTER FUNCTION public.insertvdsstatic(v_free_text_comment text, v_vds_id uuid, v_host_name character varying, v_ip character varying, v_vds_unique_id character varying, v_port integer, v_vds_group_id uuid, v_vds_name character varying, v_server_ssl_enabled boolean, v_vds_type integer, v_vds_strength integer, v_pm_type character varying, v_pm_user character varying, v_pm_password character varying, v_pm_port integer, v_pm_options character varying, v_pm_enabled boolean, v_pm_proxy_preferences character varying, v_pm_secondary_ip character varying, v_pm_secondary_type character varying, v_pm_secondary_user character varying, v_pm_secondary_password text, v_pm_secondary_port integer, v_pm_secondary_options character varying, v_pm_secondary_concurrent boolean, v_vds_spm_priority integer, v_sshkeyfingerprint character varying, v_console_address character varying, v_ssh_port integer, v_ssh_username character varying, v_disable_auto_pm boolean) OWNER TO engine;

--
-- Name: insertvdsstatistics(numeric, numeric, numeric, numeric, integer, integer, integer, uuid, bigint, bigint, bigint, bigint, bigint, integer, bigint, boolean, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvdsstatistics(v_cpu_idle numeric, v_cpu_load numeric, v_cpu_sys numeric, v_cpu_user numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_vds_id uuid, v_mem_available bigint, v_mem_free bigint, v_mem_shared bigint, v_swap_free bigint, v_swap_total bigint, v_ksm_cpu_percent integer, v_ksm_pages bigint, v_ksm_state boolean, v_ha_score integer, v_anonymous_hugepages integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
INSERT INTO vds_statistics(cpu_idle, cpu_load, cpu_sys, cpu_user, usage_cpu_percent, usage_mem_percent, usage_network_percent, vds_id, mem_available, mem_free, mem_shared,swap_free,swap_total,ksm_cpu_percent,ksm_pages,ksm_state, ha_score,anonymous_hugepages)
	VALUES(v_cpu_idle, v_cpu_load, v_cpu_sys, v_cpu_user, v_usage_cpu_percent, v_usage_mem_percent, v_usage_network_percent, v_vds_id, v_mem_available, v_mem_free, v_mem_shared,v_swap_free,v_swap_total,v_ksm_cpu_percent,v_ksm_pages,v_ksm_state, v_ha_score,v_anonymous_hugepages);
   END;

   RETURN;
END; ';


ALTER FUNCTION public.insertvdsstatistics(v_cpu_idle numeric, v_cpu_load numeric, v_cpu_sys numeric, v_cpu_user numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_vds_id uuid, v_mem_available bigint, v_mem_free bigint, v_mem_shared bigint, v_swap_free bigint, v_swap_total bigint, v_ksm_cpu_percent integer, v_ksm_pages bigint, v_ksm_state boolean, v_ha_score integer, v_anonymous_hugepages integer) OWNER TO engine;

--
-- Name: insertvm_interface_statistics(uuid, numeric, numeric, numeric, numeric, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvm_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, vm_id, iface_status)
	VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, v_vm_id,v_iface_status);
END; ';


ALTER FUNCTION public.insertvm_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vm_id uuid) OWNER TO engine;

--
-- Name: insertvm_pool_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvm_pool_map(v_vm_guid uuid, v_vm_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_pool_map(vm_guid, vm_pool_id)
	VALUES(v_vm_guid, v_vm_pool_id);
END; ';


ALTER FUNCTION public.insertvm_pool_map(v_vm_guid uuid, v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: insertvm_pools(character varying, text, uuid, character varying, integer, character varying, integer, uuid, smallint, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvm_pools(v_vm_pool_description character varying, v_vm_pool_comment text, v_vm_pool_id uuid, v_vm_pool_name character varying, v_vm_pool_type integer, v_parameters character varying, v_prestarted_vms integer, v_vds_group_id uuid, v_max_assigned_vms_per_user smallint, v_spice_proxy character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      INSERT INTO vm_pools(vm_pool_id,vm_pool_description, vm_pool_comment, vm_pool_name, vm_pool_type,parameters, prestarted_vms, vds_group_id, max_assigned_vms_per_user, spice_proxy)
      VALUES(v_vm_pool_id,v_vm_pool_description, v_vm_pool_comment, v_vm_pool_name,v_vm_pool_type,v_parameters, v_prestarted_vms, v_vds_group_id, v_max_assigned_vms_per_user, v_spice_proxy);
END; ';


ALTER FUNCTION public.insertvm_pools(v_vm_pool_description character varying, v_vm_pool_comment text, v_vm_pool_id uuid, v_vm_pool_name character varying, v_vm_pool_type integer, v_parameters character varying, v_prestarted_vms integer, v_vds_group_id uuid, v_max_assigned_vms_per_user smallint, v_spice_proxy character varying) OWNER TO engine;

--
-- Name: insertvmdevice(uuid, uuid, character varying, character varying, character varying, integer, text, boolean, boolean, boolean, character varying, text, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmdevice(v_device_id uuid, v_vm_id uuid, v_device character varying, v_type character varying, v_address character varying, v_boot_order integer, v_spec_params text, v_is_managed boolean, v_is_plugged boolean, v_is_readonly boolean, v_alias character varying, v_custom_properties text, v_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    INSERT INTO vm_device(
        device_id,
        vm_id ,
        device ,
        type,
        address ,
        boot_order ,
        spec_params,
        is_managed,
        is_plugged,
        is_readonly,
        alias,
        custom_properties,
        snapshot_id)
    VALUES(
        v_device_id ,
        v_vm_id ,
        v_device ,
        v_type ,
        v_address ,
        v_boot_order ,
        v_spec_params,
        v_is_managed,
        v_is_plugged,
        v_is_readonly,
        v_alias,
        v_custom_properties,
        v_snapshot_id);
END; ';


ALTER FUNCTION public.insertvmdevice(v_device_id uuid, v_vm_id uuid, v_device character varying, v_type character varying, v_address character varying, v_boot_order integer, v_spec_params text, v_is_managed boolean, v_is_plugged boolean, v_is_readonly boolean, v_alias character varying, v_custom_properties text, v_snapshot_id uuid) OWNER TO engine;

--
-- Name: insertvmdynamic(character varying, character varying, character varying, timestamp with time zone, timestamp with time zone, uuid, character varying, uuid, uuid, integer, uuid, character varying, character varying, character varying, timestamp with time zone, timestamp with time zone, integer, integer, boolean, integer, character varying, integer, boolean, integer, integer, integer, uuid, character varying, integer, character varying, integer, integer, character varying, integer, numeric, character varying, boolean, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmdynamic(v_app_list character varying, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, v_guest_last_login_time timestamp with time zone, v_guest_last_logout_time timestamp with time zone, v_console_user_id uuid, v_guest_os character varying, v_migrating_to_vds uuid, v_run_on_vds uuid, v_status integer, v_vm_guid uuid, v_vm_host character varying, v_vm_ip character varying, v_vm_fqdn character varying, v_last_start_time timestamp with time zone, v_last_stop_time timestamp with time zone, v_vm_pid integer, v_display integer, v_acpi_enable boolean, v_session integer, v_display_ip character varying, v_display_type integer, v_kvm_enable boolean, v_boot_sequence integer, v_display_secure_port integer, v_utc_diff integer, v_last_vds_run_on uuid, v_client_ip character varying, v_guest_requested_memory integer, v_hibernation_vol_handle character varying, v_exit_status integer, v_pause_status integer, v_exit_message character varying, v_guest_agent_nics_hash integer, v_last_watchdog_event numeric, v_last_watchdog_action character varying, v_is_run_once boolean, v_cpu_name character varying, v_current_cd character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_dynamic(app_list, guest_cur_user_name, console_cur_user_name, guest_last_login_time, guest_last_logout_time, console_user_id, guest_os, migrating_to_vds, RUN_ON_VDS, status, vm_guid, vm_host, vm_ip, last_start_time, last_stop_time, vm_pid, display, acpi_enable, session, display_ip, display_type, kvm_enable, boot_sequence, display_secure_port, utc_diff, last_vds_run_on, client_ip, guest_requested_memory, hibernation_vol_handle,exit_status,pause_status,exit_message, guest_agent_nics_hash, last_watchdog_event, last_watchdog_action, is_run_once, vm_fqdn, cpu_name, current_cd)
	VALUES(v_app_list, v_guest_cur_user_name, v_console_cur_user_name, v_guest_last_login_time, v_guest_last_logout_time, v_console_user_id, v_guest_os, v_migrating_to_vds, v_run_on_vds, v_status, v_vm_guid, v_vm_host, v_vm_ip, v_last_start_time, v_last_stop_time, v_vm_pid, v_display, v_acpi_enable, v_session, v_display_ip, v_display_type, v_kvm_enable, v_boot_sequence, v_display_secure_port, v_utc_diff, v_last_vds_run_on, v_client_ip, v_guest_requested_memory, v_hibernation_vol_handle, v_exit_status, v_pause_status, v_exit_message, v_guest_agent_nics_hash, v_last_watchdog_event, v_last_watchdog_action, v_is_run_once, v_vm_fqdn, v_cpu_name, v_current_cd);
END; ';


ALTER FUNCTION public.insertvmdynamic(v_app_list character varying, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, v_guest_last_login_time timestamp with time zone, v_guest_last_logout_time timestamp with time zone, v_console_user_id uuid, v_guest_os character varying, v_migrating_to_vds uuid, v_run_on_vds uuid, v_status integer, v_vm_guid uuid, v_vm_host character varying, v_vm_ip character varying, v_vm_fqdn character varying, v_last_start_time timestamp with time zone, v_last_stop_time timestamp with time zone, v_vm_pid integer, v_display integer, v_acpi_enable boolean, v_session integer, v_display_ip character varying, v_display_type integer, v_kvm_enable boolean, v_boot_sequence integer, v_display_secure_port integer, v_utc_diff integer, v_last_vds_run_on uuid, v_client_ip character varying, v_guest_requested_memory integer, v_hibernation_vol_handle character varying, v_exit_status integer, v_pause_status integer, v_exit_message character varying, v_guest_agent_nics_hash integer, v_last_watchdog_event numeric, v_last_watchdog_action character varying, v_is_run_once boolean, v_cpu_name character varying, v_current_cd character varying) OWNER TO engine;

--
-- Name: insertvmguestagentinterface(uuid, character varying, character varying, text, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmguestagentinterface(v_vm_id uuid, v_interface_name character varying, v_mac_address character varying, v_ipv4_addresses text, v_ipv6_addresses text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_guest_agent_interfaces(vm_id, interface_name, mac_address, ipv4_addresses, ipv6_addresses)
       VALUES(v_vm_id, v_interface_name, v_mac_address, v_ipv4_addresses, v_ipv6_addresses);
END; ';


ALTER FUNCTION public.insertvmguestagentinterface(v_vm_id uuid, v_interface_name character varying, v_mac_address character varying, v_ipv4_addresses text, v_ipv6_addresses text) OWNER TO engine;

--
-- Name: insertvminit(uuid, text, text, text, boolean, character varying, text, text, text, text, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvminit(v_vm_id uuid, v_host_name text, v_domain text, v_authorized_keys text, v_regenerate_keys boolean, v_time_zone character varying, v_dns_servers text, v_dns_search_domains text, v_networks text, v_password text, v_winkey character varying, v_custom_script text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_init(vm_id, host_name, domain, authorized_keys, regenerate_keys, time_zone, dns_servers, dns_search_domains,
                    networks, password, winkey, custom_script)
       VALUES(v_vm_id, v_host_name, v_domain, v_authorized_keys, v_regenerate_keys, v_time_zone, v_dns_servers, v_dns_search_domains,
                    v_networks, v_password, v_winkey, v_custom_script);

END; ';


ALTER FUNCTION public.insertvminit(v_vm_id uuid, v_host_name text, v_domain text, v_authorized_keys text, v_regenerate_keys boolean, v_time_zone character varying, v_dns_servers text, v_dns_search_domains text, v_networks text, v_password text, v_winkey character varying, v_custom_script text) OWNER TO engine;

--
-- Name: insertvminterface(uuid, character varying, character varying, integer, uuid, uuid, uuid, integer, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvminterface(v_id uuid, v_mac_addr character varying, v_name character varying, v_speed integer, v_vnic_profile_id uuid, v_vm_guid uuid, v_vmt_guid uuid, v_type integer, v_linked boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_interface(id, mac_addr, name, speed, vnic_profile_id, vm_guid, vmt_guid, type, linked)
       VALUES(v_id, v_mac_addr, v_name, v_speed, v_vnic_profile_id, v_vm_guid, v_vmt_guid, v_type, v_linked);
END; ';


ALTER FUNCTION public.insertvminterface(v_id uuid, v_mac_addr character varying, v_name character varying, v_speed integer, v_vnic_profile_id uuid, v_vm_guid uuid, v_vmt_guid uuid, v_type integer, v_linked boolean) OWNER TO engine;

--
-- Name: insertvmstatic(character varying, text, integer, integer, uuid, uuid, character varying, uuid, timestamp with time zone, integer, boolean, boolean, boolean, integer, integer, integer, character varying, boolean, boolean, boolean, boolean, character varying, uuid, boolean, integer, integer, integer, integer, integer, integer, character varying, integer, character varying, character varying, character varying, integer, character varying, character varying, integer, uuid, character varying, boolean, boolean, character varying, boolean, uuid, uuid, uuid, uuid, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmstatic(v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_os integer, v_vds_group_id uuid, v_vm_guid uuid, v_vm_name character varying, v_vmt_guid uuid, v_creation_date timestamp with time zone, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_is_initialized boolean, v_num_of_sockets integer, v_cpu_per_socket integer, v_usb_policy integer, v_time_zone character varying, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_dedicated_vm_for_vds uuid, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_migration_support integer, v_predefined_properties character varying, v_userdefined_properties character varying, v_min_allocated_mem integer, v_quota_id uuid, v_cpu_pinning character varying, v_host_cpu_flags boolean, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_instance_type_id uuid, v_image_type_id uuid, v_original_template_id uuid, v_original_template_name character varying, v_migration_downtime integer, v_template_version_number integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, vds_group_id, vm_guid, VM_NAME, vmt_guid,creation_date,num_of_monitors, single_qxl_pci, allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy, time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem, entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, original_template_id, original_template_name, migration_downtime, template_version_number)
	VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_creation_date, v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, v_default_display_type, v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem, ''VM'', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, v_original_template_id, v_original_template_name, v_migration_downtime, v_template_version_number);

-- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation.
DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vm_guid;
INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id) VALUES (v_vm_guid, (SELECT storage_pool_id FROM vds_groups vg WHERE vg.vds_group_id = v_vds_group_id));
END; ';


ALTER FUNCTION public.insertvmstatic(v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_os integer, v_vds_group_id uuid, v_vm_guid uuid, v_vm_name character varying, v_vmt_guid uuid, v_creation_date timestamp with time zone, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_is_initialized boolean, v_num_of_sockets integer, v_cpu_per_socket integer, v_usb_policy integer, v_time_zone character varying, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_dedicated_vm_for_vds uuid, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_migration_support integer, v_predefined_properties character varying, v_userdefined_properties character varying, v_min_allocated_mem integer, v_quota_id uuid, v_cpu_pinning character varying, v_host_cpu_flags boolean, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_instance_type_id uuid, v_image_type_id uuid, v_original_template_id uuid, v_original_template_name character varying, v_migration_downtime integer, v_template_version_number integer) OWNER TO engine;

--
-- Name: insertvmstatistics(numeric, numeric, numeric, integer, integer, integer, text, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmstatistics(v_cpu_sys numeric, v_cpu_user numeric, v_elapsed_time numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_disks_usage text, v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
INSERT INTO vm_statistics(cpu_sys, cpu_user, elapsed_time, usage_cpu_percent, usage_mem_percent, usage_network_percent, disks_usage, vm_guid)
	VALUES(v_cpu_sys, v_cpu_user, v_elapsed_time, v_usage_cpu_percent, v_usage_mem_percent, v_usage_network_percent, v_disks_usage, v_vm_guid);
END; ';


ALTER FUNCTION public.insertvmstatistics(v_cpu_sys numeric, v_cpu_user numeric, v_elapsed_time numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_disks_usage text, v_vm_guid uuid) OWNER TO engine;

--
-- Name: insertvmtemplate(integer, timestamp with time zone, character varying, text, integer, character varying, integer, integer, integer, uuid, uuid, integer, boolean, boolean, integer, integer, character varying, boolean, integer, integer, integer, integer, integer, integer, boolean, boolean, boolean, boolean, character varying, boolean, character varying, integer, character varying, character varying, character varying, uuid, integer, uuid, boolean, character varying, integer, boolean, uuid, character varying, integer, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvmtemplate(v_child_count integer, v_creation_date timestamp with time zone, v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_name character varying, v_num_of_sockets integer, v_cpu_per_socket integer, v_os integer, v_vmt_guid uuid, v_vds_group_id uuid, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_status integer, v_usb_policy integer, v_time_zone character varying, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_is_disabled boolean, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_quota_id uuid, v_migration_support integer, v_dedicated_vm_for_vds uuid, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_min_allocated_mem integer, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_template_type character varying, v_migration_downtime integer, v_base_template_id uuid, v_template_version_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
v_template_version_number INTEGER;
BEGIN
  -- get current max version and use next
  SELECT max(template_version_number) + 1 into v_template_version_number
  from vm_static
  where vmt_guid = v_base_template_id
        and entity_type = ''TEMPLATE'';

  -- if no versions exist it might return null, so this is a new base template
  if v_template_version_number is null then
    v_template_version_number = 1;
  end if;

INSERT
INTO vm_static(
    child_count,
    creation_date,
    description,
    free_text_comment,
    mem_size_mb,
    vm_name,
    num_of_sockets,
    cpu_per_socket,
    os,
    vm_guid,
    vds_group_id,
    num_of_monitors,
    single_qxl_pci,
    allow_console_reconnect,
    template_status,
    usb_policy,
    time_zone,
    fail_back,
    vm_type,
    nice_level,
    cpu_shares,
    default_boot_sequence,
    default_display_type,
    priority,
    auto_startup,
    is_stateless,
    iso_path,
    origin,
    initrd_url,
    kernel_url,
    kernel_params,
    entity_type,
    quota_id,
    migration_support,
    is_disabled,
    dedicated_vm_for_vds,
    is_smartcard_enabled,
    is_delete_protected,
    sso_method,
    tunnel_migration,
    vnc_keyboard_layout,
    min_allocated_mem,
    is_run_and_pause,
    created_by_user_id,
    migration_downtime,
    template_version_number,
    vmt_guid,
    template_version_name)
VALUES(
    v_child_count,
    v_creation_date,
    v_description,
    v_free_text_comment,
    v_mem_size_mb,
    v_name,
    v_num_of_sockets,
    v_cpu_per_socket,
    v_os,
    v_vmt_guid,
    v_vds_group_id,
    v_num_of_monitors,
    v_single_qxl_pci,
    v_allow_console_reconnect,
    v_status,
    v_usb_policy,
    v_time_zone,
    v_fail_back,
    v_vm_type,
    v_nice_level,
    v_cpu_shares,
    v_default_boot_sequence,
    v_default_display_type,
    v_priority,
    v_auto_startup,
    v_is_stateless,
    v_iso_path,
    v_origin,
    v_initrd_url,
    v_kernel_url,
    v_kernel_params,
    v_template_type,
    v_quota_id,
    v_migration_support,
    v_is_disabled,
    v_dedicated_vm_for_vds,
    v_is_smartcard_enabled,
    v_is_delete_protected,
    v_sso_method,
    v_tunnel_migration,
    v_vnc_keyboard_layout,
    v_min_allocated_mem,
    v_is_run_and_pause,
    v_created_by_user_id,
    v_migration_downtime,
    v_template_version_number,
    v_base_template_id,
    v_template_version_name);
-- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation.
DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vmt_guid;
INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id)
VALUES (v_vmt_guid, (SELECT storage_pool_id
                     FROM vds_groups vg
                     WHERE vg.vds_group_id = v_vds_group_id));
END; ';


ALTER FUNCTION public.insertvmtemplate(v_child_count integer, v_creation_date timestamp with time zone, v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_name character varying, v_num_of_sockets integer, v_cpu_per_socket integer, v_os integer, v_vmt_guid uuid, v_vds_group_id uuid, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_status integer, v_usb_policy integer, v_time_zone character varying, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_is_disabled boolean, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_quota_id uuid, v_migration_support integer, v_dedicated_vm_for_vds uuid, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_min_allocated_mem integer, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_template_type character varying, v_migration_downtime integer, v_base_template_id uuid, v_template_version_name character varying) OWNER TO engine;

--
-- Name: insertvnicprofile(uuid, character varying, uuid, uuid, boolean, text, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION insertvnicprofile(v_id uuid, v_name character varying, v_network_id uuid, v_network_qos_id uuid, v_port_mirroring boolean, v_custom_properties text, v_description text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   INSERT INTO vnic_profiles(id, name, network_id, network_qos_id, port_mirroring, custom_properties, description)
       VALUES(v_id, v_name, v_network_id, v_network_qos_id, v_port_mirroring, v_custom_properties, v_description);

END; ';


ALTER FUNCTION public.insertvnicprofile(v_id uuid, v_name character varying, v_network_id uuid, v_network_qos_id uuid, v_port_mirroring boolean, v_custom_properties text, v_description text) OWNER TO engine;

--
-- Name: inst_add_iso_storage_domain(uuid, character varying, uuid, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inst_add_iso_storage_domain(v_storage_domain_id uuid, v_name character varying, v_connection_id uuid, v_connection character varying, v_available integer, v_used integer) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
BEGIN
    if not exists (select 1 from storage_server_connections where connection = v_connection) then
        -- Insert storage server connection info
        perform Insertstorage_server_connections(v_connection,cast(v_connection_id as varchar(250)),NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL);
        -- Insert storage domain static info
        perform Insertstorage_domain_static(v_storage_domain_id,cast(v_connection_id as varchar(250)),v_name,v_name,'''',1,2,''0'',0);
        -- Insert storage domain dynamic  info
        perform Insertstorage_domain_dynamic(v_available,v_storage_domain_id,v_used);
    end if;
    exception
        when others then
	    RAISE EXCEPTION ''NUM:%, DETAILS:%'', SQLSTATE, SQLERRM;
END; ';


ALTER FUNCTION public.inst_add_iso_storage_domain(v_storage_domain_id uuid, v_name character varying, v_connection_id uuid, v_connection character varying, v_available integer, v_used integer) OWNER TO engine;

--
-- Name: inst_update_default_storage_pool_type(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inst_update_default_storage_pool_type(v_storage_pool_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      if (v_storage_pool_type > 0 and v_storage_pool_type < 7) then
         UPDATE storage_pool
         SET storage_pool_type = v_storage_pool_type, _update_date = LOCALTIMESTAMP
         WHERE storage_pool.name = ''Default'' and not exists
         (select 1 from storage_domains where storage_domains.storage_pool_name = ''Default'');
      end if;
END; ';


ALTER FUNCTION public.inst_update_default_storage_pool_type(v_storage_pool_type integer) OWNER TO engine;

--
-- Name: inst_update_service_type(uuid, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION inst_update_service_type(v_cluster_id uuid, v_virt_service boolean, v_gluster_service boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
begin
    update  vds_groups set virt_service = v_virt_service, gluster_service = v_gluster_service
    where vds_group_id = v_cluster_id;
END; ';


ALTER FUNCTION public.inst_update_service_type(v_cluster_id uuid, v_virt_service boolean, v_gluster_service boolean) OWNER TO engine;

--
-- Name: ismaterializedviewrefreshed(name); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION ismaterializedviewrefreshed(v_matview name) RETURNS boolean
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_is_refreshed boolean;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
    END IF;

    -- check if materialized View should refresh
    v_is_refreshed := (((CURRENT_TIMESTAMP - to_interval(refresh_rate_in_sec)) <= last_refresh) and
                      ((CURRENT_TIMESTAMP - to_interval(min_refresh_rate_in_sec)) <= last_refresh)) or
                      not active from materialized_views
                       where mv_name = v_matview;
    RETURN v_is_refreshed;
 END; ';


ALTER FUNCTION public.ismaterializedviewrefreshed(v_matview name) OWNER TO engine;

--
-- Name: ismemballoonenabled(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION ismemballoonenabled(v_vm_id uuid) RETURNS boolean
    LANGUAGE plpgsql STABLE
    AS '
declare
    result boolean := false;
begin
    if exists (select 1 from vm_device where vm_id = v_vm_id and type = ''balloon'' and device = ''memballoon'') then
        result := true;
    end if;
    return result;
end;
';


ALTER FUNCTION public.ismemballoonenabled(v_vm_id uuid) OWNER TO engine;

--
-- Name: isquotainuse(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION isquotainuse(v_quota_id uuid) RETURNS boolean
    LANGUAGE plpgsql STABLE
    AS '
DECLARE
    result boolean := FALSE;
BEGIN
    if EXISTS (SELECT quota_id
                    FROM image_storage_domain_map
                    WHERE quota_id = v_quota_id
    UNION SELECT quota_id
              FROM vm_static
              WHERE quota_id = v_quota_id) then
        result := TRUE;
    END if;
    return result;
END; ';


ALTER FUNCTION public.isquotainuse(v_quota_id uuid) OWNER TO engine;

--
-- Name: refreshallmaterializedviews(boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION refreshallmaterializedviews(v_force boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and refresh only needed snapshots
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           IF ((v_force and v_record.min_refresh_rate_in_sec = 0) or not IsMaterializedViewRefreshed(v_record.mv_name)) THEN
              perform RefreshMaterializedView(v_record.mv_name);
           END IF;
       END LOOP;
       CLOSE v_cur;
END; ';


ALTER FUNCTION public.refreshallmaterializedviews(v_force boolean) OWNER TO engine;

--
-- Name: refreshmaterializedview(name); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION refreshmaterializedview(v_matview name) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_drop_index_sp NAME;
     v_create_index_sp NAME;
     v_start_time TIMESTAMP WITH TIME ZONE;
     v_avg_cost_ms int;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
    END IF;

    -- get start time
    v_start_time:=CURRENT_TIMESTAMP;
    -- SP for Drop / create Index should follow naming convention Mt[Drop|Create]<v_matview>Indexes
    v_drop_index_sp := ''MtDrop'' || v_matview || ''Indexes'';
    v_create_index_sp := ''MtCreate'' || v_matview || ''Indexes'';

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_drop_index_sp) THEN
        v_drop_index_sp := NULL;
    END IF;

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
        v_create_index_sp := NULL;
    END IF;

    -- Lock materialized_views table until refresh completes to prevent duplicate refreshes by other threads
    LOCK TABLE materialized_views;
    -- taking a lock on the snapshot materialized view until it refreshed
    EXECUTE ''LOCK TABLE '' || v_matview;
    -- drop indexes on the snapshot materialized view if exists
    IF (v_drop_index_sp IS NOT NULL) THEN
        EXECUTE ''select '' || v_drop_index_sp || ''()'';
    END IF;
    -- refresh the view
    EXECUTE ''TRUNCATE TABLE '' || v_matview;
    EXECUTE ''INSERT INTO '' || v_matview
        || '' SELECT * FROM '' || v_entry.v_name;
    -- restore  indexes on the snapshot materialized view if exists
    IF (v_create_index_sp IS NOT NULL) THEN
        EXECUTE ''select '' || v_create_index_sp || ''()'';
    END IF;
    -- update last refresh time and average cost in [ms]
    IF (v_entry.avg_cost_ms = 0) THEN
        v_avg_cost_ms:=EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000;
    ELSE
        v_avg_cost_ms:=((EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000) + v_entry.avg_cost_ms)/2;
    END IF;
    update materialized_views set last_refresh = CURRENT_TIMESTAMP,
                                  avg_cost_ms = v_avg_cost_ms
                              where  mv_name = v_matview;
    RETURN;
 END; ';


ALTER FUNCTION public.refreshmaterializedview(v_matview name) OWNER TO engine;

--
-- Name: removeallvmtagsbyvmid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removeallvmtagsbyvmid(v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      delete FROM tags_vm_map
      where vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.removeallvmtagsbyvmid(v_vm_id uuid) OWNER TO engine;

--
-- Name: removeconnectionfromiscsibond(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removeconnectionfromiscsibond(v_iscsi_bond_id uuid, v_connection_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM iscsi_bonds_storage_connections_map
      WHERE iscsi_bond_id = v_iscsi_bond_id and connection_id = v_connection_id;
END; ';


ALTER FUNCTION public.removeconnectionfromiscsibond(v_iscsi_bond_id uuid, v_connection_id character varying) OWNER TO engine;

--
-- Name: removememoryfromsnapshotbysnapshotid(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removememoryfromsnapshotbysnapshotid(v_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE snapshots
    SET    memory_volume = NULL
    WHERE  snapshot_id = v_snapshot_id;
END; ';


ALTER FUNCTION public.removememoryfromsnapshotbysnapshotid(v_snapshot_id uuid) OWNER TO engine;

--
-- Name: removememoryfromsnapshotbyvmidandtype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removememoryfromsnapshotbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE snapshots
    SET    memory_volume = NULL
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type;
END; ';


ALTER FUNCTION public.removememoryfromsnapshotbyvmidandtype(v_vm_id uuid, v_snapshot_type character varying) OWNER TO engine;

--
-- Name: removenetworkfromiscsibond(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removenetworkfromiscsibond(v_iscsi_bond_id uuid, v_network_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      DELETE FROM iscsi_bonds_networks_map
      WHERE iscsi_bond_id = v_iscsi_bond_id and network_id = v_network_id;
END; ';


ALTER FUNCTION public.removenetworkfromiscsibond(v_iscsi_bond_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: removevmfromaffinitygroups(uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION removevmfromaffinitygroups(v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    DELETE
    FROM affinity_group_members
    WHERE vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.removevmfromaffinitygroups(v_vm_id uuid) OWNER TO engine;

--
-- Name: renamemanagementnetwork(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION renamemanagementnetwork(v_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    v_management_network_id UUID;
    v_old_name  varchar(4000);
BEGIN
    select option_value into v_old_name from vdc_options where option_name = ''ManagementNetwork'' and version = ''general'';
    select id into v_management_network_id from network where name = v_old_name;
    perform fn_db_update_config_value(''ManagementNetwork'', v_name, ''general'');
    update network set name = v_name where id = v_management_network_id;
END; ';


ALTER FUNCTION public.renamemanagementnetwork(v_name character varying) OWNER TO engine;

--
-- Name: set_network_exclusively_as_display(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION set_network_exclusively_as_display(v_cluster_id uuid, v_network_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   UPDATE network_cluster
   SET is_display = true
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

   IF FOUND THEN
       UPDATE network_cluster
       SET is_display = false
       WHERE cluster_id = v_cluster_id AND network_id != v_network_id;
   END IF;

END; ';


ALTER FUNCTION public.set_network_exclusively_as_display(v_cluster_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: set_network_exclusively_as_migration(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION set_network_exclusively_as_migration(v_cluster_id uuid, v_network_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   UPDATE network_cluster
   SET migration = true
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

   IF FOUND THEN
       UPDATE network_cluster
       SET migration = false
       WHERE cluster_id = v_cluster_id AND network_id != v_network_id;
   END IF;

END; ';


ALTER FUNCTION public.set_network_exclusively_as_migration(v_cluster_id uuid, v_network_id uuid) OWNER TO engine;

--
-- Name: to_interval(integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION to_interval(sec integer) RETURNS interval
    LANGUAGE plpgsql IMMUTABLE STRICT
    AS '
BEGIN
  RETURN (sec || '' seconds'')::INTERVAL;
END;
';


ALTER FUNCTION public.to_interval(sec integer) OWNER TO engine;

--
-- Name: updateaffinitygroupwithmembers(uuid, character varying, character varying, uuid, boolean, boolean, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateaffinitygroupwithmembers(v_id uuid, v_name character varying, v_description character varying, v_cluster_id uuid, v_positive boolean, v_enforcing boolean, v_vm_ids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    PERFORM DeleteAffinityGroup(v_id);
    PERFORM InsertAffinityGroupWithMembers(
        v_id,
        v_name,
        v_description,
        v_cluster_id,
        v_positive,
        v_enforcing,
        v_vm_ids);
END; ';


ALTER FUNCTION public.updateaffinitygroupwithmembers(v_id uuid, v_name character varying, v_description character varying, v_cluster_id uuid, v_positive boolean, v_enforcing boolean, v_vm_ids character varying) OWNER TO engine;

--
-- Name: updateasync_tasks(integer, integer, integer, uuid, uuid, text, character varying, text, character varying, uuid, uuid, uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateasync_tasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_storage_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE async_tasks
      SET action_type = v_action_type,
          result = v_result,
          status = v_status,
          action_parameters = v_action_parameters,
          action_params_class = v_action_params_class,
          task_parameters = v_task_parameters,
          task_params_class = v_task_params_class,
          step_id = v_step_id,
          command_id = v_command_id,
          root_command_id = v_root_command_id,
          vdsm_task_id = v_vdsm_task_id,
          storage_pool_id = v_storage_pool_id
      WHERE task_id = v_task_id;
END; ';


ALTER FUNCTION public.updateasync_tasks(v_action_type integer, v_result integer, v_status integer, v_vdsm_task_id uuid, v_task_id uuid, v_action_parameters text, v_action_params_class character varying, v_task_parameters text, v_task_params_class character varying, v_step_id uuid, v_command_id uuid, v_root_command_id uuid, v_storage_pool_id uuid) OWNER TO engine;

--
-- Name: updatebasedisk(uuid, character varying, boolean, character varying, character varying, character varying, boolean, boolean, integer, smallint, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatebasedisk(v_disk_id uuid, v_disk_interface character varying, v_wipe_after_delete boolean, v_propagate_errors character varying, v_disk_alias character varying, v_disk_description character varying, v_shareable boolean, v_boot boolean, v_sgio integer, v_alignment smallint, v_last_alignment_scan timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE base_disks
    SET    disk_interface = v_disk_interface,
           wipe_after_delete = v_wipe_after_delete,
           propagate_errors = v_propagate_errors,
           disk_alias = v_disk_alias,
           disk_description = v_disk_description,
           shareable = v_shareable,
           boot = v_boot,
           sgio = v_sgio,
           alignment = v_alignment,
           last_alignment_scan = v_last_alignment_scan
    WHERE  disk_id = v_disk_id;
END; ';


ALTER FUNCTION public.updatebasedisk(v_disk_id uuid, v_disk_interface character varying, v_wipe_after_delete boolean, v_propagate_errors character varying, v_disk_alias character varying, v_disk_description character varying, v_shareable boolean, v_boot boolean, v_sgio integer, v_alignment smallint, v_last_alignment_scan timestamp with time zone) OWNER TO engine;

--
-- Name: updatebookmark(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatebookmark(v_bookmark_id uuid, v_bookmark_name character varying, v_bookmark_value character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE bookmarks
      SET bookmark_name = v_bookmark_name,bookmark_value = v_bookmark_value
      WHERE bookmark_Id = v_bookmark_id;
END; ';


ALTER FUNCTION public.updatebookmark(v_bookmark_id uuid, v_bookmark_name character varying, v_bookmark_value character varying) OWNER TO engine;

--
-- Name: updateclusterpolicy(uuid, character varying, character varying, boolean, boolean, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateclusterpolicy(v_id uuid, v_name character varying, v_description character varying, v_is_locked boolean, v_is_default boolean, v_custom_properties text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE cluster_policies
    SET    name = v_name,
           description = v_description,
           is_locked = v_is_locked,
           is_default = v_is_default,
           custom_properties = v_custom_properties
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.updateclusterpolicy(v_id uuid, v_name character varying, v_description character varying, v_is_locked boolean, v_is_default boolean, v_custom_properties text) OWNER TO engine;

--
-- Name: updateconsoleuserwithoptimisticlocking(uuid, uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateconsoleuserwithoptimisticlocking(v_vm_guid uuid, v_console_user_id uuid, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, OUT v_updated boolean) RETURNS boolean
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vm_dynamic SET
        console_user_id = v_console_user_id,
        guest_cur_user_name = v_guest_cur_user_name,
        console_cur_user_name = v_console_cur_user_name
    WHERE
        vm_guid = v_vm_guid AND
        (console_user_id = v_console_user_id OR console_user_id IS NULL);
    v_updated := FOUND;
END; ';


ALTER FUNCTION public.updateconsoleuserwithoptimisticlocking(v_vm_guid uuid, v_console_user_id uuid, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, OUT v_updated boolean) OWNER TO engine;

--
-- Name: updatecustom_actions(integer, character varying, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatecustom_actions(v_action_id integer, v_action_name character varying, v_path character varying, v_tab integer, v_description character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE custom_actions
      SET action_name = v_action_name,path = v_path,tab = v_tab,description = v_description
      WHERE action_id = v_action_id;
END; ';


ALTER FUNCTION public.updatecustom_actions(v_action_id integer, v_action_name character varying, v_path character varying, v_tab integer, v_description character varying) OWNER TO engine;

--
-- Name: updatedisk_image_dynamic(uuid, integer, integer, bigint, numeric, numeric, numeric); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatedisk_image_dynamic(v_image_id uuid, v_read_rate integer, v_write_rate integer, v_actual_size bigint, v_read_latency_seconds numeric, v_write_latency_seconds numeric, v_flush_latency_seconds numeric) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE disk_image_dynamic
      SET read_rate = v_read_rate,write_rate = v_write_rate,actual_size = v_actual_size,read_latency_seconds = v_read_latency_seconds,write_latency_seconds = v_write_latency_seconds,flush_latency_seconds = v_flush_latency_seconds, _update_date = LOCALTIMESTAMP
      WHERE image_id = v_image_id;
END; ';


ALTER FUNCTION public.updatedisk_image_dynamic(v_image_id uuid, v_read_rate integer, v_write_rate integer, v_actual_size bigint, v_read_latency_seconds numeric, v_write_latency_seconds numeric, v_flush_latency_seconds numeric) OWNER TO engine;

--
-- Name: updatedwhhistorytimekeeping(character varying, character varying, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatedwhhistorytimekeeping(v_var_name character varying, v_var_value character varying, v_var_datetime timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE dwh_history_timekeeping
      SET var_value = v_var_value,
          var_datetime = v_var_datetime
      WHERE var_name = v_var_name;
END; ';


ALTER FUNCTION public.updatedwhhistorytimekeeping(v_var_name character varying, v_var_value character varying, v_var_datetime timestamp with time zone) OWNER TO engine;

--
-- Name: updateevent_subscriber(character varying, integer, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateevent_subscriber(v_event_up_name character varying, v_old_method_id integer, v_new_method_id integer, v_subscriber_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      update event_subscriber set method_id = v_new_method_id
      where event_up_name = v_event_up_name
      and method_id = v_old_method_id
      and subscriber_id = v_subscriber_id;
END; ';


ALTER FUNCTION public.updateevent_subscriber(v_event_up_name character varying, v_old_method_id integer, v_new_method_id integer, v_subscriber_id uuid) OWNER TO engine;

--
-- Name: updateglusterbricktaskbyserveridbrickdir(uuid, character varying, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterbricktaskbyserveridbrickdir(v_server_id uuid, v_brick_dir character varying, v_task_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_volume_bricks
    SET     task_id = v_task_id,
            _update_date = LOCALTIMESTAMP
    WHERE   server_id = v_server_id
    AND brick_dir = v_brick_dir;
END; ';


ALTER FUNCTION public.updateglusterbricktaskbyserveridbrickdir(v_server_id uuid, v_brick_dir character varying, v_task_id uuid) OWNER TO engine;

--
-- Name: updateglusterclusterservice(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterclusterservice(v_cluster_id uuid, v_service_type character varying, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_cluster_services
    SET     status = v_status,
            _update_date = LOCALTIMESTAMP
    WHERE   cluster_id = v_cluster_id
    AND     service_type = v_service_type;
END; ';


ALTER FUNCTION public.updateglusterclusterservice(v_cluster_id uuid, v_service_type character varying, v_status character varying) OWNER TO engine;

--
-- Name: updateglusterhook(uuid, character varying, character varying, character varying, text, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterhook(v_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying, v_content text, v_conflict_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_hooks
    SET hook_status = v_hook_status,
        content_type = v_content_type,
        checksum = v_checksum,
        content = v_content,
        conflict_status = v_conflict_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglusterhook(v_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying, v_content text, v_conflict_status integer) OWNER TO engine;

--
-- Name: updateglusterhookconflictstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterhookconflictstatus(v_id uuid, v_conflict_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_hooks
    SET conflict_status = v_conflict_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglusterhookconflictstatus(v_id uuid, v_conflict_status integer) OWNER TO engine;

--
-- Name: updateglusterhookcontent(uuid, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterhookcontent(v_id uuid, v_checksum character varying, v_content text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_hooks
    SET checksum = v_checksum,
        content = v_content,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglusterhookcontent(v_id uuid, v_checksum character varying, v_content text) OWNER TO engine;

--
-- Name: updateglusterhookcontenttype(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterhookcontenttype(v_id uuid, v_content_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_hooks
    SET content_type = v_content_type,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglusterhookcontenttype(v_id uuid, v_content_type character varying) OWNER TO engine;

--
-- Name: updateglusterhookstatus(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterhookstatus(v_id uuid, v_hook_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_hooks
    SET hook_status = v_hook_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglusterhookstatus(v_id uuid, v_hook_status character varying) OWNER TO engine;

--
-- Name: updateglusterserver(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserver(v_server_id uuid, v_gluster_server_uuid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_server
    SET gluster_server_uuid = v_gluster_server_uuid
    WHERE server_id = v_server_id;
END; ';


ALTER FUNCTION public.updateglusterserver(v_server_id uuid, v_gluster_server_uuid uuid) OWNER TO engine;

--
-- Name: updateglusterserverhook(uuid, uuid, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserverhook(v_hook_id uuid, v_server_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_server_hooks
    SET hook_status = v_hook_status,
        content_type = v_content_type,
        checksum = v_checksum,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; ';


ALTER FUNCTION public.updateglusterserverhook(v_hook_id uuid, v_server_id uuid, v_hook_status character varying, v_content_type character varying, v_checksum character varying) OWNER TO engine;

--
-- Name: updateglusterserverhookchecksum(uuid, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserverhookchecksum(v_hook_id uuid, v_server_id uuid, v_checksum character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_server_hooks
    SET checksum = v_checksum,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
END; ';


ALTER FUNCTION public.updateglusterserverhookchecksum(v_hook_id uuid, v_server_id uuid, v_checksum character varying) OWNER TO engine;

--
-- Name: updateglusterserverhookstatus(uuid, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserverhookstatus(v_hook_id uuid, v_server_id uuid, v_hook_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_server_hooks
    SET hook_status = v_hook_status,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; ';


ALTER FUNCTION public.updateglusterserverhookstatus(v_hook_id uuid, v_server_id uuid, v_hook_status character varying) OWNER TO engine;

--
-- Name: updateglusterserverservice(uuid, integer, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserverservice(v_id uuid, v_pid integer, v_status character varying, v_message character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_server_services
    SET     pid = v_pid,
            status = v_status,
            message = v_message,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.updateglusterserverservice(v_id uuid, v_pid integer, v_status character varying, v_message character varying) OWNER TO engine;

--
-- Name: updateglusterserverservicebyserveridandservicetype(uuid, uuid, integer, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglusterserverservicebyserveridandservicetype(v_server_id uuid, v_service_id uuid, v_pid integer, v_status character varying, v_message character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_server_services
    SET     pid = v_pid,
            status = v_status,
            message = v_message,
            _update_date = LOCALTIMESTAMP
    WHERE   server_id = v_server_id
    AND     service_id = v_service_id;
END; ';


ALTER FUNCTION public.updateglusterserverservicebyserveridandservicetype(v_server_id uuid, v_service_id uuid, v_pid integer, v_status character varying, v_message character varying) OWNER TO engine;

--
-- Name: updateglustervolume(uuid, uuid, character varying, character varying, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolume(v_id uuid, v_cluster_id uuid, v_vol_name character varying, v_vol_type character varying, v_status character varying, v_replica_count integer, v_stripe_count integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volumes
    SET cluster_id = v_cluster_id,
        vol_name = v_vol_name,
        vol_type = v_vol_type,
        status = v_status,
        replica_count = v_replica_count,
        stripe_count = v_stripe_count,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolume(v_id uuid, v_cluster_id uuid, v_vol_name character varying, v_vol_type character varying, v_status character varying, v_replica_count integer, v_stripe_count integer) OWNER TO engine;

--
-- Name: updateglustervolumeasynctask(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumeasynctask(v_volume_id uuid, v_task_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volumes
    SET
        task_id = v_task_id,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_volume_id;
END; ';


ALTER FUNCTION public.updateglustervolumeasynctask(v_volume_id uuid, v_task_id uuid) OWNER TO engine;

--
-- Name: updateglustervolumebrick(uuid, uuid, uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumebrick(v_id uuid, v_new_id uuid, v_new_server_id uuid, v_new_brick_dir character varying, v_new_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volume_bricks
    SET    id = v_new_id,
           server_id = v_new_server_id,
           brick_dir = v_new_brick_dir,
           status = v_new_status,
           _update_date = LOCALTIMESTAMP
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolumebrick(v_id uuid, v_new_id uuid, v_new_server_id uuid, v_new_brick_dir character varying, v_new_status character varying) OWNER TO engine;

--
-- Name: updateglustervolumebrickasynctask(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumebrickasynctask(v_id uuid, v_task_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_volume_bricks
    SET     task_id = v_task_id,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolumebrickasynctask(v_id uuid, v_task_id uuid) OWNER TO engine;

--
-- Name: updateglustervolumebrickorder(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumebrickorder(v_id uuid, v_brick_order integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_volume_bricks
    SET     brick_order = v_brick_order,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolumebrickorder(v_id uuid, v_brick_order integer) OWNER TO engine;

--
-- Name: updateglustervolumebrickstatus(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumebrickstatus(v_id uuid, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE  gluster_volume_bricks
    SET     status = v_status,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolumebrickstatus(v_id uuid, v_status character varying) OWNER TO engine;

--
-- Name: updateglustervolumeoption(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumeoption(v_id uuid, v_option_val character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volume_options
    SET option_val = v_option_val
    WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateglustervolumeoption(v_id uuid, v_option_val character varying) OWNER TO engine;

--
-- Name: updateglustervolumestatus(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumestatus(v_volume_id uuid, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volumes
    SET
        status = v_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_volume_id;
END; ';


ALTER FUNCTION public.updateglustervolumestatus(v_volume_id uuid, v_status character varying) OWNER TO engine;

--
-- Name: updateglustervolumestatusbyname(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateglustervolumestatusbyname(v_cluster_id uuid, v_vol_name character varying, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE gluster_volumes
    SET
        status = v_status,
        _update_date = LOCALTIMESTAMP
    WHERE cluster_id = v_cluster_id
    AND   vol_name = v_vol_name;
END; ';


ALTER FUNCTION public.updateglustervolumestatusbyname(v_cluster_id uuid, v_vol_name character varying, v_status character varying) OWNER TO engine;

--
-- Name: updategroup(uuid, character varying, boolean, character varying, character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updategroup(v_id uuid, v_name character varying, v_active boolean, v_domain character varying, v_distinguishedname character varying, v_external_id bytea) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE ad_groups
      SET name = v_name,active = v_active,domain = v_domain,distinguishedname = v_distinguishedname,external_id = v_external_id
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updategroup(v_id uuid, v_name character varying, v_active boolean, v_domain character varying, v_distinguishedname character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: updateimage(timestamp with time zone, uuid, uuid, bigint, uuid, integer, timestamp with time zone, uuid, integer, integer, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateimage(v_creation_date timestamp with time zone, v_image_guid uuid, v_it_guid uuid, v_size bigint, v_parentid uuid, v_imagestatus integer, v_lastmodified timestamp with time zone, v_vm_snapshot_id uuid, v_volume_type integer, v_volume_format integer, v_image_group_id uuid, v_active boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE images
    SET    creation_date = v_creation_date,
           it_guid = v_it_guid,
           size = v_size,
           ParentId = v_ParentId,
           imageStatus = v_imageStatus,
           lastModified = v_lastModified,
           vm_snapshot_id = v_vm_snapshot_id,
           volume_type = v_volume_type,
           image_group_id = v_image_group_id,
           volume_format = v_volume_format,
           active = v_active,
           _update_date = LOCALTIMESTAMP
    WHERE  image_guid = v_image_guid;
END; ';


ALTER FUNCTION public.updateimage(v_creation_date timestamp with time zone, v_image_guid uuid, v_it_guid uuid, v_size bigint, v_parentid uuid, v_imagestatus integer, v_lastmodified timestamp with time zone, v_vm_snapshot_id uuid, v_volume_type integer, v_volume_format integer, v_image_group_id uuid, v_active boolean) OWNER TO engine;

--
-- Name: updateimagesize(uuid, bigint, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateimagesize(v_image_id uuid, v_size bigint, v_lastmodified timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE images
    SET    size = v_size,
           lastModified = v_lastModified
    WHERE  image_guid = v_image_id;
END; ';


ALTER FUNCTION public.updateimagesize(v_image_id uuid, v_size bigint, v_lastmodified timestamp with time zone) OWNER TO engine;

--
-- Name: updateimagestatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateimagestatus(v_image_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE images
    SET    imageStatus = v_status
    WHERE  image_guid = v_image_id;
END; ';


ALTER FUNCTION public.updateimagestatus(v_image_id uuid, v_status integer) OWNER TO engine;

--
-- Name: updateimagevmsnapshotid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateimagevmsnapshotid(v_image_id uuid, v_vm_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE images
    SET    vm_snapshot_id = v_vm_snapshot_id
    WHERE  image_guid = v_image_id;
END; ';


ALTER FUNCTION public.updateimagevmsnapshotid(v_image_id uuid, v_vm_snapshot_id uuid) OWNER TO engine;

--
-- Name: updateiscsibond(uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateiscsibond(v_id uuid, v_name character varying, v_description character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE iscsi_bonds
      SET name = v_name, description = v_description
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updateiscsibond(v_id uuid, v_name character varying, v_description character varying) OWNER TO engine;

--
-- Name: updateisinitialized(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateisinitialized(v_vm_guid uuid, v_is_initialized boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET is_initialized = v_is_initialized
      WHERE vm_guid = v_vm_guid
      AND   entity_type = ''VM'';
END; ';


ALTER FUNCTION public.updateisinitialized(v_vm_guid uuid, v_is_initialized boolean) OWNER TO engine;

--
-- Name: updatejob(uuid, character varying, text, character varying, uuid, boolean, timestamp with time zone, timestamp with time zone, timestamp with time zone, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatejob(v_job_id uuid, v_action_type character varying, v_description text, v_status character varying, v_owner_id uuid, v_visible boolean, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_last_update_time timestamp with time zone, v_correlation_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    update job
    SET action_type = v_action_type,
        description = v_description,
        status = v_status,
        owner_id = v_owner_id,
        visible = v_visible,
        start_time = v_start_time,
        end_time = v_end_time,
        last_update_time = v_last_update_time,
        correlation_id = v_correlation_id
    WHERE job_id = v_job_id;
END; ';


ALTER FUNCTION public.updatejob(v_job_id uuid, v_action_type character varying, v_description text, v_status character varying, v_owner_id uuid, v_visible boolean, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_last_update_time timestamp with time zone, v_correlation_id character varying) OWNER TO engine;

--
-- Name: updatejoblastupdatetime(uuid, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatejoblastupdatetime(v_job_id uuid, v_last_update_time timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    update job
    SET last_update_time = v_last_update_time
    WHERE job_id = v_job_id;
END; ';


ALTER FUNCTION public.updatejoblastupdatetime(v_job_id uuid, v_last_update_time timestamp with time zone) OWNER TO engine;

--
-- Name: updatejobstepscompleted(uuid, character varying, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatejobstepscompleted(v_job_id uuid, v_status character varying, v_end_time timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE step
    SET status = v_status,
        end_time = v_end_time
    WHERE job_id = v_job_id
    AND   status = ''STARTED''
    AND   STATUS != v_status;
END; ';


ALTER FUNCTION public.updatejobstepscompleted(v_job_id uuid, v_status character varying, v_end_time timestamp with time zone) OWNER TO engine;

--
-- Name: updatelastadmincheckstatus(character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatelastadmincheckstatus(v_userids character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
   DECLARE
   v_id  UUID;
   v_tempId  VARCHAR(4000);
   myCursor cursor for select id from fnSplitter(v_userIds);
   v_result  INTEGER;
BEGIN
	-- get users and its groups
	-- get their permission based on ad_element_id.
	-- if one permissions role''s type is ADMIN(1) then set the user last_admin_check_status to 1
   OPEN myCursor;
   FETCH myCursor into v_tempId;
   WHILE FOUND LOOP
      v_id := CAST(v_tempId AS UUID);
      select   count(*) INTO v_result from users where user_id in(select ad_element_id as user_id from permissions,roles
         where permissions.role_id = roles.id
         and ad_element_id in((select id from ad_groups,users where users.user_id = v_id
               and ad_groups.id in(select * from fnsplitteruuid(users.group_ids))
               union
               select v_id))
         and (roles.role_type = 1 or permissions.role_id = ''00000000-0000-0000-0000-000000000001''));
      update users set last_admin_check_status =
      case
      when v_result = 0 then FALSE
      else TRUE
      end
      where user_id = v_id;
      FETCH myCursor into v_tempId;
   END LOOP;
   CLOSE myCursor;
END; ';


ALTER FUNCTION public.updatelastadmincheckstatus(v_userids character varying) OWNER TO engine;

--
-- Name: updatelun_storage_server_connection_map(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatelun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
END; ';


ALTER FUNCTION public.updatelun_storage_server_connection_map(v_lun_id character varying, v_storage_server_connection character varying) OWNER TO engine;

--
-- Name: updatelunsdevicesize(character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatelunsdevicesize(v_lun_id character varying, v_device_size integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
UPDATE LUNs set device_size = v_device_size where LUN_id = v_LUN_ID;
END; ';


ALTER FUNCTION public.updatelunsdevicesize(v_lun_id character varying, v_device_size integer) OWNER TO engine;

--
-- Name: updatelunsvolumegroupid(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatelunsvolumegroupid(v_lun_id character varying, v_volume_group_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
UPDATE LUNs set volume_group_id = v_volume_group_id where LUN_id = v_LUN_ID;
END; ';


ALTER FUNCTION public.updatelunsvolumegroupid(v_lun_id character varying, v_volume_group_id character varying) OWNER TO engine;

--
-- Name: updatematerializedviewminrefreshrate(name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatematerializedviewminrefreshrate(v_matview name, v_min_refresh_rate integer) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
    END IF;

    update materialized_views set min_refresh_rate_in_sec = v_min_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; ';


ALTER FUNCTION public.updatematerializedviewminrefreshrate(v_matview name, v_min_refresh_rate integer) OWNER TO engine;

--
-- Name: updatematerializedviewrefreshrate(name, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatematerializedviewrefreshrate(v_matview name, v_refresh_rate integer) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION ''Materialized view % does not exist.'', v_matview;
    END IF;

    update materialized_views set refresh_rate_in_sec = v_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; ';


ALTER FUNCTION public.updatematerializedviewrefreshrate(v_matview name, v_refresh_rate integer) OWNER TO engine;

--
-- Name: updatenetwork(character varying, character varying, text, uuid, character varying, character varying, character varying, integer, integer, boolean, uuid, integer, boolean, uuid, text, uuid, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatenetwork(v_addr character varying, v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_subnet character varying, v_gateway character varying, v_type integer, v_vlan_id integer, v_stp boolean, v_storage_pool_id uuid, v_mtu integer, v_vm_network boolean, v_provider_network_provider_id uuid, v_provider_network_external_id text, v_qos_id uuid, v_label text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE network
      SET addr = v_addr,description = v_description, free_text_comment = v_free_text_comment, name = v_name,subnet = v_subnet,
      gateway = v_gateway,type = v_type,vlan_id = v_vlan_id,
      stp = v_stp,storage_pool_id = v_storage_pool_id, mtu = v_mtu,
      vm_network = v_vm_network,
      provider_network_provider_id = v_provider_network_provider_id,
      provider_network_external_id = v_provider_network_external_id,
      qos_id = v_qos_id,
      label = v_label
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatenetwork(v_addr character varying, v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_subnet character varying, v_gateway character varying, v_type integer, v_vlan_id integer, v_stp boolean, v_storage_pool_id uuid, v_mtu integer, v_vm_network boolean, v_provider_network_provider_id uuid, v_provider_network_external_id text, v_qos_id uuid, v_label text) OWNER TO engine;

--
-- Name: updatenetwork_cluster(uuid, uuid, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatenetwork_cluster(v_cluster_id uuid, v_network_id uuid, v_status integer, v_is_display boolean, v_required boolean, v_migration boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   UPDATE network_cluster
   SET status = v_status,is_display = v_is_display, required = v_required, migration = v_migration
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;
END; ';


ALTER FUNCTION public.updatenetwork_cluster(v_cluster_id uuid, v_network_id uuid, v_status integer, v_is_display boolean, v_required boolean, v_migration boolean) OWNER TO engine;

--
-- Name: updatenetwork_cluster_status(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatenetwork_cluster_status(v_cluster_id uuid, v_network_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   UPDATE network_cluster
   SET status = v_status
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;
END; ';


ALTER FUNCTION public.updatenetwork_cluster_status(v_cluster_id uuid, v_network_id uuid, v_status integer) OWNER TO engine;

--
-- Name: updatenetworkqos(uuid, character varying, uuid, integer, integer, integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatenetworkqos(v_id uuid, v_name character varying, v_storage_pool_id uuid, v_inbound_average integer, v_inbound_peak integer, v_inbound_burst integer, v_outbound_average integer, v_outbound_peak integer, v_outbound_burst integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE network_qos
      SET name = v_name, storage_pool_id = v_storage_pool_id, inbound_average = v_inbound_average, inbound_peak = v_inbound_peak, inbound_burst = v_inbound_burst,
      outbound_average = v_outbound_average, outbound_peak = v_outbound_peak, outbound_burst = v_outbound_burst, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatenetworkqos(v_id uuid, v_name character varying, v_storage_pool_id uuid, v_inbound_average integer, v_inbound_peak integer, v_inbound_burst integer, v_outbound_average integer, v_outbound_peak integer, v_outbound_burst integer) OWNER TO engine;

--
-- Name: updateoriginaltemplatename(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateoriginaltemplatename(v_original_template_id uuid, v_original_template_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET original_template_name = v_original_template_name
      WHERE original_template_id = v_original_template_id;
END; ';


ALTER FUNCTION public.updateoriginaltemplatename(v_original_template_id uuid, v_original_template_name character varying) OWNER TO engine;

--
-- Name: updateovfgenerations(character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateovfgenerations(v_vms_ids character varying, v_vms_db_generations character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
curs_vmids CURSOR FOR SELECT * FROM fnSplitterUuid(v_vms_ids);
curs_newovfgen CURSOR FOR SELECT * FROM fnSplitter(v_vms_db_generations);
id UUID;
new_ovf_gen BIGINT;
BEGIN
 OPEN curs_vmids;
 OPEN curs_newovfgen;
LOOP
    FETCH curs_vmids INTO id;
    FETCH curs_newovfgen INTO new_ovf_gen;
    IF NOT FOUND THEN
     EXIT;
    END IF;
    UPDATE vm_ovf_generations
    SET ovf_generation = new_ovf_gen WHERE vm_guid = id;
END LOOP;
CLOSE curs_vmids;
CLOSE curs_newovfgen;
END; ';


ALTER FUNCTION public.updateovfgenerations(v_vms_ids character varying, v_vms_db_generations character varying) OWNER TO engine;

--
-- Name: updatepartialvdsdynamiccalc(uuid, integer, integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatepartialvdsdynamiccalc(v_vds_guid uuid, v_vmcount integer, v_pendingvcpuscount integer, v_pendingvmemsize integer, v_memcommited integer, v_vmscorescount integer) RETURNS void
    LANGUAGE plpgsql
    AS '
DECLARE
    sign int;
BEGIN
	IF (v_memCommited = 0 ) THEN
	  sign = 0;
	ELSEIF (v_memCommited > 0) THEN
	  sign = 1;
	ELSE
	  sign = -1;
	END IF;

    UPDATE vds_dynamic
    SET
      vm_count = GREATEST(vm_count + v_vmCount, 0),
      pending_vcpus_count = GREATEST(pending_vcpus_count + v_pendingVcpusCount, 0),
      pending_vmem_size = GREATEST(pending_vmem_size + v_pendingVmemSize, 0),
      mem_commited = GREATEST(mem_commited + sign * (abs(v_memCommited) + guest_overhead), 0),
      vms_cores_count = GREATEST(vms_cores_count + v_vmsCoresCount, 0)
    WHERE vds_id = v_vds_guid;
END; ';


ALTER FUNCTION public.updatepartialvdsdynamiccalc(v_vds_guid uuid, v_vmcount integer, v_pendingvcpuscount integer, v_pendingvmemsize integer, v_memcommited integer, v_vmscorescount integer) OWNER TO engine;

--
-- Name: updatepolicyunit(uuid, boolean, text, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatepolicyunit(v_id uuid, v_enabled boolean, v_custom_properties_regex text, v_description text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE policy_units
    SET    custom_properties_regex = v_custom_properties_regex,
           enabled = v_enabled,
           description = v_description
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.updatepolicyunit(v_id uuid, v_enabled boolean, v_custom_properties_regex text, v_description text) OWNER TO engine;

--
-- Name: updateprovider(uuid, character varying, character varying, character varying, character varying, boolean, character varying, text, text, character varying, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateprovider(v_id uuid, v_name character varying, v_description character varying, v_url character varying, v_provider_type character varying, v_auth_required boolean, v_auth_username character varying, v_auth_password text, v_custom_properties text, v_tenant_name character varying DEFAULT NULL::character varying, v_plugin_type character varying DEFAULT NULL::character varying, v_agent_configuration text DEFAULT NULL::text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE providers
    SET    name = v_name,
           description = v_description,
           url = v_url,
           provider_type = v_provider_type,
           auth_required = v_auth_required,
           auth_username = v_auth_username,
           auth_password = v_auth_password,
           custom_properties = v_custom_properties,
           tenant_name = v_tenant_name,
           plugin_type = v_plugin_type,
           _update_date = NOW(),
           agent_configuration = v_agent_configuration
    WHERE  id = v_id;
END; ';


ALTER FUNCTION public.updateprovider(v_id uuid, v_name character varying, v_description character varying, v_url character varying, v_provider_type character varying, v_auth_required boolean, v_auth_username character varying, v_auth_password text, v_custom_properties text, v_tenant_name character varying, v_plugin_type character varying, v_agent_configuration text) OWNER TO engine;

--
-- Name: updatequotaforimageandsnapshots(uuid, uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatequotaforimageandsnapshots(v_disk_id uuid, v_storage_domain_id uuid, v_quota_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
UPDATE image_storage_domain_map as isdm
    SET quota_id = v_quota_id
    FROM images as i
    WHERE i.image_group_id = v_disk_id AND i.image_guid = isdm.image_id AND storage_domain_id = v_storage_domain_id;
END; ';


ALTER FUNCTION public.updatequotaforimageandsnapshots(v_disk_id uuid, v_storage_domain_id uuid, v_quota_id uuid) OWNER TO engine;

--
-- Name: updatequotametadata(uuid, uuid, character varying, character varying, integer, integer, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatequotametadata(v_id uuid, v_storage_pool_id uuid, v_quota_name character varying, v_description character varying, v_threshold_vds_group_percentage integer, v_threshold_storage_percentage integer, v_grace_vds_group_percentage integer, v_grace_storage_percentage integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
UPDATE quota
   SET storage_pool_id = v_storage_pool_id,
   quota_name = v_quota_name,
   description = v_description,
   _update_date = LOCALTIMESTAMP,
   threshold_vds_group_percentage = v_threshold_vds_group_percentage,
   threshold_storage_percentage = v_threshold_storage_percentage,
   grace_vds_group_percentage = v_grace_vds_group_percentage,
   grace_storage_percentage = v_grace_storage_percentage
   WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatequotametadata(v_id uuid, v_storage_pool_id uuid, v_quota_name character varying, v_description character varying, v_threshold_vds_group_percentage integer, v_threshold_storage_percentage integer, v_grace_vds_group_percentage integer, v_grace_storage_percentage integer) OWNER TO engine;

--
-- Name: updatereplicacount(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatereplicacount(v_volume_id uuid, v_replica_count integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
UPDATE gluster_volumes
SET
replica_count = v_replica_count,
_update_date = LOCALTIMESTAMP
WHERE id = v_volume_id;
END; ';


ALTER FUNCTION public.updatereplicacount(v_volume_id uuid, v_replica_count integer) OWNER TO engine;

--
-- Name: updaterole(character varying, uuid, character varying, boolean, integer, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updaterole(v_description character varying, v_id uuid, v_name character varying, v_is_readonly boolean, v_role_type integer, v_allows_viewing_children boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE roles
      SET description    = v_description,
          name           = v_name,
          is_readonly    = v_is_readonly,
          role_type      = v_role_type,
          allows_viewing_children = v_allows_viewing_children
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updaterole(v_description character varying, v_id uuid, v_name character varying, v_is_readonly boolean, v_role_type integer, v_allows_viewing_children boolean) OWNER TO engine;

--
-- Name: updatesnapshot(uuid, uuid, character varying, character varying, character varying, timestamp with time zone, text, text, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatesnapshot(v_snapshot_id uuid, v_vm_id uuid, v_snapshot_type character varying, v_status character varying, v_description character varying, v_creation_date timestamp with time zone, v_app_list text, v_vm_configuration text, v_memory_volume character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE snapshots
    SET    status = v_status,
           vm_id = v_vm_id,
           snapshot_type = v_snapshot_type,
           description = v_description,
           creation_date = v_creation_date,
           app_list = v_app_list,
           vm_configuration = v_vm_configuration,
           memory_volume = v_memory_volume,
           _update_date = NOW()
    WHERE  snapshot_id = v_snapshot_id;
END; ';


ALTER FUNCTION public.updatesnapshot(v_snapshot_id uuid, v_vm_id uuid, v_snapshot_type character varying, v_status character varying, v_description character varying, v_creation_date timestamp with time zone, v_app_list text, v_vm_configuration text, v_memory_volume character varying) OWNER TO engine;

--
-- Name: updatesnapshotid(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatesnapshotid(v_snapshot_id uuid, v_new_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE snapshots
    SET    snapshot_id = v_new_snapshot_id
    WHERE  snapshot_id = v_snapshot_id;
END; ';


ALTER FUNCTION public.updatesnapshotid(v_snapshot_id uuid, v_new_snapshot_id uuid) OWNER TO engine;

--
-- Name: updatesnapshotstatus(uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatesnapshotstatus(v_snapshot_id uuid, v_status character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE snapshots
    SET    status = v_status
    WHERE  snapshot_id = v_snapshot_id;
END; ';


ALTER FUNCTION public.updatesnapshotstatus(v_snapshot_id uuid, v_status character varying) OWNER TO engine;

--
-- Name: updatestartedexecutionentitiestounknown(timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestartedexecutionentitiestounknown(v_end_time timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

update job
set status = ''UNKNOWN'',
    end_time = v_end_time,
    last_update_time = v_end_time
where job.status = ''STARTED''
and job_id not in (select job_id
                   from step
                   where external_id is not null);

update step
set status = ''UNKNOWN'',
    end_time = v_end_time
where status = ''STARTED''
and job_id not in (select step.job_id
                   from step step
                   where step.external_id is not null);

END; ';


ALTER FUNCTION public.updatestartedexecutionentitiestounknown(v_end_time timestamp with time zone) OWNER TO engine;

--
-- Name: updatestatusofimagesbyimagegroupid(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestatusofimagesbyimagegroupid(v_image_group_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE images
    SET    imageStatus = v_status
    WHERE  image_group_id = v_image_group_id;
END; ';


ALTER FUNCTION public.updatestatusofimagesbyimagegroupid(v_image_group_id uuid, v_status integer) OWNER TO engine;

--
-- Name: updatestep(uuid, uuid, uuid, character varying, text, integer, character varying, timestamp with time zone, timestamp with time zone, character varying, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestep(v_step_id uuid, v_parent_step_id uuid, v_job_id uuid, v_step_type character varying, v_description text, v_step_number integer, v_status character varying, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_correlation_id character varying, v_external_id uuid, v_external_system_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE step
    SET parent_step_id = v_parent_step_id,
        job_id = v_job_id,
        step_type = v_step_type,
        description = v_description,
        step_number = v_step_number,
        status = v_status,
        start_time = v_start_time,
        end_time = v_end_time,
        correlation_id = v_correlation_id,
        external_id = v_external_id,
        external_system_type = v_external_system_type
    WHERE step_id = v_step_id;
END; ';


ALTER FUNCTION public.updatestep(v_step_id uuid, v_parent_step_id uuid, v_job_id uuid, v_step_type character varying, v_description text, v_step_number integer, v_status character varying, v_start_time timestamp with time zone, v_end_time timestamp with time zone, v_correlation_id character varying, v_external_id uuid, v_external_system_type character varying) OWNER TO engine;

--
-- Name: updatestepexternalidandtype(uuid, uuid, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestepexternalidandtype(v_step_id uuid, v_external_id uuid, v_external_system_type character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE step
    SET external_id = v_external_id,
        external_system_type = v_external_system_type
    WHERE step_id = v_step_id;
END; ';


ALTER FUNCTION public.updatestepexternalidandtype(v_step_id uuid, v_external_id uuid, v_external_system_type character varying) OWNER TO engine;

--
-- Name: updatestepstatusandendtime(uuid, character varying, timestamp with time zone); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestepstatusandendtime(v_step_id uuid, v_status character varying, v_end_time timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE step
    SET status = v_status,
        end_time = v_end_time
    WHERE step_id = v_step_id;
END; ';


ALTER FUNCTION public.updatestepstatusandendtime(v_step_id uuid, v_status character varying, v_end_time timestamp with time zone) OWNER TO engine;

--
-- Name: updatestorage_domain_dynamic(integer, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_domain_dynamic(v_available_disk_size integer, v_id uuid, v_used_disk_size integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_domain_dynamic
      SET available_disk_size = v_available_disk_size,used_disk_size = v_used_disk_size, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_domain_dynamic(v_available_disk_size integer, v_id uuid, v_used_disk_size integer) OWNER TO engine;

--
-- Name: updatestorage_domain_static(uuid, character varying, character varying, character varying, text, integer, integer, integer, bigint); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_domain_static(v_id uuid, v_storage character varying, v_storage_name character varying, v_storage_description character varying, v_storage_comment text, v_storage_type integer, v_storage_domain_type integer, v_storage_domain_format_type integer, v_last_time_used_as_master bigint) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_domain_static
      SET storage = v_storage, storage_name = v_storage_name, storage_type = v_storage_type,
      storage_domain_type = v_storage_domain_type, _update_date = LOCALTIMESTAMP,
      storage_domain_format_type = v_storage_domain_format_type,
      last_time_used_as_master = v_last_time_used_as_master,
      storage_description = v_storage_description, storage_comment = v_storage_comment
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_domain_static(v_id uuid, v_storage character varying, v_storage_name character varying, v_storage_description character varying, v_storage_comment text, v_storage_type integer, v_storage_domain_type integer, v_storage_domain_format_type integer, v_last_time_used_as_master bigint) OWNER TO engine;

--
-- Name: updatestorage_pool(character varying, text, uuid, character varying, integer, boolean, character varying, integer, uuid, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_pool(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_status integer, v_is_local boolean, v_storage_pool_format_type character varying, v_master_domain_version integer, v_spm_vds_id uuid, v_compatibility_version character varying, v_quota_enforcement_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_pool
      SET description = v_description, free_text_comment = v_free_text_comment,  name = v_name, is_local = v_is_local,
      status = v_status,storage_pool_format_type = v_storage_pool_format_type,master_domain_version = v_master_domain_version,
      spm_vds_id = v_spm_vds_id,compatibility_version = v_compatibility_version,
      _update_date = LOCALTIMESTAMP,quota_enforcement_type=v_quota_enforcement_type
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_pool(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_status integer, v_is_local boolean, v_storage_pool_format_type character varying, v_master_domain_version integer, v_spm_vds_id uuid, v_compatibility_version character varying, v_quota_enforcement_type integer) OWNER TO engine;

--
-- Name: updatestorage_pool_iso_map_status(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_pool_iso_map_status(v_storage_id uuid, v_storage_pool_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
   UPDATE storage_pool_iso_map
   SET status = v_status
   WHERE storage_pool_id = v_storage_pool_id AND storage_id = v_storage_id;
END; ';


ALTER FUNCTION public.updatestorage_pool_iso_map_status(v_storage_id uuid, v_storage_pool_id uuid, v_status integer) OWNER TO engine;

--
-- Name: updatestorage_pool_partial(character varying, text, uuid, character varying, boolean, character varying, character varying, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_pool_partial(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_is_local boolean, v_storage_pool_format_type character varying, v_compatibility_version character varying, v_quota_enforcement_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_pool
      SET description = v_description, free_text_comment = v_free_text_comment, name = v_name, is_local = v_is_local,
      storage_pool_format_type = v_storage_pool_format_type,compatibility_version = v_compatibility_version,
      _update_date = LOCALTIMESTAMP,quota_enforcement_type = v_quota_enforcement_type
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_pool_partial(v_description character varying, v_free_text_comment text, v_id uuid, v_name character varying, v_is_local boolean, v_storage_pool_format_type character varying, v_compatibility_version character varying, v_quota_enforcement_type integer) OWNER TO engine;

--
-- Name: updatestorage_pool_status(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_pool_status(v_id uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_pool
      SET
      status = v_status,
      _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_pool_status(v_id uuid, v_status integer) OWNER TO engine;

--
-- Name: updatestorage_server_connections(character varying, character varying, character varying, text, integer, character varying, character varying, character varying, character varying, character varying, character varying, smallint, smallint); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatestorage_server_connections(v_connection character varying, v_id character varying, v_iqn character varying, v_password text, v_storage_type integer, v_port character varying, v_portal character varying, v_user_name character varying, v_mount_options character varying, v_vfs_type character varying, v_nfs_version character varying, v_nfs_timeo smallint, v_nfs_retrans smallint) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE storage_server_connections
      SET connection = v_connection,iqn = v_iqn,password = v_password,port = v_port,
      portal = v_portal,storage_type = v_storage_type,user_name = v_user_name,mount_options = v_mount_options, vfs_type = v_vfs_type, nfs_version = v_nfs_version, nfs_timeo = v_nfs_timeo, nfs_retrans = v_nfs_retrans
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatestorage_server_connections(v_connection character varying, v_id character varying, v_iqn character varying, v_password text, v_storage_type integer, v_port character varying, v_portal character varying, v_user_name character varying, v_mount_options character varying, v_vfs_type character varying, v_nfs_version character varying, v_nfs_timeo smallint, v_nfs_retrans smallint) OWNER TO engine;

--
-- Name: updatetags(character varying, uuid, character varying, uuid, boolean, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatetags(v_description character varying, v_tag_id uuid, v_tag_name character varying, v_parent_id uuid, v_readonly boolean, v_type integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE tags
      SET description = v_description,tag_name = v_tag_name,parent_id = v_parent_id,
      readonly	= v_readonly,type = v_type,_update_date = LOCALTIMESTAMP
      WHERE tag_id = v_tag_id;
END; ';


ALTER FUNCTION public.updatetags(v_description character varying, v_tag_id uuid, v_tag_name character varying, v_parent_id uuid, v_readonly boolean, v_type integer) OWNER TO engine;

--
-- Name: updatetags_vm_pool_map(integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatetags_vm_pool_map(v_tag_id integer, v_vm_pool_id integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
END; ';


ALTER FUNCTION public.updatetags_vm_pool_map(v_tag_id integer, v_vm_pool_id integer) OWNER TO engine;

--
-- Name: updateuser(character varying, character varying, character varying, character varying, character varying, character varying, character varying, boolean, character varying, uuid, character varying, boolean, character varying, bytea); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updateuser(v_department character varying, v_domain character varying, v_email character varying, v_groups character varying, v_name character varying, v_note character varying, v_role character varying, v_active boolean, v_surname character varying, v_user_id uuid, v_username character varying, v_last_admin_check_status boolean, v_group_ids character varying, v_external_id bytea) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE users
      SET department = v_department,domain = v_domain,
      email = v_email,groups = v_groups,name = v_name,note = v_note,
      role = v_role,active = v_active,surname = v_surname,
      username = v_username,
      last_admin_check_status = v_last_admin_check_status,
      group_ids = v_group_ids,
      external_id = v_external_id
      WHERE user_id = v_user_id;
END; ';


ALTER FUNCTION public.updateuser(v_department character varying, v_domain character varying, v_email character varying, v_groups character varying, v_name character varying, v_note character varying, v_role character varying, v_active boolean, v_surname character varying, v_user_id uuid, v_username character varying, v_last_admin_check_status boolean, v_group_ids character varying, v_external_id bytea) OWNER TO engine;

--
-- Name: updatevdcoption(character varying, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdcoption(v_option_name character varying, v_option_value character varying, v_option_id integer, v_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vdc_options
      SET OPTION_NAME = v_option_name,option_value = v_option_value,version = v_version
      WHERE option_id = v_option_id;
END; ';


ALTER FUNCTION public.updatevdcoption(v_option_name character varying, v_option_value character varying, v_option_id integer, v_version character varying) OWNER TO engine;

--
-- Name: updatevds_interface(character varying, character varying, integer, character varying, uuid, boolean, character varying, character varying, character varying, character varying, integer, character varying, integer, integer, uuid, integer, integer, boolean, boolean, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevds_interface(v_addr character varying, v_bond_name character varying, v_bond_type integer, v_gateway character varying, v_id uuid, v_is_bond boolean, v_bond_opts character varying, v_mac_addr character varying, v_name character varying, v_network_name character varying, v_speed integer, v_subnet character varying, v_boot_protocol integer, v_type integer, v_vds_id uuid, v_vlan_id integer, v_mtu integer, v_bridged boolean, v_qos_overridden boolean, v_labels text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vds_interface
      SET addr = v_addr,bond_name = v_bond_name,bond_type = v_bond_type,gateway = v_gateway,
      is_bond = v_is_bond,bond_opts = v_bond_opts,mac_addr = v_mac_addr,
      name = v_name,network_name = v_network_name,speed = v_speed,
      subnet = v_subnet,boot_protocol = v_boot_protocol,
      type = v_type,VDS_ID = v_vds_id,vlan_id = v_vlan_id,_update_date = LOCALTIMESTAMP, mtu = v_mtu,
      bridged = v_bridged, qos_overridden = v_qos_overridden, labels = v_labels
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatevds_interface(v_addr character varying, v_bond_name character varying, v_bond_type integer, v_gateway character varying, v_id uuid, v_is_bond boolean, v_bond_opts character varying, v_mac_addr character varying, v_name character varying, v_network_name character varying, v_speed integer, v_subnet character varying, v_boot_protocol integer, v_type integer, v_vds_id uuid, v_vlan_id integer, v_mtu integer, v_bridged boolean, v_qos_overridden boolean, v_labels text) OWNER TO engine;

--
-- Name: updatevds_interface_statistics(uuid, numeric, numeric, numeric, numeric, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevds_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vds_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vds_interface_statistics
      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate = v_tx_rate,
      vds_id = v_vds_id,iface_status = v_iface_status, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatevds_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vds_id uuid) OWNER TO engine;

--
-- Name: updatevdsdynamic(integer, integer, character varying, numeric, character varying, boolean, integer, integer, integer, uuid, integer, integer, integer, integer, integer, integer, character varying, character varying, character varying, character varying, integer, character varying, timestamp with time zone, integer, integer, integer, boolean, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying, integer, character varying, integer, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsdynamic(v_cpu_cores integer, v_cpu_threads integer, v_cpu_model character varying, v_cpu_speed_mh numeric, v_if_total_speed character varying, v_kvm_enabled boolean, v_mem_commited integer, v_physical_mem_mb integer, v_status integer, v_vds_id uuid, v_vm_active integer, v_vm_count integer, v_vms_cores_count integer, v_vm_migrating integer, v_reserved_mem integer, v_guest_overhead integer, v_rpm_version character varying, v_software_version character varying, v_version_name character varying, v_build_name character varying, v_previous_status integer, v_cpu_flags character varying, v_cpu_over_commit_time_stamp timestamp with time zone, v_pending_vcpus_count integer, v_pending_vmem_size integer, v_cpu_sockets integer, v_net_config_dirty boolean, v_supported_cluster_levels character varying, v_supported_engines character varying, v_host_os character varying, v_kvm_version character varying, v_libvirt_version character varying, v_spice_version character varying, v_gluster_version character varying, v_kernel_version character varying, v_iscsi_initiator_name character varying, v_transparent_hugepages_state integer, v_hooks character varying, v_non_operational_reason integer, v_hw_manufacturer character varying, v_hw_product_name character varying, v_hw_version character varying, v_hw_serial_number character varying, v_hw_uuid character varying, v_hw_family character varying, v_hbas character varying, v_supported_emulated_machines character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
      UPDATE vds_dynamic
      SET cpu_cores = v_cpu_cores,cpu_threads = v_cpu_threads,
      cpu_model = v_cpu_model,cpu_speed_mh = v_cpu_speed_mh,
      if_total_speed = v_if_total_speed,kvm_enabled = v_kvm_enabled,
      mem_commited = v_mem_commited,physical_mem_mb = v_physical_mem_mb,
      status = v_status,vm_active = v_vm_active,vm_count = v_vm_count,
      vm_migrating = v_vm_migrating,reserved_mem = v_reserved_mem,
      guest_overhead = v_guest_overhead,rpm_version = v_rpm_version, software_version = v_software_version,
      version_name = v_version_name,build_name = v_build_name,previous_status = v_previous_status,
      cpu_flags = v_cpu_flags,cpu_over_commit_time_stamp = v_cpu_over_commit_time_stamp,
      vms_cores_count = v_vms_cores_count,pending_vcpus_count = v_pending_vcpus_count,
      pending_vmem_size = v_pending_vmem_size,
      cpu_sockets = v_cpu_sockets,net_config_dirty = v_net_config_dirty,
      supported_cluster_levels = v_supported_cluster_levels,
      supported_engines = v_supported_engines,host_os = v_host_os,
      kvm_version = v_kvm_version,libvirt_version = v_libvirt_version,spice_version = v_spice_version,
      gluster_version = v_gluster_version,
      kernel_version = v_kernel_version,iscsi_initiator_name = v_iscsi_initiator_name,
      transparent_hugepages_state = v_transparent_hugepages_state,
      hooks = v_hooks,
      _update_date = LOCALTIMESTAMP,non_operational_reason = v_non_operational_reason,
      hw_manufacturer = v_hw_manufacturer, hw_product_name = v_hw_product_name,
      hw_version = v_hw_version, hw_serial_number = v_hw_serial_number,
      hw_uuid = v_hw_uuid, hw_family = v_hw_family, hbas = v_hbas, supported_emulated_machines = v_supported_emulated_machines
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.updatevdsdynamic(v_cpu_cores integer, v_cpu_threads integer, v_cpu_model character varying, v_cpu_speed_mh numeric, v_if_total_speed character varying, v_kvm_enabled boolean, v_mem_commited integer, v_physical_mem_mb integer, v_status integer, v_vds_id uuid, v_vm_active integer, v_vm_count integer, v_vms_cores_count integer, v_vm_migrating integer, v_reserved_mem integer, v_guest_overhead integer, v_rpm_version character varying, v_software_version character varying, v_version_name character varying, v_build_name character varying, v_previous_status integer, v_cpu_flags character varying, v_cpu_over_commit_time_stamp timestamp with time zone, v_pending_vcpus_count integer, v_pending_vmem_size integer, v_cpu_sockets integer, v_net_config_dirty boolean, v_supported_cluster_levels character varying, v_supported_engines character varying, v_host_os character varying, v_kvm_version character varying, v_libvirt_version character varying, v_spice_version character varying, v_gluster_version character varying, v_kernel_version character varying, v_iscsi_initiator_name character varying, v_transparent_hugepages_state integer, v_hooks character varying, v_non_operational_reason integer, v_hw_manufacturer character varying, v_hw_product_name character varying, v_hw_version character varying, v_hw_serial_number character varying, v_hw_uuid character varying, v_hw_family character varying, v_hbas character varying, v_supported_emulated_machines character varying) OWNER TO engine;

--
-- Name: updatevdsdynamicnetconfigdirty(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsdynamicnetconfigdirty(v_vds_guid uuid, v_net_config_dirty boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vds_dynamic
      SET
      net_config_dirty = v_net_config_dirty
      WHERE vds_id = v_vds_guid;
END; ';


ALTER FUNCTION public.updatevdsdynamicnetconfigdirty(v_vds_guid uuid, v_net_config_dirty boolean) OWNER TO engine;

--
-- Name: updatevdsdynamicpowermanagementpolicyflag(uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsdynamicpowermanagementpolicyflag(v_vds_id uuid, v_controlled_by_pm_policy boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
  BEGIN
    UPDATE vds_dynamic
    SET controlled_by_pm_policy = v_controlled_by_pm_policy
    WHERE vds_id = v_vds_id;
  END;
  RETURN;
END; ';


ALTER FUNCTION public.updatevdsdynamicpowermanagementpolicyflag(v_vds_id uuid, v_controlled_by_pm_policy boolean) OWNER TO engine;

--
-- Name: updatevdsdynamicstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsdynamicstatus(v_vds_guid uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vds_dynamic
      SET
      status = v_status
      WHERE vds_id = v_vds_guid;
END; ';


ALTER FUNCTION public.updatevdsdynamicstatus(v_vds_guid uuid, v_status integer) OWNER TO engine;

--
-- Name: updatevdsgroup(character varying, text, character varying, uuid, character varying, uuid, integer, boolean, character varying, boolean, integer, boolean, boolean, boolean, character varying, boolean, boolean, boolean, uuid, text, boolean, integer, smallint, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsgroup(v_description character varying, v_free_text_comment text, v_name character varying, v_vds_group_id uuid, v_cpu_name character varying, v_storage_pool_id uuid, v_max_vds_memory_over_commit integer, v_count_threads_as_cores boolean, v_compatibility_version character varying, v_transparent_hugepages boolean, v_migrate_on_error integer, v_virt_service boolean, v_gluster_service boolean, v_tunnel_migration boolean, v_emulated_machine character varying, v_detect_emulated_machine boolean, v_trusted_service boolean, v_ha_reservation boolean, v_cluster_policy_id uuid, v_cluster_policy_custom_properties text, v_enable_balloon boolean, v_architecture integer, v_optimization_type smallint, v_spice_proxy character varying, v_enable_ksm boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vds_groups
      SET description = v_description, free_text_comment = v_free_text_comment, name = v_name,cpu_name = v_cpu_name,
      storage_pool_id = v_storage_pool_id,_update_date = LOCALTIMESTAMP,
      max_vds_memory_over_commit = v_max_vds_memory_over_commit,
      count_threads_as_cores = v_count_threads_as_cores,
      compatibility_version = v_compatibility_version,transparent_hugepages = v_transparent_hugepages,
      migrate_on_error = v_migrate_on_error,
      virt_service = v_virt_service, gluster_service = v_gluster_service, tunnel_migration = v_tunnel_migration,
      emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine, trusted_service = v_trusted_service, ha_reservation = v_ha_reservation , cluster_policy_id = v_cluster_policy_id,
      cluster_policy_custom_properties = v_cluster_policy_custom_properties, enable_balloon = v_enable_balloon, architecture = v_architecture,
      optimization_type = v_optimization_type, spice_proxy = v_spice_proxy, enable_ksm = v_enable_ksm
      WHERE vds_group_id = v_vds_group_id;
END; ';


ALTER FUNCTION public.updatevdsgroup(v_description character varying, v_free_text_comment text, v_name character varying, v_vds_group_id uuid, v_cpu_name character varying, v_storage_pool_id uuid, v_max_vds_memory_over_commit integer, v_count_threads_as_cores boolean, v_compatibility_version character varying, v_transparent_hugepages boolean, v_migrate_on_error integer, v_virt_service boolean, v_gluster_service boolean, v_tunnel_migration boolean, v_emulated_machine character varying, v_detect_emulated_machine boolean, v_trusted_service boolean, v_ha_reservation boolean, v_cluster_policy_id uuid, v_cluster_policy_custom_properties text, v_enable_balloon boolean, v_architecture integer, v_optimization_type smallint, v_spice_proxy character varying, v_enable_ksm boolean) OWNER TO engine;

--
-- Name: updatevdsgroupemulatedmachine(uuid, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsgroupemulatedmachine(v_vds_group_id uuid, v_emulated_machine character varying, v_detect_emulated_machine boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vds_groups
    SET emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine
    WHERE vds_group_id = v_vds_group_id;
END; ';


ALTER FUNCTION public.updatevdsgroupemulatedmachine(v_vds_group_id uuid, v_emulated_machine character varying, v_detect_emulated_machine boolean) OWNER TO engine;

--
-- Name: updatevdsstatic(character varying, text, character varying, character varying, integer, uuid, uuid, character varying, boolean, integer, integer, character varying, character varying, character varying, integer, character varying, boolean, character varying, character varying, character varying, character varying, text, integer, character varying, boolean, bigint, integer, character varying, character varying, integer, character varying, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsstatic(v_host_name character varying, v_free_text_comment text, v_ip character varying, v_vds_unique_id character varying, v_port integer, v_vds_group_id uuid, v_vds_id uuid, v_vds_name character varying, v_server_ssl_enabled boolean, v_vds_type integer, v_vds_strength integer, v_pm_type character varying, v_pm_user character varying, v_pm_password character varying, v_pm_port integer, v_pm_options character varying, v_pm_enabled boolean, v_pm_proxy_preferences character varying, v_pm_secondary_ip character varying, v_pm_secondary_type character varying, v_pm_secondary_user character varying, v_pm_secondary_password text, v_pm_secondary_port integer, v_pm_secondary_options character varying, v_pm_secondary_concurrent boolean, v_otp_validity bigint, v_vds_spm_priority integer, v_sshkeyfingerprint character varying, v_console_address character varying, v_ssh_port integer, v_ssh_username character varying, v_disable_auto_pm boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
      UPDATE vds_static
      SET host_name = v_host_name, free_text_comment = v_free_text_comment, ip = v_ip,vds_unique_id = v_vds_unique_id,
      port = v_port, vds_group_id = v_vds_group_id,vds_name = v_vds_name,server_SSL_enabled = v_server_SSL_enabled,
      vds_type = v_vds_type,
      _update_date = LOCALTIMESTAMP,vds_strength = v_vds_strength,
      pm_type = v_pm_type,pm_user = v_pm_user,pm_password = v_pm_password,
      pm_port = v_pm_port,pm_options = v_pm_options,pm_enabled = v_pm_enabled, pm_proxy_preferences = v_pm_proxy_preferences,
      pm_secondary_ip = v_pm_secondary_ip, pm_secondary_type = v_pm_secondary_type,
      pm_secondary_user = v_pm_secondary_user, pm_secondary_password = v_pm_secondary_password,
      pm_secondary_port = v_pm_secondary_port, pm_secondary_options = v_pm_secondary_options,
      pm_secondary_concurrent = v_pm_secondary_concurrent,
      otp_validity = v_otp_validity, vds_spm_priority = v_vds_spm_priority, sshKeyFingerprint = v_sshKeyFingerprint,
      console_address = v_console_address, ssh_port = v_ssh_port, ssh_username = v_ssh_username, disable_auto_pm = v_disable_auto_pm
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.updatevdsstatic(v_host_name character varying, v_free_text_comment text, v_ip character varying, v_vds_unique_id character varying, v_port integer, v_vds_group_id uuid, v_vds_id uuid, v_vds_name character varying, v_server_ssl_enabled boolean, v_vds_type integer, v_vds_strength integer, v_pm_type character varying, v_pm_user character varying, v_pm_password character varying, v_pm_port integer, v_pm_options character varying, v_pm_enabled boolean, v_pm_proxy_preferences character varying, v_pm_secondary_ip character varying, v_pm_secondary_type character varying, v_pm_secondary_user character varying, v_pm_secondary_password text, v_pm_secondary_port integer, v_pm_secondary_options character varying, v_pm_secondary_concurrent boolean, v_otp_validity bigint, v_vds_spm_priority integer, v_sshkeyfingerprint character varying, v_console_address character varying, v_ssh_port integer, v_ssh_username character varying, v_disable_auto_pm boolean) OWNER TO engine;

--
-- Name: updatevdsstatistics(numeric, numeric, numeric, numeric, integer, integer, integer, uuid, bigint, bigint, bigint, bigint, bigint, integer, bigint, boolean, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevdsstatistics(v_cpu_idle numeric, v_cpu_load numeric, v_cpu_sys numeric, v_cpu_user numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_vds_id uuid, v_mem_available bigint, v_mem_free bigint, v_mem_shared bigint, v_swap_free bigint, v_swap_total bigint, v_ksm_cpu_percent integer, v_ksm_pages bigint, v_ksm_state boolean, v_ha_score integer, v_anonymous_hugepages integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   BEGIN
      UPDATE vds_statistics
      SET cpu_idle = v_cpu_idle,cpu_load = v_cpu_load,cpu_sys = v_cpu_sys,
      cpu_user = v_cpu_user,usage_cpu_percent = v_usage_cpu_percent,usage_mem_percent = v_usage_mem_percent,
      usage_network_percent = v_usage_network_percent,
      mem_available = v_mem_available, mem_free = v_mem_free, mem_shared = v_mem_shared,
      swap_free = v_swap_free,swap_total = v_swap_total,ksm_cpu_percent = v_ksm_cpu_percent,
      ksm_pages = v_ksm_pages,ksm_state = v_ksm_state, ha_score = v_ha_score, _update_date = LOCALTIMESTAMP,
      anonymous_hugepages = v_anonymous_hugepages
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; ';


ALTER FUNCTION public.updatevdsstatistics(v_cpu_idle numeric, v_cpu_load numeric, v_cpu_sys numeric, v_cpu_user numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_vds_id uuid, v_mem_available bigint, v_mem_free bigint, v_mem_shared bigint, v_swap_free bigint, v_swap_total bigint, v_ksm_cpu_percent integer, v_ksm_pages bigint, v_ksm_state boolean, v_ha_score integer, v_anonymous_hugepages integer) OWNER TO engine;

--
-- Name: updatevm_interface_statistics(uuid, numeric, numeric, numeric, numeric, integer, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevm_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vm_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_interface_statistics
      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate = v_tx_rate,
      vm_id = v_vm_id,iface_status = v_iface_status, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatevm_interface_statistics(v_id uuid, v_rx_drop numeric, v_rx_rate numeric, v_tx_drop numeric, v_tx_rate numeric, v_iface_status integer, v_vm_id uuid) OWNER TO engine;

--
-- Name: updatevm_pool_map(uuid, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevm_pool_map(v_vm_guid uuid, v_vm_pool_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_pool_map
      SET vm_pool_id = v_vm_pool_id
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.updatevm_pool_map(v_vm_guid uuid, v_vm_pool_id uuid) OWNER TO engine;

--
-- Name: updatevm_pools(character varying, text, uuid, character varying, integer, character varying, integer, uuid, smallint, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevm_pools(v_vm_pool_description character varying, v_vm_pool_comment text, v_vm_pool_id uuid, v_vm_pool_name character varying, v_vm_pool_type integer, v_parameters character varying, v_prestarted_vms integer, v_vds_group_id uuid, v_max_assigned_vms_per_user smallint, v_spice_proxy character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_pools
      SET vm_pool_description = v_vm_pool_description, vm_pool_comment = v_vm_pool_comment, vm_pool_name = v_vm_pool_name,
      vm_pool_type = v_vm_pool_type,parameters = v_parameters, prestarted_vms = v_prestarted_vms, vds_group_id = v_vds_group_id,
      max_assigned_vms_per_user = v_max_assigned_vms_per_user, spice_proxy = v_spice_proxy
      WHERE vm_pool_id = v_vm_pool_id;
END; ';


ALTER FUNCTION public.updatevm_pools(v_vm_pool_description character varying, v_vm_pool_comment text, v_vm_pool_id uuid, v_vm_pool_name character varying, v_vm_pool_type integer, v_parameters character varying, v_prestarted_vms integer, v_vds_group_id uuid, v_max_assigned_vms_per_user smallint, v_spice_proxy character varying) OWNER TO engine;

--
-- Name: updatevmdevice(uuid, uuid, character varying, character varying, character varying, integer, text, boolean, boolean, boolean, character varying, text, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdevice(v_device_id uuid, v_vm_id uuid, v_device character varying, v_type character varying, v_address character varying, v_boot_order integer, v_spec_params text, v_is_managed boolean, v_is_plugged boolean, v_is_readonly boolean, v_alias character varying, v_custom_properties text, v_snapshot_id uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vm_device
    SET
           device = v_device,
           type = v_type,
           address = v_address,
           boot_order = v_boot_order,
           spec_params = v_spec_params,
           is_managed = v_is_managed,
           is_plugged = v_is_plugged,
           is_readonly = v_is_readonly,
           alias = v_alias,
           custom_properties = v_custom_properties,
           snapshot_id = v_snapshot_id,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevmdevice(v_device_id uuid, v_vm_id uuid, v_device character varying, v_type character varying, v_address character varying, v_boot_order integer, v_spec_params text, v_is_managed boolean, v_is_plugged boolean, v_is_readonly boolean, v_alias character varying, v_custom_properties text, v_snapshot_id uuid) OWNER TO engine;

--
-- Name: updatevmdevicebootorder(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdevicebootorder(v_device_id uuid, v_vm_id uuid, v_boot_order integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vm_device
    SET
           boot_order = v_boot_order,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevmdevicebootorder(v_device_id uuid, v_vm_id uuid, v_boot_order integer) OWNER TO engine;

--
-- Name: updatevmdeviceforhotplugdisk(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdeviceforhotplugdisk(v_device_id uuid, v_vm_id uuid, v_is_plugged boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vm_device
    SET
           is_plugged = v_is_plugged,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevmdeviceforhotplugdisk(v_device_id uuid, v_vm_id uuid, v_is_plugged boolean) OWNER TO engine;

--
-- Name: updatevmdeviceruntimeinfo(uuid, uuid, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdeviceruntimeinfo(v_device_id uuid, v_vm_id uuid, v_address character varying, v_alias character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
    UPDATE vm_device
    SET
           address = v_address,
           alias = v_alias,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevmdeviceruntimeinfo(v_device_id uuid, v_vm_id uuid, v_address character varying, v_alias character varying) OWNER TO engine;

--
-- Name: updatevmdynamic(character varying, character varying, character varying, timestamp with time zone, timestamp with time zone, uuid, character varying, uuid, uuid, integer, uuid, character varying, character varying, character varying, timestamp with time zone, timestamp with time zone, integer, integer, boolean, integer, character varying, integer, boolean, integer, integer, integer, uuid, character varying, integer, character varying, integer, integer, character varying, character varying, integer, numeric, character varying, boolean, character varying, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdynamic(v_app_list character varying, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, v_guest_last_login_time timestamp with time zone, v_guest_last_logout_time timestamp with time zone, v_console_user_id uuid, v_guest_os character varying, v_migrating_to_vds uuid, v_run_on_vds uuid, v_status integer, v_vm_guid uuid, v_vm_host character varying, v_vm_ip character varying, v_vm_fqdn character varying, v_last_start_time timestamp with time zone, v_last_stop_time timestamp with time zone, v_vm_pid integer, v_display integer, v_acpi_enable boolean, v_session integer, v_display_ip character varying, v_display_type integer, v_kvm_enable boolean, v_boot_sequence integer, v_display_secure_port integer, v_utc_diff integer, v_last_vds_run_on uuid, v_client_ip character varying, v_guest_requested_memory integer, v_hibernation_vol_handle character varying, v_exit_status integer, v_pause_status integer, v_exit_message character varying, v_hash character varying, v_guest_agent_nics_hash integer, v_last_watchdog_event numeric, v_last_watchdog_action character varying, v_is_run_once boolean, v_cpu_name character varying, v_current_cd character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_dynamic
      SET app_list = v_app_list,guest_cur_user_name = v_guest_cur_user_name,
      console_cur_user_name = v_console_cur_user_name,
      guest_last_login_time = v_guest_last_login_time,
      guest_last_logout_time = v_guest_last_logout_time,
      console_user_id = v_console_user_id,
      guest_os = v_guest_os,migrating_to_vds = v_migrating_to_vds,RUN_ON_VDS = v_run_on_vds,
      status = v_status,vm_host = v_vm_host,vm_ip = v_vm_ip,vm_fqdn = v_vm_fqdn,
      last_start_time = v_last_start_time,
      last_stop_time = v_last_stop_time,
      vm_pid = v_vm_pid,display = v_display,acpi_enable = v_acpi_enable,
      session = v_session,display_ip = v_display_ip,
      display_type = v_display_type,kvm_enable = v_kvm_enable,boot_sequence = v_boot_sequence,
      display_secure_port = v_display_secure_port,
      utc_diff = v_utc_diff,last_vds_run_on = v_last_vds_run_on,client_ip = v_client_ip,
      guest_requested_memory = v_guest_requested_memory,
      hibernation_vol_handle = v_hibernation_vol_handle,exit_status = v_exit_status,
      pause_status = v_pause_status,exit_message = v_exit_message, hash=v_hash, guest_agent_nics_hash = v_guest_agent_nics_hash,
      last_watchdog_event = v_last_watchdog_event, last_watchdog_action = v_last_watchdog_action, is_run_once = v_is_run_once, cpu_name = v_cpu_name,
      current_cd = v_current_cd
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.updatevmdynamic(v_app_list character varying, v_guest_cur_user_name character varying, v_console_cur_user_name character varying, v_guest_last_login_time timestamp with time zone, v_guest_last_logout_time timestamp with time zone, v_console_user_id uuid, v_guest_os character varying, v_migrating_to_vds uuid, v_run_on_vds uuid, v_status integer, v_vm_guid uuid, v_vm_host character varying, v_vm_ip character varying, v_vm_fqdn character varying, v_last_start_time timestamp with time zone, v_last_stop_time timestamp with time zone, v_vm_pid integer, v_display integer, v_acpi_enable boolean, v_session integer, v_display_ip character varying, v_display_type integer, v_kvm_enable boolean, v_boot_sequence integer, v_display_secure_port integer, v_utc_diff integer, v_last_vds_run_on uuid, v_client_ip character varying, v_guest_requested_memory integer, v_hibernation_vol_handle character varying, v_exit_status integer, v_pause_status integer, v_exit_message character varying, v_hash character varying, v_guest_agent_nics_hash integer, v_last_watchdog_event numeric, v_last_watchdog_action character varying, v_is_run_once boolean, v_cpu_name character varying, v_current_cd character varying) OWNER TO engine;

--
-- Name: updatevmdynamicstatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmdynamicstatus(v_vm_guid uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_dynamic
      SET
      status = v_status
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.updatevmdynamicstatus(v_vm_guid uuid, v_status integer) OWNER TO engine;

--
-- Name: updatevminit(uuid, text, text, text, boolean, character varying, text, text, text, text, character varying, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevminit(v_vm_id uuid, v_host_name text, v_domain text, v_authorized_keys text, v_regenerate_keys boolean, v_time_zone character varying, v_dns_servers text, v_dns_search_domains text, v_networks text, v_password text, v_winkey character varying, v_custom_script text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_init
      SET host_name=v_host_name, domain=v_domain, authorized_keys=v_authorized_keys, regenerate_keys=v_regenerate_keys,
          time_zone=v_time_zone, dns_servers=v_dns_servers, dns_search_domains=v_dns_search_domains,
          networks=v_networks, password=v_password, winkey=v_winkey, custom_script=v_custom_script
      WHERE vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevminit(v_vm_id uuid, v_host_name text, v_domain text, v_authorized_keys text, v_regenerate_keys boolean, v_time_zone character varying, v_dns_servers text, v_dns_search_domains text, v_networks text, v_password text, v_winkey character varying, v_custom_script text) OWNER TO engine;

--
-- Name: updatevminterface(uuid, character varying, character varying, integer, uuid, uuid, uuid, integer, boolean); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevminterface(v_id uuid, v_mac_addr character varying, v_name character varying, v_speed integer, v_vnic_profile_id uuid, v_vm_guid uuid, v_vmt_guid uuid, v_type integer, v_linked boolean) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_interface
      SET mac_addr = v_mac_addr,name = v_name, speed = v_speed, vnic_profile_id = v_vnic_profile_id, vm_guid = v_vm_guid,
      vmt_guid = v_vmt_guid,type = v_type, _update_date = LOCALTIMESTAMP, linked = v_linked
      WHERE id = v_id;
END; ';


ALTER FUNCTION public.updatevminterface(v_id uuid, v_mac_addr character varying, v_name character varying, v_speed integer, v_vnic_profile_id uuid, v_vm_guid uuid, v_vmt_guid uuid, v_type integer, v_linked boolean) OWNER TO engine;

--
-- Name: updatevmstatic(character varying, text, integer, integer, uuid, uuid, character varying, uuid, timestamp with time zone, integer, boolean, boolean, boolean, integer, integer, integer, character varying, boolean, boolean, boolean, boolean, character varying, uuid, boolean, integer, integer, integer, integer, integer, integer, character varying, integer, character varying, character varying, character varying, integer, character varying, character varying, integer, uuid, character varying, boolean, boolean, character varying, boolean, uuid, uuid, uuid, uuid, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmstatic(v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_os integer, v_vds_group_id uuid, v_vm_guid uuid, v_vm_name character varying, v_vmt_guid uuid, v_creation_date timestamp with time zone, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_is_initialized boolean, v_num_of_sockets integer, v_cpu_per_socket integer, v_usb_policy integer, v_time_zone character varying, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_dedicated_vm_for_vds uuid, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_migration_support integer, v_predefined_properties character varying, v_userdefined_properties character varying, v_min_allocated_mem integer, v_quota_id uuid, v_cpu_pinning character varying, v_host_cpu_flags boolean, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_instance_type_id uuid, v_image_type_id uuid, v_original_template_id uuid, v_original_template_name character varying, v_migration_downtime integer, v_template_version_number integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET description = v_description, free_text_comment = v_free_text_comment ,mem_size_mb = v_mem_size_mb,os = v_os,vds_group_id = v_vds_group_id,
      VM_NAME = v_vm_name,vmt_guid = v_vmt_guid,
      creation_date = v_creation_date,num_of_monitors = v_num_of_monitors,single_qxl_pci = v_single_qxl_pci,
      allow_console_reconnect = v_allow_console_reconnect,
      is_initialized = v_is_initialized,
      num_of_sockets = v_num_of_sockets,cpu_per_socket = v_cpu_per_socket,
      usb_policy = v_usb_policy,time_zone = v_time_zone,auto_startup = v_auto_startup,
      is_stateless = v_is_stateless,dedicated_vm_for_vds = v_dedicated_vm_for_vds,
      fail_back = v_fail_back,vm_type = v_vm_type,
      nice_level = v_nice_level,
      cpu_shares = v_cpu_shares,
      _update_date = LOCALTIMESTAMP,default_boot_sequence = v_default_boot_sequence,
      default_display_type = v_default_display_type,
      priority = v_priority,iso_path = v_iso_path,origin = v_origin,
      initrd_url = v_initrd_url,kernel_url = v_kernel_url,
      kernel_params = v_kernel_params,migration_support = v_migration_support,
      predefined_properties = v_predefined_properties,userdefined_properties = v_userdefined_properties,
      min_allocated_mem = v_min_allocated_mem, quota_id = v_quota_id, cpu_pinning = v_cpu_pinning, is_smartcard_enabled = v_is_smartcard_enabled,
      is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, host_cpu_flags = v_host_cpu_flags, tunnel_migration = v_tunnel_migration,
      vnc_keyboard_layout = v_vnc_keyboard_layout, is_run_and_pause = v_is_run_and_pause, created_by_user_id = v_created_by_user_id,
      instance_type_id = v_instance_type_id, image_type_id = v_image_type_id, original_template_id = v_original_template_id,
      original_template_name = v_original_template_name,
      migration_downtime = v_migration_downtime, template_version_number = v_template_version_number
      WHERE vm_guid = v_vm_guid
      AND   entity_type = ''VM'';
END; ';


ALTER FUNCTION public.updatevmstatic(v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_os integer, v_vds_group_id uuid, v_vm_guid uuid, v_vm_name character varying, v_vmt_guid uuid, v_creation_date timestamp with time zone, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_is_initialized boolean, v_num_of_sockets integer, v_cpu_per_socket integer, v_usb_policy integer, v_time_zone character varying, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_dedicated_vm_for_vds uuid, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_migration_support integer, v_predefined_properties character varying, v_userdefined_properties character varying, v_min_allocated_mem integer, v_quota_id uuid, v_cpu_pinning character varying, v_host_cpu_flags boolean, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_instance_type_id uuid, v_image_type_id uuid, v_original_template_id uuid, v_original_template_name character varying, v_migration_downtime integer, v_template_version_number integer) OWNER TO engine;

--
-- Name: updatevmstatistics(numeric, numeric, numeric, integer, integer, integer, text, uuid); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmstatistics(v_cpu_sys numeric, v_cpu_user numeric, v_elapsed_time numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_disks_usage text, v_vm_guid uuid) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_statistics
      SET cpu_sys = v_cpu_sys,cpu_user = v_cpu_user,elapsed_time = v_elapsed_time,
      usage_cpu_percent = v_usage_cpu_percent,usage_mem_percent = v_usage_mem_percent,
      usage_network_percent = v_usage_network_percent,disks_usage = v_disks_usage, _update_date = LOCALTIMESTAMP
      WHERE vm_guid = v_vm_guid;
END; ';


ALTER FUNCTION public.updatevmstatistics(v_cpu_sys numeric, v_cpu_user numeric, v_elapsed_time numeric, v_usage_cpu_percent integer, v_usage_mem_percent integer, v_usage_network_percent integer, v_disks_usage text, v_vm_guid uuid) OWNER TO engine;

--
-- Name: updatevmtagsdefaultdisplaytype(uuid, uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmtagsdefaultdisplaytype(v_tag_id uuid, v_vm_id uuid, v_defaultdisplaytype integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      update tags_vm_map
      set DefaultDisplayType = v_DefaultDisplayType
      where tags_vm_map.tag_id = v_tag_id
      and tags_vm_map.vm_id = v_vm_id;
END; ';


ALTER FUNCTION public.updatevmtagsdefaultdisplaytype(v_tag_id uuid, v_vm_id uuid, v_defaultdisplaytype integer) OWNER TO engine;

--
-- Name: updatevmtemplate(integer, timestamp with time zone, character varying, text, integer, character varying, integer, integer, integer, uuid, uuid, integer, boolean, boolean, integer, integer, character varying, boolean, integer, integer, integer, integer, integer, integer, boolean, boolean, boolean, boolean, character varying, boolean, character varying, integer, character varying, character varying, character varying, uuid, integer, uuid, boolean, character varying, integer, boolean, uuid, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmtemplate(v_child_count integer, v_creation_date timestamp with time zone, v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_name character varying, v_num_of_sockets integer, v_cpu_per_socket integer, v_os integer, v_vmt_guid uuid, v_vds_group_id uuid, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_status integer, v_usb_policy integer, v_time_zone character varying, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_is_disabled boolean, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_quota_id uuid, v_migration_support integer, v_dedicated_vm_for_vds uuid, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_min_allocated_mem integer, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_template_type character varying, v_migration_downtime integer, v_template_version_name character varying) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET child_count = v_child_count,creation_date = v_creation_date,description = v_description, free_text_comment = v_free_text_comment,
      mem_size_mb = v_mem_size_mb,vm_name = v_name,num_of_sockets = v_num_of_sockets,
      cpu_per_socket = v_cpu_per_socket,os = v_os,
      vds_group_id = v_vds_group_id,num_of_monitors = v_num_of_monitors,
      single_qxl_pci = v_single_qxl_pci, allow_console_reconnect = v_allow_console_reconnect,
      template_status = v_status,usb_policy = v_usb_policy,time_zone = v_time_zone,
      fail_back = v_fail_back,
      vm_type = v_vm_type,
      nice_level = v_nice_level,
      cpu_shares = v_cpu_shares, default_boot_sequence = v_default_boot_sequence,
      default_display_type = v_default_display_type,
      priority = v_priority,auto_startup = v_auto_startup,is_stateless = v_is_stateless,
      iso_path = v_iso_path,origin = v_origin,initrd_url = v_initrd_url,
      kernel_url = v_kernel_url,kernel_params = v_kernel_params, _update_date = CURRENT_TIMESTAMP, quota_id = v_quota_id,
      migration_support = v_migration_support, dedicated_vm_for_vds = v_dedicated_vm_for_vds, is_smartcard_enabled = v_is_smartcard_enabled,
      is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, is_disabled = v_is_disabled, tunnel_migration = v_tunnel_migration,
      vnc_keyboard_layout = v_vnc_keyboard_layout, min_allocated_mem = v_min_allocated_mem, is_run_and_pause = v_is_run_and_pause, created_by_user_id = v_created_by_user_id,
      migration_downtime = v_migration_downtime,
      template_version_name = v_template_version_name
      WHERE vm_guid = v_vmt_guid
      AND   entity_type = v_template_type;
END; ';


ALTER FUNCTION public.updatevmtemplate(v_child_count integer, v_creation_date timestamp with time zone, v_description character varying, v_free_text_comment text, v_mem_size_mb integer, v_name character varying, v_num_of_sockets integer, v_cpu_per_socket integer, v_os integer, v_vmt_guid uuid, v_vds_group_id uuid, v_num_of_monitors integer, v_single_qxl_pci boolean, v_allow_console_reconnect boolean, v_status integer, v_usb_policy integer, v_time_zone character varying, v_fail_back boolean, v_vm_type integer, v_nice_level integer, v_cpu_shares integer, v_default_boot_sequence integer, v_default_display_type integer, v_priority integer, v_auto_startup boolean, v_is_stateless boolean, v_is_smartcard_enabled boolean, v_is_delete_protected boolean, v_sso_method character varying, v_is_disabled boolean, v_iso_path character varying, v_origin integer, v_initrd_url character varying, v_kernel_url character varying, v_kernel_params character varying, v_quota_id uuid, v_migration_support integer, v_dedicated_vm_for_vds uuid, v_tunnel_migration boolean, v_vnc_keyboard_layout character varying, v_min_allocated_mem integer, v_is_run_and_pause boolean, v_created_by_user_id uuid, v_template_type character varying, v_migration_downtime integer, v_template_version_name character varying) OWNER TO engine;

--
-- Name: updatevmtemplatestatus(uuid, integer); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevmtemplatestatus(v_vmt_guid uuid, v_status integer) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN
      UPDATE vm_static
      SET    template_status = v_status
      WHERE  vm_guid = v_vmt_guid;
END; ';


ALTER FUNCTION public.updatevmtemplatestatus(v_vmt_guid uuid, v_status integer) OWNER TO engine;

--
-- Name: updatevnicprofile(uuid, character varying, uuid, uuid, boolean, text, text); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION updatevnicprofile(v_id uuid, v_name character varying, v_network_id uuid, v_network_qos_id uuid, v_port_mirroring boolean, v_custom_properties text, v_description text) RETURNS void
    LANGUAGE plpgsql
    AS '
BEGIN

   UPDATE vnic_profiles
   SET id = v_id, name = v_name, network_id = v_network_id, network_qos_id = v_network_qos_id,
   port_mirroring = v_port_mirroring, custom_properties = v_custom_properties,
   description = v_description,_update_date = LOCALTIMESTAMP
   WHERE id = v_id;

END; ';


ALTER FUNCTION public.updatevnicprofile(v_id uuid, v_name character varying, v_network_id uuid, v_network_qos_id uuid, v_port_mirroring boolean, v_custom_properties text, v_description text) OWNER TO engine;

--
-- Name: uuid_generate_v1(); Type: FUNCTION; Schema: public; Owner: engine
--

CREATE FUNCTION uuid_generate_v1() RETURNS uuid
    LANGUAGE plpgsql STABLE
    AS '
declare
    v_val bigint;
    v_4_part char(4);
    v_8_part char(8);
    v_12_part char(12);
    v_4_part_max int;
begin
    -- The only part we should use modulo is the 4 digit part, all the
    -- rest are really big numbers (i.e 16^8 - 1 and 16^12 - 1)
    -- The use of round(random() * 1000 is for getting a different id
    -- for DC/Cluster in different installations
    v_4_part_max = 65535; -- this is 16^4 -1
    v_val := nextval(''uuid_sequence'');
    v_4_part := lpad(to_hex(v_val % v_4_part_max), 4, ''0'');
    v_8_part := lpad(to_hex(v_val), 8, ''0'');
    v_12_part := lpad(to_hex((v_val + (round(random() * 1000))::bigint)), 12, ''0'');
    return v_8_part || v_4_part || v_4_part || v_4_part || v_12_part;
end; ';


ALTER FUNCTION public.uuid_generate_v1() OWNER TO engine;

--
-- Name: desktop_vms; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW desktop_vms AS
    SELECT vms.vm_name, vms.vm_mem_size_mb, vms.nice_level, vms.cpu_shares, vms.vmt_guid, vms.vm_os, vms.vm_description, vms.vm_comment, vms.vds_group_id, vms.vm_creation_date, vms.auto_startup, vms.is_stateless, vms.is_smartcard_enabled, vms.is_delete_protected, vms.sso_method, vms.dedicated_vm_for_vds, vms.fail_back, vms.default_boot_sequence, vms.vm_type, vms.vm_pool_spice_proxy, vms.vds_group_name, vms.transparent_hugepages, vms.trusted_service, vms.storage_pool_id, vms.storage_pool_name, vms.vds_group_description, vms.vds_group_spice_proxy, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date, vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_num_of_cpus, vms.vmt_description, vms.status, vms.vm_ip, vms.vm_host, vms.vm_pid, vms.last_start_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.guest_last_logout_time, vms.guest_os, vms.console_user_id, vms.guest_agent_nics_hash, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display, vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci, vms.allow_console_reconnect, vms.is_initialized, vms.num_of_sockets, vms.cpu_per_socket, vms.usb_policy, vms.acpi_enable, vms.session, vms.num_of_cpus, vms.quota_id, vms.quota_name, vms.quota_enforcement_type, vms.display_ip, vms.display_type, vms.kvm_enable, vms.boot_sequence, vms.display_secure_port, vms.utc_diff, vms.last_vds_run_on, vms.client_ip, vms.guest_requested_memory, vms.time_zone, vms.cpu_user, vms.cpu_sys, vms.elapsed_time, vms.usage_network_percent, vms.usage_mem_percent, vms.usage_cpu_percent, vms.run_on_vds_name, vms.vds_group_cpu_name, vms.default_display_type, vms.priority, vms.iso_path, vms.origin, vms.vds_group_compatibility_version, vms.initrd_url, vms.kernel_url, vms.kernel_params, vms.pause_status, vms.exit_message, vms.exit_status, vms.migration_support, vms.predefined_properties, vms.userdefined_properties, vms.min_allocated_mem, vms.hash, vms.cpu_pinning, vms.db_generation, vms.host_cpu_flags, vms.tunnel_migration, vms.vnc_keyboard_layout, vms.is_run_and_pause, vms.created_by_user_id, vms.last_watchdog_event, vms.last_watchdog_action, vms.is_run_once, vms.vm_fqdn, vms.cpu_name, vms.current_cd, vms.instance_type_id, vms.image_type_id, vms.architecture, vms.original_template_id, vms.original_template_name, vms.last_stop_time, vms.migration_downtime, vms.template_version_number FROM vms WHERE (vms.vm_type = 0);


ALTER TABLE public.desktop_vms OWNER TO engine;

--
-- Name: dwh_add_tags_relations_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_add_tags_relations_history_view AS
    ((((SELECT tags.tag_id AS entity_id, tags.parent_id, (18)::smallint AS entity_type, tags._create_date AS attach_date, tags._update_date AS move_date FROM tags WHERE ((tags._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (tags._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))) UNION ALL SELECT tags_vds_map.vds_id AS entity_id, tags_vds_map.tag_id AS parent_id, (3)::smallint AS entity_type, tags_vds_map._create_date AS attach_date, NULL::unknown AS move_date FROM tags_vds_map WHERE (tags_vds_map._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text)))) UNION ALL SELECT tags_vm_pool_map.vm_pool_id AS entity_id, tags_vm_pool_map.tag_id AS parent_id, (5)::smallint AS entity_type, tags_vm_pool_map._create_date AS attach_date, NULL::unknown AS move_date FROM tags_vm_pool_map WHERE (tags_vm_pool_map._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text)))) UNION ALL SELECT tags_vm_map.vm_id AS entity_id, tags_vm_map.tag_id AS parent_id, (2)::smallint AS entity_type, tags_vm_map._create_date AS attach_date, NULL::unknown AS move_date FROM tags_vm_map WHERE (tags_vm_map._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text)))) UNION ALL SELECT tags_user_map.user_id AS entity_id, tags_user_map.tag_id AS parent_id, (15)::smallint AS entity_type, tags_user_map._create_date AS attach_date, NULL::unknown AS move_date FROM tags_user_map WHERE (tags_user_map._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text)))) UNION ALL SELECT tags_user_group_map.group_id AS entity_id, tags_user_group_map.tag_id AS parent_id, (17)::smallint AS entity_type, tags_user_group_map._create_date AS attach_date, NULL::unknown AS move_date FROM tags_user_group_map WHERE (tags_user_group_map._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text)));


ALTER TABLE public.dwh_add_tags_relations_history_view OWNER TO engine;

--
-- Name: dwh_cluster_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_cluster_configuration_history_view AS
    SELECT vds_groups.vds_group_id AS cluster_id, vds_groups.name AS cluster_name, vds_groups.description AS cluster_description, vds_groups.storage_pool_id AS datacenter_id, vds_groups.cpu_name, vds_groups.compatibility_version, vds_groups._create_date AS create_date, vds_groups._update_date AS update_date FROM vds_groups WHERE ((vds_groups._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (vds_groups._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text))));


ALTER TABLE public.dwh_cluster_configuration_history_view OWNER TO engine;

--
-- Name: dwh_datacenter_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_datacenter_configuration_history_view AS
    SELECT storage_pool.id AS datacenter_id, storage_pool.name AS datacenter_name, storage_pool.description AS datacenter_description, storage_pool.is_local AS is_local_storage, storage_pool._create_date AS create_date, storage_pool._update_date AS update_date FROM storage_pool WHERE ((storage_pool._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (storage_pool._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text))));


ALTER TABLE public.dwh_datacenter_configuration_history_view OWNER TO engine;

--
-- Name: dwh_datacenter_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_datacenter_history_view AS
    SELECT storage_pool.id AS datacenter_id, (storage_pool.status)::smallint AS datacenter_status FROM storage_pool;


ALTER TABLE public.dwh_datacenter_history_view OWNER TO engine;

--
-- Name: dwh_datacenter_storage_map_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_datacenter_storage_map_history_view AS
    SELECT DISTINCT storage_pool_iso_map.storage_pool_id AS datacenter_id, storage_pool_iso_map.storage_id AS storage_domain_id FROM storage_pool_iso_map;


ALTER TABLE public.dwh_datacenter_storage_map_history_view OWNER TO engine;

--
-- Name: dwh_disk_vm_map_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_disk_vm_map_history_view AS
    SELECT images.image_guid AS vm_disk_id, vm_device.vm_id FROM (vm_device JOIN images ON ((vm_device.device_id = images.image_group_id))) WHERE (images.active = true);


ALTER TABLE public.dwh_disk_vm_map_history_view OWNER TO engine;

--
-- Name: dwh_host_configuration_full_check_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_host_configuration_full_check_view AS
    SELECT a.vds_id AS host_id, a.vds_unique_id AS host_unique_id, a.vds_name AS host_name, a.vds_group_id AS cluster_id, (a.vds_type)::smallint AS host_type, a.host_name AS fqdn_or_ip, b.physical_mem_mb AS memory_size_mb, (c.swap_total)::integer AS swap_size_mb, b.cpu_model, (b.cpu_cores)::smallint AS number_of_cores, (b.cpu_sockets)::smallint AS number_of_sockets, b.cpu_speed_mh, b.host_os, a.ip AS pm_ip_address, b.kernel_version, b.kvm_version, b.libvirt_version, CASE substr((b.software_version)::text, 1, 3) WHEN '4.4'::text THEN (('2.1'::text || substr((b.software_version)::text, 4, length((b.software_version)::text))))::character varying WHEN '4.5'::text THEN (('2.2'::text || substr((b.software_version)::text, 4, length((b.software_version)::text))))::character varying WHEN '4.9'::text THEN (('2.3'::text || substr((b.software_version)::text, 4, length((b.software_version)::text))))::character varying ELSE b.software_version END AS vdsm_version, a.port AS vdsm_port, a._create_date AS create_date, a._update_date AS update_date FROM ((vds_static a JOIN vds_dynamic b ON ((a.vds_id = b.vds_id))) JOIN vds_statistics c ON ((c.vds_id = a.vds_id)));


ALTER TABLE public.dwh_host_configuration_full_check_view OWNER TO engine;

--
-- Name: dwh_host_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_host_configuration_history_view AS
    SELECT a.vds_id AS host_id, a.vds_unique_id AS host_unique_id, a.vds_name AS host_name, a.vds_group_id AS cluster_id, (a.vds_type)::smallint AS host_type, a.host_name AS fqdn_or_ip, b.physical_mem_mb AS memory_size_mb, (c.swap_total)::integer AS swap_size_mb, b.cpu_model, (b.cpu_cores)::smallint AS number_of_cores, (b.cpu_sockets)::smallint AS number_of_sockets, b.cpu_speed_mh, b.host_os, a.ip AS pm_ip_address, b.kernel_version, b.kvm_version, b.libvirt_version, b.software_version AS vdsm_version, a.port AS vdsm_port, a._create_date AS create_date, a._update_date AS update_date FROM ((vds_static a JOIN vds_dynamic b ON ((a.vds_id = b.vds_id))) JOIN vds_statistics c ON ((c.vds_id = a.vds_id))) WHERE ((a._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (a._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text))));


ALTER TABLE public.dwh_host_configuration_history_view OWNER TO engine;

--
-- Name: dwh_host_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_host_history_view AS
    SELECT b.vds_id AS host_id, (b.status)::smallint AS host_status, (c.usage_mem_percent)::smallint AS memory_usage_percent, (c.usage_cpu_percent)::smallint AS cpu_usage_percent, (c.ksm_cpu_percent)::smallint AS ksm_cpu_percent, (c.cpu_load)::integer AS cpu_load, (c.cpu_sys)::smallint AS system_cpu_usage_percent, (c.cpu_user)::smallint AS user_cpu_usage_percent, ((c.swap_total - c.swap_free))::integer AS swap_used_mb, (b.vm_active)::smallint AS vm_active, (b.vm_count)::smallint AS total_vms, b.vms_cores_count AS total_vms_vcpus, (c.mem_shared)::smallint AS ksm_shared_memory_percent FROM vds_dynamic b, vds_statistics c WHERE (b.vds_id = c.vds_id);


ALTER TABLE public.dwh_host_history_view OWNER TO engine;

--
-- Name: dwh_host_interface_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_host_interface_configuration_history_view AS
    SELECT a.id AS host_interface_id, a.name AS host_interface_name, a.vds_id AS host_id, (a.type)::smallint AS host_interface_type, a.speed AS host_interface_speed_bps, a.mac_addr AS mac_address, a.network_name, a.addr AS ip_address, a.gateway, a.is_bond AS bond, a.bond_name, a.vlan_id, a._create_date AS create_date, a._update_date AS update_date FROM vds_interface a WHERE (((a._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (a._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))) AND ((a.is_bond IS NULL) OR ((a.is_bond = true) AND ((a.name)::text IN (SELECT b.bond_name FROM vds_interface b WHERE ((b.is_bond IS NULL) AND (b.vds_id = a.vds_id)))))));


ALTER TABLE public.dwh_host_interface_configuration_history_view OWNER TO engine;

--
-- Name: dwh_host_interface_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_host_interface_history_view AS
    SELECT vds_interface_statistics.id AS host_interface_id, (vds_interface_statistics.rx_rate)::smallint AS receive_rate_percent, (vds_interface_statistics.tx_rate)::smallint AS transmit_rate_percent FROM vds_interface_statistics;


ALTER TABLE public.dwh_host_interface_history_view OWNER TO engine;

--
-- Name: dwh_osinfo; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE dwh_osinfo (
    os_id integer NOT NULL,
    os_name character varying(255)
);


ALTER TABLE public.dwh_osinfo OWNER TO engine;

--
-- Name: dwh_remove_tags_relations_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_remove_tags_relations_history_view AS
    ((((SELECT tags.tag_id AS entity_id, tags.parent_id FROM tags UNION ALL SELECT tags_vds_map.vds_id AS entity_id, tags_vds_map.tag_id AS parent_id FROM tags_vds_map) UNION ALL SELECT tags_vm_pool_map.vm_pool_id AS entity_id, tags_vm_pool_map.tag_id AS parent_id FROM tags_vm_pool_map) UNION ALL SELECT tags_vm_map.vm_id AS entity_id, tags_vm_map.tag_id AS parent_id FROM tags_vm_map) UNION ALL SELECT tags_user_map.user_id AS entity_id, tags_user_map.tag_id AS parent_id FROM tags_user_map) UNION ALL SELECT tags_user_group_map.group_id AS entity_id, tags_user_group_map.tag_id AS parent_id FROM tags_user_group_map;


ALTER TABLE public.dwh_remove_tags_relations_history_view OWNER TO engine;

--
-- Name: dwh_storage_domain_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_storage_domain_configuration_history_view AS
    SELECT storage_domain_static.id AS storage_domain_id, storage_domain_static.storage_name AS storage_domain_name, (storage_domain_static.storage_domain_type)::smallint AS storage_domain_type, (storage_domain_static.storage_type)::smallint AS storage_type, storage_domain_static._create_date AS create_date, storage_domain_static._update_date AS update_date FROM storage_domain_static WHERE ((storage_domain_static._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (storage_domain_static._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text))));


ALTER TABLE public.dwh_storage_domain_configuration_history_view OWNER TO engine;

--
-- Name: dwh_storage_domain_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_storage_domain_history_view AS
    SELECT storage_domain_dynamic.id AS storage_domain_id, fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, status_table.status, storage_domain_static.storage_domain_type) AS storage_domain_status, storage_domain_dynamic.available_disk_size AS available_disk_size_gb, storage_domain_dynamic.used_disk_size AS used_disk_size_gb FROM ((storage_domain_dynamic JOIN storage_domain_static ON ((storage_domain_dynamic.id = storage_domain_static.id))) LEFT JOIN (SELECT storage_pool_iso_map.storage_id, max(storage_pool_iso_map.status) AS status FROM storage_pool_iso_map GROUP BY storage_pool_iso_map.storage_id) status_table ON ((storage_domain_static.id = status_table.storage_id)));


ALTER TABLE public.dwh_storage_domain_history_view OWNER TO engine;

--
-- Name: dwh_tags_details_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_tags_details_history_view AS
    SELECT tags.tag_id, tags.tag_name, tags.description AS tag_description, tags._create_date AS create_date, tags._update_date AS update_date FROM tags WHERE ((tags._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (tags._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text))));


ALTER TABLE public.dwh_tags_details_history_view OWNER TO engine;

--
-- Name: dwh_vm_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_configuration_history_view AS
    SELECT a.vm_guid AS vm_id, a.vm_name, a.description AS vm_description, (a.vm_type)::smallint AS vm_type, a.vds_group_id AS cluster_id, a.vmt_guid AS template_id, b.vm_name AS template_name, (a.cpu_per_socket)::smallint AS cpu_per_socket, (a.num_of_sockets)::smallint AS number_of_sockets, a.mem_size_mb AS memory_size_mb, (a.os)::smallint AS operating_system, a.dedicated_vm_for_vds AS default_host, a.auto_startup AS high_availability, a.is_initialized AS initialized, a.is_stateless AS stateless, a.fail_back, (a.usb_policy)::smallint AS usb_policy, a.time_zone, c.vm_pool_id, d.vm_pool_name, a.created_by_user_id, e.username AS created_by_user_name, a._create_date AS create_date, a._update_date AS update_date FROM ((((vm_static a JOIN vm_static b ON ((a.vmt_guid = b.vm_guid))) LEFT JOIN vm_pool_map c ON ((a.vm_guid = c.vm_guid))) LEFT JOIN vm_pools d ON ((c.vm_pool_id = d.vm_pool_id))) LEFT JOIN users e ON ((a.created_by_user_id = e.user_id))) WHERE ((((a.entity_type)::text = 'VM'::text) AND ((b.entity_type)::text = 'TEMPLATE'::text)) AND (((a._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (a._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))) OR (b._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))));


ALTER TABLE public.dwh_vm_configuration_history_view OWNER TO engine;

--
-- Name: dwh_vm_device_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_device_history_view AS
    SELECT vm_device.device_id, vm_device.vm_id, vm_device.type, vm_device.address, vm_device.is_managed, vm_device.is_plugged, vm_device.is_readonly, vm_device._create_date AS create_date, vm_device._update_date AS update_date FROM vm_device WHERE (((((vm_device.type)::text = 'disk'::text) AND ((vm_device.device)::text = 'disk'::text)) OR ((vm_device.type)::text = 'interface'::text)) AND ((vm_device._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (vm_device._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))));


ALTER TABLE public.dwh_vm_device_history_view OWNER TO engine;

--
-- Name: dwh_vm_disk_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_disk_configuration_history_view AS
    SELECT d.disk_id AS vm_disk_id, d.disk_alias AS vm_disk_name, d.disk_description AS vm_disk_description, i.image_guid AS image_id, image_storage_domain_map.storage_domain_id, ((i.size / 1048576))::integer AS vm_disk_size_mb, (i.volume_type)::smallint AS vm_disk_type, (i.volume_format)::smallint AS vm_disk_format, CASE WHEN ((d.disk_interface)::text = 'IDE'::text) THEN (0)::smallint WHEN ((d.disk_interface)::text = 'SCSI'::text) THEN (1)::smallint WHEN ((d.disk_interface)::text = 'VirtIO'::text) THEN (2)::smallint ELSE NULL::smallint END AS vm_disk_interface, d.shareable AS is_shared, i._create_date AS create_date, i._update_date AS update_date FROM ((((images i JOIN base_disks d ON ((i.image_group_id = d.disk_id))) JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = i.image_guid))) LEFT JOIN vm_device ON ((vm_device.device_id = i.image_group_id))) LEFT JOIN vm_static ON ((vm_static.vm_guid = vm_device.vm_id))) WHERE (((i.active = true) AND (((vm_static.entity_type)::text = 'VM'::text) OR (vm_static.entity_type IS NULL))) AND ((i._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (i._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))));


ALTER TABLE public.dwh_vm_disk_configuration_history_view OWNER TO engine;

--
-- Name: dwh_vm_disks_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_disks_history_view AS
    SELECT d.disk_id AS vm_disk_id, images.image_guid AS image_id, (images.imagestatus)::smallint AS vm_disk_status, ((disk_image_dynamic.actual_size / 1048576))::integer AS vm_disk_actual_size_mb, disk_image_dynamic.read_rate AS read_rate_bytes_per_second, disk_image_dynamic.read_latency_seconds, disk_image_dynamic.write_rate AS write_rate_bytes_per_second, disk_image_dynamic.write_latency_seconds, disk_image_dynamic.flush_latency_seconds FROM ((((images JOIN disk_image_dynamic ON ((images.image_guid = disk_image_dynamic.image_id))) JOIN base_disks d ON ((images.image_group_id = d.disk_id))) LEFT JOIN vm_device ON ((vm_device.device_id = images.image_group_id))) LEFT JOIN vm_static ON ((vm_static.vm_guid = vm_device.vm_id))) WHERE ((images.active = true) AND (((vm_static.entity_type)::text = 'VM'::text) OR (vm_static.entity_type IS NULL)));


ALTER TABLE public.dwh_vm_disks_history_view OWNER TO engine;

--
-- Name: dwh_vm_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_history_view AS
    SELECT c.vm_guid AS vm_id, (b.status)::smallint AS vm_status, (c.usage_cpu_percent)::smallint AS cpu_usage_percent, (c.usage_mem_percent)::smallint AS memory_usage_percent, (c.cpu_sys)::smallint AS system_cpu_usage_percent, (c.cpu_user)::smallint AS user_cpu_usage_percent, c.disks_usage, b.vm_ip, b.vm_fqdn, b.client_ip AS vm_client_ip, b.console_cur_user_name AS current_user_name, CASE WHEN (b.guest_cur_user_name IS NULL) THEN false ELSE true END AS user_logged_in_to_guest, b.run_on_vds AS currently_running_on_host FROM vm_dynamic b, vm_statistics c WHERE (c.vm_guid = b.vm_guid);


ALTER TABLE public.dwh_vm_history_view OWNER TO engine;

--
-- Name: dwh_vm_interface_configuration_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_interface_configuration_history_view AS
    SELECT vm_interface.id AS vm_interface_id, vm_interface.name AS vm_interface_name, vm_interface.vm_guid AS vm_id, (vm_interface.type)::smallint AS vm_interface_type, vm_interface.speed AS vm_interface_speed_bps, vm_interface.mac_addr AS mac_address, network.name AS network_name, vm_interface._create_date AS create_date, vm_interface._update_date AS update_date FROM (vm_interface LEFT JOIN (vnic_profiles JOIN network ON ((network.id = vnic_profiles.network_id))) ON ((vnic_profiles.id = vm_interface.vnic_profile_id))) WHERE ((vm_interface.vmt_guid IS NULL) AND ((vm_interface._create_date > (SELECT dwh_history_timekeeping.var_datetime FROM dwh_history_timekeeping WHERE ((dwh_history_timekeeping.var_name)::text = 'lastSync'::text))) OR (vm_interface._update_date > (SELECT history_timekeeping_1.var_datetime FROM dwh_history_timekeeping history_timekeeping_1 WHERE ((history_timekeeping_1.var_name)::text = 'lastSync'::text)))));


ALTER TABLE public.dwh_vm_interface_configuration_history_view OWNER TO engine;

--
-- Name: dwh_vm_interface_history_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW dwh_vm_interface_history_view AS
    SELECT vm_interface_statistics.id AS vm_interface_id, (vm_interface_statistics.rx_rate)::smallint AS receive_rate_percent, (vm_interface_statistics.tx_rate)::smallint AS transmit_rate_percent FROM vm_interface_statistics;


ALTER TABLE public.dwh_vm_interface_history_view OWNER TO engine;

--
-- Name: vm_templates_storage_domain; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_templates_storage_domain AS
    SELECT vm_templates.vm_guid AS vmt_guid, vm_templates.vm_name AS name, vm_templates.mem_size_mb, vm_templates.os, vm_templates.creation_date, vm_templates.child_count, vm_templates.num_of_sockets, vm_templates.cpu_per_socket, (vm_templates.num_of_sockets * vm_templates.cpu_per_socket) AS num_of_cpus, vm_templates.description, vm_templates.free_text_comment, vm_templates.vds_group_id, vm_templates.num_of_monitors, vm_templates.single_qxl_pci, vm_templates.allow_console_reconnect, vm_templates.template_status AS status, vm_templates.usb_policy, vm_templates.time_zone, vm_templates.fail_back, vds_groups.name AS vds_group_name, vm_templates.vm_type, vm_templates.nice_level, vm_templates.cpu_shares, storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, vm_templates.default_boot_sequence, vm_templates.default_display_type, vm_templates.priority, vm_templates.auto_startup, vm_templates.is_stateless, vm_templates.iso_path, vm_templates.origin, vm_templates.initrd_url, vm_templates.kernel_url, vm_templates.kernel_params, image_storage_domain_map.storage_domain_id AS storage_id, quota.quota_name, vm_templates.is_disabled, vm_templates.min_allocated_mem, vm_templates.is_run_and_pause, vm_templates.created_by_user_id, vm_templates.migration_downtime, vm_templates.entity_type, vds_groups.architecture, vm_templates.template_version_number, vm_templates.vmt_guid AS base_template_id, vm_templates.template_version_name FROM ((((((vm_static vm_templates JOIN vds_groups ON ((vm_templates.vds_group_id = vds_groups.vds_group_id))) LEFT JOIN storage_pool ON ((storage_pool.id = vds_groups.storage_pool_id))) JOIN vm_device ON ((vm_device.vm_id = vm_templates.vm_guid))) LEFT JOIN images ON ((images.image_group_id = vm_device.device_id))) LEFT JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = images.image_guid))) LEFT JOIN quota quota ON ((quota.id = vm_templates.quota_id))) WHERE ((((vm_templates.entity_type)::text = 'TEMPLATE'::text) OR ((vm_templates.entity_type)::text = 'INSTANCE_TYPE'::text)) OR ((vm_templates.entity_type)::text = 'IMAGE_TYPE'::text)) UNION SELECT vm_templates_1.vm_guid AS vmt_guid, vm_templates_1.vm_name AS name, vm_templates_1.mem_size_mb, vm_templates_1.os, vm_templates_1.creation_date, vm_templates_1.child_count, vm_templates_1.num_of_sockets, vm_templates_1.cpu_per_socket, (vm_templates_1.num_of_sockets * vm_templates_1.cpu_per_socket) AS num_of_cpus, vm_templates_1.description, vm_templates_1.free_text_comment, vm_templates_1.vds_group_id, vm_templates_1.num_of_monitors, vm_templates_1.single_qxl_pci, vm_templates_1.allow_console_reconnect, vm_templates_1.template_status AS status, vm_templates_1.usb_policy, vm_templates_1.time_zone, vm_templates_1.fail_back, vds_groups_1.name AS vds_group_name, vm_templates_1.vm_type, vm_templates_1.nice_level, vm_templates_1.cpu_shares, storage_pool_1.id AS storage_pool_id, storage_pool_1.name AS storage_pool_name, vm_templates_1.default_boot_sequence, vm_templates_1.default_display_type, vm_templates_1.priority, vm_templates_1.auto_startup, vm_templates_1.is_stateless, vm_templates_1.iso_path, vm_templates_1.origin, vm_templates_1.initrd_url, vm_templates_1.kernel_url, vm_templates_1.kernel_params, image_storage_domain_map.storage_domain_id AS storage_id, quota.quota_name, vm_templates_1.is_disabled, vm_templates_1.min_allocated_mem, vm_templates_1.is_run_and_pause, vm_templates_1.created_by_user_id, vm_templates_1.migration_downtime, vm_templates_1.entity_type, vds_groups_1.architecture, vm_templates_1.template_version_number, vm_templates_1.vmt_guid AS base_template_id, vm_templates_1.template_version_name FROM ((((((vm_static vm_templates_1 JOIN vds_groups vds_groups_1 ON ((vm_templates_1.vds_group_id = vds_groups_1.vds_group_id))) LEFT JOIN storage_pool storage_pool_1 ON ((storage_pool_1.id = vds_groups_1.storage_pool_id))) JOIN vm_device vm_device_1 ON ((vm_device_1.vm_id = vm_templates_1.vm_guid))) JOIN images images_1 ON ((images_1.image_group_id = vm_device_1.device_id))) JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = images_1.image_guid))) LEFT JOIN quota quota ON ((quota.id = vm_templates_1.quota_id))) WHERE ((((vm_templates_1.entity_type)::text = 'TEMPLATE'::text) OR ((vm_templates_1.entity_type)::text = 'INSTANCE_TYPE'::text)) OR ((vm_templates_1.entity_type)::text = 'IMAGE_TYPE'::text));


ALTER TABLE public.vm_templates_storage_domain OWNER TO engine;

--
-- Name: image_types_storage_domain; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW image_types_storage_domain AS
    SELECT vm_templates_storage_domain.vmt_guid, vm_templates_storage_domain.name, vm_templates_storage_domain.mem_size_mb, vm_templates_storage_domain.os, vm_templates_storage_domain.creation_date, vm_templates_storage_domain.child_count, vm_templates_storage_domain.num_of_sockets, vm_templates_storage_domain.cpu_per_socket, vm_templates_storage_domain.num_of_cpus, vm_templates_storage_domain.description, vm_templates_storage_domain.free_text_comment, vm_templates_storage_domain.vds_group_id, vm_templates_storage_domain.num_of_monitors, vm_templates_storage_domain.single_qxl_pci, vm_templates_storage_domain.allow_console_reconnect, vm_templates_storage_domain.status, vm_templates_storage_domain.usb_policy, vm_templates_storage_domain.time_zone, vm_templates_storage_domain.fail_back, vm_templates_storage_domain.vds_group_name, vm_templates_storage_domain.vm_type, vm_templates_storage_domain.nice_level, vm_templates_storage_domain.cpu_shares, vm_templates_storage_domain.storage_pool_id, vm_templates_storage_domain.storage_pool_name, vm_templates_storage_domain.default_boot_sequence, vm_templates_storage_domain.default_display_type, vm_templates_storage_domain.priority, vm_templates_storage_domain.auto_startup, vm_templates_storage_domain.is_stateless, vm_templates_storage_domain.iso_path, vm_templates_storage_domain.origin, vm_templates_storage_domain.initrd_url, vm_templates_storage_domain.kernel_url, vm_templates_storage_domain.kernel_params, vm_templates_storage_domain.storage_id, vm_templates_storage_domain.quota_name, vm_templates_storage_domain.is_disabled, vm_templates_storage_domain.min_allocated_mem, vm_templates_storage_domain.is_run_and_pause, vm_templates_storage_domain.created_by_user_id, vm_templates_storage_domain.migration_downtime, vm_templates_storage_domain.entity_type, vm_templates_storage_domain.architecture, vm_templates_storage_domain.template_version_number, vm_templates_storage_domain.base_template_id, vm_templates_storage_domain.template_version_name FROM vm_templates_storage_domain WHERE ((vm_templates_storage_domain.entity_type)::text = 'IMAGE_TYPE'::text);


ALTER TABLE public.image_types_storage_domain OWNER TO engine;

--
-- Name: image_types_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW image_types_view AS
    SELECT vm_templates_view.vmt_guid, vm_templates_view.name, vm_templates_view.mem_size_mb, vm_templates_view.os, vm_templates_view.creation_date, vm_templates_view.child_count, vm_templates_view.num_of_sockets, vm_templates_view.cpu_per_socket, vm_templates_view.num_of_cpus, vm_templates_view.description, vm_templates_view.free_text_comment, vm_templates_view.vds_group_id, vm_templates_view.num_of_monitors, vm_templates_view.single_qxl_pci, vm_templates_view.allow_console_reconnect, vm_templates_view.status, vm_templates_view.usb_policy, vm_templates_view.time_zone, vm_templates_view.fail_back, vm_templates_view.vds_group_name, vm_templates_view.trusted_service, vm_templates_view.vm_type, vm_templates_view.nice_level, vm_templates_view.cpu_shares, vm_templates_view.storage_pool_id, vm_templates_view.storage_pool_name, vm_templates_view.quota_enforcement_type, vm_templates_view.default_boot_sequence, vm_templates_view.default_display_type, vm_templates_view.priority, vm_templates_view.auto_startup, vm_templates_view.is_stateless, vm_templates_view.is_smartcard_enabled, vm_templates_view.is_delete_protected, vm_templates_view.sso_method, vm_templates_view.iso_path, vm_templates_view.origin, vm_templates_view.initrd_url, vm_templates_view.kernel_url, vm_templates_view.kernel_params, vm_templates_view.quota_id, vm_templates_view.quota_name, vm_templates_view.db_generation, vm_templates_view.migration_support, vm_templates_view.dedicated_vm_for_vds, vm_templates_view.is_disabled, vm_templates_view.tunnel_migration, vm_templates_view.vnc_keyboard_layout, vm_templates_view.min_allocated_mem, vm_templates_view.is_run_and_pause, vm_templates_view.created_by_user_id, vm_templates_view.entity_type, vm_templates_view.migration_downtime, vm_templates_view.architecture, vm_templates_view.template_version_number, vm_templates_view.base_template_id, vm_templates_view.template_version_name FROM vm_templates_view WHERE ((vm_templates_view.entity_type)::text = 'IMAGE_TYPE'::text);


ALTER TABLE public.image_types_view OWNER TO engine;

--
-- Name: instance_types_storage_domain; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW instance_types_storage_domain AS
    SELECT vm_templates_storage_domain.vmt_guid, vm_templates_storage_domain.name, vm_templates_storage_domain.mem_size_mb, vm_templates_storage_domain.os, vm_templates_storage_domain.creation_date, vm_templates_storage_domain.child_count, vm_templates_storage_domain.num_of_sockets, vm_templates_storage_domain.cpu_per_socket, vm_templates_storage_domain.num_of_cpus, vm_templates_storage_domain.description, vm_templates_storage_domain.free_text_comment, vm_templates_storage_domain.vds_group_id, vm_templates_storage_domain.num_of_monitors, vm_templates_storage_domain.single_qxl_pci, vm_templates_storage_domain.allow_console_reconnect, vm_templates_storage_domain.status, vm_templates_storage_domain.usb_policy, vm_templates_storage_domain.time_zone, vm_templates_storage_domain.fail_back, vm_templates_storage_domain.vds_group_name, vm_templates_storage_domain.vm_type, vm_templates_storage_domain.nice_level, vm_templates_storage_domain.cpu_shares, vm_templates_storage_domain.storage_pool_id, vm_templates_storage_domain.storage_pool_name, vm_templates_storage_domain.default_boot_sequence, vm_templates_storage_domain.default_display_type, vm_templates_storage_domain.priority, vm_templates_storage_domain.auto_startup, vm_templates_storage_domain.is_stateless, vm_templates_storage_domain.iso_path, vm_templates_storage_domain.origin, vm_templates_storage_domain.initrd_url, vm_templates_storage_domain.kernel_url, vm_templates_storage_domain.kernel_params, vm_templates_storage_domain.storage_id, vm_templates_storage_domain.quota_name, vm_templates_storage_domain.is_disabled, vm_templates_storage_domain.min_allocated_mem, vm_templates_storage_domain.is_run_and_pause, vm_templates_storage_domain.created_by_user_id, vm_templates_storage_domain.migration_downtime, vm_templates_storage_domain.entity_type, vm_templates_storage_domain.architecture, vm_templates_storage_domain.template_version_number, vm_templates_storage_domain.base_template_id, vm_templates_storage_domain.template_version_name FROM vm_templates_storage_domain WHERE ((vm_templates_storage_domain.entity_type)::text = 'INSTANCE_TYPE'::text);


ALTER TABLE public.instance_types_storage_domain OWNER TO engine;

--
-- Name: instance_types_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW instance_types_view AS
    SELECT vm_templates_view.vmt_guid, vm_templates_view.name, vm_templates_view.mem_size_mb, vm_templates_view.os, vm_templates_view.creation_date, vm_templates_view.child_count, vm_templates_view.num_of_sockets, vm_templates_view.cpu_per_socket, vm_templates_view.num_of_cpus, vm_templates_view.description, vm_templates_view.free_text_comment, vm_templates_view.vds_group_id, vm_templates_view.num_of_monitors, vm_templates_view.single_qxl_pci, vm_templates_view.allow_console_reconnect, vm_templates_view.status, vm_templates_view.usb_policy, vm_templates_view.time_zone, vm_templates_view.fail_back, vm_templates_view.vds_group_name, vm_templates_view.trusted_service, vm_templates_view.vm_type, vm_templates_view.nice_level, vm_templates_view.cpu_shares, vm_templates_view.storage_pool_id, vm_templates_view.storage_pool_name, vm_templates_view.quota_enforcement_type, vm_templates_view.default_boot_sequence, vm_templates_view.default_display_type, vm_templates_view.priority, vm_templates_view.auto_startup, vm_templates_view.is_stateless, vm_templates_view.is_smartcard_enabled, vm_templates_view.is_delete_protected, vm_templates_view.sso_method, vm_templates_view.iso_path, vm_templates_view.origin, vm_templates_view.initrd_url, vm_templates_view.kernel_url, vm_templates_view.kernel_params, vm_templates_view.quota_id, vm_templates_view.quota_name, vm_templates_view.db_generation, vm_templates_view.migration_support, vm_templates_view.dedicated_vm_for_vds, vm_templates_view.is_disabled, vm_templates_view.tunnel_migration, vm_templates_view.vnc_keyboard_layout, vm_templates_view.min_allocated_mem, vm_templates_view.is_run_and_pause, vm_templates_view.created_by_user_id, vm_templates_view.entity_type, vm_templates_view.migration_downtime, vm_templates_view.architecture, vm_templates_view.template_version_number, vm_templates_view.base_template_id, vm_templates_view.template_version_name FROM vm_templates_view WHERE ((vm_templates_view.entity_type)::text = 'INSTANCE_TYPE'::text);


ALTER TABLE public.instance_types_view OWNER TO engine;

--
-- Name: internal_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW internal_permissions_view AS
    SELECT permissions.id, permissions.role_id, permissions.ad_element_id, permissions.object_id, permissions.object_type_id, roles.name AS role_name, roles.role_type, roles.allows_viewing_children FROM (permissions JOIN roles ON ((permissions.role_id = roles.id)));


ALTER TABLE public.internal_permissions_view OWNER TO engine;

--
-- Name: iscsi_bonds_networks_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE iscsi_bonds_networks_map (
    iscsi_bond_id uuid NOT NULL,
    network_id uuid NOT NULL
);


ALTER TABLE public.iscsi_bonds_networks_map OWNER TO engine;

--
-- Name: iscsi_bonds_storage_connections_map; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE iscsi_bonds_storage_connections_map (
    iscsi_bond_id uuid NOT NULL,
    connection_id character varying(50) NOT NULL
);


ALTER TABLE public.iscsi_bonds_storage_connections_map OWNER TO engine;

SET default_with_oids = false;

--
-- Name: materialized_views; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE materialized_views (
    mv_name name NOT NULL,
    v_name name NOT NULL,
    refresh_rate_in_sec integer,
    last_refresh timestamp with time zone,
    avg_cost_ms integer DEFAULT 0 NOT NULL,
    min_refresh_rate_in_sec integer DEFAULT 0,
    custom boolean DEFAULT false,
    active boolean DEFAULT true
);


ALTER TABLE public.materialized_views OWNER TO engine;

--
-- Name: network_cluster_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW network_cluster_view AS
    SELECT network_cluster.cluster_id, network_cluster.network_id, network.name AS network_name, network_cluster.status, network_cluster.required, network_cluster.is_display, network_cluster.migration, vds_groups.name AS cluster_name FROM ((network_cluster JOIN network ON ((network_cluster.network_id = network.id))) JOIN vds_groups ON ((network_cluster.cluster_id = vds_groups.vds_group_id)));


ALTER TABLE public.network_cluster_view OWNER TO engine;

--
-- Name: network_vds_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW network_vds_view AS
    SELECT network.id AS network_id, network.name AS network_name, vds_static.vds_name FROM (((vds_interface JOIN vds_static ON ((vds_interface.vds_id = vds_static.vds_id))) JOIN network ON (((vds_interface.network_name)::text = (network.name)::text))) JOIN network_cluster ON ((network_cluster.network_id = network.id))) WHERE (network_cluster.cluster_id = vds_static.vds_group_id);


ALTER TABLE public.network_vds_view OWNER TO engine;

SET default_with_oids = true;

--
-- Name: object_column_white_list; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE object_column_white_list (
    object_name character varying(128) NOT NULL,
    column_name character varying(128) NOT NULL
);


ALTER TABLE public.object_column_white_list OWNER TO engine;

--
-- Name: object_column_white_list_sql; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE object_column_white_list_sql (
    object_name character varying(128) NOT NULL,
    sql text NOT NULL
);


ALTER TABLE public.object_column_white_list_sql OWNER TO engine;

--
-- Name: quota_limitations_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW quota_limitations_view AS
    SELECT q_limit.quota_id, q.storage_pool_id, storage_pool.name AS storage_pool_name, q.quota_name, q.description, q.threshold_vds_group_percentage, q.threshold_storage_percentage, q.grace_vds_group_percentage, q.grace_storage_percentage, q_limit.virtual_cpu, q_limit.mem_size_mb, q_limit.storage_size_gb, storage_pool.quota_enforcement_type, q_limit.vds_group_id, q_limit.storage_id, (COALESCE(q_limit.vds_group_id, q_limit.storage_id) IS NULL) AS is_global, (COALESCE((q_limit.virtual_cpu)::bigint, q_limit.mem_size_mb, q_limit.storage_size_gb) IS NULL) AS is_empty FROM ((quota q JOIN storage_pool ON ((storage_pool.id = q.storage_pool_id))) LEFT JOIN quota_limitation q_limit ON ((q_limit.quota_id = q.id)));


ALTER TABLE public.quota_limitations_view OWNER TO engine;

--
-- Name: schema_version_seq; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE schema_version_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.schema_version_seq OWNER TO engine;

--
-- Name: schema_version_seq; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('schema_version_seq', 209, true);


SET default_with_oids = false;

--
-- Name: schema_version; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE schema_version (
    id integer DEFAULT nextval('schema_version_seq'::regclass) NOT NULL,
    version character varying(10) NOT NULL,
    script character varying(255) NOT NULL,
    checksum character varying(128),
    installed_by character varying(30) NOT NULL,
    started_at timestamp without time zone DEFAULT now(),
    ended_at timestamp without time zone,
    state character varying(15) NOT NULL,
    current boolean NOT NULL,
    comment text DEFAULT ''::text
);


ALTER TABLE public.schema_version OWNER TO engine;

--
-- Name: server_vms; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW server_vms AS
    SELECT vms.vm_name, vms.vm_mem_size_mb, vms.nice_level, vms.cpu_shares, vms.vmt_guid, vms.vm_os, vms.vm_description, vms.vm_comment, vms.vds_group_id, vms.vm_creation_date, vms.auto_startup, vms.is_stateless, vms.is_smartcard_enabled, vms.is_delete_protected, vms.sso_method, vms.dedicated_vm_for_vds, vms.fail_back, vms.default_boot_sequence, vms.vm_type, vms.vm_pool_spice_proxy, vms.vds_group_name, vms.transparent_hugepages, vms.trusted_service, vms.storage_pool_id, vms.storage_pool_name, vms.vds_group_description, vms.vds_group_spice_proxy, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date, vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_num_of_cpus, vms.vmt_description, vms.status, vms.vm_ip, vms.vm_host, vms.vm_pid, vms.last_start_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.guest_last_logout_time, vms.guest_os, vms.console_user_id, vms.guest_agent_nics_hash, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display, vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci, vms.allow_console_reconnect, vms.is_initialized, vms.num_of_sockets, vms.cpu_per_socket, vms.usb_policy, vms.acpi_enable, vms.session, vms.num_of_cpus, vms.quota_id, vms.quota_name, vms.quota_enforcement_type, vms.display_ip, vms.display_type, vms.kvm_enable, vms.boot_sequence, vms.display_secure_port, vms.utc_diff, vms.last_vds_run_on, vms.client_ip, vms.guest_requested_memory, vms.time_zone, vms.cpu_user, vms.cpu_sys, vms.elapsed_time, vms.usage_network_percent, vms.usage_mem_percent, vms.usage_cpu_percent, vms.run_on_vds_name, vms.vds_group_cpu_name, vms.default_display_type, vms.priority, vms.iso_path, vms.origin, vms.vds_group_compatibility_version, vms.initrd_url, vms.kernel_url, vms.kernel_params, vms.pause_status, vms.exit_message, vms.exit_status, vms.migration_support, vms.predefined_properties, vms.userdefined_properties, vms.min_allocated_mem, vms.hash, vms.cpu_pinning, vms.db_generation, vms.host_cpu_flags, vms.tunnel_migration, vms.vnc_keyboard_layout, vms.is_run_and_pause, vms.created_by_user_id, vms.last_watchdog_event, vms.last_watchdog_action, vms.is_run_once, vms.vm_fqdn, vms.cpu_name, vms.current_cd, vms.instance_type_id, vms.image_type_id, vms.architecture, vms.original_template_id, vms.original_template_name, vms.last_stop_time, vms.migration_downtime, vms.template_version_number FROM vms WHERE (vms.vm_type = 1);


ALTER TABLE public.server_vms OWNER TO engine;

--
-- Name: storage_domain_file_repos; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domain_file_repos AS
    SELECT storage_domain_static.id AS storage_domain_id, storage_domain_static.storage_domain_type, storage_pool_iso_map.storage_pool_id, storage_pool_iso_map.status AS storage_domain_status, repo_file_meta_data.repo_image_id, repo_file_meta_data.size, repo_file_meta_data.date_created, repo_file_meta_data.last_refreshed, repo_file_meta_data.file_type, vds_dynamic.status AS vds_status, storage_pool.status AS storage_pool_status FROM ((((storage_domain_static JOIN storage_pool_iso_map ON ((storage_domain_static.id = storage_pool_iso_map.storage_id))) JOIN storage_pool ON ((storage_pool.id = storage_pool_iso_map.storage_pool_id))) JOIN vds_dynamic ON ((vds_dynamic.vds_id = storage_pool.spm_vds_id))) LEFT JOIN repo_file_meta_data ON ((storage_pool_iso_map.storage_id = repo_file_meta_data.repo_domain_id)));


ALTER TABLE public.storage_domain_file_repos OWNER TO engine;

--
-- Name: storage_domains_for_search; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domains_for_search AS
    SELECT storage_domain_static.id, storage_domain_static.storage, storage_domain_static.storage_name, storage_domain_static.storage_description, storage_domain_static.storage_comment, storage_domain_static.storage_type, storage_domain_static.storage_domain_type, storage_domain_static.storage_domain_format_type, storage_domain_static.last_time_used_as_master, CASE WHEN status_table.is_multi_domain THEN NULL::integer WHEN (status_table.status IS NULL) THEN 2 ELSE status_table.status END AS status, NULL::unknown AS storage_pool_id, NULL::unknown AS storage_pool_name, storage_domain_dynamic.available_disk_size, storage_domain_dynamic.used_disk_size, fn_get_disk_commited_value_by_storage(storage_domain_static.id) AS commited_disk_size, fn_get_actual_images_size_by_storage(storage_domain_static.id) AS actual_images_size, fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, status_table.status, storage_domain_static.storage_domain_type) AS storage_domain_shared_status, storage_domain_static.recoverable FROM ((storage_domain_static JOIN storage_domain_dynamic ON ((storage_domain_static.id = storage_domain_dynamic.id))) LEFT JOIN (SELECT storage_pool_iso_map.storage_id, (count(storage_pool_iso_map.storage_id) > 1) AS is_multi_domain, max(storage_pool_iso_map.status) AS status FROM storage_pool_iso_map GROUP BY storage_pool_iso_map.storage_id) status_table ON ((storage_domain_static.id = status_table.storage_id)));


ALTER TABLE public.storage_domains_for_search OWNER TO engine;

--
-- Name: storage_domains_with_hosts_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_domains_with_hosts_view AS
    SELECT storage_domain_static.id, storage_domain_static.storage, storage_domain_static.storage_name, storage_domain_static.storage_description, storage_domain_static.storage_comment, storage_domain_dynamic.available_disk_size, storage_domain_dynamic.used_disk_size, fn_get_disk_commited_value_by_storage(storage_domain_static.id) AS commited_disk_size, fn_get_actual_images_size_by_storage(storage_domain_static.id) AS actual_images_size, storage_pool.name AS storage_pool_name, storage_domain_static.storage_type, storage_domain_static.storage_domain_type, storage_domain_static.storage_domain_format_type, storage_domain_static.last_time_used_as_master, fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, storage_pool_iso_map.status, storage_domain_static.storage_domain_type) AS storage_domain_shared_status, vds_groups.vds_group_id, vds_static.vds_id, storage_pool_iso_map.storage_pool_id, vds_static.recoverable FROM (((((storage_domain_static JOIN storage_domain_dynamic ON ((storage_domain_static.id = storage_domain_dynamic.id))) LEFT JOIN storage_pool_iso_map ON ((storage_domain_static.id = storage_pool_iso_map.storage_id))) LEFT JOIN storage_pool ON ((storage_pool_iso_map.storage_pool_id = storage_pool.id))) LEFT JOIN vds_groups ON ((storage_pool_iso_map.storage_pool_id = vds_groups.storage_pool_id))) LEFT JOIN vds_static ON ((vds_groups.vds_group_id = vds_static.vds_group_id)));


ALTER TABLE public.storage_domains_with_hosts_view OWNER TO engine;

--
-- Name: storage_pool_with_storage_domain; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW storage_pool_with_storage_domain AS
    SELECT storage_pool.id, storage_pool.name, storage_pool.description, storage_pool.free_text_comment, storage_pool.status, storage_pool.is_local, storage_pool.master_domain_version, storage_pool.spm_vds_id, storage_pool.compatibility_version, storage_pool._create_date, storage_pool._update_date, storage_pool_iso_map.storage_id, storage_pool_iso_map.storage_pool_id, storage_domain_static.storage_type, storage_domain_static.storage_domain_type, storage_domain_static.storage_domain_format_type, storage_domain_static.storage_name, storage_domain_static.storage, storage_domain_static.last_time_used_as_master FROM ((storage_pool LEFT JOIN storage_pool_iso_map ON ((storage_pool.id = storage_pool_iso_map.storage_pool_id))) LEFT JOIN storage_domain_static ON ((storage_pool_iso_map.storage_id = storage_domain_static.id)));


ALTER TABLE public.storage_pool_with_storage_domain OWNER TO engine;

--
-- Name: user_db_users_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_db_users_permissions_view AS
    SELECT DISTINCT permissions.ad_element_id, roles_groups.role_id, roles_groups.action_group_id FROM (permissions JOIN roles_groups ON ((permissions.role_id = roles_groups.role_id))) WHERE (roles_groups.action_group_id = 502);


ALTER TABLE public.user_db_users_permissions_view OWNER TO engine;

--
-- Name: user_flat_groups; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_flat_groups AS
    (SELECT users.user_id, fnsplitteruuid(users.group_ids) AS granted_id FROM users UNION ALL SELECT users.user_id, users.user_id AS granted_id FROM users) UNION ALL SELECT users.user_id, 'EEE00000-0000-0000-0000-123456789EEE' AS granted_id FROM users;


ALTER TABLE public.user_flat_groups OWNER TO engine;

--
-- Name: user_vm_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_permissions_view_base AS
    ((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 2) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vm_static.vm_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_static JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = vm_static.vds_group_id) AND (internal_permissions_view.object_type_id = 9)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_static.vm_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vm_static JOIN vds_groups ON ((vds_groups.vds_group_id = vm_static.vds_group_id))) JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = vds_groups.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_static.vm_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vm_static) WHERE (((internal_permissions_view.object_type_id = 1) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_vm_permissions_view_base OWNER TO engine;

--
-- Name: user_vm_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_permissions_view AS
    SELECT DISTINCT user_vm_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vm_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vm_permissions_view OWNER TO engine;

--
-- Name: user_vm_template_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_template_permissions_view_base AS
    ((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 4) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vm_static.vmt_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_static JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_static.vm_guid) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_static.vm_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vm_static JOIN vds_groups ON ((vds_groups.vds_group_id = vm_static.vds_group_id))) JOIN internal_permissions_view ON ((((((internal_permissions_view.object_id = vds_groups.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2)) AND ((vm_static.entity_type)::text = 'TEMPLATE'::text))))) UNION ALL SELECT vm_static.vm_guid AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vm_static) WHERE ((((internal_permissions_view.object_type_id = 1) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2)) AND ((((vm_static.entity_type)::text = 'TEMPLATE'::text) OR ((vm_static.entity_type)::text = 'INSTANCE_TYPE'::text)) OR ((vm_static.entity_type)::text = 'IMAGE_TYPE'::text)));


ALTER TABLE public.user_vm_template_permissions_view_base OWNER TO engine;

--
-- Name: user_vm_template_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_template_permissions_view AS
    SELECT DISTINCT user_vm_template_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vm_template_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vm_template_permissions_view OWNER TO engine;

--
-- Name: user_disk_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_disk_permissions_view_base AS
    ((((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 19) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vm_device.device_id AS entity_id, user_vm_permissions_view.user_id AS granted_id FROM (vm_device JOIN user_vm_permissions_view ON ((user_vm_permissions_view.entity_id = vm_device.vm_id))) WHERE (((vm_device.type)::text = 'disk'::text) AND ((vm_device.device)::text = 'disk'::text))) UNION ALL SELECT vm_device.device_id AS entity_id, user_vm_template_permissions_view.user_id AS granted_id FROM (vm_device JOIN user_vm_template_permissions_view ON ((user_vm_template_permissions_view.entity_id = vm_device.vm_id))) WHERE (((vm_device.type)::text = 'disk'::text) AND ((vm_device.device)::text = 'disk'::text))) UNION ALL SELECT images.image_group_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((image_storage_domain_map JOIN images ON ((images.image_guid = image_storage_domain_map.image_id))) JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = image_storage_domain_map.storage_domain_id) AND (internal_permissions_view.object_type_id = 11)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT images.image_group_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (((image_storage_domain_map JOIN storage_pool_iso_map ON ((image_storage_domain_map.storage_domain_id = storage_pool_iso_map.storage_id))) JOIN images ON ((images.image_guid = image_storage_domain_map.image_id))) JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = storage_pool_iso_map.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_device.device_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vm_device) WHERE (((internal_permissions_view.object_type_id = 1) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_disk_permissions_view_base OWNER TO engine;

--
-- Name: user_disk_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_disk_permissions_view AS
    SELECT DISTINCT user_disk_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_disk_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_disk_permissions_view OWNER TO engine;

--
-- Name: user_vnic_profile_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vnic_profile_permissions_view_base AS
    (((((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 27) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vnic_profiles.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vnic_profiles JOIN internal_permissions_view ON ((internal_permissions_view.object_id = vnic_profiles.network_id))) WHERE (((internal_permissions_view.object_type_id = 20) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))) UNION ALL SELECT vnic_profiles.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vnic_profiles JOIN network ON ((network.id = vnic_profiles.network_id))) JOIN internal_permissions_view ON ((internal_permissions_view.object_id = network.storage_pool_id))) WHERE (((internal_permissions_view.object_type_id = 14) AND (internal_permissions_view.role_type = 2)) AND internal_permissions_view.allows_viewing_children)) UNION ALL SELECT vnic_profiles.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vnic_profiles JOIN network_cluster ON ((network_cluster.network_id = vnic_profiles.network_id))) JOIN internal_permissions_view ON ((internal_permissions_view.object_id = network_cluster.cluster_id))) WHERE (((internal_permissions_view.object_type_id = 9) AND (internal_permissions_view.role_type = 2)) AND internal_permissions_view.allows_viewing_children)) UNION ALL SELECT DISTINCT vm_interface.vnic_profile_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_interface JOIN internal_permissions_view ON ((internal_permissions_view.object_id = vm_interface.vm_guid))) WHERE ((internal_permissions_view.object_type_id = 2) AND (internal_permissions_view.role_type = 2))) UNION ALL SELECT DISTINCT vm_interface.vnic_profile_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_interface JOIN internal_permissions_view ON ((internal_permissions_view.object_id = vm_interface.vmt_guid))) WHERE ((internal_permissions_view.object_type_id = 4) AND (internal_permissions_view.role_type = 2))) UNION ALL SELECT vnic_profiles.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vnic_profiles) WHERE (((internal_permissions_view.object_type_id = 1) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_vnic_profile_permissions_view_base OWNER TO engine;

--
-- Name: user_vnic_profile_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vnic_profile_permissions_view AS
    SELECT DISTINCT user_vnic_profile_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vnic_profile_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vnic_profile_permissions_view OWNER TO engine;

--
-- Name: user_network_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_network_permissions_view_base AS
    SELECT network.id AS entity_id, user_vnic_profile_permissions_view.user_id AS granted_id FROM ((network JOIN vnic_profiles ON ((vnic_profiles.network_id = network.id))) JOIN user_vnic_profile_permissions_view ON ((user_vnic_profile_permissions_view.entity_id = vnic_profiles.id)));


ALTER TABLE public.user_network_permissions_view_base OWNER TO engine;

--
-- Name: user_network_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_network_permissions_view AS
    SELECT DISTINCT user_network_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_network_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_network_permissions_view OWNER TO engine;

--
-- Name: user_object_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_object_permissions_view AS
    SELECT DISTINCT permissions.object_id AS entity_id, user_flat_groups.user_id FROM ((permissions JOIN roles ON ((permissions.role_id = roles.id))) JOIN user_flat_groups ON ((user_flat_groups.granted_id = permissions.ad_element_id))) WHERE (permissions.ad_element_id <> getglobalids('everyone'::character varying));


ALTER TABLE public.user_object_permissions_view OWNER TO engine;

--
-- Name: user_permissions_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_permissions_permissions_view AS
    SELECT DISTINCT internal_permissions_view.id AS entity_id, user_flat_groups.user_id FROM (internal_permissions_view JOIN user_flat_groups ON ((user_flat_groups.granted_id = internal_permissions_view.ad_element_id)));


ALTER TABLE public.user_permissions_permissions_view OWNER TO engine;

--
-- Name: user_storage_domain_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_storage_domain_permissions_view_base AS
    ((((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 11) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT storage_domains.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (((storage_domains JOIN vds_groups ON ((vds_groups.storage_pool_id = storage_domains.storage_pool_id))) JOIN vm_static ON ((vds_groups.vds_group_id = vm_static.vds_group_id))) JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_static.vm_guid) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_templates_storage_domain.storage_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_templates_storage_domain JOIN internal_permissions_view ON ((((vm_templates_storage_domain.vmt_guid = internal_permissions_view.object_id) AND (internal_permissions_view.object_type_id = 4)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_templates_storage_domain.storage_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vm_static JOIN vm_templates_storage_domain ON ((vm_static.vmt_guid = vm_templates_storage_domain.vmt_guid))) JOIN internal_permissions_view ON ((((vm_static.vm_guid = internal_permissions_view.object_id) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT storage_domains.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (storage_domains JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = storage_domains.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT storage_domains.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN storage_domains) WHERE ((internal_permissions_view.object_type_id = 1) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_storage_domain_permissions_view_base OWNER TO engine;

--
-- Name: user_storage_domain_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_storage_domain_permissions_view AS
    SELECT DISTINCT user_storage_domain_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_storage_domain_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_storage_domain_permissions_view OWNER TO engine;

--
-- Name: user_storage_pool_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_storage_pool_permissions_view_base AS
    (((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 14) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vds_groups.storage_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vds_groups JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vds_groups.vds_group_id) AND (internal_permissions_view.object_type_id = 9)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vds_groups.storage_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vds_groups JOIN vm_pools ON ((vds_groups.vds_group_id = vm_pools.vds_group_id))) JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_pools.vm_pool_id) AND (internal_permissions_view.object_type_id = 5)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vds_groups.storage_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vm_static JOIN vds_groups ON ((vds_groups.vds_group_id = vm_static.vds_group_id))) JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_static.vm_guid) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT storage_pool.id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN storage_pool) WHERE ((internal_permissions_view.object_type_id = 1) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_storage_pool_permissions_view_base OWNER TO engine;

--
-- Name: user_storage_pool_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_storage_pool_permissions_view AS
    SELECT DISTINCT user_storage_pool_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_storage_pool_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_storage_pool_permissions_view OWNER TO engine;

--
-- Name: user_vds_groups_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vds_groups_permissions_view_base AS
    ((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 9) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vm_static.vds_group_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_static JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_static.vm_guid) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vds_groups.vds_group_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vds_groups JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vds_groups.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vds_groups.vds_group_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vds_groups) WHERE ((internal_permissions_view.object_type_id = 1) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_vds_groups_permissions_view_base OWNER TO engine;

--
-- Name: user_vds_groups_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vds_groups_permissions_view AS
    SELECT DISTINCT user_vds_groups_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vds_groups_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vds_groups_permissions_view OWNER TO engine;

--
-- Name: user_vds_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vds_permissions_view_base AS
    (SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 3) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vds.vds_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vds JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vds.vds_group_id) AND (internal_permissions_view.object_type_id = 9)) OR (((internal_permissions_view.object_id = vds.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND (internal_permissions_view.role_type = 2)))))) UNION ALL SELECT vds.vds_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vds) WHERE ((internal_permissions_view.object_type_id = 1) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_vds_permissions_view_base OWNER TO engine;

--
-- Name: user_vds_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vds_permissions_view AS
    SELECT DISTINCT user_vds_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vds_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vds_permissions_view OWNER TO engine;

--
-- Name: user_vm_pool_permissions_view_base; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_pool_permissions_view_base AS
    (((SELECT internal_permissions_view.object_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM internal_permissions_view WHERE ((internal_permissions_view.object_type_id = 5) AND (internal_permissions_view.role_type = 2)) UNION ALL SELECT vm_pool_map.vm_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_pool_map JOIN internal_permissions_view ON ((((internal_permissions_view.object_id = vm_pool_map.vm_guid) AND (internal_permissions_view.object_type_id = 2)) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_pools.vm_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (vm_pools JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = vm_pools.vds_group_id) AND (internal_permissions_view.object_type_id = 9)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_pools.vm_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM ((vm_pools JOIN vds_groups ON ((vm_pools.vds_group_id = vds_groups.vds_group_id))) JOIN internal_permissions_view ON (((((internal_permissions_view.object_id = vds_groups.storage_pool_id) AND (internal_permissions_view.object_type_id = 14)) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2))))) UNION ALL SELECT vm_pools.vm_pool_id AS entity_id, internal_permissions_view.ad_element_id AS granted_id FROM (internal_permissions_view CROSS JOIN vm_pools) WHERE (((internal_permissions_view.object_type_id = 1) AND internal_permissions_view.allows_viewing_children) AND (internal_permissions_view.role_type = 2));


ALTER TABLE public.user_vm_pool_permissions_view_base OWNER TO engine;

--
-- Name: user_vm_pool_permissions_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW user_vm_pool_permissions_view AS
    SELECT DISTINCT user_vm_pool_permissions_view_base.entity_id, user_flat_groups.user_id FROM (user_vm_pool_permissions_view_base NATURAL JOIN user_flat_groups);


ALTER TABLE public.user_vm_pool_permissions_view OWNER TO engine;

--
-- Name: users_and_groups_to_vm_pool_map_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW users_and_groups_to_vm_pool_map_view AS
    SELECT p.vm_pool_id, p.vm_pool_name, per.ad_element_id AS user_id FROM (vm_pools p JOIN permissions per ON ((per.object_id = p.vm_pool_id)));


ALTER TABLE public.users_and_groups_to_vm_pool_map_view OWNER TO engine;

--
-- Name: uuid_sequence; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE uuid_sequence
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.uuid_sequence OWNER TO engine;

--
-- Name: uuid_sequence; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('uuid_sequence', 15, true);


--
-- Name: vdc_db_log_seq; Type: SEQUENCE; Schema: public; Owner: engine
--

CREATE SEQUENCE vdc_db_log_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.vdc_db_log_seq OWNER TO engine;

--
-- Name: vdc_db_log_seq; Type: SEQUENCE SET; Schema: public; Owner: engine
--

SELECT pg_catalog.setval('vdc_db_log_seq', 1, false);


--
-- Name: vdc_db_log; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vdc_db_log (
    error_id bigint DEFAULT nextval('vdc_db_log_seq'::regclass) NOT NULL,
    occured_at timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    error_code character varying(16) NOT NULL,
    error_message character varying(2048),
    error_proc character varying(126),
    error_line integer
);


ALTER TABLE public.vdc_db_log OWNER TO engine;

--
-- Name: vdc_users; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vdc_users AS
    SELECT 'user' AS user_group, users_1.name, users_1.user_id, users_1.surname, users_1.domain, users_1.username, users_1.groups, users_1.department, users_1.role, users_1.email, users_1.note, users_1.active, 0 AS vm_admin, users_1.last_admin_check_status, users_1.group_ids, users_1.external_id FROM users users_1 UNION SELECT 'group' AS user_group, ad_groups.name, ad_groups.id AS user_id, '' AS surname, ad_groups.domain, '' AS username, '' AS groups, '' AS department, '' AS role, '' AS email, '' AS note, ad_groups.active, 1 AS vm_admin, NULL::unknown AS last_admin_check_status, '' AS group_ids, ad_groups.external_id FROM ad_groups;


ALTER TABLE public.vdc_users OWNER TO engine;

--
-- Name: vdc_users_with_tags; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vdc_users_with_tags AS
    SELECT users_1.user_group, users_1.name, permissions.object_id AS vm_guid, users_1.user_id, users_1.surname, users_1.domain, users_1.username, users_1.groups, users_1.department, users_1.role, roles1.name AS mla_role, users_1.email, users_1.note, users_1.active, users_1.vm_admin, tags_user_map_view_1.tag_name, tags_user_map_view_1.tag_id, users_1.last_admin_check_status, users_1.group_ids, pools.vm_pool_name FROM (((((vdc_users users_1 LEFT JOIN users_and_groups_to_vm_pool_map_view pools ON ((users_1.user_id = pools.user_id))) LEFT JOIN permissions ON ((users_1.user_id = permissions.ad_element_id))) LEFT JOIN tags ON ((tags.type = 1))) LEFT JOIN tags_user_map_view tags_user_map_view_1 ON ((users_1.user_id = tags_user_map_view_1.user_id))) LEFT JOIN roles roles1 ON ((roles1.id = permissions.role_id))) WHERE (users_1.user_group = 'user'::text) UNION SELECT users_2.user_group, users_2.name, permissions_1.object_id AS vm_guid, users_2.user_id, users_2.surname, users_2.domain, users_2.username, users_2.groups, users_2.department, users_2.role, roles2.name AS mla_role, users_2.email, users_2.note, users_2.active, users_2.vm_admin, tags_user_group_map_view.tag_name, tags_user_group_map_view.tag_id, users_2.last_admin_check_status, users_2.group_ids, pools1.vm_pool_name FROM (((((vdc_users users_2 LEFT JOIN users_and_groups_to_vm_pool_map_view pools1 ON ((users_2.user_id = pools1.user_id))) LEFT JOIN permissions permissions_1 ON ((users_2.user_id = permissions_1.ad_element_id))) LEFT JOIN tags tags_1 ON ((tags_1.type = 1))) LEFT JOIN tags_user_group_map_view ON ((users_2.user_id = tags_user_group_map_view.group_id))) LEFT JOIN roles roles2 ON ((roles2.id = permissions_1.role_id))) WHERE (users_2.user_group = 'group'::text);


ALTER TABLE public.vdc_users_with_tags OWNER TO engine;

--
-- Name: vds_groups_storage_domain; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vds_groups_storage_domain AS
    SELECT vds_groups.vds_group_id, vds_groups.name, vds_groups.description, vds_groups.free_text_comment, vds_groups.cpu_name, vds_groups._create_date, vds_groups._update_date, vds_groups.storage_pool_id, vds_groups.max_vds_memory_over_commit, vds_groups.count_threads_as_cores, vds_groups.compatibility_version, vds_groups.transparent_hugepages, vds_groups.migrate_on_error, vds_groups.architecture, storage_pool_iso_map.storage_id, storage_pool.name AS storage_pool_name FROM ((vds_groups LEFT JOIN storage_pool_iso_map ON ((vds_groups.storage_pool_id = storage_pool_iso_map.storage_pool_id))) LEFT JOIN storage_pool ON ((vds_groups.storage_pool_id = storage_pool.id)));


ALTER TABLE public.vds_groups_storage_domain OWNER TO engine;

--
-- Name: vds_with_tags; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vds_with_tags AS
    SELECT vds_groups.vds_group_id, vds_groups.name AS vds_group_name, vds_groups.description AS vds_group_description, vds_groups.architecture, vds_static.vds_id, vds_static.vds_name, vds_static.ip, vds_static.vds_unique_id, vds_static.host_name, vds_static.free_text_comment, vds_static.port, vds_static.vds_strength, vds_static.server_ssl_enabled, vds_static.vds_type, vds_static.pm_type, vds_static.pm_user, vds_static.pm_password, vds_static.pm_port, vds_dynamic.hw_product_name, vds_dynamic.hw_version, vds_dynamic.hw_serial_number, vds_dynamic.hw_uuid, vds_dynamic.hw_family, vds_static.pm_options, vds_static.pm_enabled, vds_static.pm_proxy_preferences, vds_static.pm_secondary_ip, vds_static.pm_secondary_options, vds_static.pm_secondary_port, vds_static.pm_secondary_password, vds_static.pm_secondary_user, vds_static.pm_secondary_type, vds_static.pm_secondary_concurrent, vds_dynamic.hooks, vds_dynamic.status, vds_dynamic.cpu_cores, vds_dynamic.cpu_threads, vds_dynamic.cpu_model, vds_dynamic.cpu_speed_mh, vds_dynamic.if_total_speed, vds_dynamic.kvm_enabled, vds_dynamic.physical_mem_mb, vds_dynamic.pending_vcpus_count, vds_dynamic.pending_vmem_size, vds_dynamic.mem_commited, vds_dynamic.vm_active, vds_dynamic.vm_count, vds_dynamic.vm_migrating, vds_dynamic.vms_cores_count, vds_dynamic.cpu_over_commit_time_stamp, vds_dynamic.net_config_dirty, vds_groups.max_vds_memory_over_commit, vds_groups.count_threads_as_cores, storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, tags_vds_map_view.tag_name, tags_vds_map_view.tag_id, vds_dynamic.reserved_mem, vds_dynamic.guest_overhead, vds_dynamic.rpm_version, vds_dynamic.software_version, vds_dynamic.version_name, vds_dynamic.build_name, vds_dynamic.previous_status, vds_statistics.cpu_idle, vds_statistics.cpu_load, vds_statistics.cpu_sys, vds_statistics.cpu_user, vds_statistics.usage_mem_percent, vds_statistics.usage_cpu_percent, vds_statistics.usage_network_percent, vds_statistics.mem_available, vds_statistics.mem_free, vds_statistics.mem_shared, vds_statistics.swap_free, vds_statistics.swap_total, vds_statistics.ksm_cpu_percent, vds_statistics.ksm_pages, vds_statistics.ksm_state, vds_dynamic.cpu_flags, vds_groups.cpu_name AS vds_group_cpu_name, vds_dynamic.cpu_sockets, vds_spm_id_map.vds_spm_id, vds_static.otp_validity, vds_static.console_address, CASE WHEN (storage_pool.spm_vds_id = vds_static.vds_id) THEN CASE WHEN (storage_pool.status = 5) THEN 1 ELSE 2 END ELSE 0 END AS spm_status, vds_dynamic.supported_cluster_levels, vds_dynamic.supported_engines, vds_groups.compatibility_version AS vds_group_compatibility_version, vds_dynamic.host_os, vds_dynamic.kvm_version, vds_dynamic.libvirt_version, vds_dynamic.spice_version, vds_dynamic.gluster_version, vds_dynamic.kernel_version, vds_dynamic.iscsi_initiator_name, vds_dynamic.transparent_hugepages_state, vds_statistics.anonymous_hugepages, vds_dynamic.non_operational_reason, storage_pool_iso_map.storage_id, vds_static.ssh_port, vds_static.ssh_username, vds_statistics.ha_score, vds_static.disable_auto_pm, vds_dynamic.controlled_by_pm_policy FROM (((((((vds_groups JOIN vds_static ON ((vds_groups.vds_group_id = vds_static.vds_group_id))) JOIN vds_dynamic ON ((vds_static.vds_id = vds_dynamic.vds_id))) JOIN vds_statistics ON ((vds_static.vds_id = vds_statistics.vds_id))) LEFT JOIN storage_pool ON ((vds_groups.storage_pool_id = storage_pool.id))) LEFT JOIN tags_vds_map_view ON ((vds_static.vds_id = tags_vds_map_view.vds_id))) LEFT JOIN vds_spm_id_map ON ((vds_static.vds_id = vds_spm_id_map.vds_id))) LEFT JOIN storage_pool_iso_map ON ((storage_pool_iso_map.storage_pool_id = storage_pool.id)));


ALTER TABLE public.vds_with_tags OWNER TO engine;

--
-- Name: vm_images_storage_domains_view; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vm_images_storage_domains_view AS
    SELECT vm_images_view.storage_id, vm_images_view.storage_path, vm_images_view.storage_pool_id, vm_images_view.image_guid, vm_images_view.creation_date, vm_images_view.actual_size, vm_images_view.read_rate, vm_images_view.write_rate, vm_images_view.size, vm_images_view.it_guid, vm_images_view.description, vm_images_view.parentid, vm_images_view.imagestatus, vm_images_view.lastmodified, vm_images_view.app_list, vm_images_view.vm_snapshot_id, vm_images_view.volume_type, vm_images_view.image_group_id, vm_images_view.active, vm_images_view.volume_format, vm_images_view.disk_interface, vm_images_view.boot, vm_images_view.wipe_after_delete, vm_images_view.propagate_errors, vm_images_view.entity_type, vm_images_view.number_of_vms, vm_images_view.vm_names, vm_images_view.quota_id, vm_images_view.quota_name, vm_images_view.disk_alias, vm_images_view.disk_description, vm_images_view.sgio, storage_domains_with_hosts_view.id, storage_domains_with_hosts_view.storage, storage_domains_with_hosts_view.storage_name, storage_domains_with_hosts_view.available_disk_size, storage_domains_with_hosts_view.used_disk_size, storage_domains_with_hosts_view.commited_disk_size, storage_domains_with_hosts_view.actual_images_size, storage_domains_with_hosts_view.storage_type, storage_domains_with_hosts_view.storage_domain_type, storage_domains_with_hosts_view.storage_domain_format_type, storage_domains_with_hosts_view.storage_domain_shared_status, storage_domains_with_hosts_view.vds_group_id, storage_domains_with_hosts_view.vds_id, storage_domains_with_hosts_view.recoverable, storage_domains_with_hosts_view.storage_pool_name, storage_domains_with_hosts_view.storage_name AS name FROM ((vm_images_view JOIN images_storage_domain_view ON ((vm_images_view.image_guid = images_storage_domain_view.image_guid))) JOIN storage_domains_with_hosts_view ON ((storage_domains_with_hosts_view.id = images_storage_domain_view.storage_id)));


ALTER TABLE public.vm_images_storage_domains_view OWNER TO engine;

--
-- Name: vm_ovf_generations; Type: TABLE; Schema: public; Owner: engine; Tablespace: 
--

CREATE TABLE vm_ovf_generations (
    vm_guid uuid NOT NULL,
    storage_pool_id uuid,
    ovf_generation bigint DEFAULT 0
);


ALTER TABLE public.vm_ovf_generations OWNER TO engine;

--
-- Name: vms_with_tags; Type: VIEW; Schema: public; Owner: engine
--

CREATE VIEW vms_with_tags AS
    SELECT vms.vm_name, vms.vm_mem_size_mb, vms.nice_level, vms.cpu_shares, vms.vmt_guid, vms.vm_os, vms.vm_description, vms.vm_comment, vms.vds_group_id, vms.vm_creation_date, vms.auto_startup, vms.is_stateless, vms.is_smartcard_enabled, vms.is_delete_protected, vms.sso_method, vms.dedicated_vm_for_vds, vms.fail_back, vms.default_boot_sequence, vms.vm_type, vms.vds_group_name, vms.storage_pool_id, vms.storage_pool_name, vms.vds_group_description, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date, vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_description, vms.status, vms.vm_ip, vms.vm_host, (vms.vmt_num_of_sockets * vms.vmt_cpu_per_socket) AS vmt_num_of_cpus, vms.vm_pid, vms.last_start_time, vms.last_stop_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.console_user_id, vms.guest_last_logout_time, vms.guest_os, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display, vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci, vms.allow_console_reconnect, vms.is_initialized, vms.num_of_sockets, vms.cpu_per_socket, vms.usb_policy, vms.acpi_enable, vms.session, (vms.num_of_sockets * vms.cpu_per_socket) AS num_of_cpus, vms.display_ip, vms.display_type, vms.kvm_enable, vms.boot_sequence, vms.display_secure_port, vms.utc_diff, vms.last_vds_run_on, vms.client_ip, vms.guest_requested_memory, vms.time_zone, vms.cpu_user, vms.cpu_sys, vms.elapsed_time, vms.usage_network_percent, vms.usage_mem_percent, vms.usage_cpu_percent, vms.run_on_vds_name, vms.vds_group_cpu_name, tags_vm_map_view.tag_name, tags_vm_map_view.tag_id, vms.default_display_type, vms.priority, vms.vds_group_compatibility_version, vms.initrd_url, vms.kernel_url, vms.kernel_params, vms.pause_status, vms.exit_status, vms.exit_message, vms.min_allocated_mem, storage_domain_static.id AS storage_id, vms.quota_id, vms.quota_name, vms.tunnel_migration, vms.vnc_keyboard_layout, vms.is_run_and_pause, vms.created_by_user_id, vms.vm_fqdn, vms.cpu_name, vms.vm_pool_spice_proxy, vms.vds_group_spice_proxy, vms.instance_type_id, vms.image_type_id, vms.architecture, vms.original_template_id, vms.original_template_name, vms.migration_downtime, vms.template_version_number, vms.current_cd FROM (((((vms LEFT JOIN tags_vm_map_view ON ((vms.vm_guid = tags_vm_map_view.vm_id))) LEFT JOIN vm_device ON ((vm_device.vm_id = vms.vm_guid))) LEFT JOIN images ON ((images.image_group_id = vm_device.device_id))) LEFT JOIN image_storage_domain_map ON ((image_storage_domain_map.image_id = images.image_guid))) LEFT JOIN storage_domain_static ON ((storage_domain_static.id = image_storage_domain_map.storage_domain_id))) WHERE ((images.active IS NULL) OR (images.active = true));


ALTER TABLE public.vms_with_tags OWNER TO engine;

--
-- Data for Name: action_version_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version) FROM stdin;
41	3.1	3.1
158	3.1	3.0
52	3.1	3.1
1009	3.1	*
1400	3.1	*
1401	3.1	*
1402	3.1	*
1403	3.1	*
1404	3.1	*
1405	3.1	*
1406	3.1	*
1407	3.1	*
1408	3.1	*
1409	3.1	*
1410	3.2	*
1411	3.2	*
1010	3.2	3.2
1011	3.2	3.2
1001	3.3	3.3
1412	3.1	*
232	3.3	*
1013	3.3	3.3
1014	3.3	*
1015	3.3	*
6	3.4	*
\.


--
-- Data for Name: ad_groups; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY ad_groups (id, name, domain, distinguishedname, active, external_id) FROM stdin;
eee00000-0000-0000-0000-123456789eee	Everyone			t	\\356\\340\\000\\000\\000\\000\\000\\000\\000\\000\\0224Vx\\236\\356
\.


--
-- Data for Name: affinity_group_members; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY affinity_group_members (affinity_group_id, vm_id) FROM stdin;
\.


--
-- Data for Name: affinity_groups; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY affinity_groups (id, name, description, cluster_id, positive, enforcing, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: async_tasks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY async_tasks (task_id, action_type, status, result, action_parameters, action_params_class, step_id, command_id, started_at, storage_pool_id, task_type, task_parameters, task_params_class, vdsm_task_id, root_command_id) FROM stdin;
\.


--
-- Data for Name: async_tasks_entities; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY async_tasks_entities (async_task_id, entity_id, entity_type) FROM stdin;
\.


--
-- Data for Name: audit_log; Type: TABLE DATA; Schema: public; Owner: engine
--


--
-- Data for Name: base_disks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY base_disks (disk_id, disk_interface, wipe_after_delete, propagate_errors, disk_alias, disk_description, shareable, boot, sgio, alignment, last_alignment_scan) FROM stdin;
1caad5ea-38d3-4b41-b864-d2998a8a8ebd	IDE	f	Off	ayllok_Disk1	\N	f	t	\N	0	\N
745ed552-b70e-4ae4-afb4-e291f3ae68f7	VirtIO	t	Off	rh6prova1_Disk1	\N	f	t	\N	3	2014-02-26 22:35:10.284+01
e9a851df-ad72-4718-a343-bc9662944fe4	VirtIO	f	Off	C6_nfs02_lvmdisk_a	\N	f	t	\N	3	2014-03-01 12:01:24.297+01
5147580f-fe0b-4a59-9591-579322ddd9da	VirtIO	f	Off	C6_nfs02_opt_a	\N	f	f	\N	3	2014-03-01 12:01:49.743+01
faa397fd-8e72-459a-a5f4-594f7d007533	IDE	f	Off	ayllok_Disk1	\N	f	t	\N	2	2014-03-01 12:02:33.685+01
\.


--
-- Data for Name: bookmarks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY bookmarks (bookmark_id, bookmark_name, bookmark_value) FROM stdin;
\.


--
-- Data for Name: business_entity_snapshot; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY business_entity_snapshot (id, command_id, command_type, entity_id, entity_type, entity_snapshot, snapshot_class, snapshot_type, insertion_order, started_at) FROM stdin;
\.


--
-- Data for Name: cluster_policies; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY cluster_policies (id, name, description, is_locked, is_default, custom_properties) FROM stdin;
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	Evenly_Distributed		t	f	{\n  "CpuOverCommitDurationMinutes" : "2",\n  "HighUtilization" : "80"\n}
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	Power_Saving		t	f	{\n  "CpuOverCommitDurationMinutes" : "2",\n  "HighUtilization" : "80",\n  "LowUtilization" : "20"\n}
b4ed2332-a7ac-4d5f-9596-99a439cb2812	None		t	t	\N
8d5d7bec-68de-4a67-b53e-0ac54686d579	VM_Evenly_Distributed		t	f	{\n  "HighVmCount" : "10",\n  "MigrationThreshold" : "5",\n  "SpmVmGrace" : "5"\n}
\.


--
-- Data for Name: cluster_policy_units; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) FROM stdin;
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	c9ddbb34-0e1d-4061-a8d7-b0893fa80932	0	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	6d636bf6-a35c-4f9d-b68d-0731f720cddc	0	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	12262ab6-9690-4bc3-a2b3-35573b172d54	-1	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	7db4ab05-81ab-42e8-868a-aee2df483ed2	0	1
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	72163d1c-9468-4480-99d9-0888664eb143	1	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	c9ddbb34-0e1d-4061-a8d7-b0893fa80932	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	736999d0-1023-46a4-9a75-1316ed50e151	0	1
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	6d636bf6-a35c-4f9d-b68d-0731f720cddc	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	72163d1c-9468-4480-99d9-0888664eb143	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	38440000-8cf0-14bd-c43e-10b96e4ef00a	0	1
b4ed2332-a7ac-4d5f-9596-99a439cb2812	c9ddbb34-0e1d-4061-a8d7-b0893fa80932	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	6d636bf6-a35c-4f9d-b68d-0731f720cddc	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	12262ab6-9690-4bc3-a2b3-35573b172d54	-1	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	72163d1c-9468-4480-99d9-0888664eb143	1	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	38440000-8cf0-14bd-c43e-10b96e4ef00b	0	1
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	736999d0-1023-46a4-9a75-1316ed50e15b	0	1
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	7db4ab05-81ab-42e8-868a-aee2df483edb	0	1
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	438b052c-90ab-40e8-9be0-a22560202ea6	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	438b052c-90ab-40e8-9be0-a22560202ea6	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	438b052c-90ab-40e8-9be0-a22560202ea6	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	12262ab6-9690-4bc3-a2b3-35573b172d54	-1	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	e659c871-0bf1-4ccc-b748-f28f5d08dffd	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	e659c871-0bf1-4ccc-b748-f28f5d08dffd	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	e659c871-0bf1-4ccc-b748-f28f5d08dffd	0	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	98e92667-6161-41fb-b3fa-34f820ccbc4b	0	1
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	98e92667-6161-41fb-b3fa-34f820ccbc4b	0	1
b4ed2332-a7ac-4d5f-9596-99a439cb2812	98e92667-6161-41fb-b3fa-34f820ccbc4b	0	1
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	7f262d70-6cac-11e3-981f-0800200c9a66	0	1
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	7f262d70-6cac-11e3-981f-0800200c9a66	0	1
b4ed2332-a7ac-4d5f-9596-99a439cb2812	7f262d70-6cac-11e3-981f-0800200c9a66	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	d58c8e32-44e1-418f-9222-52cd887bf9e0	0	1
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	84e6ddee-ab0d-42dd-82f0-c297779db566	0	0
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	84e6ddee-ab0d-42dd-82f0-c297779db566	0	0
b4ed2332-a7ac-4d5f-9596-99a439cb2812	84e6ddee-ab0d-42dd-82f0-c297779db566	0	0
8d5d7bec-68de-4a67-b53e-0ac54686d579	84e6ddee-ab0d-42dd-82f0-c297779db566	0	0
20d25257-b4bd-4589-92a6-c4c5c5d3fd1a	84e6ddee-ab0d-42dd-82f0-c297779db567	0	1
5a2b0939-7d46-4b73-a469-e9c2c7fc6a53	84e6ddee-ab0d-42dd-82f0-c297779db567	0	1
b4ed2332-a7ac-4d5f-9596-99a439cb2812	84e6ddee-ab0d-42dd-82f0-c297779db567	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	84e6ddee-ab0d-42dd-82f0-c297779db567	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	3ba8c988-f779-42c0-90ce-caa8243edee7	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	12262ab6-9690-4bc3-a2b3-35573b172d54	-1	0
8d5d7bec-68de-4a67-b53e-0ac54686d579	72163d1c-9468-4480-99d9-0888664eb143	1	0
8d5d7bec-68de-4a67-b53e-0ac54686d579	6d636bf6-a35c-4f9d-b68d-0731f720cddc	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	c9ddbb34-0e1d-4061-a8d7-b0893fa80932	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	438b052c-90ab-40e8-9be0-a22560202ea6	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	e659c871-0bf1-4ccc-b748-f28f5d08dffd	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	7f262d70-6cac-11e3-981f-0800200c9a66	0	1
8d5d7bec-68de-4a67-b53e-0ac54686d579	98e92667-6161-41fb-b3fa-34f820ccbc4b	0	1
\.


--
-- Data for Name: custom_actions; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY custom_actions (action_id, action_name, path, tab, description) FROM stdin;
\.


--
-- Data for Name: disk_image_dynamic; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY disk_image_dynamic (image_id, read_rate, write_rate, actual_size, read_latency_seconds, write_latency_seconds, flush_latency_seconds, _update_date) FROM stdin;
4a1be3d8-ac7d-46cf-ae1c-ba154bc9a400	0	32678	3892314112	0.000000000	0.001084498	0.000399144	2014-03-03 10:37:36.061761+01
e4b86b91-80ec-4bba-8372-10522046ee6b	9473	1703	9663676416	0.007977214	0.000971445	0.000510323	2014-03-03 10:37:48.915606+01
931c7593-ff5d-4012-9738-8dae2f55d9c9	0	0	92341796864	0.000000000	0.000000000	0.000000000	2014-03-03 10:37:48.915606+01
7b617ab1-70c1-42ea-9303-ceffac1da72d	0	29678	4160749568	0.000000000	0.001096591	0.000999916	2014-03-03 10:38:07.112565+01
5c8bb733-4b0c-43a9-9471-0fde3d159fb2	0	272	11811160064	0.000000000	0.000922815	0.000308220	2014-03-03 10:38:38.139932+01
\.


--
-- Data for Name: disk_lun_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY disk_lun_map (disk_id, lun_id) FROM stdin;
\.


--
-- Data for Name: dwh_history_timekeeping; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY dwh_history_timekeeping (var_name, var_value, var_datetime) FROM stdin;
lastSync	\N	2000-01-01 00:00:00+01
lastFullHostCheck	\N	2000-01-01 00:00:00+01
DwhCurrentlyRunning	0	\N
heartBeat	\N	2014-03-04 03:26:43.968+01
lastOsinfoUpdate	\N	2014-03-01 11:59:04.849227+01
\.


--
-- Data for Name: dwh_osinfo; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY dwh_osinfo (os_id, os_name) FROM stdin;
0	Other OS
1	Windows XP
3	Windows 2003
4	Windows 2008
5	Linux
7	Red Hat Enterprise Linux 5.x
8	Red Hat Enterprise Linux 4.x
9	Red Hat Enterprise Linux 3.x
10	Windows 2003 x64
11	Windows 7
12	Windows 7 x64
13	Red Hat Enterprise Linux 5.x x64
14	Red Hat Enterprise Linux 4.x x64
15	Red Hat Enterprise Linux 3.x x64
1001	Other OS
17	Windows 2008 R2 x64
16	Windows 2008 x64
1003	Red Hat Enterprise Linux 6.x
19	Red Hat Enterprise Linux 6.x x64
1002	Linux
18	Red Hat Enterprise Linux 6.x
21	Windows 8 x64
20	Windows 8
1004	SUSE Linux Enterprise Server 11
23	Windows 2012 x64
1255	Ubuntu Saucy Salamander
1254	Ubuntu Raring Ringtails
1253	Ubuntu Quantal Quetzal
1252	Ubuntu Precise Pangolin LTS
1193	SUSE Linux Enterprise Server 11
\.


--
-- Data for Name: event_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY event_map (event_up_name, event_down_name) FROM stdin;
VDC_STOP	VDC_START
IRS_FAILURE	UNASSIGNED
IRS_DISK_SPACE_LOW	UNASSIGNED
IRS_DISK_SPACE_LOW_ERROR	UNASSIGNED
VDS_FAILURE	VDS_ACTIVATE
USER_VDS_MAINTENANCE	VDS_ACTIVATE
USER_VDS_MAINTENANCE_MIGRATION_FAILED	USER_VDS_MAINTENANCE
VDS_ACTIVATE_FAILED	VDS_ACTIVATE
VDS_RECOVER_FAILED	VDS_RECOVER
VDS_SLOW_STORAGE_RESPONSE_TIME	VDS_ACTIVATE
VDS_APPROVE_FAILED	VDS_APPROVE
VDS_INSTALL_FAILED	VDS_INSTALL
VM_FAILURE	UNASSIGNED
VM_MIGRATION_START	VM_MIGRATION_DONE
VM_MIGRATION_FAILED	UNASSIGNED
VM_MIGRATION_FAILED_FROM_TO	UNASSIGNED
VM_NOT_RESPONDING	UNASSIGNED
DWH_STOPPED	DWH_STARTED
DWH_ERROR	UNASSIGNED
VDS_TIME_DRIFT_ALERT	
GLUSTER_VOLUME_CREATE	UNASSIGNED
GLUSTER_VOLUME_CREATE_FAILED	UNASSIGNED
GLUSTER_VOLUME_START	UNASSIGNED
GLUSTER_VOLUME_START_FAILED	GLUSTER_VOLUME_START
GLUSTER_VOLUME_STOP	GLUSTER_VOLUME_START
GLUSTER_VOLUME_STOP_FAILED	GLUSTER_VOLUME_STOP
GLUSTER_VOLUME_OPTION_SET	UNASSIGNED
GLUSTER_VOLUME_OPTION_SET_FAILED	GLUSTER_VOLUME_OPTION_SET
GLUSTER_VOLUME_OPTIONS_RESET	UNASSIGNED
GLUSTER_VOLUME_OPTIONS_RESET_FAILED	GLUSTER_VOLUME_OPTIONS_RESET
GLUSTER_VOLUME_DELETE	UNASSIGNED
GLUSTER_VOLUME_DELETE_FAILED	GLUSTER_VOLUME_DELETE
GLUSTER_VOLUME_REBALANCE_START	UNASSIGNED
GLUSTER_VOLUME_REBALANCE_START_FAILED	GLUSTER_VOLUME_REBALANCE_START
GLUSTER_VOLUME_REMOVE_BRICKS	UNASSIGNED
GLUSTER_VOLUME_REMOVE_BRICKS_FAILED	GLUSTER_VOLUME_REMOVE_BRICKS
GLUSTER_VOLUME_REPLACE_BRICK_FAILED	UNASSIGNED
GLUSTER_VOLUME_REPLACE_BRICK_START	UNASSIGNED
GLUSTER_VOLUME_REPLACE_BRICK_START_FAILED	GLUSTER_VOLUME_REPLACE_BRICK_START
GLUSTER_VOLUME_ADD_BRICK	UNASSIGNED
GLUSTER_VOLUME_ADD_BRICK_FAILED	GLUSTER_VOLUME_ADD_BRICK
GLUSTER_VOLUME_CREATED_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_DELETED_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_OPTION_SET_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_OPTION_RESET_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_PROPERTIES_CHANGED_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_BRICK_ADDED_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_BRICK_REMOVED_FROM_CLI	UNASSIGNED
GLUSTER_SERVER_REMOVED_FROM_CLI	UNASSIGNED
GLUSTER_SERVER_ADD_FAILED	UNASSIGNED
GLUSTER_SERVER_REMOVE_FAILED	UNASSIGNED
HA_VM_RESTART_FAILED	
HA_VM_FAILED	
SYSTEM_DEACTIVATED_STORAGE_DOMAIN	
SYSTEM_CHANGE_STORAGE_POOL_STATUS_NO_HOST_FOR_SPM	
GLUSTER_VOLUME_STARTED_FROM_CLI	UNASSIGNED
GLUSTER_VOLUME_STOPPED_FROM_CLI	UNASSIGNED
VDS_HIGH_MEM_USE	
VDS_HIGH_NETWORK_USE	
VDS_HIGH_CPU_USE	
VDS_HIGH_SWAP_USE	
VDS_LOW_SWAP	
GLUSTER_VOLUME_OPTION_CHANGED_FROM_CLI	UNASSIGNED
GLUSTER_HOOK_ENABLE	GLUSTER_HOOK_ENABLE_FAILED
GLUSTER_HOOK_ENABLE_FAILED	UNASSIGNED
GLUSTER_HOOK_DISABLE	GLUSTER_HOOK_DISABLE_FAILED
GLUSTER_HOOK_DISABLE_FAILED	UNASSIGNED
GLUSTER_HOOK_DETECTED_NEW	UNASSIGNED
GLUSTER_HOOK_CONFLICT_DETECTED	UNASSIGNED
GLUSTER_HOOK_DETECTED_DELETE	UNASSIGNED
GLUSTER_HOOK_ADDED	GLUSTER_HOOK_ADD_FAILED
GLUSTER_HOOK_ADD_FAILED	UNASSIGNED
GLUSTER_HOOK_REMOVED	GLUSTER_HOOK_REMOVE_FAILED
GLUSTER_HOOK_REMOVE_FAILED	UNASSIGNED
GLUSTER_SERVICE_STARTED	GLUSTER_SERVICE_START_FAILED
GLUSTER_SERVICE_START_FAILED	UNASSIGNED
GLUSTER_SERVICE_STOPPED	GLUSTER_SERVICE_STOP_FAILED
GLUSTER_SERVICE_STOP_FAILED	UNASSIGNED
GLUSTER_SERVICE_RESTARTED	GLUSTER_SERVICE_RESTART_FAILED
GLUSTER_SERVICE_RESTART_FAILED	UNASSIGNED
VDS_UNTRUSTED	
USER_UPDATE_VM_FROM_TRUSTED_TO_UNTRUSTED	
USER_UPDATE_VM_FROM_UNTRUSTED_TO_TRUSTED	
IMPORTEXPORT_IMPORT_VM_FROM_TRUSTED_TO_UNTRUSTED	
IMPORTEXPORT_IMPORT_VM_FROM_UNTRUSTED_TO_TRUSTED	
USER_ADD_VM_FROM_TRUSTED_TO_UNTRUSTED	
USER_ADD_VM_FROM_UNTRUSTED_TO_TRUSTED	
IMPORTEXPORT_IMPORT_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED	
IMPORTEXPORT_IMPORT_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED	
USER_ADD_VM_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED	
USER_ADD_VM_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED	
USER_UPDATE_VM_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED	
USER_UPDATE_VM_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED	
VM_STATUS_RESTORED	UNASSIGNED
GLUSTER_SERVER_REMOVE	GLUSTER_SERVER_REMOVE_FAILED
GLUSTER_VOLUME_OPTION_ADDED	UNASSIGNED
GLUSTER_VOLUME_OPTION_MODIFIED	UNASSIGNED
GLUSTER_VOLUME_OPTIONS_RESET_ALL	UNASSIGNED
GLUSTER_VOLUME_PROFILE_START	GLUSTER_VOLUME_PROFILE_START_FAILED
GLUSTER_VOLUME_PROFILE_START_FAILED	UNASSIGNED
GLUSTER_VOLUME_PROFILE_STOP	GLUSTER_VOLUME_PROFILE_STOP_FAILED
GLUSTER_VOLUME_PROFILE_STOP_FAILED	UNASSIGNED
GLUSTER_VOLUME_REBALANCE_STOP	UNASSIGNED
GLUSTER_VOLUME_REBALANCE_STOP_FAILED	GLUSTER_VOLUME_REBALANCE_STOP
START_REMOVING_GLUSTER_VOLUME_BRICKS	UNASSIGNED
START_REMOVING_GLUSTER_VOLUME_BRICKS_FAILED	START_REMOVING_GLUSTER_VOLUME_BRICKS
GLUSTER_BRICK_STATUS_CHANGED	UNASSIGNED
VDS_SET_NONOPERATIONAL	VDS_DETECTED
VDS_SET_NONOPERATIONAL_IFACE_DOWN	VDS_DETECTED
VDS_SET_NONOPERATIONAL_DOMAIN	VDS_DETECTED
GLUSTER_VOLUME_REBALANCE_FINISHED	UNASSIGNED
GLUSTER_VOLUME_MIGRATE_BRICK_DATA_FINISHED	UNASSIGNED
GLUSTER_VOLUME_REMOVE_BRICKS_STOP	UNASSIGNED
GLUSTER_VOLUME_REMOVE_BRICKS_STOP_FAILED	UNASSIGNED
GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI	UNASSIGNED
START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI	UNASSIGNED
VM_CONSOLE_CONNECTED	
VM_CONSOLE_DISCONNECTED	
VM_SET_TICKET	
VM_DOWN_ERROR	
VDS_INITIATED_RUN_VM_FAIL	
GLUSTER_VOLUME_REBALANCE_NOT_FOUND_FROM_CLI	UNASSIGNED
REMOVE_GLUSTER_VOLUME_BRICKS_NOT_FOUND_FROM_CLI	UNASSIGNED
CLUSTER_ALERT_HA_RESERVATION	
VDS_INITIATED_RUN_VM_FAILED	
\.


--
-- Data for Name: event_notification_hist; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY event_notification_hist (subscriber_id, event_name, audit_log_id, method_type, sent_at, status, reason) FROM stdin;
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW_ERROR	616	EMAIL     	2014-02-28 16:45:33.71+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	645	EMAIL     	2014-02-28 18:31:34.139+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	645	EMAIL     	2014-02-28 18:31:34.255+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE	646	EMAIL     	2014-02-28 18:35:34.38+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	647	EMAIL     	2014-02-28 18:35:34.484+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	658	EMAIL     	2014-02-28 18:37:34.61+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	658	EMAIL     	2014-02-28 18:37:34.738+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE	661	EMAIL     	2014-02-28 18:41:34.898+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	662	EMAIL     	2014-02-28 18:41:35.008+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	SYSTEM_DEACTIVATED_STORAGE_DOMAIN	670	EMAIL     	2014-03-01 11:25:37.677+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW	672	EMAIL     	2014-03-01 11:27:37.803+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	674	EMAIL     	2014-03-01 11:51:38.005+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	675	EMAIL     	2014-03-01 11:51:38.12+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW	680	EMAIL     	2014-03-01 11:55:38.244+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	683	EMAIL     	2014-03-01 11:59:38.38+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	684	EMAIL     	2014-03-01 11:59:38.635+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW	687	EMAIL     	2014-03-01 11:59:38.767+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	713	EMAIL     	2014-03-03 10:41:45.482+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	713	EMAIL     	2014-03-03 10:41:45.597+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	714	EMAIL     	2014-03-03 10:41:45.72+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	714	EMAIL     	2014-03-03 10:41:45.835+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE	718	EMAIL     	2014-03-03 15:29:46.646+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	719	EMAIL     	2014-03-03 15:29:46.766+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE	726	EMAIL     	2014-03-03 15:31:46.885+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	727	EMAIL     	2014-03-03 15:31:47.007+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	SYSTEM_DEACTIVATED_STORAGE_DOMAIN	734	EMAIL     	2014-03-03 15:35:47.139+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	743	EMAIL     	2014-03-03 15:51:47.316+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	743	EMAIL     	2014-03-03 15:51:47.431+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE	748	EMAIL     	2014-03-03 15:53:47.555+01	t	                                                                                                                                                                                                                                                               
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_DETECTED	749	EMAIL     	2014-03-03 15:53:47.67+01	t	                                                                                                                                                                                                                                                               
\.


--
-- Data for Name: event_notification_methods; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY event_notification_methods (method_id, method_type) FROM stdin;
0	Email     
\.


--
-- Data for Name: event_subscriber; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY event_subscriber (subscriber_id, event_up_name, method_id, method_address, tag_name) FROM stdin;
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_FAILURE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	USER_VDS_MAINTENANCE_MIGRATION_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_ACTIVATE_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_RECOVER_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_APPROVE_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_INSTALL_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_TIME_DRIFT_ALERT	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_SET_NONOPERATIONAL	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_SET_NONOPERATIONAL_IFACE_DOWN	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_HIGH_MEM_USE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_HIGH_NETWORK_USE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_HIGH_CPU_USE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_HIGH_SWAP_USE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_LOW_SWAP	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	GLUSTER_SERVER_ADD_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	GLUSTER_SERVER_REMOVE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	GLUSTER_SERVER_REMOVE_FAILED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_UNTRUSTED	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_SET_NONOPERATIONAL_DOMAIN	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	SYSTEM_CHANGE_STORAGE_POOL_STATUS_NO_HOST_FOR_SPM	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	SYSTEM_DEACTIVATED_STORAGE_DOMAIN	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDS_SLOW_STORAGE_RESPONSE_TIME	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_FAILURE	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	IRS_DISK_SPACE_LOW_ERROR	0	ovmanager@satservizi.eu	
fdfc627c-d875-11e0-90f0-83df133b58cc	VDC_STOP	0	ovmanager@satservizi.eu	
\.


--
-- Data for Name: gluster_cluster_services; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_cluster_services (cluster_id, service_type, status, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: gluster_hooks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_hooks (id, cluster_id, gluster_command, stage, name, hook_status, content_type, checksum, content, conflict_status, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: gluster_server; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_server (server_id, gluster_server_uuid) FROM stdin;
\.


--
-- Data for Name: gluster_server_hooks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_server_hooks (hook_id, server_id, hook_status, content_type, checksum, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: gluster_server_services; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_server_services (id, server_id, service_id, pid, status, message, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: gluster_service_types; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_service_types (service_type) FROM stdin;
GLUSTER
GLUSTER_SWIFT
SMB
\.


--
-- Data for Name: gluster_services; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_services (id, service_type, service_name) FROM stdin;
00000007-0007-0007-0007-0000000001e0	GLUSTER	glusterd
00000008-0008-0008-0008-00000000003b	GLUSTER_SWIFT	gluster-swift-proxy
00000009-0009-0009-0009-000000000114	GLUSTER_SWIFT	gluster-swift-container
0000000a-000a-000a-000a-00000000035f	GLUSTER_SWIFT	gluster-swift-object
0000000b-000b-000b-000b-0000000001c3	GLUSTER_SWIFT	gluster-swift-account
0000000c-000c-000c-000c-000000000324	GLUSTER_SWIFT	memcached
0000000d-000d-000d-000d-0000000001d0	SMB	smb
\.


--
-- Data for Name: gluster_volume_access_protocols; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_volume_access_protocols (volume_id, access_protocol) FROM stdin;
\.


--
-- Data for Name: gluster_volume_bricks; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_volume_bricks (volume_id, server_id, brick_dir, status, _create_date, _update_date, id, brick_order, task_id) FROM stdin;
\.


--
-- Data for Name: gluster_volume_options; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_volume_options (volume_id, option_key, option_val, id) FROM stdin;
\.


--
-- Data for Name: gluster_volume_transport_types; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_volume_transport_types (volume_id, transport_type) FROM stdin;
\.


--
-- Data for Name: gluster_volumes; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY gluster_volumes (id, cluster_id, vol_name, vol_type, status, replica_count, stripe_count, _create_date, _update_date, task_id) FROM stdin;
\.


--
-- Data for Name: image_storage_domain_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY image_storage_domain_map (image_id, storage_domain_id, quota_id) FROM stdin;
5c8bb733-4b0c-43a9-9471-0fde3d159fb2	a689cb30-743e-4261-bfd1-b8b194dc85db	\N
7b617ab1-70c1-42ea-9303-ceffac1da72d	a689cb30-743e-4261-bfd1-b8b194dc85db	\N
4a1be3d8-ac7d-46cf-ae1c-ba154bc9a400	a689cb30-743e-4261-bfd1-b8b194dc85db	\N
931c7593-ff5d-4012-9738-8dae2f55d9c9	e5de5969-e6a2-4aed-9e3d-241f186ff014	\N
e4b86b91-80ec-4bba-8372-10522046ee6b	a689cb30-743e-4261-bfd1-b8b194dc85db	\N
\.


--
-- Data for Name: images; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY images (image_guid, creation_date, size, it_guid, parentid, imagestatus, lastmodified, vm_snapshot_id, volume_type, volume_format, image_group_id, _create_date, _update_date, active) FROM stdin;
00000000-0000-0000-0000-000000000000	2008-03-31 23:00:00+02	85899345920	00000000-0000-0000-0000-000000000000	\N	0	\N	\N	2	4	\N	2013-12-25 14:31:57.219114+01	\N	t
5c8bb733-4b0c-43a9-9471-0fde3d159fb2	2014-02-24 14:44:41+01	11811160064	00000000-0000-0000-0000-000000000000	00000000-0000-0000-0000-000000000000	1	2014-02-24 14:44:41+01	6e5dafc9-d38a-4a8a-8acc-6db5ab87dc43	1	5	745ed552-b70e-4ae4-afb4-e291f3ae68f7	2014-02-24 14:44:38.010704+01	2014-02-24 14:44:46.831217+01	t
7b617ab1-70c1-42ea-9303-ceffac1da72d	2014-02-26 14:02:19+01	4294967296	00000000-0000-0000-0000-000000000000	00000000-0000-0000-0000-000000000000	1	2014-02-26 14:02:21+01	6ce54994-1a41-4760-a2b4-a58ac5752062	2	4	1caad5ea-38d3-4b41-b864-d2998a8a8ebd	2014-02-26 14:02:16.083784+01	2014-02-26 14:03:04.835773+01	t
4a1be3d8-ac7d-46cf-ae1c-ba154bc9a400	2014-02-27 15:25:57+01	4294967296	00000000-0000-0000-0000-000000000000	00000000-0000-0000-0000-000000000000	1	2014-02-27 15:26:01+01	eefcb99e-e30f-43cc-94fa-6b8bbfa69d3a	1	5	faa397fd-8e72-459a-a5f4-594f7d007533	2014-02-27 15:25:53.209517+01	2014-02-27 15:26:59.653787+01	t
931c7593-ff5d-4012-9738-8dae2f55d9c9	2014-02-28 16:43:43+01	92341796864	00000000-0000-0000-0000-000000000000	00000000-0000-0000-0000-000000000000	1	2014-02-28 16:43:43+01	0663cdaa-c9d4-44b5-bcb7-11bee352af82	1	5	5147580f-fe0b-4a59-9591-579322ddd9da	2014-02-28 16:43:39.979767+01	2014-02-28 16:43:43.667933+01	t
e4b86b91-80ec-4bba-8372-10522046ee6b	2014-03-01 11:20:59+01	9663676416	00000000-0000-0000-0000-000000000000	00000000-0000-0000-0000-000000000000	1	2014-03-01 11:21:01+01	0663cdaa-c9d4-44b5-bcb7-11bee352af82	1	5	e9a851df-ad72-4718-a343-bc9662944fe4	2014-02-28 16:42:30.96889+01	2014-03-01 11:25:57.092075+01	t
\.


--
-- Data for Name: iscsi_bonds; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY iscsi_bonds (id, name, description, storage_pool_id) FROM stdin;
\.


--
-- Data for Name: iscsi_bonds_networks_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY iscsi_bonds_networks_map (iscsi_bond_id, network_id) FROM stdin;
\.


--
-- Data for Name: iscsi_bonds_storage_connections_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY iscsi_bonds_storage_connections_map (iscsi_bond_id, connection_id) FROM stdin;
\.


--
-- Data for Name: job; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY job (job_id, action_type, description, status, owner_id, visible, start_time, end_time, last_update_time, correlation_id, is_external, is_auto_cleared) FROM stdin;
\.


--
-- Data for Name: job_subject_entity; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY job_subject_entity (job_id, entity_id, entity_type) FROM stdin;
\.


--
-- Data for Name: lun_storage_server_connection_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY lun_storage_server_connection_map (lun_id, storage_server_connection) FROM stdin;
3600c0ff000153604fe470b5301000000	dd12e8b8-0352-42ca-81cd-b525068d5203
3600c0ff000153604fe470b5301000000	aa355d71-b912-4d15-8d8a-d4061eb01a1f
3600c0ff000153604fe470b5301000000	af6d1b3d-614b-4f2f-a0fc-4bf55653e0c6
3600c0ff000153604fe470b5301000000	1bab0797-dc98-423e-882a-decc8d9b615f
3600c0ff000153604fe470b5301000000	020e1d9f-5f22-459b-a30b-35e6063a88ee
3600c0ff000153604fe470b5301000000	fcaa1493-483b-45dd-afb6-a0839e52b828
3600c0ff000153604fe470b5301000000	c26c706d-048d-4744-b633-207b4201ab1a
3600c0ff000153604fe470b5301000000	00c28b95-981c-4ce8-8b93-7839a9f2d654
3600c0ff000153604e4aa105301000000	aa355d71-b912-4d15-8d8a-d4061eb01a1f
3600c0ff000153604e4aa105301000000	1bab0797-dc98-423e-882a-decc8d9b615f
3600c0ff000153604e4aa105301000000	00c28b95-981c-4ce8-8b93-7839a9f2d654
3600c0ff000153604e4aa105301000000	af6d1b3d-614b-4f2f-a0fc-4bf55653e0c6
3600c0ff000153604e4aa105301000000	dd12e8b8-0352-42ca-81cd-b525068d5203
3600c0ff000153604e4aa105301000000	fcaa1493-483b-45dd-afb6-a0839e52b828
3600c0ff000153604e4aa105301000000	c26c706d-048d-4744-b633-207b4201ab1a
3600c0ff000153604e4aa105301000000	020e1d9f-5f22-459b-a30b-35e6063a88ee
3600c0ff000152d405699145301000000	00c28b95-981c-4ce8-8b93-7839a9f2d654
3600c0ff000152d405699145301000000	aa355d71-b912-4d15-8d8a-d4061eb01a1f
3600c0ff000152d405699145301000000	fcaa1493-483b-45dd-afb6-a0839e52b828
3600c0ff000152d405699145301000000	1bab0797-dc98-423e-882a-decc8d9b615f
3600c0ff000152d405699145301000000	c26c706d-048d-4744-b633-207b4201ab1a
3600c0ff000152d405699145301000000	020e1d9f-5f22-459b-a30b-35e6063a88ee
3600c0ff000152d405699145301000000	af6d1b3d-614b-4f2f-a0fc-4bf55653e0c6
3600c0ff000152d405699145301000000	dd12e8b8-0352-42ca-81cd-b525068d5203
\.


--
-- Data for Name: luns; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY luns (physical_volume_id, lun_id, volume_group_id, serial, lun_mapping, vendor_id, product_id, device_size) FROM stdin;
cTlhFj-Uhsx-GJDH-DRge-MiMg-WeEA-oNJAH6	3600c0ff000153604e4aa105301000000	RH7mQx-yNIp-PwHa-nyZO-h9At-wzPB-MvOGSi	SHP_P2000_G3_iSCSI_00c0ff1536040000e4aa105301000000	1	HP	P2000 G3 iSCSI	104
mzqneW-ODfN-PDOW-sYZv-sQHo-abnT-blK22F	3600c0ff000152d405699145301000000	D9Idek-weJA-q1zI-asWs-YNuW-I92Q-VYU9sU	SHP_P2000_G3_iSCSI_00c0ff152d4000005699145301000000	9	HP	P2000 G3 iSCSI	65
llP3MU-Tj28-4s3r-L0AJ-IPOl-LeJ9-HmO0Z1	3600c0ff000153604fe470b5301000000	9dbhlt-fOih-tTf8-cB9A-vFwg-lYzf-bofQ6y	SHP_P2000_G3_iSCSI_00c0ff1536040000fe470b5301000000	8	HP	P2000 G3 iSCSI	62
\.


--
-- Data for Name: materialized_views; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY materialized_views (mv_name, v_name, refresh_rate_in_sec, last_refresh, avg_cost_ms, min_refresh_rate_in_sec, custom, active) FROM stdin;
\.


--
-- Data for Name: network; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY network (id, name, description, type, addr, subnet, gateway, vlan_id, stp, storage_pool_id, mtu, vm_network, provider_network_provider_id, provider_network_external_id, free_text_comment, label, qos_id) FROM stdin;
00000000-0000-0000-0000-000000000009	ovirtmgmt	Management Network - vlan244	\N	\N	\N	\N	244	f	00000002-0002-0002-0002-000000000051	9000	t	\N	\N	\N	\N	\N
e3ea893b-1f4e-4697-9b27-756b7d4f3c47	b0br1	default vlan - non obbligatoria	\N	\N	\N	\N	1	f	00000002-0002-0002-0002-000000000051	0	t	\N	\N	\N	\N	\N
74987b9e-82ce-4f67-a70a-c3a52bfb86d6	b0br48	videosorveglianza - N.O.	\N	\N	\N	\N	48	f	00000002-0002-0002-0002-000000000051	1500	t	\N	\N	\N	\N	\N
3aa34709-4cf0-4cad-9f2d-7ded9f79f544	b0br3300	\N	\N	\N	\N	\N	3300	f	00000002-0002-0002-0002-000000000051	1500	t	\N	\N	\N	\N	\N
\.


--
-- Data for Name: network_cluster; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY network_cluster (network_id, cluster_id, status, is_display, required, migration) FROM stdin;
e3ea893b-1f4e-4697-9b27-756b7d4f3c47	00000001-0001-0001-0001-00000000031e	1	t	f	f
3aa34709-4cf0-4cad-9f2d-7ded9f79f544	00000001-0001-0001-0001-00000000031e	1	f	f	f
74987b9e-82ce-4f67-a70a-c3a52bfb86d6	00000001-0001-0001-0001-00000000031e	1	f	f	f
00000000-0000-0000-0000-000000000009	00000001-0001-0001-0001-00000000031e	1	f	t	t
\.


--
-- Data for Name: network_qos; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY network_qos (id, name, storage_pool_id, inbound_average, inbound_peak, inbound_burst, outbound_average, outbound_peak, outbound_burst, _create_date, _update_date) FROM stdin;
ee8ad8b8-6b4e-4cf5-85af-14f00c4b622d	nonusare_100Mb_in_out	00000002-0002-0002-0002-000000000051	100	100	100	100	100	100	2014-02-23 21:21:01.882555+01	2014-02-24 10:28:06.164386+01
81ee9c23-3a6d-43e4-a56c-a75c22ef95f9	nonusare_ADSL10down1up	00000002-0002-0002-0002-000000000051	10	10	10	1	1	2	2014-02-23 21:22:36.527797+01	2014-02-24 10:28:24.125741+01
\.


--
-- Data for Name: object_column_white_list; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY object_column_white_list (object_name, column_name) FROM stdin;
vds	vds_group_id
vds	vds_group_name
vds	vds_group_description
vds	vds_id
vds	vds_name
vds	ip
vds	vds_unique_id
vds	host_name
vds	port
vds	vds_strength
vds	server_ssl_enabled
vds	vds_type
vds	pm_type
vds	pm_user
vds	pm_port
vds	pm_options
vds	pm_enabled
vds	pm_proxy_preferences
vds	pm_secondary_ip
vds	pm_secondary_options
vds	pm_secondary_port
vds	pm_secondary_user
vds	pm_secondary_type
vds	pm_secondary_concurrent
vds	vds_spm_priority
vds	hooks
vds	status
vds	cpu_cores
vds	cpu_threads
vds	cpu_model
vds	cpu_speed_mh
vds	if_total_speed
vds	kvm_enabled
vds	physical_mem_mb
vds	pending_vcpus_count
vds	pending_vmem_size
vds	mem_commited
vds	vm_active
vds	vm_count
vds	vm_migrating
vds	vms_cores_count
vds	cpu_over_commit_time_stamp
vds	max_vds_memory_over_commit
vds	net_config_dirty
vds	count_threads_as_cores
vds	storage_pool_id
vds	storage_pool_name
vds	reserved_mem
vds	guest_overhead
vds	software_version
vds	version_name
vds	build_name
vds	previous_status
vds	cpu_idle
vds	cpu_load
vds	cpu_sys
vds	cpu_user
vds	usage_mem_percent
vds	usage_cpu_percent
vds	usage_network_percent
vds	mem_available
vds	mem_shared
vds	swap_free
vds	swap_total
vds	ksm_cpu_percent
vds	ksm_pages
vds	ksm_state
vds	cpu_flags
vds	vds_group_cpu_name
vds	cpu_sockets
vds	vds_spm_id
vds	otp_validity
vds	spm_status
vds	supported_cluster_levels
vds	supported_engines
vds	vds_group_compatibility_version
vds	vds_group_virt_service
vds	vds_group_gluster_service
vds	host_os
vds	kvm_version
vds	libvirt_version
vds	spice_version
vds	kernel_version
vds	iscsi_initiator_name
vds	transparent_hugepages_state
vds	anonymous_hugepages
vds	non_operational_reason
vds	recoverable
vds	sshkeyfingerprint
vds	hw_manufacturer
vds	hw_product_name
vds	hw_version
vds	hw_serial_number
vds	hw_uuid
vds	hw_family
vds	ssh_port
vds	ssh_username
\.


--
-- Data for Name: object_column_white_list_sql; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY object_column_white_list_sql (object_name, sql) FROM stdin;
vds	SELECT x::public.vds as rec FROM (SELECT vds_group_id, vds_group_name, vds_group_description, NULL::int4 as architecture, vds_id, vds_name, ip, vds_unique_id, host_name, NULL::text as free_text_comment, port, vds_strength, server_ssl_enabled, vds_type, pm_type, pm_user, NULL::text as pm_password, pm_port, pm_options, pm_enabled, pm_proxy_preferences, pm_secondary_ip, pm_secondary_options, pm_secondary_port, NULL::text as pm_secondary_password, pm_secondary_user, pm_secondary_type, pm_secondary_concurrent, vds_spm_priority, hooks, status, cpu_cores, cpu_threads, cpu_model, cpu_speed_mh, if_total_speed, kvm_enabled, physical_mem_mb, pending_vcpus_count, pending_vmem_size, mem_commited, vm_active, vm_count, vm_migrating, vms_cores_count, cpu_over_commit_time_stamp, max_vds_memory_over_commit, net_config_dirty, count_threads_as_cores, storage_pool_id, storage_pool_name, reserved_mem, guest_overhead, NULL::"varchar" as rpm_version, software_version, version_name, build_name, previous_status, cpu_idle, cpu_load, cpu_sys, cpu_user, usage_mem_percent, usage_cpu_percent, usage_network_percent, mem_available, NULL::int8 as mem_free, mem_shared, swap_free, swap_total, ksm_cpu_percent, ksm_pages, ksm_state, cpu_flags, vds_group_cpu_name, cpu_sockets, vds_spm_id, otp_validity, spm_status, supported_cluster_levels, supported_engines, vds_group_compatibility_version, vds_group_virt_service, vds_group_gluster_service, host_os, kvm_version, libvirt_version, spice_version, NULL::"varchar" as gluster_version, kernel_version, iscsi_initiator_name, transparent_hugepages_state, anonymous_hugepages, non_operational_reason, recoverable, sshkeyfingerprint, hw_manufacturer, hw_product_name, hw_version, hw_serial_number, hw_uuid, hw_family, NULL::"varchar" as console_address, NULL::text as hbas, NULL::"varchar" as supported_emulated_machines, ssh_port, ssh_username, NULL::int4 as ha_score, NULL::bool as disable_auto_pm, NULL::bool as controlled_by_pm_policy FROM public.vds) as x
\.


--
-- Data for Name: permissions; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY permissions (id, role_id, ad_element_id, object_id, object_type_id) FROM stdin;
00000003-0003-0003-0003-0000000002bf	00000000-0000-0000-0000-000000000001	fdfc627c-d875-11e0-90f0-83df133b58cc	aaa00000-0000-0000-0000-123456789aaa	1
00000004-0004-0004-0004-000000000294	def00009-0000-0000-0000-def000000009	eee00000-0000-0000-0000-123456789eee	00000000-0000-0000-0000-000000000000	4
00000006-0006-0006-0006-000000000084	00000000-0000-0000-0001-000000000002	fdfc627c-d875-11e0-90f0-83df133b58cc	aaa00000-0000-0000-0000-123456789aaa	1
0000000f-000f-000f-000f-000000000256	def0000a-0000-0000-0000-def000000010	eee00000-0000-0000-0000-123456789eee	0000000e-000e-000e-000e-0000000000c1	27
3f99ae9c-a313-4f2d-8321-a8f3a1a98451	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	e3ea893b-1f4e-4697-9b27-756b7d4f3c47	20
9574d411-e510-4776-a04a-5033450ef038	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	506a337e-cefe-460b-8d48-245651383b37	27
86e709af-ecdb-46ff-8e41-f1c1f663b518	def0000a-0000-0000-0000-def000000010	eee00000-0000-0000-0000-123456789eee	506a337e-cefe-460b-8d48-245651383b37	27
57e5bd53-faa4-4704-993a-e05799dca880	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	f78c64c4-31ff-4e97-a93f-406c394ebfca	27
5ff636a6-243e-47d3-bd61-484229384afb	def0000a-0000-0000-0000-def000000010	eee00000-0000-0000-0000-123456789eee	f78c64c4-31ff-4e97-a93f-406c394ebfca	27
db97e655-ba1c-40ed-af7c-9495a4ccf4c6	def0000a-0000-0000-0000-def00000000b	fdfc627c-d875-11e0-90f0-83df133b58cc	745ed552-b70e-4ae4-afb4-e291f3ae68f7	19
cd3ade47-37d4-4d17-8380-fe27d68daf3a	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	3aa34709-4cf0-4cad-9f2d-7ded9f79f544	20
8a01f27e-a479-4d62-a77b-3562c5ca2b3f	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	80d975fa-9138-49a7-8ef2-f27053b23ff4	27
b403f77e-d494-4544-93e0-076796c4c18d	def0000a-0000-0000-0000-def000000010	eee00000-0000-0000-0000-123456789eee	80d975fa-9138-49a7-8ef2-f27053b23ff4	27
3d57b261-500c-435c-a5bc-3bd50847b3ae	00000000-0000-0000-0001-000000000001	fdfc627c-d875-11e0-90f0-83df133b58cc	63263ab7-b153-401d-98bf-baf0ee99d49b	2
9e0e67e2-f1ae-4bc1-b0d8-961ae8cc944d	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	74987b9e-82ce-4f67-a70a-c3a52bfb86d6	20
69e500a4-680e-4a9b-8599-f4dae0c00afa	def00005-0000-0000-0000-def000000005	fdfc627c-d875-11e0-90f0-83df133b58cc	a0fd075f-3d5b-41d2-b21a-528b0fe1ac72	27
7ce912be-a3b5-4a8c-986d-b3a23497011b	def0000a-0000-0000-0000-def000000010	eee00000-0000-0000-0000-123456789eee	a0fd075f-3d5b-41d2-b21a-528b0fe1ac72	27
73612c7a-3bf4-4697-8c9a-83a3c02ca62e	def0000a-0000-0000-0000-def00000000b	fdfc627c-d875-11e0-90f0-83df133b58cc	e9a851df-ad72-4718-a343-bc9662944fe4	19
69fd792d-ecbf-4666-acf3-0fd8b4315e72	def0000a-0000-0000-0000-def00000000b	fdfc627c-d875-11e0-90f0-83df133b58cc	5147580f-fe0b-4a59-9591-579322ddd9da	19
\.


--
-- Data for Name: policy_units; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY policy_units (id, name, is_internal, custom_properties_regex, type, enabled, description) FROM stdin;
12262ab6-9690-4bc3-a2b3-35573b172d54	PinToHost	t	\N	0	t	Filters out all hosts that VM is not pinned to
6d636bf6-a35c-4f9d-b68d-0731f720cddc	CPU	t	\N	0	t	Filters out hosts with less CPUs than VM's CPUs
c9ddbb34-0e1d-4061-a8d7-b0893fa80932	Memory	t	\N	0	t	Filters out hosts that have insufficient memory to run the VM
72163d1c-9468-4480-99d9-0888664eb143	Network	t	\N	0	t	Filters out hosts that are missing networks required by VM NICs, or missing cluster's display network
38440000-8cf0-14bd-c43e-10b96e4ef00a	None	t	\N	2	t	No load balancing operation
38440000-8cf0-14bd-c43e-10b96e4ef00b	None	t	\N	1	t	Follows Even Distribution weight module
438b052c-90ab-40e8-9be0-a22560202ea6	CPU-Level	t	\N	0	t	Runs VMs only on hosts with a proper CPU level
736999d0-1023-46a4-9a75-1316ed50e15b	OptimalForPowerSaving	t	\N	1	t	Gives hosts with higher CPU usage, higher weight (means that hosts with lower CPU usage are more likely to be selected)
7db4ab05-81ab-42e8-868a-aee2df483ed2	OptimalForEvenDistribution	t	{\n  "CpuOverCommitDurationMinutes" : "^([1-9])$",\n  "HighUtilization" : "^([5-9][0-9])$"\n}	2	t	Load balancing VMs in cluster according to hosts CPU load, striving cluster's hosts CPU load to be under 'HighUtilization'
7db4ab05-81ab-42e8-868a-aee2df483edb	OptimalForEvenDistribution	t	\N	1	t	Gives hosts with lower CPU usage, higher weight (means that hosts with higher CPU usage are more likely to be selected)
e659c871-0bf1-4ccc-b748-f28f5d08dffd	HA	t	\N	0	t	Runs the hosted engine VM only on hosts with a positive score
98e92667-6161-41fb-b3fa-34f820ccbc4b	HA	t	\N	1	t	Weights hosts according to their HA score
7f262d70-6cac-11e3-981f-0800200c9a66	OptimalForHaReservation	t	{\n  "ScaleDown" : "(100|[1-9]|[1-9][0-9])$"\n}	1	t	Weights hosts according to their HA score regardless of hosted engine
d58c8e32-44e1-418f-9222-52cd887bf9e0	OptimalForEvenGuestDistribution	t	{\n  "HighVmCount" : "^([0-9][0-9]*)$",\n  "MigrationThreshold" : "^([5-9][0-9]*)$",\n  "SpmVmGrace":"^([5-9][0-9]*)$"\n}	2	t	Even VM count distribution policy
736999d0-1023-46a4-9a75-1316ed50e151	OptimalForPowerSaving	t	{\n  "CpuOverCommitDurationMinutes" : "^([1-9])$",\n  "HighUtilization" : "^([5-9][0-9])$",\n  "LowUtilization" : "^([1-4][0-9])$",\n  "HostsInReserve": "^[0-9][0-9]*$",\n  "EnableAutomaticHostPowerManagement": "^(true|false)$"\n}	2	t	Load balancing VMs in cluster according to hosts CPU load, striving cluster's hosts CPU load to be over 'LowUtilization' and under 'HighUtilization'
84e6ddee-ab0d-42dd-82f0-c297779db566	VmAffinityGroups	t	\N	0	t	Enables Affinity Groups hard enforcement for VMs; VMs in group are required to run either on the same hypervisor host (positive) or on independent hypervisor hosts (negative)
84e6ddee-ab0d-42dd-82f0-c297779db567	VmAffinityGroups	t	\N	1	t	Enables Affinity Groups soft enforcement for VMs; VMs in group are most likely to run either on the same hypervisor host (positive) or on independent hypervisor hosts (negative)
3ba8c988-f779-42c0-90ce-caa8243edee7	OptimalForEvenGuestDistribution	t	\N	1	t	Weights host according the number of running VMs
\.


--
-- Data for Name: providers; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY providers (id, name, description, url, provider_type, auth_required, auth_username, auth_password, _create_date, _update_date, custom_properties, tenant_name, plugin_type, agent_configuration) FROM stdin;
\.


--
-- Data for Name: quota; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY quota (id, storage_pool_id, quota_name, description, _create_date, _update_date, threshold_vds_group_percentage, threshold_storage_percentage, grace_vds_group_percentage, grace_storage_percentage) FROM stdin;
\.


--
-- Data for Name: quota_limitation; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY quota_limitation (id, quota_id, storage_id, vds_group_id, virtual_cpu, mem_size_mb, storage_size_gb) FROM stdin;
\.


--
-- Data for Name: repo_file_meta_data; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY repo_file_meta_data (repo_domain_id, repo_image_id, size, date_created, last_refreshed, file_type, repo_image_name) FROM stdin;
abcd4385-6f38-4efa-93a2-55f4b7bc1468	virtio-win-1.5.3.vfd	1474560	\N	1393837450510	2	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	rhel-everything-7.0-beta-1-x86_64-boot.iso	328204288	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	CentOS-6.5-x86_64-minimal.iso	417333248	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	ItalianWinServer2003R2StandardwithSP2DISC2.iso	130803712	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	virtio-win-0.1-30.iso	45762560	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	CentOS-5.7-x86_64-netinstall.iso	14049280	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	CentOS-6.5-i386-minimal.iso	339738624	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	ItalianWinServer2003R2StandardwithSP2DISC1.iso	626259968	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	vyatta-livecd_VC6.6R1_amd64.iso	233832448	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	virtio-win-0.1-74.iso	61272064	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	virtio-win-1.5.3.iso	56680448	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	CentOS-6.5-x86_64-netinstall.iso	254803968	\N	1393837450545	1	\N
abcd4385-6f38-4efa-93a2-55f4b7bc1468	win2k8r2x86_64.iso	5043701760	\N	1393837450545	1	\N
\.


--
-- Data for Name: roles; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY roles (id, name, description, is_readonly, role_type, allows_viewing_children, app_mode) FROM stdin;
00000000-0000-0000-0000-000000000001	SuperUser	Roles management administrator	t	1	t	255
00000000-0000-0000-0001-000000000001	UserRole	Standard User Role	t	2	t	1
00000000-0000-0000-0001-000000000002	PowerUserRole	User Role, allowed to create VMs, Templates and Disks	t	2	f	1
def00001-0000-0000-0000-def000000001	ClusterAdmin	Administrator Role, permission for all the objects underneath a specific Cluster	t	1	t	255
def00002-0000-0000-0000-def000000002	DataCenterAdmin	Administrator Role, permission for all the objects underneath a specific Data Center, except Storage	t	1	t	1
def00003-0000-0000-0000-def000000003	StorageAdmin	Administrator Role, permission for all operations on a specific Storage Domain	t	1	t	1
def00004-0000-0000-0000-def000000004	HostAdmin	Administrator Role, permission for all operations on a specific Host	t	1	t	255
def00005-0000-0000-0000-def000000005	NetworkAdmin	Administrator Role, permission for all operations on a specific Logical Network	t	1	t	255
def00006-0000-0000-0000-def000000006	UserVmManager	User Role, with permission for any operation on Vms	t	2	t	1
def00007-0000-0000-0000-def000000007	VmPoolAdmin	Administrator Role, permission for all operations on a specific VM Pool	t	1	t	1
def00008-0000-0000-0000-def000000008	TemplateAdmin	Administrator Role, permission for all operations on a specific Template	t	1	t	1
def0000a-0000-0000-0000-def00000000a	QuotaConsumer	User Role, permissions to consume the Quota resources	t	2	f	1
def0000a-0000-0000-0000-def00000000b	DiskOperator	User Role, permissions for all operations on a specific disk	t	2	t	1
def0000a-0000-0000-0000-def00000000c	DiskCreator	User Role, permission to create Disks	t	2	f	1
def0000b-0000-0000-0000-def00000000b	GlusterAdmin	Administrator Role, permissions for operations on Gluster objects	t	1	t	2
def0000a-0000-0000-0000-def00000000d	VmCreator	User Role, permission to create VMs	t	2	f	1
def0000a-0000-0000-0000-def00000000e	TemplateCreator	User Role, permission to create Templates	t	2	f	1
def0000a-0000-0000-0000-def00000000f	TemplateOwner	User Role, permissions for all operations on Templates	t	2	t	1
def0000c-0000-0000-0000-def000000000	ExternalEventsCreator	External Events Creator	t	2	f	255
def0000d-0000-0000-0000-def000000000	ExternalTasksCreator	External Tasks Creator	t	2	f	255
def0000a-0000-0000-0000-def000000010	VnicProfileUser	VM Network Interface Profile User	t	2	f	1
def00009-0000-0000-0000-def000000009	UserTemplateBasedVm	Template User	t	2	f	1
def00011-0000-0000-0000-def000000011	InstanceCreator	User Role, permission to create Instances	t	2	f	1
def00012-0000-0000-0000-def000000012	UserInstanceManager	User Role, with permission for any operation on Instances	t	2	f	1
def0000c-0000-0000-0000-def00000000c	ReadOnlyAdmin	Read Only Administrator Role	t	1	t	1
def00011-0000-0000-0000-def000000013	TagManager	Tag Manager	t	1	f	255
def00011-0000-0000-0000-def000000014	BookmarkManager	Bookmark Manager	t	1	f	255
def00011-0000-0000-0000-def000000015	EventNotificationManager	Event Notification Manager	t	1	f	255
\.


--
-- Data for Name: roles_groups; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY roles_groups (role_id, action_group_id) FROM stdin;
00000000-0000-0000-0000-000000000001	1
00000000-0000-0000-0000-000000000001	2
00000000-0000-0000-0000-000000000001	3
00000000-0000-0000-0000-000000000001	4
00000000-0000-0000-0000-000000000001	5
00000000-0000-0000-0000-000000000001	6
00000000-0000-0000-0000-000000000001	7
00000000-0000-0000-0000-000000000001	8
00000000-0000-0000-0000-000000000001	9
00000000-0000-0000-0000-000000000001	10
00000000-0000-0000-0000-000000000001	11
00000000-0000-0000-0000-000000000001	12
00000000-0000-0000-0000-000000000001	100
00000000-0000-0000-0000-000000000001	101
00000000-0000-0000-0000-000000000001	102
00000000-0000-0000-0000-000000000001	103
00000000-0000-0000-0000-000000000001	104
00000000-0000-0000-0000-000000000001	200
00000000-0000-0000-0000-000000000001	201
00000000-0000-0000-0000-000000000001	202
00000000-0000-0000-0000-000000000001	203
00000000-0000-0000-0000-000000000001	204
00000000-0000-0000-0000-000000000001	300
00000000-0000-0000-0000-000000000001	301
00000000-0000-0000-0000-000000000001	302
00000000-0000-0000-0000-000000000001	303
00000000-0000-0000-0000-000000000001	400
00000000-0000-0000-0000-000000000001	401
00000000-0000-0000-0000-000000000001	402
00000000-0000-0000-0000-000000000001	403
00000000-0000-0000-0000-000000000001	500
00000000-0000-0000-0000-000000000001	501
00000000-0000-0000-0000-000000000001	502
00000000-0000-0000-0000-000000000001	600
00000000-0000-0000-0000-000000000001	601
00000000-0000-0000-0000-000000000001	602
00000000-0000-0000-0000-000000000001	603
00000000-0000-0000-0000-000000000001	700
00000000-0000-0000-0000-000000000001	701
00000000-0000-0000-0000-000000000001	702
00000000-0000-0000-0000-000000000001	703
00000000-0000-0000-0000-000000000001	800
00000000-0000-0000-0001-000000000001	4
00000000-0000-0000-0001-000000000001	5
00000000-0000-0000-0001-000000000001	7
00000000-0000-0000-0001-000000000001	303
00000000-0000-0000-0001-000000000002	1
00000000-0000-0000-0001-000000000002	200
def00001-0000-0000-0000-def000000001	1
def00001-0000-0000-0000-def000000001	2
def00001-0000-0000-0000-def000000001	3
def00001-0000-0000-0000-def000000001	4
def00001-0000-0000-0000-def000000001	5
def00001-0000-0000-0000-def000000001	6
def00001-0000-0000-0000-def000000001	7
def00001-0000-0000-0000-def000000001	8
def00001-0000-0000-0000-def000000001	9
def00001-0000-0000-0000-def000000001	10
def00001-0000-0000-0000-def000000001	11
def00001-0000-0000-0000-def000000001	12
def00001-0000-0000-0000-def000000001	300
def00001-0000-0000-0000-def000000001	301
def00001-0000-0000-0000-def000000001	302
def00001-0000-0000-0000-def000000001	303
def00001-0000-0000-0000-def000000001	100
def00001-0000-0000-0000-def000000001	101
def00001-0000-0000-0000-def000000001	102
def00001-0000-0000-0000-def000000001	103
def00001-0000-0000-0000-def000000001	104
def00001-0000-0000-0000-def000000001	400
def00001-0000-0000-0000-def000000001	401
def00001-0000-0000-0000-def000000001	402
def00001-0000-0000-0000-def000000001	403
def00002-0000-0000-0000-def000000002	1
def00002-0000-0000-0000-def000000002	2
def00002-0000-0000-0000-def000000002	3
def00002-0000-0000-0000-def000000002	4
def00002-0000-0000-0000-def000000002	5
def00002-0000-0000-0000-def000000002	6
def00002-0000-0000-0000-def000000002	7
def00002-0000-0000-0000-def000000002	8
def00002-0000-0000-0000-def000000002	9
def00002-0000-0000-0000-def000000002	10
def00002-0000-0000-0000-def000000002	11
def00002-0000-0000-0000-def000000002	12
def00002-0000-0000-0000-def000000002	200
def00002-0000-0000-0000-def000000002	201
def00002-0000-0000-0000-def000000002	202
def00002-0000-0000-0000-def000000002	203
def00002-0000-0000-0000-def000000002	204
def00002-0000-0000-0000-def000000002	300
def00002-0000-0000-0000-def000000002	301
def00002-0000-0000-0000-def000000002	302
def00002-0000-0000-0000-def000000002	303
def00002-0000-0000-0000-def000000002	100
def00002-0000-0000-0000-def000000002	101
def00002-0000-0000-0000-def000000002	102
def00002-0000-0000-0000-def000000002	103
def00002-0000-0000-0000-def000000002	104
def00002-0000-0000-0000-def000000002	400
def00002-0000-0000-0000-def000000002	401
def00002-0000-0000-0000-def000000002	402
def00002-0000-0000-0000-def000000002	403
def00002-0000-0000-0000-def000000002	700
def00002-0000-0000-0000-def000000002	701
def00002-0000-0000-0000-def000000002	702
def00002-0000-0000-0000-def000000002	703
def00003-0000-0000-0000-def000000003	600
def00003-0000-0000-0000-def000000003	601
def00003-0000-0000-0000-def000000003	602
def00003-0000-0000-0000-def000000003	603
def00004-0000-0000-0000-def000000004	100
def00004-0000-0000-0000-def000000004	101
def00004-0000-0000-0000-def000000004	102
def00004-0000-0000-0000-def000000004	103
def00004-0000-0000-0000-def000000004	104
def00004-0000-0000-0000-def000000004	600
def00004-0000-0000-0000-def000000004	601
def00004-0000-0000-0000-def000000004	602
def00004-0000-0000-0000-def000000004	603
def00005-0000-0000-0000-def000000005	104
def00005-0000-0000-0000-def000000005	403
def00006-0000-0000-0000-def000000006	1
def00006-0000-0000-0000-def000000006	2
def00006-0000-0000-0000-def000000006	3
def00006-0000-0000-0000-def000000006	4
def00006-0000-0000-0000-def000000006	5
def00006-0000-0000-0000-def000000006	7
def00006-0000-0000-0000-def000000006	9
def00006-0000-0000-0000-def000000006	10
def00006-0000-0000-0000-def000000006	12
def00007-0000-0000-0000-def000000007	300
def00007-0000-0000-0000-def000000007	301
def00007-0000-0000-0000-def000000007	302
def00007-0000-0000-0000-def000000007	303
def00008-0000-0000-0000-def000000008	200
def00008-0000-0000-0000-def000000008	201
def00008-0000-0000-0000-def000000008	202
def00008-0000-0000-0000-def000000008	203
def00008-0000-0000-0000-def000000008	204
def00009-0000-0000-0000-def000000009	1
def00002-0000-0000-0000-def000000002	900
00000000-0000-0000-0000-000000000001	900
def00002-0000-0000-0000-def000000002	901
00000000-0000-0000-0000-000000000001	901
00000000-0000-0000-0000-000000000001	13
00000000-0000-0000-0000-000000000001	1100
00000000-0000-0000-0000-000000000001	1101
00000000-0000-0000-0000-000000000001	1102
00000000-0000-0000-0000-000000000001	1103
00000000-0000-0000-0000-000000000001	1104
00000000-0000-0000-0001-000000000002	1100
def00001-0000-0000-0000-def000000001	1100
def00001-0000-0000-0000-def000000001	1101
def00001-0000-0000-0000-def000000001	1102
def00001-0000-0000-0000-def000000001	1103
def00001-0000-0000-0000-def000000001	1104
def00002-0000-0000-0000-def000000002	1100
def00002-0000-0000-0000-def000000002	1101
def00002-0000-0000-0000-def000000002	1102
def00002-0000-0000-0000-def000000002	1103
def00002-0000-0000-0000-def000000002	1104
def00003-0000-0000-0000-def000000003	1100
def00003-0000-0000-0000-def000000003	1101
def00003-0000-0000-0000-def000000003	1102
def00003-0000-0000-0000-def000000003	1103
def00003-0000-0000-0000-def000000003	1104
def00006-0000-0000-0000-def000000006	1100
def00006-0000-0000-0000-def000000006	1101
def00006-0000-0000-0000-def000000006	1102
def00006-0000-0000-0000-def000000006	1104
def0000a-0000-0000-0000-def00000000b	1100
def0000a-0000-0000-0000-def00000000b	1101
def0000a-0000-0000-0000-def00000000b	1102
def0000a-0000-0000-0000-def00000000b	1104
def0000a-0000-0000-0000-def00000000c	1100
00000000-0000-0000-0000-000000000001	1000
00000000-0000-0000-0000-000000000001	1001
00000000-0000-0000-0000-000000000001	1002
def0000b-0000-0000-0000-def00000000b	1000
def0000b-0000-0000-0000-def00000000b	1001
def0000b-0000-0000-0000-def00000000b	1002
def0000a-0000-0000-0000-def00000000d	1
def0000a-0000-0000-0000-def00000000e	200
def0000a-0000-0000-0000-def00000000f	201
def0000a-0000-0000-0000-def00000000f	202
def0000a-0000-0000-0000-def00000000f	203
def0000a-0000-0000-0000-def00000000f	204
def0000a-0000-0000-0000-def00000000f	1300
00000000-0000-0000-0000-000000000001	14
def00001-0000-0000-0000-def000000001	14
def00002-0000-0000-0000-def000000002	14
def0000a-0000-0000-0000-def00000000d	1100
def00001-0000-0000-0000-def000000001	502
def00002-0000-0000-0000-def000000002	502
def0000a-0000-0000-0000-def00000000f	502
def0000a-0000-0000-0000-def00000000b	502
def00006-0000-0000-0000-def000000006	502
def00007-0000-0000-0000-def000000007	1
def00002-0000-0000-0000-def000000002	1300
00000000-0000-0000-0001-000000000002	1300
def0000a-0000-0000-0000-def00000000c	1300
def0000a-0000-0000-0000-def00000000e	1300
def00008-0000-0000-0000-def000000008	1300
def00003-0000-0000-0000-def000000003	1300
def00006-0000-0000-0000-def000000006	1300
00000000-0000-0000-0000-000000000001	1300
def0000a-0000-0000-0000-def00000000d	1300
def0000a-0000-0000-0000-def00000000b	1300
def00001-0000-0000-0000-def000000001	1300
00000000-0000-0000-0001-000000000001	1300
def00004-0000-0000-0000-def000000004	1300
def00007-0000-0000-0000-def000000007	1300
def00005-0000-0000-0000-def000000005	1300
def0000b-0000-0000-0000-def00000000b	1300
00000000-0000-0000-0000-000000000001	704
def00002-0000-0000-0000-def000000002	704
def00002-0000-0000-0000-def000000002	705
00000000-0000-0000-0000-000000000001	705
00000000-0000-0000-0000-000000000001	404
def00002-0000-0000-0000-def000000002	404
def00005-0000-0000-0000-def000000005	404
def00005-0000-0000-0000-def000000005	703
def00005-0000-0000-0000-def000000005	704
def00005-0000-0000-0000-def000000005	705
def00005-0000-0000-0000-def000000005	9
def00005-0000-0000-0000-def000000005	204
00000000-0000-0000-0000-000000000001	1400
def0000c-0000-0000-0000-def000000000	1400
def0000a-0000-0000-0000-def00000000a	901
00000000-0000-0000-0000-000000000001	1003
def0000b-0000-0000-0000-def00000000b	1003
00000000-0000-0000-0000-000000000001	15
def00001-0000-0000-0000-def000000001	15
def00002-0000-0000-0000-def000000002	15
00000000-0000-0000-0000-000000000001	205
def00002-0000-0000-0000-def000000002	205
def00008-0000-0000-0000-def000000008	205
00000000-0000-0000-0000-000000000001	1004
def0000b-0000-0000-0000-def00000000b	1004
def00002-0000-0000-0000-def000000002	1105
00000000-0000-0000-0000-000000000001	1105
00000000-0000-0000-0000-000000000001	1500
def0000d-0000-0000-0000-def000000000	1500
def00002-0000-0000-0000-def000000002	1203
00000000-0000-0000-0000-000000000001	1203
def00005-0000-0000-0000-def000000005	1203
def00005-0000-0000-0000-def000000005	1204
def00002-0000-0000-0000-def000000002	1204
00000000-0000-0000-0000-000000000001	1204
def00005-0000-0000-0000-def000000005	1205
def00002-0000-0000-0000-def000000002	1205
00000000-0000-0000-0000-000000000001	1205
def0000a-0000-0000-0000-def000000010	9
def0000a-0000-0000-0000-def000000010	204
def0000a-0000-0000-0000-def000000010	1300
00000000-0000-0000-0001-000000000001	1106
def00008-0000-0000-0000-def000000008	1106
00000000-0000-0000-0000-000000000001	1106
def00003-0000-0000-0000-def000000003	1106
00000000-0000-0000-0001-000000000002	1106
def00011-0000-0000-0000-def000000011	16
def00011-0000-0000-0000-def000000011	1100
def00011-0000-0000-0000-def000000011	1300
def00012-0000-0000-0000-def000000012	2
def00012-0000-0000-0000-def000000012	3
def00012-0000-0000-0000-def000000012	4
def00012-0000-0000-0000-def000000012	5
def00012-0000-0000-0000-def000000012	7
def00012-0000-0000-0000-def000000012	8
def00012-0000-0000-0000-def000000012	10
def00012-0000-0000-0000-def000000012	12
def00012-0000-0000-0000-def000000012	1100
def00012-0000-0000-0000-def000000012	1101
def00012-0000-0000-0000-def000000012	1102
def00012-0000-0000-0000-def000000012	1104
def00012-0000-0000-0000-def000000012	1300
def00012-0000-0000-0000-def000000012	502
def0000b-0000-0000-0000-def00000000b	400
def0000b-0000-0000-0000-def00000000b	401
def0000b-0000-0000-0000-def00000000b	402
def0000b-0000-0000-0000-def00000000b	403
def0000b-0000-0000-0000-def00000000b	404
def0000b-0000-0000-0000-def00000000b	100
def0000b-0000-0000-0000-def00000000b	101
def0000b-0000-0000-0000-def00000000b	102
def0000b-0000-0000-0000-def00000000b	103
def0000b-0000-0000-0000-def00000000b	104
def0000c-0000-0000-0000-def00000000c	1300
def00001-0000-0000-0000-def000000001	1301
def0000b-0000-0000-0000-def00000000b	1301
def00005-0000-0000-0000-def000000005	1301
def00007-0000-0000-0000-def000000007	1301
def00004-0000-0000-0000-def000000004	1301
def00002-0000-0000-0000-def000000002	1301
def00003-0000-0000-0000-def000000003	1301
00000000-0000-0000-0000-000000000001	1301
def00008-0000-0000-0000-def000000008	1301
def00003-0000-0000-0000-def000000003	1302
00000000-0000-0000-0000-000000000001	1302
def00008-0000-0000-0000-def000000008	1302
def00002-0000-0000-0000-def000000002	1302
def0000b-0000-0000-0000-def00000000b	1302
def00005-0000-0000-0000-def000000005	1302
def00004-0000-0000-0000-def000000004	1302
def00007-0000-0000-0000-def000000007	1302
def00001-0000-0000-0000-def000000001	1302
def0000b-0000-0000-0000-def00000000b	1303
def00007-0000-0000-0000-def000000007	1303
def00004-0000-0000-0000-def000000004	1303
def00005-0000-0000-0000-def000000005	1303
def00001-0000-0000-0000-def000000001	1303
def00008-0000-0000-0000-def000000008	1303
00000000-0000-0000-0000-000000000001	1303
def00003-0000-0000-0000-def000000003	1303
def00002-0000-0000-0000-def000000002	1303
def00011-0000-0000-0000-def000000013	1301
def00011-0000-0000-0000-def000000013	1300
def00011-0000-0000-0000-def000000014	1302
def00011-0000-0000-0000-def000000014	1300
def00011-0000-0000-0000-def000000015	1303
def00011-0000-0000-0000-def000000015	1300
00000000-0000-0000-0000-000000000001	163
00000000-0000-0000-0000-000000000001	164
00000000-0000-0000-0000-000000000001	165
00000000-0000-0000-0000-000000000001	166
def00002-0000-0000-0000-def000000002	163
def00002-0000-0000-0000-def000000002	164
def00002-0000-0000-0000-def000000002	165
def00002-0000-0000-0000-def000000002	166
def00005-0000-0000-0000-def000000005	163
def00005-0000-0000-0000-def000000005	164
def00005-0000-0000-0000-def000000005	165
def00005-0000-0000-0000-def000000005	166
def00004-0000-0000-0000-def000000004	165
def00004-0000-0000-0000-def000000004	166
00000000-0000-0000-0000-000000000001	1550
def00002-0000-0000-0000-def000000002	1550
def00001-0000-0000-0000-def000000001	1550
\.


--
-- Data for Name: schema_version; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY schema_version (id, version, script, checksum, installed_by, started_at, ended_at, state, current, comment) FROM stdin;
1	03020000	upgrade/03_02_0000_set_version.sql	0	engine	2014-02-23 15:40:43.988168	2014-02-23 15:40:43.988168	INSTALLED	f	
2	03020010	upgrade/03_02_0010_delete_action_version_map.sql	84e88314443552214c45db15d34804e9	engine	2014-02-23 15:40:50.204658	2014-02-23 15:40:50.319356	INSTALLED	f	
3	03020020	upgrade/03_02_0020_add_libvirt_version_col.sql	f1b104fb064a3bec328cf351e7199440	engine	2014-02-23 15:40:50.354259	2014-02-23 15:40:50.48012	INSTALLED	f	
4	03020030	upgrade/03_02_0030_delete_permissions_on_vnic.sql	7567aae3c8ba5d2be46bb4bfa60f11ee	engine	2014-02-23 15:40:50.514406	2014-02-23 15:40:50.574642	INSTALLED	f	
5	03020040	upgrade/03_02_0040_add_permissions_on_networks.sql	33225bc9d773a89f60da415668140d36	engine	2014-02-23 15:40:50.611199	2014-02-23 15:40:50.699517	INSTALLED	f	
6	03020050	upgrade/03_02_0050_add_vm_guest_agent_interfaces_table.sql	65edf706e34765b75a77c2db8bc29310	engine	2014-02-23 15:40:50.734846	2014-02-23 15:40:50.830423	INSTALLED	f	
7	03020060	upgrade/03_02_0060_change_host_to_server_event_map.sql	b273948dc21738fad6bc7dfc85aea606	engine	2014-02-23 15:40:50.868552	2014-02-23 15:40:50.96333	INSTALLED	f	
8	03020070	upgrade/03_02_0070_ha_vm_event_notifications.sql	dca15dfad765018764e3d63f825d71b7	engine	2014-02-23 15:40:50.998803	2014-02-23 15:40:51.062128	INSTALLED	f	
9	03020080	upgrade/03_02_0080_add_user_vm_manager_to_vm_power_users.sql	41c260b12a313277138d3da221dfc9d8	engine	2014-02-23 15:40:51.096852	2014-02-23 15:40:51.150087	INSTALLED	f	
10	03020090	upgrade/03_02_0090_cpuhost_support.sql	c929c7786b124dc82155af72d17208bf	engine	2014-02-23 15:40:51.182449	2014-02-23 15:40:51.310195	INSTALLED	f	
11	03020100	upgrade/03_02_0100_add_cpu_thread_columns.sql	6d87a53bdc58171b7f1cc03d05ae819b	engine	2014-02-23 15:40:51.342285	2014-02-23 15:40:51.460087	INSTALLED	f	
12	03020110	upgrade/03_02_0110_add_nic_hash_column_to_vm_dynamic.sql	5a95f112e3514e3572f6d393efd665a6	engine	2014-02-23 15:40:51.492949	2014-02-23 15:40:51.557323	INSTALLED	f	
13	03020120	upgrade/03_02_0120_add_index_to_vm_guest_agent_interfaces.sql	63d54a665ce1007264de1094c62f9e95	engine	2014-02-23 15:40:51.590337	2014-02-23 15:40:51.658113	INSTALLED	f	
14	03020130	upgrade/03_02_0130_add_linked_to_vm_interface.sql	a44460422c65331586ca3b1841810572	engine	2014-02-23 15:40:51.690015	2014-02-23 15:40:51.823693	INSTALLED	f	
15	03020140	upgrade/03_02_0140_allow_null_network_name_in_vm_interfaces.sql	cbf894d9eb0196e51d151e23ee96426a	engine	2014-02-23 15:40:51.859411	2014-02-23 15:40:51.927653	INSTALLED	f	
16	03020150	upgrade/03_02_0150_add_console_cur_user_name.sql	7ca1176340122aa64e698ac3f7878545	engine	2014-02-23 15:40:51.962378	2014-02-23 15:40:52.032742	INSTALLED	f	
17	03020160	upgrade/03_02_0160_drop_guest_user_id_column.sql	a1b3af75c751e7d115c44fc4124ac2ed	engine	2014-02-23 15:40:52.066436	2014-02-23 15:40:52.134519	INSTALLED	f	
18	03020170	upgrade/03_02_0170_add_admin_internal_user_role_system.sql	21ce7b3c593193a51b89fd8943dff82a	engine	2014-02-23 15:40:52.177642	2014-02-23 15:40:52.258166	INSTALLED	f	
19	03020180	upgrade/03_02_0180_add_pm_proxy_preferences.sql	832f8501fabdad9fe9f3523567223c83	engine	2014-02-23 15:40:52.293056	2014-02-23 15:40:52.465377	INSTALLED	f	
20	03020190	upgrade/03_02_0190_add_vds_hardware_info.sql	9f92824010d8507ae96cc811f9ef339b	engine	2014-02-23 15:40:52.520488	2014-02-23 15:40:52.634952	INSTALLED	f	
21	03020200	upgrade/03_02_0200_add_vm_generation_columns.sql	94775a6a7a4829b24b833f0eda89b218	engine	2014-02-23 15:40:52.677396	2014-02-23 15:40:52.964801	INSTALLED	f	
22	03020210	upgrade/03_02_0210_add_external_events.sql	36b63817157f4d7a61251f04e2d7e1db	engine	2014-02-23 15:40:53.002616	2014-02-23 15:40:54.368141	INSTALLED	f	
23	03020220	upgrade/03_02_0220_add_pm_multi_agent_support.sql	9d3408d944a67d0b64c6790498d4b122	engine	2014-02-23 15:40:54.40193	2014-02-23 15:40:54.580476	INSTALLED	f	
24	03020230	upgrade/03_02_0230_extend_lun_size.sql	e1138d52b0ab05aec5f8de17662b0a18	engine	2014-02-23 15:40:54.612645	2014-02-23 15:40:54.765748	INSTALLED	f	
25	03020240	upgrade/03_02_0240_add_gluster_action_version_map.sql	5aedc7d3167bcbc829e608ef08331831	engine	2014-02-23 15:40:54.800701	2014-02-23 15:40:54.964755	INSTALLED	f	
26	03020250	upgrade/03_02_0250_delete_actiongroups_uservmmanager.sql	ec3142a5f89ca5948509afba0c8f5f1d	engine	2014-02-23 15:40:54.999787	2014-02-23 15:40:55.060422	INSTALLED	f	
27	03020260	upgrade/03_02_0260_add_delete_protection.sql	fc5b46ed69cb53b8d510b35cb373d0f0	engine	2014-02-23 15:40:55.096404	2014-02-23 15:40:55.286978	INSTALLED	f	
28	03020270	upgrade/03_02_0270_gluster_volume_name_unique_constraint.sql	aba145f0dc7b5398d4568033154a0041	engine	2014-02-23 15:40:55.326895	2014-02-23 15:40:55.437814	INSTALLED	f	
29	03020280	upgrade/03_02_0280_drop_licenses.sql	241c52cf11670a6909cb62e117799178	engine	2014-02-23 15:40:55.47422	2014-02-23 15:40:55.525977	INSTALLED	f	
30	03020290	upgrade/03_02_0290_change_vm_guest_agent_interface_mac_address_type.sql	ddf74384ce703881d1da19aedf78490e	engine	2014-02-23 15:40:55.56371	2014-02-23 15:40:55.691668	INSTALLED	f	
31	03020300	upgrade/03_02_0300_add_quota_consume_action_group_link.sql	b17c27f5b6ee7e9c78ac922fda6e4d53	engine	2014-02-23 15:40:55.728154	2014-02-23 15:40:55.787824	INSTALLED	f	
32	03020310	upgrade/03_02_0310_add_disabled_to_vm_static.sql	58e6d3b1ba05bc1fc1e493dcb23df2c9	engine	2014-02-23 15:40:55.825439	2014-02-23 15:40:55.978994	INSTALLED	f	
33	03020320	upgrade/03_02_0320_fix_principal_name_in_users_for_ad_users.sql	4b4176a2bdd91760c8a18a9265f66b2a	engine	2014-02-23 15:40:56.016049	2014-02-23 15:40:56.069629	INSTALLED	f	
34	03020330	upgrade/03_02_0330_add_vds_event_notifications.sql	5ce63eb59ef6cf194139a88549a7bffe	engine	2014-02-23 15:40:56.10462	2014-02-23 15:40:56.202075	INSTALLED	f	
35	03020340	upgrade/03_02_0340_gluster_volume_status_events.sql	ed551a3a8817c72e1a08543a598b153c	engine	2014-02-23 15:40:56.245098	2014-02-23 15:40:56.309795	INSTALLED	f	
36	03020350	upgrade/03_02_0350_add_console_address.sql	6d2b46e3a90a56536f35744684631e46	engine	2014-02-23 15:40:56.344546	2014-02-23 15:40:56.521981	INSTALLED	f	
37	03020360	upgrade/03_02_0360_add_secondary_index_to_network.sql	96c806adc03289d83605e3a9ba076619	engine	2014-02-23 15:40:56.556731	2014-02-23 15:40:56.647616	INSTALLED	f	
38	03020370	upgrade/03_02_0370_add_vds_performance_notifications.sql	88bdb03c076d03b1c232328f3906ab6d	engine	2014-02-23 15:40:56.684957	2014-02-23 15:40:56.795952	INSTALLED	f	
39	03020380	upgrade/03_02_0380_gluster_option_changed_event.sql	d7406eec62e062df3d39f3a1ebbb6817	engine	2014-02-23 15:40:56.829101	2014-02-23 15:40:56.884265	INSTALLED	f	
40	03020390	upgrade/03_02_0390_align_lun_volume_group_id.sql	2b48a7bdff6caa9dcaf32e6be1acdc46	engine	2014-02-23 15:40:56.916744	2014-02-23 15:40:56.976775	INSTALLED	f	
41	03020400	upgrade/03_02_0400_add_login_permission_to_network_user_role.sql	4c6de8af820dac3f30660ebf4c923187	engine	2014-02-23 15:40:57.008639	2014-02-23 15:40:57.069771	INSTALLED	f	
42	03020410	upgrade/03_02_0410_remove_user_session.sql	891bdf7fb83e39ee3f83f1a848408951	engine	2014-02-23 15:40:57.100906	2014-02-23 15:40:57.17537	INSTALLED	f	
43	03020420	upgrade/03_02_0420_materialized_views_extensions.sql	b0daec9757116ad9f729a62fec829ea6	engine	2014-02-23 15:40:57.21717	2014-02-23 15:40:57.292334	INSTALLED	f	
44	03020430	upgrade/03_02_0430_dummy.sql	2b12e74c31668931085f73945b2b2909	engine	2014-02-23 15:40:57.326063	2014-02-23 15:40:57.378779	INSTALLED	f	
45	03020440	upgrade/03_02_0440_dummy.sql	aa24ef08dd428cdaa1cc30f2b0c27150	engine	2014-02-23 15:40:57.413777	2014-02-23 15:40:57.467595	INSTALLED	f	
46	03020450	upgrade/03_02_0450_dummy.sql	111aff33af9fe8db5e1b9ac1c070421a	engine	2014-02-23 15:40:57.502235	2014-02-23 15:40:57.553914	INSTALLED	f	
47	03020460	upgrade/03_02_0460_add_async_task_task_parameters.sql	112ab7499c34a558de800391d0c07149	engine	2014-02-23 15:40:57.588758	2014-02-23 15:40:57.663749	INSTALLED	f	
48	03020470	upgrade/03_02_0470_lsm_version_support.sql	0950f168720d25167eaa3c0c7602f701	engine	2014-02-23 15:40:57.695218	2014-02-23 15:40:57.76239	INSTALLED	f	
49	03020480	upgrade/03_02_0480_fix_stateless_snapshot.sql	21888170848e81ea4cd21b89a758826d	engine	2014-02-23 15:40:57.798602	2014-02-23 15:40:57.849279	INSTALLED	f	
50	03020490	upgrade/03_02_0490_add_update_column_to_statistics_tables.sql	cb4062e536a132e444ad407a0c8147ed	engine	2014-02-23 15:40:57.884734	2014-02-23 15:40:58.022834	INSTALLED	f	
51	03020500	upgrade/03_02_0500_add_gluster_hooks_table.sql	8427728950a30011f3373e542a711873	engine	2014-02-23 15:40:58.058028	2014-02-23 15:40:58.326951	INSTALLED	f	
52	03030010	upgrade/03_03_0010_add_migration_to_network_cluster.sql	14657ad84e48a1fb0553b2d14b913a50	engine	2014-02-23 15:40:58.361942	2014-02-23 15:40:58.494311	INSTALLED	f	
53	03030020	upgrade/03_03_0020_add_gluster_hooks_roles.sql	63618f380f89992d792718ac880c612f	engine	2014-02-23 15:40:58.538143	2014-02-23 15:40:58.629329	INSTALLED	f	
54	03030030	upgrade/03_03_0030_add_edit_admin_vm_props.sql	b0e32a380ee4d3329a546bfde1d6376e	engine	2014-02-23 15:40:58.664025	2014-02-23 15:40:58.737589	INSTALLED	f	
55	03030040	upgrade/03_03_0040_add_run_and_pause_to_vm.sql	88f85d30bb24d7812614a5cb38ff67f6	engine	2014-02-23 15:40:58.779674	2014-02-23 15:40:58.9925	INSTALLED	f	
56	03030050	upgrade/03_03_0050_repo_file_id.sql	3edad27779af5e251733e06078b097cd	engine	2014-02-23 15:40:59.033521	2014-02-23 15:40:59.167956	INSTALLED	f	
57	03030060	upgrade/03_03_0060_drop_desktop_device.sql	d042caf4334fad676ba3de539bee496d	engine	2014-02-23 15:40:59.207595	2014-02-23 15:40:59.283324	INSTALLED	f	
58	03030070	upgrade/03_03_0070_drop_iconpath.sql	7f0d66775591a4b929ef6d093e4a551d	engine	2014-02-23 15:40:59.319126	2014-02-23 15:40:59.392412	INSTALLED	f	
59	03030080	upgrade/03_03_0080_drop_roles_relations.sql	0a1f47a0d9c28a5c2435557463f4a7ae	engine	2014-02-23 15:40:59.433718	2014-02-23 15:40:59.50757	INSTALLED	f	
60	03030090	upgrade/03_03_0090_edit_storage_conn_version_support.sql	23a0dc5122d0af152ace8c76340e3da3	engine	2014-02-23 15:40:59.552514	2014-02-23 15:40:59.612565	INSTALLED	f	
61	03030100	upgrade/03_03_0100_update_imagestatus_invalid_to_illegal.sql	8fabb2467eb8c825e21926269ad48938	engine	2014-02-23 15:40:59.648074	2014-02-23 15:40:59.700164	INSTALLED	f	
62	03030110	upgrade/03_03_0110_drop_storage_owner.sql	44be16c6adca0aa0150f513e6d3f74fb	engine	2014-02-23 15:40:59.741335	2014-02-23 15:40:59.815258	INSTALLED	f	
63	03030120	upgrade/03_03_0120_add_max_assigned_vms_per_user.sql	32d9393e3868b4df8afb0d5f756f9cd7	engine	2014-02-23 15:40:59.849169	2014-02-23 15:41:00.031681	INSTALLED	f	
64	03030130	upgrade/03_03_0130_add_gluster_services_tables.sql	bdf04686a2b4357bbeb88f21a31824b3	engine	2014-02-23 15:41:00.068778	2014-02-23 15:41:00.370961	INSTALLED	f	
65	03030140	upgrade/03_03_0140_add_gluster_server_table.sql	dc857d7c5892ea725181f1078c6f8e82	engine	2014-02-23 15:41:00.405144	2014-02-23 15:41:00.509031	INSTALLED	f	
66	03030150	upgrade/03_03_0150_add_providers_table.sql	ae7ed87dcab412c54b0934358319f4bf	engine	2014-02-23 15:41:00.544918	2014-02-23 15:41:00.63958	INSTALLED	f	
67	03030160	upgrade/03_03_0160_increase_guest_ram.sql	e970c6a5ec6cbd64488ff8bea564a1f1	engine	2014-02-23 15:41:00.673612	2014-02-23 15:41:00.72673	INSTALLED	f	
68	03030170	upgrade/03_03_0170_watchdog.sql	6ff9cc7e1943ec549e8bf02234904034	engine	2014-02-23 15:41:00.770579	2014-02-23 15:41:00.852667	INSTALLED	f	
69	03030180	upgrade/03_03_0180_add_device_custom_prop.sql	2273f644a116b0b3f752b0c75a72009f	engine	2014-02-23 15:41:00.889529	2014-02-23 15:41:00.961499	INSTALLED	f	
70	03030190	upgrade/03_03_0190_add_memory_volume_to_snapshots.sql	4de97c27650b670b485b35f8402dcaca	engine	2014-02-23 15:41:00.998526	2014-02-23 15:41:01.072226	INSTALLED	f	
71	03030200	upgrade/03_03_0200_add_gluster_service_roles.sql	d3b6d7e1e539cc516147a40a593db799	engine	2014-02-23 15:41:01.107554	2014-02-23 15:41:01.191596	INSTALLED	f	
72	03030210	upgrade/03_03_0210_add_hbas_col.sql	ed0a9dc6c1df3521b22b7cb7889abb93	engine	2014-02-23 15:41:01.228989	2014-02-23 15:41:01.302411	INSTALLED	f	
73	03030220	upgrade/03_03_0220_add_call_stack_to_audit_log.sql	3ae0cd0201dddd7097362f0e2caa2987	engine	2014-02-23 15:41:01.338305	2014-02-23 15:41:01.813622	INSTALLED	f	
74	03030230	upgrade/03_03_0230_update_removeglusterserver_action_version_map.sql	8a265bce277ddd5f937977db81257b57	engine	2014-02-23 15:41:01.857048	2014-02-23 15:41:01.924747	INSTALLED	f	
75	03030240	upgrade/03_03_0240_add_gluster_hooks_services_events.sql	f712b853fe78bd771f05093f451a58da	engine	2014-02-23 15:41:01.968571	2014-02-23 15:41:02.255575	INSTALLED	f	
76	03030250	upgrade/03_03_0250_upgrade_utcdiff_and_timezone_for_linux.sql	34cff43ab6e7eb4e6ddc468fadd9895a	engine	2014-02-23 15:41:02.29597	2014-02-23 15:41:02.364943	INSTALLED	f	
77	03030260	upgrade/03_03_0260_add_base_disks_sgio_column.sql	621d4e9fdbb22d285209344522149dfb	engine	2014-02-23 15:41:02.403352	2014-02-23 15:41:02.473105	INSTALLED	f	
78	03030270	upgrade/03_03_0270_add_permission_to_configure_sgio.sql	2c4eaeff183598467ab8d909886bfef4	engine	2014-02-23 15:41:02.516052	2014-02-23 15:41:02.592318	INSTALLED	f	
79	03030280	upgrade/03_03_0280_add_comment_storage_pool.sql	57379977f9f0cdfa875ccc6523a322a6	engine	2014-02-23 15:41:02.63111	2014-02-23 15:41:02.704117	INSTALLED	f	
80	03030290	upgrade/03_03_0290_add_custom_properties_to_providers.sql	d163dcb673e89f20ccb9883bafedbe66	engine	2014-02-23 15:41:02.740083	2014-02-23 15:41:02.820346	INSTALLED	f	
81	03030300	upgrade/03_03_0300_add_tenant_and_plugin_type_to_providers.sql	109ae5d625554b9543d3603b8e0421ac	engine	2014-02-23 15:41:02.858764	2014-02-23 15:41:02.938566	INSTALLED	f	
82	03030310	upgrade/03_03_0310_add_provided_by_to_network.sql	ef07f127231fd254f1ac526dc06f7a8b	engine	2014-02-23 15:41:02.978292	2014-02-23 15:41:03.054386	INSTALLED	f	
83	03030320	upgrade/03_03_0320_base_disks_alignment.sql	adf2c330ad04864a438238a4a3465b0b	engine	2014-02-23 15:41:03.089627	2014-02-23 15:41:03.227997	INSTALLED	f	
84	03030330	upgrade/03_03_0330_add_emulated_machine_to_host_and_cluster.sql	f9f3700b4af48c9d5cdf3171f3a5c27c	engine	2014-02-23 15:41:03.263048	2014-02-23 15:41:03.338175	INSTALLED	f	
85	03030340	upgrade/03_03_0340_upgrade_to_cluster_emulated_machine.sql	7bf799b7b3f1af8297bd470159f05fea	engine	2014-02-23 15:41:03.371822	2014-02-23 15:41:03.429414	INSTALLED	f	
86	03030350	upgrade/03_03_0350_add_vdsm_task_id_and_index_to_async_tasks.sql	045b9941a8075bb8775ca6c0b08e8693	engine	2014-02-23 15:41:03.462142	2014-02-23 15:41:03.559522	INSTALLED	f	
87	03030360	upgrade/03_03_0360_add_root_command_id_to_async_tasks.sql	dcf3623c26e94a3359048b8cac8ebeba	engine	2014-02-23 15:41:03.595229	2014-02-23 15:41:03.67252	INSTALLED	f	
88	03030370	upgrade/03_03_0370_add_trusted_service_to_vds_groups.sql	bdd57b3dba231b0abddc12c003cdeb78	engine	2014-02-23 15:41:03.708957	2014-02-23 15:41:03.851286	INSTALLED	f	
89	03030380	upgrade/03_03_0380_remove_auto_suspend.sql	d42a3a305b824dee627b6df68b995311	engine	2014-02-23 15:41:03.89047	2014-02-23 15:41:03.953036	INSTALLED	f	
90	03030390	upgrade/03_03_0390_add_created_by_user_id_column.sql	0fdc27335402e2fdf052a11d4f379b09	engine	2014-02-23 15:41:03.989213	2014-02-23 15:41:04.057932	INSTALLED	f	
91	03030400	upgrade/03_03_0400_remove_unused_colums_from_user.sql	0864debce07384c0183d125b836c796c	engine	2014-02-23 15:41:04.094439	2014-02-23 15:41:04.185778	INSTALLED	f	
92	03030410	upgrade/03_03_0410_alignment_not_null.sql	321362c10a0ea1ed1cbc0d6df582abd5	engine	2014-02-23 15:41:04.221579	2014-02-23 15:41:04.289666	INSTALLED	f	
93	03030420	upgrade/03_03_0420_add_storage_static_description_column.sql	b69f6c08efd1204628367957e922c761	engine	2014-02-23 15:41:04.330493	2014-02-23 15:41:04.415238	INSTALLED	f	
94	03030430	upgrade/03_03_0430_add_tunnel_migration.sql	4068a6da0ae03d632d6c50e7cef7c3f4	engine	2014-02-23 15:41:04.45378	2014-02-23 15:41:04.617419	INSTALLED	f	
95	03030440	upgrade/03_03_0440_add_free_mem_to_vds_statistics.sql	26902644988ab6f408677f7547e5e09a	engine	2014-02-23 15:41:04.65331	2014-02-23 15:41:04.729566	INSTALLED	f	
96	03030450	upgrade/03_03_0450_add_external_tasks_support.sql	322e457b17a0ee8e1c259ac2449e2f54	engine	2014-02-23 15:41:04.779961	2014-02-23 15:41:05.120945	INSTALLED	f	
97	03030460	upgrade/03_03_0460_add_network_qos_table.sql	cda2b0460123aea8dba5b55b4d7984b1	engine	2014-02-23 15:41:05.161116	2014-02-23 15:41:05.292657	INSTALLED	f	
98	03030470	upgrade/03_03_0470_add_extend_image_size_action_version_map.sql	e7efbb2058c89cc1e02469c5544dd2f7	engine	2014-02-23 15:41:05.334912	2014-02-23 15:41:05.40432	INSTALLED	f	
99	03030480	upgrade/03_03_0480_upgrade_cluster_policy.sql	4c602aa8a350503e46a32a4d3a78932d	engine	2014-02-23 15:41:05.44288	2014-02-23 15:41:05.899096	INSTALLED	f	
100	03030490	upgrade/03_03_0490_add_agent_configuration_to_provider.sql	37d69cebc37f8b0e2262ff268ae7849b	engine	2014-02-23 15:41:05.935673	2014-02-23 15:41:06.005399	INSTALLED	f	
101	03030500	upgrade/03_03_0500_add_enable_balloon_to_vds_groups.sql	cc8a8b6b02daaab78b2c07aba6ec33c5	engine	2014-02-23 15:41:06.039608	2014-02-23 15:41:06.146339	INSTALLED	f	
102	03030510	upgrade/03_03_0510_add_vds_ssh_fields.sql	e1c9e3855c9a8515619a50aa47a08c87	engine	2014-02-23 15:41:06.181344	2014-02-23 15:41:06.261347	INSTALLED	f	
103	03030520	upgrade/03_03_0520_add_comment_network.sql	89d23482613c815d4bfaef05fa593590	engine	2014-02-23 15:41:06.297019	2014-02-23 15:41:06.369664	INSTALLED	f	
104	03030530	upgrade/03_03_0530_add_comment_vds_static.sql	1163d17d614e09967e96f56d99e24153	engine	2014-02-23 15:41:06.404715	2014-02-23 15:41:06.475348	INSTALLED	f	
105	03030540	upgrade/03_03_0540_add_comment_vds_groups.sql	6826c2deffeed563884484bc93cc4fc0	engine	2014-02-23 15:41:06.511775	2014-02-23 15:41:06.580107	INSTALLED	f	
106	03030550	upgrade/03_03_0550_glance_import_command.sql	e45ce0da39ef38767a9af2089c155f88	engine	2014-02-23 15:41:06.614072	2014-02-23 15:41:06.66898	INSTALLED	f	
107	03030560	upgrade/03_03_0560_glance_export_command.sql	61333e3af8dd9870b45750b3fc6ab17e	engine	2014-02-23 15:41:06.703674	2014-02-23 15:41:06.764336	INSTALLED	f	
108	03030570	upgrade/03_03_0570_add_comment_storage_domain_static.sql	d23f4e822fcab373747d9e3d6850752f	engine	2014-02-23 15:41:06.801642	2014-02-23 15:41:06.877678	INSTALLED	f	
109	03030580	upgrade/03_03_0580_remove_selection_algorithm_columns.sql	f9dd5604cb14525d614151469b5bfc28	engine	2014-02-23 15:41:06.917686	2014-02-23 15:41:07.020049	INSTALLED	f	
110	03030590	upgrade/03_03_0590_add_comment_vm_static_and_pool.sql	49acc482703246c80d759f969b83edb5	engine	2014-02-23 15:41:07.055577	2014-02-23 15:41:07.134216	INSTALLED	f	
111	03030600	upgrade/03_03_0600_add_trusted_service_notifications.sql	e539a82b81b20e02bb05a4a9d0a2ff5e	engine	2014-02-23 15:41:07.17216	2014-02-23 15:41:07.330356	INSTALLED	f	
112	03030610	upgrade/03_03_0610_spice_as_default_display_type_on_blank_template.sql	ddd0fe73a751aa4c006598b3691d2df6	engine	2014-02-23 15:41:07.366013	2014-02-23 15:41:07.43077	INSTALLED	f	
113	03030620	upgrade/03_03_0620_add_external_id_to_users.sql	7eea8208937f8feb9cc1118e3ffbb675	engine	2014-02-23 15:41:07.475417	2014-02-23 15:41:07.64803	INSTALLED	f	
114	03030630	upgrade/03_03_0630_add_missing_event_map.sql	032a02a250b9920451b029ca91f19584	engine	2014-02-23 15:41:07.694237	2014-02-23 15:41:07.813795	INSTALLED	f	
115	03030640	upgrade/03_03_0640_default_vdsstatic_values_to_ssh_fields.sql	861882357bafaa6baaafacaba1783975	engine	2014-02-23 15:41:07.851584	2014-02-23 15:41:07.906115	INSTALLED	f	
116	03030650	upgrade/03_03_0650_add_signle_qxl_pci_column.sql	990e32dae84250ad9d4380d6055eeb3c	engine	2014-02-23 15:41:07.942498	2014-02-23 15:41:08.09996	INSTALLED	f	
117	03030660	upgrade/03_03_0660_alter_os_type_unassigned_to_other.sql	6cba9baffcf58bc26bce8970c527d375	engine	2014-02-23 15:41:08.134847	2014-02-23 15:41:08.199164	INSTALLED	f	
118	03030670	upgrade/03_03_0670_allow_single_logic_for_policy_unit.sql	eaa2d4f025a49d60aab436098ea8fcb0	engine	2014-02-23 15:41:08.237196	2014-02-23 15:41:08.521541	INSTALLED	f	
119	03030680	upgrade/03_03_0680_add_cpu_shares_to_vm.sql	2dbab629d1955c8a968a75b4e68cc87d	engine	2014-02-23 15:41:08.558788	2014-02-23 15:41:08.71584	INSTALLED	f	
120	03030690	upgrade/03_03_0690_add_enabled_column_to_policy_unit.sql	5e791c91f298ca662f275e21524e9e30	engine	2014-02-23 15:41:08.751403	2014-02-23 15:41:08.872793	INSTALLED	f	
121	03030700	upgrade/03_03_0700_add_is_run_once_to_vm_dynamic.sql	8a6d1a83664bf61ba09682a7dad9adc7	engine	2014-02-23 15:41:08.925416	2014-02-23 15:41:09.067822	INSTALLED	f	
122	03030710	upgrade/03_03_0710_add_profile_to_network_interface.sql	f48faa57cf2e239f8a50826beef07454	engine	2014-02-23 15:41:09.101278	2014-02-23 15:41:09.325583	INSTALLED	f	
123	03030720	upgrade/03_03_0720_drop_columns_from_vm_interface.sql	6753cd3b20d17f13f04a8fe2053aad5c	engine	2014-02-23 15:41:09.357216	2014-02-23 15:41:09.442692	INSTALLED	f	
124	03030730	upgrade/03_03_0730_update_attestation_server.sql	7e8c66b9e054db8bfa1a07fc8e7895ba	engine	2014-02-23 15:41:09.47626	2014-02-23 15:41:09.537462	INSTALLED	f	
125	03030740	upgrade/03_03_0740_add_description_to_policy_unit.sql	c635e848573440648bfddc6e0d121c04	engine	2014-02-23 15:41:09.572696	2014-02-23 15:41:09.649299	INSTALLED	f	
126	03030750	upgrade/03_03_0750_add_network_qos_id_to_vnic_profiles.sql	05d5709e53f5168e8d1f4b1ba4033c01	engine	2014-02-23 15:41:09.694654	2014-02-23 15:41:09.827392	INSTALLED	f	
127	03030760	upgrade/03_03_0760_preserve_network_user_id_for_vnic_profile.sql	c4522ca5c52ec4174f40267543f492c5	engine	2014-02-23 15:41:09.866582	2014-02-23 15:41:09.959662	INSTALLED	f	
128	03030770	upgrade/03_03_0770_alter_vm_interface_vnic_profile_fk.sql	274f7a4eb8d400fed7611fa6e802eb8f	engine	2014-02-23 15:41:09.997267	2014-02-23 15:41:10.083739	INSTALLED	f	
129	03030780	upgrade/03_03_0780_convert_empty_timezone_to_null.sql	74640430f3f97950a46f2b6258882c2c	engine	2014-02-23 15:41:10.121035	2014-02-23 15:41:10.179406	INSTALLED	f	
130	03030790	upgrade/03_03_0790_remove_migration_domain_filter.sql	945d75162ad7fb49d1a703dd123faf85	engine	2014-02-23 15:41:10.216794	2014-02-23 15:41:10.276254	INSTALLED	f	
131	03030800	upgrade/03_03_0800_add_vm_vnc_keyboard_layout.sql	33457aaf71dd232cddc160279b0ee620	engine	2014-02-23 15:41:10.312293	2014-02-23 15:41:10.475484	INSTALLED	f	
132	03030810	upgrade/03_03_0810_add_app_mode_to_roles.sql	884a2c6fa87fde2fc9692d6b60b20bef	engine	2014-02-23 15:41:10.512903	2014-02-23 15:41:10.645988	INSTALLED	f	
133	03030820	upgrade/03_03_0820_add_task_id_to_volumeandbricks.sql	24203193c8fba359e2a56d068b013cb7	engine	2014-02-23 15:41:10.681667	2014-02-23 15:41:10.81277	INSTALLED	f	
134	03030830	upgrade/03_03_0830_add_stop_rebalance_gluster_volume_to_event_map.sql	ea2acce934513bd745fcb050d721c380	engine	2014-02-23 15:41:10.850018	2014-02-23 15:41:10.922448	INSTALLED	f	
135	03030840	upgrade/03_03_0840_add_job_start_time_index.sql	88afac0e6b7ec133fe4987aad00ba851	engine	2014-02-23 15:41:10.959131	2014-02-23 15:41:11.042433	INSTALLED	f	
136	03030850	upgrade/03_03_0850_rename_template_user_role.sql	aa0fcfafd9c56b7de67b06a9041781ad	engine	2014-02-23 15:41:11.077221	2014-02-23 15:41:11.138812	INSTALLED	f	
137	03030860	upgrade/03_03_0860_remove_import_export_permissions_from_vm_user_manager.sql	2f3b7741eb66a6c4e63e4e8040be0324	engine	2014-02-23 15:41:11.17373	2014-02-23 15:41:11.247658	INSTALLED	f	
138	03030870	upgrade/03_03_0870_add_detect_emulated_machine_to_cluster.sql	20f487f0d97e57ea73e770c7b897a6e9	engine	2014-02-23 15:41:11.283975	2014-02-23 15:41:11.434929	INSTALLED	f	
139	03030880	upgrade/03_03_0880_add_dwh_osinfo_table.sql	c2c056c31aafd1164703aaf995e8632c	engine	2014-02-23 15:41:11.472665	2014-02-23 15:41:11.567039	INSTALLED	f	
140	03030890	upgrade/03_03_0890_image_domains_permissions.sql	a50800283727293978bdf4f385052b77	engine	2014-02-23 15:41:11.605378	2014-02-23 15:41:11.697221	INSTALLED	f	
141	03030900	upgrade/03_03_0900_quota_id_foreign_key.sql	ce97ffa9d2e7613565d1d88132f3d5de	engine	2014-02-23 15:41:11.732979	2014-02-23 15:41:11.821679	INSTALLED	f	
142	03030910	upgrade/03_03_0910_remove_migration_filter.sql	f0cfc8a3d39bbb61d7570b959c51831b	engine	2014-02-23 15:41:11.858187	2014-02-23 15:41:11.918767	INSTALLED	f	
143	03030920	upgrade/03_03_0920_add_fqdn_to_vm_dynamic.sql	d571d5e094bd5701b73d94dae4d443d9	engine	2014-02-23 15:41:11.955529	2014-02-23 15:41:12.142405	INSTALLED	f	
144	03030930	upgrade/03_03_0930_add_cpu_name_to_vm_dynamic.sql	ed6010f56953ba4cf4fe122ce0e9ce1a	engine	2014-02-23 15:41:12.174953	2014-02-23 15:41:12.243826	INSTALLED	f	
145	03030940	upgrade/03_03_0940_add_cpu_level_policy_unit.sql	32120ee3a7d62ea0179dee171f02941d	engine	2014-02-23 15:41:12.276657	2014-02-23 15:41:12.356839	INSTALLED	f	
146	03030950	upgrade/03_03_0950_change_policy_names.sql	3dea9bd8eff3161611809d8098113344	engine	2014-02-23 15:41:12.390776	2014-02-23 15:41:12.46527	INSTALLED	f	
147	03030960	upgrade/03_03_0960_add_dwh_heartbeat.sql	562db867159794b87b8e8087d7ade2d1	engine	2014-02-23 15:41:12.500006	2014-02-23 15:41:12.555352	INSTALLED	f	
148	03030970	upgrade/03_03_0970_add_start_remove_gluster_volume_brick_to_event_map.sql	de57f1db1bf172974e0d38be2807ab03	engine	2014-02-23 15:41:12.588874	2014-02-23 15:41:12.650066	INSTALLED	f	
149	03030980	upgrade/03_03_0980_clear_snapshot_id_of_floating_disks.sql	55338f3e06afea74da09d5e6f638c1f5	engine	2014-02-23 15:41:12.684329	2014-02-23 15:41:12.735007	INSTALLED	f	
150	03030990	upgrade/03_03_0990_pin_to_host_first_in_powersaving_policy.sql	863471b00575de09c70fe38264f7a80d	engine	2014-02-23 15:41:12.774382	2014-02-23 15:41:12.835876	INSTALLED	f	
151	03040010	upgrade/03_04_0010_add_instance_type_to_vm.sql	d5ffb43021d6bf95736bb419dce86e8e	engine	2014-02-23 15:41:12.872289	2014-02-23 15:41:12.952848	INSTALLED	f	
152	03040020	upgrade/03_04_0020_add_instance_permissions.sql	8ec875e63637626cd1fc34bfbee16f43	engine	2014-02-23 15:41:12.990212	2014-02-23 15:41:13.075042	INSTALLED	f	
153	03040030	upgrade/03_04_0030_add_ha_score_to_vds_statistics.sql	63f31857c334677cfc8b042234c86bde	engine	2014-02-23 15:41:13.111646	2014-02-23 15:41:13.219046	INSTALLED	f	
154	03040040	upgrade/03_04_0040_add_ha_policy_units.sql	3f254a4a85bf40f17bfc1c6ea4ef74de	engine	2014-02-23 15:41:13.256819	2014-02-23 15:41:13.357283	INSTALLED	f	
155	03040050	upgrade/03_04_0050_move_rename_of_other_linux_type.sql	3977c2b068b9d22d903f7a0925406e37	engine	2014-02-23 15:41:13.393498	2014-02-23 15:41:13.452041	INSTALLED	f	
156	03040060	upgrade/03_04_0060_add_snapshot_id_column_to_vm_device.sql	c9786a3a67d5ffa23f14cb45be3168d2	engine	2014-02-23 15:41:13.489214	2014-02-23 15:41:13.570969	INSTALLED	f	
157	03040070	upgrade/03_04_0070_index_network_by_external_id.sql	0190b94f2e7a07126c36c28fcc6359f6	engine	2014-02-23 15:41:13.616105	2014-02-23 15:41:13.696428	INSTALLED	f	
158	03040080	upgrade/03_04_0080_add_brick_status_change_event_map.sql	2e8edf8df1b23008e2840c909e91ec7d	engine	2014-02-23 15:41:13.736516	2014-02-23 15:41:13.79641	INSTALLED	f	
159	03040090	upgrade/03_04_0090_move_quota_id.sql	a9da543d11997e2458bb47b99ff73a58	engine	2014-02-23 15:41:13.835162	2014-02-23 15:41:13.938743	INSTALLED	f	
160	03040100	upgrade/03_04_0100_add_cluster_host_permissions_to_gluster_admin_role.sql	d9f515f538aea491994030148b7d3bee	engine	2014-02-23 15:41:13.975187	2014-02-23 15:41:14.062905	INSTALLED	f	
161	03040110	upgrade/03_04_0110_change_policy_names.sql	3dea9bd8eff3161611809d8098113344	engine	2014-02-23 15:41:14.101841	2014-02-23 15:41:14.138673	SKIPPED	f	Installed already by  03030950
162	03040120	upgrade/03_04_0120_add_gluster_version_to_vds_dynamic.sql	92cfbf51b3c7ec8b7237174dafe81a27	engine	2014-02-23 15:41:14.175436	2014-02-23 15:41:14.247985	INSTALLED	f	
163	03040130	upgrade/03_04_0130_add_start_time_idx_job.sql	37e6eaabbc3266ff3c83f8aed1d3258b	engine	2014-02-23 15:41:14.281835	2014-02-23 15:41:14.385549	INSTALLED	f	
164	03040140	upgrade/03_04_0140_add_sso_method_to_vm_static.sql	e1a08bba589ea13cc0408f619813ac6a	engine	2014-02-23 15:41:14.420186	2014-02-23 15:41:14.606572	INSTALLED	f	
165	03040150	upgrade/03_04_0150_gluster_async_tasks_finished_event_map.sql	e9d8210d28a0de4fe945732a2a81fe64	engine	2014-02-23 15:41:14.642636	2014-02-23 15:41:14.70627	INSTALLED	f	
166	03040160	upgrade/03_04_0160_create_read_only_admin_role.sql	07093445ebe47847f6849a6b25ffbdeb	engine	2014-02-23 15:41:14.742045	2014-02-23 15:41:14.818621	INSTALLED	f	
167	03040170	upgrade/03_04_0170_add_architecture_name_column.sql	0926c4fc405221786acc97eb50e9c2c1	engine	2014-02-23 15:41:14.854052	2014-02-23 15:41:14.988965	INSTALLED	f	
168	03040180	upgrade/03_04_0180_add_vds_group_optimization_field.sql	28661ac96b720f6b002774695b833607	engine	2014-02-23 15:41:15.022223	2014-02-23 15:41:15.128674	INSTALLED	f	
169	03040190	upgrade/03_04_0190_gluster_async_tasks_stop_remove-brick_event_map.sql	3ebfb0d2f0e35b190a8f1f1b4609ae9f	engine	2014-02-23 15:41:15.162108	2014-02-23 15:41:15.222675	INSTALLED	f	
170	03040200	upgrade/03_04_0200_gluster_async_tasks_fromcli_event_map.sql	0f399f7c05ca20c59ee991367f9b103c	engine	2014-02-23 15:41:15.257103	2014-02-23 15:41:15.318968	INSTALLED	f	
171	03040210	upgrade/03_04_0210_replace_storage_type_all_with_unknown.sql	ae8fd303c8c87051c514b0d12616591a	engine	2014-02-23 15:41:15.352791	2014-02-23 15:41:15.403932	INSTALLED	f	
172	03040220	upgrade/03_04_0220_add_console_events.sql	1929e483fac20e769027989048620c55	engine	2014-02-23 15:41:15.437759	2014-02-23 15:41:15.502821	INSTALLED	f	
173	03040230	upgrade/03_04_0230_vm_down_error_and_vds_initiated_run_fail_event_map.sql	7c6181c01c67e1f099f9b19dba982d51	engine	2014-02-23 15:41:15.536099	2014-02-23 15:41:15.598198	INSTALLED	f	
174	03040240	upgrade/03_04_0240_gluster_async_tasks_notfound_fromcli_event_map.sql	b278b951715db212dbf8d0c9ea312aef	engine	2014-02-23 15:41:15.630344	2014-02-23 15:41:15.691603	INSTALLED	f	
175	03040250	upgrade/03_04_0250_rename_user_and_group_status_to_active.sql	be0fd40be801a2ebffcf029e356a2500	engine	2014-02-23 15:41:15.723708	2014-02-23 15:41:15.999911	INSTALLED	f	
176	03040260	upgrade/03_04_0260_add_external_id_to_groups.sql	8a5004294554af4d4930ae73075e5302	engine	2014-02-23 15:41:16.035727	2014-02-23 15:41:16.216013	INSTALLED	f	
177	03040270	upgrade/03_04_0270_add_task_id_idx_gluster_bricks.sql	2413e4ae02d943619a0a8a91d9c6b970	engine	2014-02-23 15:41:16.251729	2014-02-23 15:41:16.334661	INSTALLED	f	
178	03040280	upgrade/03_04_0280_add_original_template_to_vm_static.sql	c3ebb0eeb63fa4a066ef3f6a6e5ded8e	engine	2014-02-23 15:41:16.371266	2014-02-23 15:41:16.549138	INSTALLED	f	
179	03040290	upgrade/03_04_0290_add_spice_proxy_to_vds_groups_and_vm_pools.sql	d760094f81a4819b019e89e48cb03971	engine	2014-02-23 15:41:16.586691	2014-02-23 15:41:16.680669	INSTALLED	f	
180	03040300	upgrade/03_04_0300_add_label_column_to_networks.sql	3c77e70807009c3aa5d0f015c806a2da	engine	2014-02-23 15:41:16.727504	2014-02-23 15:41:16.802967	INSTALLED	f	
181	03040310	upgrade/03_04_0310_add_labels_column_to_vds_interfaces.sql	6ae3a6405c257409eaea6785380a32c6	engine	2014-02-23 15:41:16.841012	2014-02-23 15:41:16.911628	INSTALLED	f	
182	03040320	upgrade/03_04_0320_move_anonymousHugePages.sql	95fe97ead68a20188cdd60aba6db219b	engine	2014-02-23 15:41:16.948445	2014-02-23 15:41:17.065479	INSTALLED	f	
183	03040330	upgrade/03_04_0330_add_admin_operations_action_groups_and_roles.sql	6f98be3b8fb3d715ecf9ff8f1747fcbb	engine	2014-02-23 15:41:17.111901	2014-02-23 15:41:17.194041	INSTALLED	f	
184	03040340	upgrade/03_04_0340_add_network_labels_action_groups.sql	ff56ce3cf88976e4c561dfb7e48355c7	engine	2014-02-23 15:41:17.230052	2014-02-23 15:41:17.329032	INSTALLED	f	
185	03040350	upgrade/03_04_0350_relax_network_qos_constraints.sql	9c587817ecc1e175598d3271b8d91754	engine	2014-02-23 15:41:17.364541	2014-02-23 15:41:17.425086	INSTALLED	f	
186	03040360	upgrade/03_04_0360_add_qos_id_to_network.sql	32d659cbbc415a5b63c5569d7bed3d29	engine	2014-02-23 15:41:17.460156	2014-02-23 15:41:17.545637	INSTALLED	f	
187	03040370	upgrade/03_04_0370_add_qos_overridden_to_vds_interface.sql	a6aeeee79f2617c01517a98ad7396cf0	engine	2014-02-23 15:41:17.58314	2014-02-23 15:41:17.7416	INSTALLED	f	
188	03040380	upgrade/03_04_0380_add_last_stop_time_to_vm_dynamic.sql	762ce9adc03d468b90fbbd3502636903	engine	2014-02-23 15:41:17.778831	2014-02-23 15:41:17.855008	INSTALLED	f	
189	03040390	upgrade/03_04_0390_add_ha_reservation.sql	580aee7c34801bd4f6005217487ff11a	engine	2014-02-23 15:41:17.890132	2014-02-23 15:41:18.014898	INSTALLED	f	
190	03040400	upgrade/03_04_0400_add_var_on_dwh_status.sql	1c8df49d692499c49de73e9f055a260a	engine	2014-02-23 15:41:18.049207	2014-02-23 15:41:18.109219	INSTALLED	f	
191	03040410	upgrade/03_04_0410_add_even_guest_distribution_policy.sql	f7310beca6b3baef6084b68b3e205b31	engine	2014-02-23 15:41:18.142504	2014-02-23 15:41:18.210982	INSTALLED	f	
192	03040420	upgrade/03_04_0420_add_vds_pm_flags.sql	33552acdb8c1ad56e946ce96db476358	engine	2014-02-23 15:41:18.245767	2014-02-23 15:41:18.44528	INSTALLED	f	
193	03040430	upgrade/03_04_0430_add_power_management_to_cluster_policy.sql	5446d0003b4e2cb6e50f4ca8b7d54b10	engine	2014-02-23 15:41:18.476581	2014-02-23 15:41:18.532678	INSTALLED	f	
194	03040440	upgrade/03_04_0440_create_affinity_group_tables.sql	08e3b932bfd35de5096ed2a8246c8f2d	engine	2014-02-23 15:41:18.565397	2014-02-23 15:41:18.688597	INSTALLED	f	
195	03040450	upgrade/03_04_0450_add_affinity_group_action_group.sql	3974d01f629e099d0c0d11553ccd9eff	engine	2014-02-23 15:41:18.720428	2014-02-23 15:41:18.796759	INSTALLED	f	
196	03040460	upgrade/03_04_0460_add_affinity_group_filter_and_weight.sql	32ab3909c5cba69324ca2d5020b05def	engine	2014-02-23 15:41:18.832657	2014-02-23 15:41:18.919802	INSTALLED	f	
197	03040470	upgrade/03_04_0470_add_reboot_command.sql	e747bf9f65d2bec76e6574707b6e231a	engine	2014-02-23 15:41:18.956745	2014-02-23 15:41:19.019179	INSTALLED	f	
198	03040480	upgrade/03_04_0480_add_enable_ksm_to_vds_groups.sql	7a4596c214f991867bb865b1ffe8feaf	engine	2014-02-23 15:41:19.055494	2014-02-23 15:41:19.178997	INSTALLED	f	
199	03040490	upgrade/03_04_0490_add_vm_migration_downtime.sql	ac1b7518d2b142a8173a09d7361dfe55	engine	2014-02-23 15:41:19.215555	2014-02-23 15:41:19.284865	INSTALLED	f	
200	03040500	upgrade/03_04_0500_add_iscsi_bond.sql	773d220ff630d81a237b47a124553922	engine	2014-02-23 15:41:19.323647	2014-02-23 15:41:19.523812	INSTALLED	f	
201	03040510	upgrade/03_04_0510_add_all_basic_filters_to_even_guest_policy.sql	71629cc4cdc710a72475f547ae78eaf5	engine	2014-02-23 15:41:19.564056	2014-02-23 15:41:19.683067	INSTALLED	f	
202	03040520	upgrade/03_04_0520_add_vm_init_table.sql	8625b7d0e4695c7244c47aca2166fbb4	engine	2014-02-23 15:41:19.720269	2014-02-23 15:41:19.863554	INSTALLED	f	
203	03040530	upgrade/03_04_0530_remove_storage_pool_type.sql	e18b821a82850843c41f0481052521be	engine	2014-02-23 15:41:19.899569	2014-02-23 15:41:20.015533	INSTALLED	f	
204	03040540	upgrade/03_04_0540_add_template_version_to_vm_static.sql	1015cf2947a698c600297d39509706bc	engine	2014-02-23 15:41:20.051002	2014-02-23 15:41:20.246649	INSTALLED	f	
205	03040550	upgrade/03_04_0550_add_current_cd_to_vm_dynamic.sql	34b74bd1e459b34cc60d4e59f87c6219	engine	2014-02-23 15:41:20.282157	2014-02-23 15:41:20.419622	INSTALLED	f	
206	03040560	upgrade/03_04_0560_map_vds_detected_to_event_map.sql	821fb4b4f4b2471dc57ffd883dbc7ae8	engine	2014-02-23 15:41:20.462366	2014-02-23 15:41:20.53793	INSTALLED	f	
207	03040570	upgrade/03_04_0570_set_proxy_preferences_default.sql	ad0d2f486704100ec927a59b93c83d56	engine	2014-02-23 15:41:20.569419	2014-02-23 15:41:20.623412	INSTALLED	f	
208	03040580	upgrade/03_04_0580_fix_admin_internal_permissions.sql	0e58b30629213beaf97ab57da9a554a0	engine	2014-02-23 15:41:20.658299	2014-02-23 15:41:20.722129	INSTALLED	f	
209	03040590	upgrade/03_04_0590_add_restart_different_host_event.sql	ce1f90457eb1bed1f085b4af30185071	engine	2014-02-23 15:41:20.757971	2014-02-23 15:41:20.817735	INSTALLED	t	
\.


--
-- Data for Name: snapshots; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY snapshots (snapshot_id, vm_id, snapshot_type, status, description, creation_date, app_list, vm_configuration, _create_date, _update_date, memory_volume) FROM stdin;
6e5dafc9-d38a-4a8a-8acc-6db5ab87dc43	63263ab7-b153-401d-98bf-baf0ee99d49b	ACTIVE	OK	Active VM	2014-02-24 14:44:21.176+01	\N	\N	2014-02-24 14:44:21.16511+01	\N	\N
6ce54994-1a41-4760-a2b4-a58ac5752062	c124be96-7cd5-4199-98d3-00b8993c5e1f	ACTIVE	OK	Active VM	2014-02-26 14:02:16.092+01		\N	2014-02-26 14:02:16.083784+01	2014-02-26 14:02:16.083784+01	\N
eefcb99e-e30f-43cc-94fa-6b8bbfa69d3a	1a5142e6-47cd-4193-b446-c62e05bc5df6	ACTIVE	OK	Active VM	2014-02-27 15:25:53.246+01		\N	2014-02-27 15:25:53.209517+01	2014-02-27 15:25:53.209517+01	\N
0663cdaa-c9d4-44b5-bcb7-11bee352af82	cb7a888c-29ed-478e-9c32-4e392d00f7c9	ACTIVE	OK	Active VM	2014-02-28 16:41:18.723+01	\N	\N	2014-02-28 16:41:18.667332+01	\N	\N
\.


--
-- Data for Name: step; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY step (step_id, parent_step_id, job_id, step_type, description, step_number, status, start_time, end_time, correlation_id, external_id, external_system_type, is_external) FROM stdin;
\.


--
-- Data for Name: storage_domain_dynamic; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY storage_domain_dynamic (id, available_disk_size, used_disk_size, _update_date) FROM stdin;
529eb18f-d561-4d40-8da3-7d1d6e43cb1c	12	7	2014-02-28 18:09:45.185101+01
a689cb30-743e-4261-bfd1-b8b194dc85db	23	31	2014-03-03 10:39:50.869449+01
e5de5969-e6a2-4aed-9e3d-241f186ff014	9	90	2014-03-03 10:39:50.880932+01
abcd4385-6f38-4efa-93a2-55f4b7bc1468	12	7	2014-03-03 10:39:50.895689+01
1810e5eb-9eb6-4797-ac50-8023a939f312	\N	\N	2014-03-03 10:39:50.90146+01
4f234feb-6287-457a-a1dc-120fc2d49164	60	4	2014-03-03 16:13:58.446582+01
\.


--
-- Data for Name: storage_domain_static; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY storage_domain_static (id, storage, storage_name, storage_domain_type, storage_type, storage_domain_format_type, _create_date, _update_date, recoverable, last_time_used_as_master, storage_description, storage_comment) FROM stdin;
abcd4385-6f38-4efa-93a2-55f4b7bc1468	43f38f16-a1ee-4623-97a8-2bd9ef614180	NFS01ISO	2	1	0	2014-02-23 18:50:58.577085+01	\N	t	0	\N	\N
a689cb30-743e-4261-bfd1-b8b194dc85db	9dbhlt-fOih-tTf8-cB9A-vFwg-lYzf-bofQ6y	dt02clu6070	0	3	3	2014-02-24 14:30:58.440479+01	2014-02-24 14:37:10.767589+01	t	1393248792222	\N	\N
529eb18f-d561-4d40-8da3-7d1d6e43cb1c	0953f8c6-7b19-4046-b21c-3c5acdb1f9fa	nfs01eEXPORT	3	1	0	2014-02-26 11:28:47.240473+01	\N	t	0	\N	\N
e5de5969-e6a2-4aed-9e3d-241f186ff014	RH7mQx-yNIp-PwHa-nyZO-h9At-wzPB-MvOGSi	dt01clu6070	1	3	3	2014-02-28 16:33:37.1331+01	2014-02-28 16:33:37.15653+01	t	0	\N	\N
1810e5eb-9eb6-4797-ac50-8023a939f312	11d4972d-f227-49ed-b997-f33cf4b2aa26	nfs02EXPORT	3	1	0	2014-02-28 18:11:23.17092+01	\N	t	0	\N	\N
4f234feb-6287-457a-a1dc-120fc2d49164	D9Idek-weJA-q1zI-asWs-YNuW-I92Q-VYU9sU	dt03clu6070	1	3	3	2014-03-03 16:13:44.476626+01	2014-03-03 16:13:44.498752+01	t	0	\N	\N
\.


--
-- Data for Name: storage_pool; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY storage_pool (id, name, description, storage_pool_type, storage_pool_format_type, status, master_domain_version, spm_vds_id, compatibility_version, _create_date, _update_date, quota_enforcement_type, free_text_comment, is_local) FROM stdin;
00000002-0002-0002-0002-000000000051	Default	The default Data Center	3	3	5	2	39a203c0-e19d-49a7-9909-b713d0255d69	3.4	2014-02-23 15:40:43.988168+01	2014-03-04 03:26:53.908356+01	0		f
\.


--
-- Data for Name: storage_pool_iso_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY storage_pool_iso_map (storage_id, storage_pool_id, status) FROM stdin;
a689cb30-743e-4261-bfd1-b8b194dc85db	00000002-0002-0002-0002-000000000051	0
e5de5969-e6a2-4aed-9e3d-241f186ff014	00000002-0002-0002-0002-000000000051	0
abcd4385-6f38-4efa-93a2-55f4b7bc1468	00000002-0002-0002-0002-000000000051	0
1810e5eb-9eb6-4797-ac50-8023a939f312	00000002-0002-0002-0002-000000000051	4
\.


--
-- Data for Name: storage_server_connections; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY storage_server_connections (id, connection, user_name, password, iqn, port, portal, storage_type, mount_options, vfs_type, nfs_version, nfs_timeo, nfs_retrans) FROM stdin;
020e1d9f-5f22-459b-a30b-35e6063a88ee	192.168.246.84	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	2	3	\N	\N	\N	\N	\N
dd12e8b8-0352-42ca-81cd-b525068d5203	192.168.246.80	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	1	3	\N	\N	\N	\N	\N
aa355d71-b912-4d15-8d8a-d4061eb01a1f	192.168.246.82	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	5	3	\N	\N	\N	\N	\N
af6d1b3d-614b-4f2f-a0fc-4bf55653e0c6	192.168.246.81	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	3	3	\N	\N	\N	\N	\N
fcaa1493-483b-45dd-afb6-a0839e52b828	192.168.246.86	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	6	3	\N	\N	\N	\N	\N
1bab0797-dc98-423e-882a-decc8d9b615f	192.168.246.83	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	7	3	\N	\N	\N	\N	\N
00c28b95-981c-4ce8-8b93-7839a9f2d654	192.168.246.85	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	4	3	\N	\N	\N	\N	\N
c26c706d-048d-4744-b633-207b4201ab1a	192.168.246.87	QQQQ	PPPP	iqn.1986-03.com.hp:storage.p2000g3.122715280c	3260	8	3	\N	\N	\N	\N	\N
43f38f16-a1ee-4623-97a8-2bd9ef614180	nfs01.clusterip.priv7o:/opt/nfs_iso/domain	\N	\N	\N	\N	\N	1	\N	\N	4	\N	\N
0953f8c6-7b19-4046-b21c-3c5acdb1f9fa	nfs01e.clusterip.priv7o:/opt/nfs_export/domain	\N	\N	\N	\N	\N	1	\N	\N	4	\N	\N
11d4972d-f227-49ed-b997-f33cf4b2aa26	nfs02.clusterip.priv7o:/opt/nfs_export/domain	\N	\N	\N	\N	\N	1	\N	\N	4	\N	\N
\.


--
-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags (tag_id, tag_name, description, parent_id, readonly, type, _create_date, _update_date) FROM stdin;
\.


--
-- Data for Name: tags_user_group_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags_user_group_map (tag_id, group_id, _create_date) FROM stdin;
\.


--
-- Data for Name: tags_user_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags_user_map (tag_id, user_id, _create_date) FROM stdin;
\.


--
-- Data for Name: tags_vds_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags_vds_map (tag_id, vds_id, _create_date) FROM stdin;
\.


--
-- Data for Name: tags_vm_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags_vm_map (tag_id, vm_id, _create_date, defaultdisplaytype) FROM stdin;
\.


--
-- Data for Name: tags_vm_pool_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY tags_vm_pool_map (tag_id, vm_pool_id, _create_date) FROM stdin;
\.


--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY users (user_id, name, surname, domain, username, groups, department, role, email, note, last_admin_check_status, group_ids, external_id, active) FROM stdin;
fdfc627c-d875-11e0-90f0-83df133b58cc	admin	\N	internal	admin		\N	\N	\N	\N	t		\\375\\374b|\\330u\\021\\340\\220\\360\\203\\337\\023;X\\314	t
\.


--
-- Data for Name: vdc_db_log; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vdc_db_log (error_id, occured_at, error_code, error_message, error_proc, error_line) FROM stdin;
\.


--
-- Data for Name: vdc_options; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vdc_options (option_id, option_name, option_value, version) FROM stdin;
1	AutoRegistrationDefaultVdsGroupID	00000001-0001-0001-0001-00000000031e	general
2	AbortMigrationOnError	false	3.0
3	AbortMigrationOnError	false	3.1
4	AbortMigrationOnError	false	3.2
5	AbortMigrationOnError	false	3.3
7	CpuPinMigrationEnabled	true	general
8	CpuPinningEnabled	false	3.0
9	AdminDomain	internal	general
11	AdminUser	admin	general
12	AdUserId		general
13	AdUserName		general
14	AdUserPassword		general
15	AdvancedNFSOptionsEnabled	false	3.0
17	AllowClusterWithVirtGlusterEnabled	true	general
18	AllowDuplicateMacAddresses	false	general
19	ApplicationMode	255	general
20	AsyncTaskPollingRate	10	general
21	AsyncTaskStatusCacheRefreshRateInSeconds	30	general
22	AsyncTaskStatusCachingTimeInMinutes	1	general
24	AuditLogAgingThreshold	30	general
25	AuditLogCleanupTime	03:35:35	general
26	OnlyRequiredNetworksMandatoryForVdsSelection	false	general
27	AuthenticationMethod	LDAP	general
28	AutoApprovePatterns		general
29	AutoInstallCertificateOnApprove	true	general
30	AutoRecoverySchedule	0 0/5 * * * ?	general
31	AutoRepoDomainRefreshTime	60	general
32	BlockMigrationOnSwapUsagePercentage	0	general
33	CipherSuite	DEFAULT	general
35	ConnectToServerTimeoutInSeconds	20	general
36	ClusterEmulatedMachines	rhel6.2.0,pc-1.0	3.0
37	ClusterEmulatedMachines	rhel6.3.0,pc-1.0	3.1
38	ClusterEmulatedMachines	rhel6.4.0,pc-1.0	3.2
40	ClusterEmulatedMachines	rhel6.5.0,pc-1.0,pseries	3.4
41	CpuOverCommitDurationMinutes	2	general
44	DebugTimerLogging	true	general
45	DefaultMaxThreadPoolSize	500	general
46	DefaultMinThreadPoolSize	50	general
47	DefaultMaxThreadWaitQueueSize	100	general
48	DefaultWindowsTimeZone	GMT Standard Time	general
49	DefaultGeneralTimeZone	Etc/GMT	general
51	DisableFenceAtStartupInSec	300	general
52	DirectLUNDiskEnabled	false	3.0
54	EnableHostTimeDrift	false	general
55	EnableSpiceRootCertificateValidation	true	general
56	EnableSwapCheck	true	general
57	EnableUSBAsDefault	true	general
58	EnableVdsLoadBalancing	true	general
59	EngineMode	Active	general
60	FailedJobCleanupTimeInMinutes	60	general
63	FenceProxyDefaultPreferences	cluster,dc	general
64	FenceQuietTimeBetweenOperationsInSec	180	general
69	FilteringLUNsEnabled	true	3.0
70	FindFenceProxyDelayBetweenRetriesInSec	30	general
71	FindFenceProxyRetries	3	general
72	FreeSpaceCriticalLowInGB	5	general
73	FreeSpaceLow	10	general
74	GlusterHooksEnabled	false	3.0
75	GlusterHooksEnabled	false	3.1
76	GlusterHooksEnabled	false	3.2
77	GlusterHostUUIDSupport	false	3.0
78	GlusterHostUUIDSupport	false	3.1
79	GlusterHostUUIDSupport	false	3.2
80	GlusterRefreshHeavyWeight	false	3.0
81	GlusterRefreshHeavyWeight	false	3.1
82	GlusterRefreshRateHooks	7200	general
83	GlusterRefreshRateLight	5	general
84	GlusterRefreshRateHeavy	300	general
85	GlusterServicesEnabled	false	3.0
86	GlusterServicesEnabled	false	3.1
87	GlusterServicesEnabled	false	3.2
88	GlusterSupport	false	3.0
89	GlusterSupportForceCreateVolume	false	3.0
90	GlusterSupportForceCreateVolume	false	3.1
91	GlusterSupportForceCreateVolume	false	3.2
92	GlusterSupportForceCreateVolume	false	3.3
93	GlusterVolumeOptionGroupVirtValue	virt	general
94	GlusterVolumeOptionOwnerUserVirtValue	36	general
95	GlusterVolumeOptionOwnerGroupVirtValue	36	general
96	GlusterRefreshRateTasks	60	general
97	GlusterAysncTasksSupport	false	3.0
98	GlusterAysncTasksSupport	false	3.1
99	GlusterAysncTasksSupport	false	3.2
100	GlusterAysncTasksSupport	false	3.3
101	GlusterPeerStatusRetries	2	general
102	KeystoneAuthUrl		general
103	GuestToolsSetupIsoPrefix	RHEV-toolsSetup_	general
104	HardwareInfoEnabled	false	3.0
105	HardwareInfoEnabled	false	3.1
106	HighUtilizationForEvenlyDistribute	75	general
107	HighUtilizationForPowerSave	75	general
108	HostPreparingForMaintenanceIdleTime	300	general
109	HostTimeDriftInSec	300	general
110	HotPlugEnabled	false	3.0
199	MaxNumOfCpuPerSocket	16	3.2
43	DBEngine	Postgres	general
62	FenceAgentMapping	drac7=ipmilan,ilo2=ilo,ilo3=ipmilan,ilo4=ipmilan	general
65	FenceStartStatusDelayBetweenRetriesInSec	10	general
66	FenceStartStatusRetries	18	general
67	FenceStopStatusDelayBetweenRetriesInSec	10	general
68	FenceStopStatusRetries	18	general
39	ClusterEmulatedMachines	rhel6.4.0,pc-1.0,pseries	3.3
16	AgentAppName	ovirt-guest-agent-common,ovirt-guest-agent	general
23	AsyncTaskZombieTaskLifeInMinutes	3000	general
53	DomainName		general
34	ConfigDir	/etc/ovirt-engine	general
42	DataDir	/usr/share	general
111	HotPlugCpuEnabled	{"x86_64":"false","ppc64":"false"}	3.0
112	HotPlugCpuEnabled	{"x86_64":"false","ppc64":"false"}	3.1
113	HotPlugCpuEnabled	{"x86_64":"false","ppc64":"false"}	3.2
114	HotPlugCpuEnabled	{"x86_64":"false","ppc64":"false"}	3.3
115	HotPlugCpuEnabled	{"x86_64":"true","ppc64":"false"}	3.4
118	NetworkLinkingSupported	false	3.0
119	NetworkLinkingSupported	false	3.1
121	InitStorageSparseSizeInGB	1	general
122	TunnelMigrationEnabled	false	3.0
123	TunnelMigrationEnabled	false	3.1
124	TunnelMigrationEnabled	false	3.2
125	MigrationNetworkEnabled	false	3.0
126	MigrationNetworkEnabled	false	3.1
127	MigrationNetworkEnabled	false	3.2
128	MultipleGatewaysSupported	false	3.0
129	MultipleGatewaysSupported	false	3.1
130	MultipleGatewaysSupported	false	3.2
131	MemorySnapshotSupported	false	3.0
132	MemorySnapshotSupported	false	3.1
133	MemorySnapshotSupported	false	3.2
134	OsRepositoryConfDir	/osinfo.conf.d	general
135	VirtIoScsiEnabled	false	3.0
136	VirtIoScsiEnabled	false	3.1
137	VirtIoScsiEnabled	false	3.2
138	NormalizedMgmgNetworkEnabled	false	3.0
139	NormalizedMgmgNetworkEnabled	false	3.1
140	NormalizedMgmgNetworkEnabled	false	3.2
141	IterationsWithBalloonProblem	3	general
142	MomPoliciesOnHostSupported	false	3.0
143	MomPoliciesOnHostSupported	false	3.1
144	MomPoliciesOnHostSupported	false	3.2
145	NetworkQosSupported	false	3.0
146	NetworkQosSupported	false	3.1
147	NetworkQosSupported	false	3.2
148	HostNetworkQosSupported	false	3.0
149	HostNetworkQosSupported	false	3.1
150	HostNetworkQosSupported	false	3.2
151	HostNetworkQosSupported	false	3.3
152	CloudInitSupported	false	3.0
153	CloudInitSupported	false	3.1
154	CloudInitSupported	false	3.2
155	HotPlugDiskSnapshotSupported	false	3.0
156	HotPlugDiskSnapshotSupported	false	3.1
157	HotPlugDiskSnapshotSupported	false	3.2
158	GetFileStats	false	3.0
159	GetFileStats	false	3.1
160	GetFileStats	false	3.2
161	GetFileStats	false	3.3
162	SpiceProxyDefault		general
163	InstallVds	true	general
164	IoOpTimeoutSec	10	general
169	JobCleanupRateInMinutes	10	general
170	JobPageSize	100	general
171	LdapQueryPageSize	1000	general
172	LDAPQueryTimeout	30	general
173	LDAPConnectTimeout	30	general
174	LDAPOperationTimeout	30	general
176	LDAPServerPort	389	general
177	LdapServers		general
179	LeaseRetries	3	general
180	LeaseTimeSec	60	general
182	LiveSnapshotEnabled	false	3.0
184	LockPolicy	ON	general
185	LockRenewalIntervalSec	5	general
186	LogPhysicalMemoryThresholdInMB	1024	general
187	LowUtilizationForEvenlyDistribute	0	general
188	LowUtilizationForPowerSave	20	general
190	ManagedDevicesWhiteList		general
191	ManagementNetwork	ovirtmgmt	general
192	MaxAuditLogMessageLength	10000	general
193	MaxBlockDiskSize	8192	general
194	MaxLDAPQueryPartsNumber	100	general
195	MaxMacsCountInPool	100000	general
196	MaxNumberOfHostsInStoragePool	250	general
197	MaxNumOfCpuPerSocket	16	3.0
198	MaxNumOfCpuPerSocket	16	3.1
167	IPTablesConfigForVirt	\n# libvirt tls\n-A INPUT -p tcp --dport 16514 -j ACCEPT\n\n# guest consoles\n-A INPUT -p tcp -m multiport --dports 5900:6923 -j ACCEPT\n\n# migration\n-A INPUT -p tcp -m multiport --dports 49152:49216 -j ACCEPT\n	general
168	IsMultilevelAdministrationOn	true	general
116	MigrationSupportForNativeUsb	false	3.0
117	MigrationSupportForNativeUsb	false	3.1
120	DisconnectPoolOnReconstruct	0,2,3	general
175	LDAPSecurityAuthentication		general
178	LDAPProviderTypes		general
189	MacPoolRanges	00:1a:4a:d6:ee:00-00:1a:4a:d6:ee:ff	general
183	LocalAdminPassword	JJJJJJJJJJJ	general
200	MaxNumOfCpuPerSocket	16	3.3
201	MaxNumOfCpuPerSocket	16	3.4
205	MaxNumOfVmCpus	160	3.3
206	MaxNumOfVmCpus	160	3.4
207	MaxNumOfVmSockets	16	3.0
208	MaxNumOfVmSockets	16	3.1
209	MaxNumOfVmSockets	16	3.2
210	MaxNumOfVmSockets	16	3.3
211	MaxNumOfVmSockets	16	3.4
212	MaxRerunVmOnVdsCount	3	general
213	MaxStorageVdsDelayCheckSec	5	general
214	MaxStorageVdsTimeoutCheckSec	30	general
215	MaxVdsMemOverCommit	200	general
216	MaxVdsMemOverCommitForServers	150	general
217	MaxVdsNameLength	255	general
218	MaxVmNameLengthNonWindows	64	general
219	MaxVmNameLengthWindows	15	general
220	MaxVmsInPool	1000	general
222	NativeUSBEnabled	false	3.0
223	NicDHCPDelayGraceInMS	60	general
224	NonVmNetworkSupported	false	3.0
225	NumberOfFailedRunsOnVds	3	general
226	NumberOfUSBSlots	4	general
227	NumberVmRefreshesBeforeSave	5	general
228	SupportBridgesReportByVDSM	false	3.0
230	EnableMACAntiSpoofingFilterRules	false	3.0
231	EnableMACAntiSpoofingFilterRules	false	3.1
232	GlusterFsStorageEnabled	false	3.0
233	GlusterFsStorageEnabled	false	3.1
234	GlusterFsStorageEnabled	false	3.2
235	MaxSchedulerWeight	1000	general
236	MTUOverrideSupported	false	3.0
237	PortMirroringSupported	false	3.0
238	PortMirroringSupported	false	3.1
239	SpeedOptimizationSchedulingThreshold	10	general
240	SchedulerAllowOverBooking	false	general
241	SchedulerOverBookingThreshold	10	general
243	OriginType	OVIRT	general
244	OvfVirtualSystemType	ENGINE	general
249	oVirtUpgradeScriptName	/usr/share/vdsm-reg/vdsm-upgrade	general
250	oVirtUploadPath	/data/updates/ovirt-node-image.iso	general
251	OvfUpdateIntervalInMinutes	60	general
252	OvfItemsCountPerUpdate	100	general
253	PayloadSize	8192	general
254	PosixStorageEnabled	false	3.0
255	PostgresI18NPrefix		general
256	PostgresLikeSyntax	ILIKE	general
258	PostgresPagingType	Offset	general
260	PredefinedVMProperties	sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$	3.0
261	PredefinedVMProperties	sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$	3.1
262	PredefinedVMProperties	sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$	3.2
263	PredefinedVMProperties	sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$	3.3
264	PredefinedVMProperties	sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$	3.4
266	QuotaGraceStorage	20	general
267	QuotaGraceVdsGroup	20	general
268	QuotaThresholdStorage	80	general
269	QuotaThresholdVdsGroup	80	general
270	RedirectServletReportsPage		general
272	SANWipeAfterDelete	false	general
273	SASL_QOP	auth-conf	general
274	SearchResultsLimit	100	general
275	SendSMPOnRunVm	true	general
276	SendVmTicketUID	false	3.0
442	ScaleDownForHaReservation	1	general
443	EnableVdsHaReservation	true	general
444	VdsHaReservationIntervalInMinutes	5	general
203	MaxNumOfVmCpus	160	3.1
204	MaxNumOfVmCpus	160	3.2
221	MinimalETLVersion	3.4.0	general
245	OvirtInitialSupportedIsoVersion	2.5.5:5.8	general
247	OvirtNodeOS	^ovirt.*$:^rhev.*$	general
248	oVirtISOsRepositoryPath	/usr/share/ovirt-node-iso:/usr/share/rhev-hypervisor	general
257	PostgresPagingSyntax	OFFSET (%1$s -1) LIMIT %2$s	general
259	PostgresSearchTemplate	SELECT * FROM (%2$s) %1$s) as T1 %3$s	general
271	RhevhLocalFSPath	/data/images/rhev	general
278	ServerCPUList	3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64;	3.1
229	SupportBridgesReportByVDSM	false	3.1
242	OrganizationName	satservizi.eu	general
265	ProductRPMVersion	3.4.0-0.9.beta3.el6	general
281	ServerCPUList	3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:smx,nx,model_Opteron_G5:Opteron_G5:x86_64; :IBM POWER 7 v2.0:powernv,model_POWER7_v2.0:POWER7_v2.0:ppc64; :IBM POWER 7 v2.1:powernv,model_POWER7_v2.1:POWER7_v2.1:ppc64; :IBM POWER 7 v2.3:powernv,model_POWER7_v2.3:POWER7_v2.3:ppc64; :IBM POWER 7+ v2.1:powernv,model_POWER7+_v2.1:POWER7+_v2.1:ppc64; :IBM POWER 8 v1.0:powernv,model_POWER8_v1.0:POWER8_v1.0:ppc64;	3.4
282	ServerRebootTimeout	300	general
283	SetupNetworksPollingTimeout	3	general
284	ShareableDiskEnabled	false	3.0
285	SignCertTimeoutInSeconds	30	general
287	SpiceReleaseCursorKeys	shift+f12	general
288	SpiceToggleFullScreenKeys	shift+f11	general
289	SpiceUsbAutoShare	true	general
290	WANDisableEffects	animation	general
291	WANColorDepth	16	general
292	SpmCommandFailOverRetries	3	general
293	SPMFailOverAttempts	3	general
294	SpmVCpuConsumption	1	general
295	SSHInactivityTimoutSeconds	300	general
296	SSHInactivityHardTimoutSeconds	1800	general
298	StorageDomainFalureTimeoutInMinutes	5	general
299	StorageDomainNameSizeLimit	50	general
300	StoragePoolNameSizeLimit	40	general
301	StoragePoolNonOperationalResetTimeoutInMin	3	general
302	StoragePoolRefreshTimeInSeconds	10	general
303	SucceededJobCleanupTimeInMinutes	10	general
305	SupportedStorageFormats	0,2	3.0
306	SupportedStorageFormats	0,2,3	3.1
307	SupportedStorageFormats	0,2,3	3.2
308	SupportedStorageFormats	0,2,3	3.3
309	SupportedStorageFormats	0,2,3	3.4
311	SupportForceCreateVG	false	3.0
312	SupportForceExtendVG	false	3.0
313	SupportForceExtendVG	false	3.1
314	SysPrep2K3Path	/etc/ovirt-engine/sysprep/sysprep.2k3	general
315	SysPrep2K8Path	/etc/ovirt-engine/sysprep/sysprep.2k8x86	general
316	SysPrep2K8R2Path	/etc/ovirt-engine/sysprep/sysprep.2k8	general
317	SysPrep2K8x64Path	/etc/ovirt-engine/sysprep/sysprep.2k8	general
318	SysPrepDefaultPassword		general
319	SysPrepDefaultUser		general
320	SysPrepWindows7Path	/etc/ovirt-engine/sysprep/sysprep.w7	general
321	SysPrepWindows7x64Path	/etc/ovirt-engine/sysprep/sysprep.w7x64	general
322	SysPrepWindows8Path	/etc/ovirt-engine/sysprep/sysprep.w8	general
323	SysPrepWindows8x64Path	/etc/ovirt-engine/sysprep/sysprep.w8x64	general
324	SysPrepWindows2012x64Path	/etc/ovirt-engine/sysprep/sysprep.2k12x64	general
325	SysPrepXPPath	/etc/ovirt-engine/sysprep/sysprep.xp	general
326	ThrottlerMaxWaitForVdsUpdateInMillis	10000	general
327	TimeoutToResetVdsInSeconds	60	general
328	DelayResetForSpmInSeconds	20	general
329	DelayResetPerVmInSeconds	0.5	general
331	TimeToReduceFailedRunOnVdsInMinutes	30	general
332	UknownTaskPrePollingLapse	60000	general
333	UserDefinedVMProperties		3.0
334	UserDefinedVMProperties		3.1
335	UserDefinedVMProperties		3.2
336	UserDefinedVMProperties		3.3
337	UserDefinedVMProperties		3.4
338	UserRefreshRate	3600	general
339	UserSessionTimeOutInterval	30	general
340	UtilizationThresholdInPercent	80	general
341	ValidNumOfMonitors	1,2,4	general
342	VcpuConsumptionPercentage	10	general
344	VDSAttemptsToResetCount	2	general
345	VdsCertificateValidityInYears	5	general
346	vdsConnectionTimeout	2	general
286	SpiceDriverNameInGuest	{"windows": "RHEV-Spice", "linux" : "xorg-x11-drv-qxl" }	general
304	SupportedClusterLevels	3.0,3.1,3.2,3.3,3.4	general
310	SupportedVDSMVersions	4.9,4.10,4.11,4.12,4.13	general
343	VdcVersion	3.4.0.0	general
347	VdsFenceOptionMapping	alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port	3.0
348	VdsFenceOptionMapping	alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port	3.1
349	VdsFenceOptionMapping	apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port	3.2
297	SSLEnabled	true	general
330	EncryptHostCommunication	true	general
353	VdsFenceOptionTypes	secure=bool,port=int,slot=int	general
357	VdsFenceType	apc,apc_snmp,bladecenter,cisco_ucs,drac5,eps,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti	3.3
359	VdsLoadBalancingeIntervalInMinutes	1	general
362	VdsRecoveryTimeoutInMintues	3	general
364	vdsRetries	0	general
365	VdsSelectionAlgorithm	None	general
366	vdsTimeout	180	general
367	VM32BitMaxMemorySizeInMB	20480	general
368	VM64BitMaxMemorySizeInMB	524288	3.0
372	VM64BitMaxMemorySizeInMB	2097152	3.4
374	VmGracefulShutdownTimeout	30	general
375	VMMinMemorySizeInMB	256	general
376	VmPoolMaxSubsequentFailures	3	general
377	VmPoolMonitorBatchSize	5	general
378	VmPoolMonitorIntervalInMinutes	5	general
379	VmPoolMonitorMaxAttempts	3	general
380	VmPriorityMaxValue	100	general
382	RetryToRunAutoStartVmIntervalInSeconds	30	general
383	MaxNumOfTriesToRunFailedAutoStartVm	10	general
384	VncKeyboardLayout	en-us	general
385	VncKeyboardLayoutValidValues	ar,da,de,de-ch,en-gb,en-us,es,et,fi,fo,fr,fr-be,fr-ca,fr-ch,hr,hu,is,it,ja,lt,lv,mk,nl,nl-be,no,pl,pt,pt-br,ru,sl,sv,th,tr	general
386	WaitForVdsInitInSec	60	general
387	NetworkConnectivityCheckTimeoutInSeconds	120	general
389	ClientModeSpiceDefault	Auto	general
390	ClientModeVncDefault	Native	general
391	ClientModeRdpDefault	Auto	general
392	UseFqdnForRdpIfAvailable	true	general
394	WebSocketProxyTicketValiditySeconds	120	general
395	LogMaxPhysicalMemoryUsedThresholdInPercentage	95	general
396	LogMaxCpuUsedThresholdInPercentage	95	general
397	LogMaxNetworkUsedThresholdInPercentage	95	general
398	LogMinFreeSwapThresholdInMB	256	general
399	LogMaxSwapUsedThresholdInPercentage	95	general
400	SupportCustomDeviceProperties	false	3.0
401	SupportCustomDeviceProperties	false	3.1
402	SupportCustomDeviceProperties	false	3.2
403	CustomDeviceProperties		3.0
404	CustomDeviceProperties		3.1
405	CustomDeviceProperties		3.2
406	CustomDeviceProperties		3.3
408	SshSoftFencingCommand	service vdsmd restart	3.0
409	SshSoftFencingCommand	service vdsmd restart	3.1
410	SshSoftFencingCommand	service vdsmd restart	3.2
411	SshSoftFencingCommand	/usr/bin/vdsm-tool service-restart vdsmd	3.3
412	SshSoftFencingCommand	/usr/bin/vdsm-tool service-restart vdsmd	3.4
413	SecureConnectionWithOATServers	true	general
414	PollUri	AttestationService/resources/PollHosts	general
415	AttestationTruststore	TrustStore.jks	general
416	AttestationPort	8443	general
417	AttestationTruststorePass		general
419	AttestationFirstStageSize	10	general
420	MaxAverageNetworkQoSValue	1024	general
421	MaxPeakNetworkQoSValue	2048	general
422	MaxBurstNetworkQoSValue	10240	general
423	UserMessageOfTheDay		general
424	QoSInboundAverageDefaultValue	10	general
425	QoSInboundPeakDefaultValue	10	general
426	QoSInboundBurstDefaultValue	100	general
427	QoSOutboundAverageDefaultValue	10	general
428	QoSOutboundPeakDefaultValue	10	general
429	QoSOutboundBurstDefaultValue	100	general
430	SingleQxlPciEnabled	false	3.0
431	SingleQxlPciEnabled	false	3.1
432	SingleQxlPciEnabled	false	3.2
433	ExternalSchedulerServiceURL	http://localhost:18781/	general
434	ExternalSchedulerConnectionTimeout	100	general
435	ExternalSchedulerEnabled	false	general
436	ExternalSchedulerResponseTimeout	120000	general
437	DwhHeartBeatInterval	30	general
438	DisconnectDwh	0	general
439	GlanceImageListSize	20	general
440	GlanceImageTotalListSize	500	general
441	OverUtilizationForHaReservation	200	general
351	VdsFenceOptionMapping	apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;drac7:;eps:slot=port;hpblade:port=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port	3.4
354	VdsFenceType	alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs	3.0
355	VdsFenceType	alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs	3.1
356	VdsFenceType	apc,apc_snmp,bladecenter,cisco_ucs,drac5,eps,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti	3.2
358	VdsFenceType	apc,apc_snmp,bladecenter,cisco_ucs,drac5,drac7,eps,hpblade,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti	3.4
363	VdsRefreshRate	3	general
373	VmGracefulShutdownMessage	System Administrator has initiated shutdown of this Virtual Machine. Virtual Machine is shutting down.	general
369	VM64BitMaxMemorySizeInMB	2097152	3.1
370	VM64BitMaxMemorySizeInMB	2097152	3.2
371	VM64BitMaxMemorySizeInMB	2097152	3.3
381	AutoStartVmsRunnerIntervalInSeconds	1	general
407	CustomDeviceProperties	{type=interface;prop={SecurityGroups=^(?:(?:[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}, *)*[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}|)$}}	3.4
360	VdsLocalDisksCriticallyLowFreeSpace	500	general
361	VdsLocalDisksLowFreeSpace	1000	general
418	AttestationServer		general
393	WebSocketProxy	Engine:6100	general
445	DefaultMaximumMigrationDowntime	0	general
446	ChangePasswordMsg		general
388	AutoRecoveryAllowedTypes	{"storage domains":"true","hosts":"true"}	general
6	BootstrapMinimalVdsmVersion	4.9	general
61	FenceAgentDefaultParams	ilo3:lanplus,power_wait=4;ilo4:lanplus,power_wait=4	general
165	IPTablesConfig	\n# oVirt default firewall configuration. Automatically generated by vdsm bootstrap script.\n*filter\n:INPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT\n\n-A INPUT -i lo -j ACCEPT\n# vdsm\n-A INPUT -p tcp --dport @VDSM_PORT@ -j ACCEPT\n# SSH\n-A INPUT -p tcp --dport @SSH_PORT@ -j ACCEPT\n# snmp\n-A INPUT -p udp --dport 161 -j ACCEPT\n\n@CUSTOM_RULES@\n\n# Reject any other input traffic\n-A INPUT -j REJECT --reject-with icmp-host-prohibited\n-A FORWARD -m physdev ! --physdev-is-bridged -j REJECT --reject-with icmp-host-prohibited\nCOMMIT\n	general
166	IPTablesConfigForGluster	\n# glusterd\n-A INPUT -p tcp -m tcp --dport 24007 -j ACCEPT\n\n# gluster swift\n-A INPUT -p tcp -m tcp --dport 8080  -j ACCEPT\n\n# portmapper\n-A INPUT -p udp -m udp --dport 111   -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 38465 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 38466 -j ACCEPT\n\n# nfs\n-A INPUT -p tcp -m tcp --dport 111   -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 38467 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 2049  -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 38469 -j ACCEPT\n\n# status\n-A INPUT -p tcp -m tcp --dport 39543 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 55863 -j ACCEPT\n\n# nlockmgr\n-A INPUT -p tcp -m tcp --dport 38468 -j ACCEPT\n-A INPUT -p udp -m udp --dport 963   -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 965   -j ACCEPT\n\n# ctdbd\n-A INPUT -p tcp -m tcp --dport 4379  -j ACCEPT\n\n# smbd\n-A INPUT -p tcp -m tcp --dport 139   -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 445   -j ACCEPT\n\n# Ports for gluster volume bricks (default 100 ports)\n-A INPUT -p tcp -m tcp --dport 24009:24108 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 49152:49251 -j ACCEPT\n	general
202	MaxNumOfVmCpus	64	3.0
246	OvirtIsoPrefix	^ovirt-node-iso-(.*).*.iso$:^rhevh-(.*).*.iso$	general
277	ServerCPUList	3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64;	3.0
279	ServerCPUList	3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:smx,nx,model_Opteron_G5:Opteron_G5:x86_64;	3.2
280	ServerCPUList	3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:smx,nx,model_Opteron_G5:Opteron_G5:x86_64; :IBM POWER 7 v2.0:powernv,model_POWER7_v2.0:POWER7_v2.0:ppc64; :IBM POWER 7 v2.1:powernv,model_POWER7_v2.1:POWER7_v2.1:ppc64; :IBM POWER 7 v2.3:powernv,model_POWER7_v2.3:POWER7_v2.3:ppc64; :IBM POWER 7+ v2.1:powernv,model_POWER7+_v2.1:POWER7+_v2.1:ppc64; :IBM POWER 8 v1.0:powernv,model_POWER8_v1.0:POWER8_v1.0:ppc64;	3.3
350	VdsFenceOptionMapping	apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port	3.3
447	SpiceSecureChannels	smain,sinputs	3.0
448	SpiceSecureChannels	smain,sinputs,scursor,splayback,srecord,sdisplay,susbredir,ssmartcard	3.1
449	SpiceSecureChannels	smain,sinputs,scursor,splayback,srecord,sdisplay,susbredir,ssmartcard	3.2
450	SpiceSecureChannels	smain,sinputs,scursor,splayback,srecord,sdisplay,susbredir,ssmartcard	3.3
451	SpiceSecureChannels	smain,sinputs,scursor,splayback,srecord,sdisplay,susbredir,ssmartcard	3.4
452	PgMajorRelease	8	general
10	AdminPassword	ZZZZZZZZ	general
\.


--
-- Data for Name: vds_dynamic; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_dynamic (vds_id, status, cpu_cores, cpu_model, cpu_speed_mh, if_total_speed, kvm_enabled, physical_mem_mb, mem_commited, vm_active, vm_count, vm_migrating, reserved_mem, guest_overhead, software_version, version_name, build_name, previous_status, cpu_flags, cpu_over_commit_time_stamp, vms_cores_count, pending_vcpus_count, cpu_sockets, net_config_dirty, supported_cluster_levels, host_os, kvm_version, spice_version, kernel_version, iscsi_initiator_name, transparent_hugepages_state, hooks, _update_date, non_operational_reason, pending_vmem_size, rpm_version, supported_engines, libvirt_version, cpu_threads, hw_manufacturer, hw_product_name, hw_version, hw_serial_number, hw_uuid, hw_family, hbas, supported_emulated_machines, gluster_version, controlled_by_pm_policy) FROM stdin;
8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	3	8	Intel(R) Xeon(R) CPU           E5504  @ 2.00GHz	2000	\N	t	40181	65	0	0	0	321	65	4.14	Snow Man	\N	0	fpu,vme,de,pse,tsc,msr,pae,mce,cx8,apic,sep,mtrr,pge,mca,cmov,pat,pse36,clflush,dts,acpi,mmx,fxsr,sse,sse2,ss,ht,tm,pbe,syscall,nx,rdtscp,lm,constant_tsc,arch_perfmon,pebs,bts,rep_good,xtopology,nonstop_tsc,aperfmperf,pni,dtes64,monitor,ds_cpl,vmx,est,tm2,ssse3,cx16,xtpr,pdcm,dca,sse4_1,sse4_2,popcnt,lahf_lm,dts,tpr_shadow,vnmi,flexpriority,ept,vpid,model_Nehalem,model_Conroe,model_coreduo,model_core2duo,model_Penryn,model_n270	2014-03-04 03:26:57.852+01	0	0	2	f	3.0,3.1,3.2,3.3,3.4	RHEL - 6 - 5.el6.centos.11.2	0.12.1.2 - 2.415.el6_5.4	0.12.4 - 6.el6_5.1	2.6.32 - 431.5.1.el6.x86_64	iqn.2013-11.priv7o.vbox70:00199967ec1a	2	{}	2014-03-04 03:26:57.867366+01	0	0	vdsm-4.14.3-0.el6	3.0,3.1,3.2,3.3,3.4	libvirt-0.10.2-29.el6_5.4	8	FUJITSU	PRIMERGY RX300 S5	GS01	YKJD004150	8d4639e5-8ed2-11de-a847-00199967ec1a	SERVER	{\n  "iSCSI" : [ "java.util.ArrayList", [ [ "java.util.HashMap", {\n    "InitiatorName" : "iqn.2013-11.priv7o.vbox70:00199967ec1a"\n  } ] ] ],\n  "FC" : [ "java.util.ArrayList", [ ] ]\n}	rhel6.5.0,pc,rhel6.4.0,rhel6.3.0,rhel6.2.0,rhel6.1.0,rhel6.0.0,rhel5.5.0,rhel5.4.4,rhel5.4.0	\N	t
39a203c0-e19d-49a7-9909-b713d0255d69	3	8	Intel(R) Xeon(R) CPU           E5504  @ 2.00GHz	2000	\N	t	40181	65	0	0	0	321	65	4.14	Snow Man	\N	0	fpu,vme,de,pse,tsc,msr,pae,mce,cx8,apic,sep,mtrr,pge,mca,cmov,pat,pse36,clflush,dts,acpi,mmx,fxsr,sse,sse2,ss,ht,tm,pbe,syscall,nx,rdtscp,lm,constant_tsc,arch_perfmon,pebs,bts,rep_good,xtopology,nonstop_tsc,aperfmperf,pni,dtes64,monitor,ds_cpl,vmx,est,tm2,ssse3,cx16,xtpr,pdcm,dca,sse4_1,sse4_2,popcnt,lahf_lm,dts,tpr_shadow,vnmi,flexpriority,ept,vpid,model_Nehalem,model_Conroe,model_coreduo,model_core2duo,model_Penryn,model_n270	\N	0	0	2	f	3.0,3.1,3.2,3.3,3.4	RHEL - 6 - 5.el6.centos.11.2	0.12.1.2 - 2.415.el6_5.4	0.12.4 - 6.el6_5.1	2.6.32 - 431.5.1.el6.x86_64	iqn.2013-11.priv7o.vbox60:00199967ebca	2	{}	2014-03-04 03:26:58.169899+01	0	0	vdsm-4.14.3-0.el6	3.0,3.1,3.2,3.3,3.4	libvirt-0.10.2-29.el6_5.4	8	FUJITSU	PRIMERGY RX300 S5	GS01	YKJD004148	b08b882e-8ed3-11de-a847-00199967ebca	SERVER	{\n  "iSCSI" : [ "java.util.ArrayList", [ [ "java.util.HashMap", {\n    "InitiatorName" : "iqn.2013-11.priv7o.vbox60:00199967ebca"\n  } ] ] ],\n  "FC" : [ "java.util.ArrayList", [ ] ]\n}	rhel6.5.0,pc,rhel6.4.0,rhel6.3.0,rhel6.2.0,rhel6.1.0,rhel6.0.0,rhel5.5.0,rhel5.4.4,rhel5.4.0	\N	t
\.


--
-- Data for Name: vds_groups; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_groups (vds_group_id, name, description, cpu_name, _create_date, _update_date, storage_pool_id, max_vds_memory_over_commit, compatibility_version, transparent_hugepages, migrate_on_error, virt_service, gluster_service, count_threads_as_cores, emulated_machine, trusted_service, tunnel_migration, cluster_policy_id, cluster_policy_custom_properties, enable_balloon, free_text_comment, detect_emulated_machine, architecture, optimization_type, spice_proxy, ha_reservation, enable_ksm) FROM stdin;
00000001-0001-0001-0001-00000000031e	Default	The default server cluster	Intel Nehalem Family	2014-02-23 15:40:43.988168+01	2014-02-23 17:14:21.44957+01	00000002-0002-0002-0002-000000000051	100	3.4	t	1	t	f	f	rhel6.5.0	f	f	b4ed2332-a7ac-4d5f-9596-99a439cb2812	{\n}	f	\N	f	1	0	\N	f	t
\.


--
-- Data for Name: vds_interface; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_interface (id, name, network_name, vds_id, mac_addr, is_bond, bond_name, bond_type, bond_opts, vlan_id, speed, addr, subnet, gateway, boot_protocol, type, _create_date, _update_date, mtu, bridged, labels, qos_overridden) FROM stdin;
50a80dfd-a65c-4123-8e91-65d0054c03a3	eth2	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:15:17:BF:C3:E2	f	bond1	\N	\N	\N	1000			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	9000	f	\N	f
6e2a1e38-cace-4c9e-b62e-880ef32a0d44	eth5	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	A0:36:9F:22:4A:35	f	bond0	\N	\N	\N	1000			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
bf7074c5-ff03-468c-90ae-762057b3a5a9	eth0	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:19:99:67:EC:1A	f	bond0	\N	\N	\N	1000			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
0d2c10d2-1d7b-45b8-ad59-ca8e7ee9f2f4	bond0.3300	b0br3300	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	\N	f	\N	\N	\N	3300	\N				0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	t	\N	f
c0b8a098-8331-45e5-a981-a91cb39801d2	bond3	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
fb36914e-6d1a-4980-9311-f4a6061ee048	bond0	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:19:99:67:eb:ca	t	\N	\N	mode=1 miimon=100 use_carrier=1 updelay=3500 downdelay=0 primary=eth0	\N	\N			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
1ead8563-2341-4f33-8fcc-1d39edd5321f	bond0.1	b0br1	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	\N	f	\N	\N	\N	1	\N	192.168.248.69	255.255.252.0	192.168.248.1	2	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	t	\N	f
0755dea1-d29a-4597-99e5-83b3fc3d16da	bond4	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
bc183db5-11a9-4096-aefd-adfeb09e62e1	bond0.3300	b0br3300	39a203c0-e19d-49a7-9909-b713d0255d69	\N	f	\N	\N	\N	3300	\N				0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	t	\N	f
f993a15d-1de0-49da-bc67-46f77960fe89	bond0.1	b0br1	39a203c0-e19d-49a7-9909-b713d0255d69	\N	f	\N	\N	\N	1	\N	192.168.248.68	255.255.252.0	192.168.248.1	2	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	t	\N	f
0d6eaa7c-04bd-4c5a-81b0-613cf8c24dd0	bond3	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
511804a8-6e85-4d55-ac57-182ffd1650d5	eth3	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:15:17:c4:96:e2	f	\N	\N	\N	\N	1000	192.168.246.64	255.255.255.0	\N	2	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
14ff419e-09ea-42e6-854f-55a44b1a3f80	eth4	\N	39a203c0-e19d-49a7-9909-b713d0255d69	a0:36:9f:22:4a:66	f	\N	\N	\N	\N	1000	192.168.246.65	255.255.255.0	\N	2	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
0122802c-ba66-4baa-82f4-2a0f708bbb21	bond1	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:19:99:67:ec:1b	t	\N	\N	mode=1 miimon=100 use_carrier=1 updelay=3500 downdelay=0 primary=eth2	\N	\N			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	9000	f	\N	f
a507297a-8329-4445-918c-5ff1168d1700	bond2	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
01c7b7d6-22d7-4f4f-aea4-a6505edd9a16	eth3	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:15:17:bf:c4:3c	f	\N	\N	\N	\N	1000	192.168.246.76	255.255.255.0	\N	2	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
429684ee-03f6-4f81-955e-7288e5950cb6	eth1	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:19:99:67:EB:CB	f	bond1	\N	\N	\N	1000			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	9000	f	\N	f
a0022c92-e148-4967-b75d-4cd575be1aa6	eth2	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:15:17:BF:C1:E8	f	bond1	\N	\N	\N	1000			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	9000	f	\N	f
58919f4a-4041-4c7a-9917-8d21421ff00d	bond1.244	ovirtmgmt	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	\N	f	\N	\N	\N	244	\N	192.168.244.69	255.255.254.0		2	2	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	9000	t	\N	f
d1d4b959-7a44-4746-b913-f86fdb83a866	bond0	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:19:99:67:ec:1a	t	\N	\N	mode=1 miimon=100 use_carrier=1 updelay=3500 downdelay=0 primary=eth0	\N	\N			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
c9548741-dcf6-4033-8730-25d8bf7dc387	eth4	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	a0:36:9f:22:4a:34	f	\N	\N	\N	\N	1000	192.168.246.77	255.255.255.0	\N	2	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	1500	f	\N	f
5ec04275-1049-4894-b1c5-ee204d6ee424	eth1	\N	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	00:19:99:67:EC:1B	f	bond1	\N	\N	\N	1000			\N	0	0	2014-02-23 17:14:17.547771+01	2014-03-03 15:53:20.555657+01	9000	f	\N	f
af9ccf78-2759-4a6c-a97a-a2641fe4fd8f	eth5	\N	39a203c0-e19d-49a7-9909-b713d0255d69	A0:36:9F:22:4A:67	f	bond0	\N	\N	\N	1000			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
66e014a6-5d2e-41cc-94a0-3c0884070257	eth0	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:19:99:67:EB:CA	f	bond0	\N	\N	\N	1000			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
1d93c123-0ba7-438a-b77d-9fc3dcf3b561	bond1.244	ovirtmgmt	39a203c0-e19d-49a7-9909-b713d0255d69	\N	f	\N	\N	\N	244	\N	192.168.244.68	255.255.254.0		2	2	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	9000	t	\N	f
3b384e14-301e-41ce-a4cb-6f892a952d4b	bond4	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
c9a1fa5e-36b7-46e4-bb95-9c6d6ec3572d	bond0.48	b0br48	39a203c0-e19d-49a7-9909-b713d0255d69	\N	f	\N	\N	\N	48	\N				0	0	2014-02-26 18:10:32.731241+01	2014-03-03 15:27:47.37259+01	1500	t	\N	f
44eb216c-f23b-4410-bca7-f8083f8a7b2d	bond1	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:19:99:67:eb:cb	t	\N	\N	mode=1 miimon=100 use_carrier=1 updelay=3500 downdelay=0 primary=eth2	\N	\N			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	9000	f	\N	f
160c655e-fafb-404a-a0c7-f5a08abb134b	bond2	\N	39a203c0-e19d-49a7-9909-b713d0255d69	00:00:00:00:00:00	t	\N	\N	\N	\N	\N			\N	0	0	2014-02-23 18:30:50.901237+01	2014-03-03 15:27:47.37259+01	1500	f	\N	f
54755230-8efa-4cec-a403-518893a8ee61	bond0.48	b0br48	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	\N	f	\N	\N	\N	48	\N				0	0	2014-02-26 18:13:33.399994+01	2014-03-03 15:53:20.555657+01	1500	t	\N	f
\.


--
-- Data for Name: vds_interface_statistics; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_interface_statistics (id, vds_id, rx_rate, tx_rate, rx_drop, tx_drop, iface_status, _update_date) FROM stdin;
58919f4a-4041-4c7a-9917-8d21421ff00d	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
0755dea1-d29a-4597-99e5-83b3fc3d16da	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	2	2014-03-04 03:26:57.881432+01
0d6eaa7c-04bd-4c5a-81b0-613cf8c24dd0	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	2	2014-03-04 03:26:57.881432+01
0122802c-ba66-4baa-82f4-2a0f708bbb21	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
d1d4b959-7a44-4746-b913-f86fdb83a866	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
50a80dfd-a65c-4123-8e91-65d0054c03a3	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
bf7074c5-ff03-468c-90ae-762057b3a5a9	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
a507297a-8329-4445-918c-5ff1168d1700	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	2	2014-03-04 03:26:57.881432+01
01c7b7d6-22d7-4f4f-aea4-a6505edd9a16	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
1ead8563-2341-4f33-8fcc-1d39edd5321f	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
54755230-8efa-4cec-a403-518893a8ee61	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
c9548741-dcf6-4033-8730-25d8bf7dc387	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
0d2c10d2-1d7b-45b8-ad59-ca8e7ee9f2f4	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
5ec04275-1049-4894-b1c5-ee204d6ee424	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
6e2a1e38-cace-4c9e-b62e-880ef32a0d44	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	0	0	0	0	1	2014-03-04 03:26:57.881432+01
c9a1fa5e-36b7-46e4-bb95-9c6d6ec3572d	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
a0022c92-e148-4967-b75d-4cd575be1aa6	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
3b384e14-301e-41ce-a4cb-6f892a952d4b	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	2	2014-03-04 03:26:58.180769+01
af9ccf78-2759-4a6c-a97a-a2641fe4fd8f	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
66e014a6-5d2e-41cc-94a0-3c0884070257	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
14ff419e-09ea-42e6-854f-55a44b1a3f80	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
429684ee-03f6-4f81-955e-7288e5950cb6	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
160c655e-fafb-404a-a0c7-f5a08abb134b	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	2	2014-03-04 03:26:58.180769+01
f993a15d-1de0-49da-bc67-46f77960fe89	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
bc183db5-11a9-4096-aefd-adfeb09e62e1	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
1d93c123-0ba7-438a-b77d-9fc3dcf3b561	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
511804a8-6e85-4d55-ac57-182ffd1650d5	39a203c0-e19d-49a7-9909-b713d0255d69	1	0	0	0	1	2014-03-04 03:26:58.180769+01
fb36914e-6d1a-4980-9311-f4a6061ee048	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
c0b8a098-8331-45e5-a981-a91cb39801d2	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	2	2014-03-04 03:26:58.180769+01
44eb216c-f23b-4410-bca7-f8083f8a7b2d	39a203c0-e19d-49a7-9909-b713d0255d69	0	0	0	0	1	2014-03-04 03:26:58.180769+01
\.


--
-- Data for Name: vds_spm_id_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_spm_id_map (storage_pool_id, vds_spm_id, vds_id) FROM stdin;
00000002-0002-0002-0002-000000000051	1	8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9
00000002-0002-0002-0002-000000000051	2	39a203c0-e19d-49a7-9909-b713d0255d69
\.


--
-- Data for Name: vds_static; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_static (vds_id, vds_name, ip, vds_unique_id, host_name, port, vds_group_id, server_ssl_enabled, vds_type, vds_strength, pm_type, pm_user, pm_password, pm_port, pm_options, pm_enabled, _create_date, _update_date, otp_validity, vds_spm_priority, recoverable, sshkeyfingerprint, pm_proxy_preferences, pm_secondary_ip, pm_secondary_type, pm_secondary_user, pm_secondary_password, pm_secondary_port, pm_secondary_options, pm_secondary_concurrent, console_address, ssh_username, ssh_port, free_text_comment, disable_auto_pm) FROM stdin;
8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	vbox70	vbox70-ilo.priv7o	8D4639E5-8ED2-11DE-A847-00199967EC1A	vbox70.clusterip.priv7o	54321	00000001-0001-0001-0001-00000000031e	t	0	100	ipmilan	YYYY	XXXXX	\N		t	2014-02-23 17:13:30.788584+01	2014-02-27 10:15:27.113518+01	0	5	t	b0:80:25:99:a0:77:7f:1a:16:ef:56:ce:f5:d4:9c:69	cluster,dc	\N	apc	\N	\N	\N		f	vbox70.priv7o	root	22	\N	f
39a203c0-e19d-49a7-9909-b713d0255d69	vbox60	vbox60-ilo.priv7o	B08B882E-8ED3-11DE-A847-00199967EBCA	vbox60.clusterip.priv7o	54321	00000001-0001-0001-0001-00000000031e	t	0	100	ipmilan	YYYY	XXXXX	\N		t	2014-02-23 18:30:01.932139+01	2014-02-27 11:33:52.987495+01	0	5	t	4f:25:6d:23:f2:bf:ad:c7:59:28:8c:4b:28:b8:86:68	cluster,dc	\N	apc	\N	\N	\N		f	vbox60.priv7o	root	22	\N	f
\.


--
-- Data for Name: vds_statistics; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vds_statistics (vds_id, cpu_idle, cpu_load, cpu_sys, cpu_user, usage_mem_percent, usage_cpu_percent, usage_network_percent, mem_available, mem_shared, swap_free, swap_total, ksm_cpu_percent, ksm_pages, ksm_state, _update_date, mem_free, ha_score, anonymous_hugepages) FROM stdin;
8d3d9bf1-9b7b-4a2c-95cc-0eefaf5b0eb9	99	78	0	0	2	0	0	39217	0	29999	29999	0	100	f	2014-03-04 03:26:57.876663+01	39473	0	68
39a203c0-e19d-49a7-9909-b713d0255d69	97	94	1	2	2	3	0	39157	0	29999	29999	0	100	f	2014-03-04 03:26:58.176369+01	39413	0	78
\.


--
-- Data for Name: vm_device; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_device (device_id, vm_id, type, device, address, boot_order, spec_params, is_managed, is_plugged, is_readonly, _create_date, _update_date, alias, custom_properties, snapshot_id) FROM stdin;
00000006-0006-0006-0006-000000000006	00000000-0000-0000-0000-000000000000	video	cirrus		\N	{ "vram" : "65536" }	t	\N	f	2013-12-25 21:54:23.416857+01	\N		\N	\N
0fba1f69-50ab-4f5c-a017-c3739bd6a0b5	63263ab7-b153-401d-98bf-baf0ee99d49b	balloon	memballoon	{bus=0x00, domain=0x0000, type=pci, slot=0x07, function=0x0}	0	{\n  "model" : "virtio"\n}	t	t	t	2014-02-24 14:44:21.187998+01	2014-02-28 18:36:36.113816+01	balloon0	\N	\N
3a900476-a5e1-48d0-b9c6-8956e9bfc0cc	63263ab7-b153-401d-98bf-baf0ee99d49b	disk	cdrom	{unit=0, bus=1, target=0, controller=0, type=drive}	2	{\n  "path" : ""\n}	t	t	t	2014-02-24 14:44:21.187998+01	2014-02-28 18:36:36.113816+01	ide0-1-0	\N	\N
9929e222-5896-41a3-a994-440e09c31026	63263ab7-b153-401d-98bf-baf0ee99d49b	video	qxl	{bus=0x00, domain=0x0000, type=pci, slot=0x02, function=0x0}	0	{\n  "ram" : "65536",\n  "vram" : "32768",\n  "heads" : "1"\n}	t	t	t	2014-02-24 14:44:21.187998+01	2014-02-28 18:36:36.113816+01	video0	\N	\N
745ed552-b70e-4ae4-afb4-e291f3ae68f7	63263ab7-b153-401d-98bf-baf0ee99d49b	disk	disk	{bus=0x00, domain=0x0000, type=pci, slot=0x05, function=0x0}	1	{\n}	t	t	f	2014-02-24 14:44:37.956039+01	2014-02-28 18:36:36.113816+01	virtio-disk0	\N	\N
9e21e76a-9655-4cd9-8644-de5ae1608a4d	63263ab7-b153-401d-98bf-baf0ee99d49b	channel	unix	{port=1, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	channel0	\N	\N
33853fe9-c162-4812-8c71-416aada74a93	63263ab7-b153-401d-98bf-baf0ee99d49b	channel	unix	{port=2, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	channel1	\N	\N
97cc74f6-5b2c-45ac-9f00-ed4f4a00e6ae	63263ab7-b153-401d-98bf-baf0ee99d49b	channel	spicevmc	{port=3, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	channel2	\N	\N
b01b980a-caa1-49ff-93be-f5424db6b1aa	63263ab7-b153-401d-98bf-baf0ee99d49b	controller	usb	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x2}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	usb0	\N	\N
54d35a2f-d44c-4f35-913e-32ab49021642	63263ab7-b153-401d-98bf-baf0ee99d49b	controller	ide	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x1}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	ide0	\N	\N
72b74170-1f3c-4276-9992-eb74db80d6ad	63263ab7-b153-401d-98bf-baf0ee99d49b	controller	virtio-serial	{bus=0x00, domain=0x0000, type=pci, slot=0x06, function=0x0}	0	{\n}	f	t	f	2014-02-28 18:36:36.130148+01	\N	virtio-serial0	\N	\N
e9a851df-ad72-4718-a343-bc9662944fe4	cb7a888c-29ed-478e-9c32-4e392d00f7c9	disk	disk	{bus=0x00, domain=0x0000, type=pci, slot=0x07, function=0x0}	1	{\n}	t	t	f	2014-02-28 16:42:30.863323+01	2014-03-01 12:00:33.754193+01	virtio-disk0	\N	\N
cf983b31-43e4-45c8-be10-28f6dd44ffbd	cb7a888c-29ed-478e-9c32-4e392d00f7c9	video	qxl	{bus=0x00, domain=0x0000, type=pci, slot=0x02, function=0x0}	0	{\n  "ram" : "65536",\n  "vram" : "32768",\n  "heads" : "1"\n}	t	t	t	2014-02-28 16:41:18.739437+01	2014-03-01 12:00:33.754193+01	video0	\N	\N
3f7c66a4-032c-411a-811e-d8646afe827e	cb7a888c-29ed-478e-9c32-4e392d00f7c9	disk	cdrom	{unit=0, bus=1, target=0, controller=0, type=drive}	0	{\n  "path" : ""\n}	t	t	t	2014-02-28 16:41:18.739437+01	2014-03-01 12:00:33.754193+01	ide0-1-0	\N	\N
69d73a56-92bf-4e1e-8bbd-81f491253724	c124be96-7cd5-4199-98d3-00b8993c5e1f	channel	unix	{port=1, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	channel0	\N	\N
82347c50-f873-4c7f-857c-67dd51b62dab	c124be96-7cd5-4199-98d3-00b8993c5e1f	video	qxl	{bus=0x00, domain=0x0000, type=pci, slot=0x02, function=0x0}	0	{\n  "ram" : "65536",\n  "vram" : "32768",\n  "heads" : "1"\n}	t	t	f	2014-02-26 14:11:37.368884+01	2014-02-28 18:36:01.947012+01	video0	\N	\N
a0dd1453-f5ee-4f78-b8b2-f178b23a2d97	c124be96-7cd5-4199-98d3-00b8993c5e1f	channel	unix	{port=2, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	channel1	\N	\N
4fc02653-70fc-4d06-a262-07533fd8ffbe	c124be96-7cd5-4199-98d3-00b8993c5e1f	channel	spicevmc	{port=3, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	channel2	\N	\N
0e8b5a4f-c0d4-4043-8784-47a9c2c0d208	c124be96-7cd5-4199-98d3-00b8993c5e1f	controller	usb	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x2}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	usb0	\N	\N
a2b8e575-79e7-4894-8ddd-603442cf0508	c124be96-7cd5-4199-98d3-00b8993c5e1f	controller	ide	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x1}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	ide0	\N	\N
81f7b3ee-095e-4304-8870-4d81cfb81552	c124be96-7cd5-4199-98d3-00b8993c5e1f	controller	virtio-serial	{bus=0x00, domain=0x0000, type=pci, slot=0x04, function=0x0}	0	{\n}	f	t	f	2014-02-28 18:36:01.971433+01	\N	virtio-serial0	\N	\N
faa397fd-8e72-459a-a5f4-594f7d007533	1a5142e6-47cd-4193-b446-c62e05bc5df6	disk	disk	{unit=0, bus=0, target=0, controller=0, type=drive}	1	{\n}	t	t	f	2014-02-27 15:25:53.209517+01	2014-02-28 18:36:05.128122+01	ide0-0-0	\N	\N
807b4e46-74e8-442d-ac97-7bd4bbefab01	1a5142e6-47cd-4193-b446-c62e05bc5df6	interface	bridge	{bus=0x00, domain=0x0000, type=pci, slot=0x03, function=0x0}	0	{\n}	t	t	f	2014-02-27 15:25:53.209517+01	2014-02-28 18:36:05.128122+01	net0	\N	\N
f61cb18c-9edb-48df-a921-ab759cd68808	1a5142e6-47cd-4193-b446-c62e05bc5df6	disk	cdrom	{unit=0, bus=1, target=0, controller=0, type=drive}	0	{\n  "path" : ""\n}	t	t	t	2014-02-27 15:25:53.209517+01	2014-02-28 18:36:05.128122+01	ide0-1-0	\N	\N
1caad5ea-38d3-4b41-b864-d2998a8a8ebd	c124be96-7cd5-4199-98d3-00b8993c5e1f	disk	disk	{unit=0, bus=0, target=0, controller=0, type=drive}	1	{\n}	t	t	f	2014-02-26 14:02:16.083784+01	2014-02-28 18:36:01.947012+01	ide0-0-0	\N	\N
4c8ef654-f151-4412-a064-19fdf1ab287f	63263ab7-b153-401d-98bf-baf0ee99d49b	interface	bridge	{bus=0x00, domain=0x0000, type=pci, slot=0x04, function=0x0}	0	{\n}	t	t	f	2014-02-24 14:51:37.778917+01	2014-02-28 18:36:36.113816+01	net0	\N	\N
3f7c2c60-ae86-48f8-87ec-9ce85d6366c7	c124be96-7cd5-4199-98d3-00b8993c5e1f	interface	bridge	{bus=0x00, domain=0x0000, type=pci, slot=0x03, function=0x0}	0	{\n}	t	t	f	2014-02-26 14:02:16.083784+01	2014-02-28 18:36:01.947012+01	net0	\N	\N
3dbd6163-fb09-4e56-8746-4743a72d02a2	63263ab7-b153-401d-98bf-baf0ee99d49b	controller	virtio-scsi	{bus=0x00, domain=0x0000, type=pci, slot=0x03, function=0x0}	0	{\n}	t	t	f	2014-02-24 14:44:21.187998+01	2014-02-28 18:36:36.113816+01	scsi0	\N	\N
8d590258-cd56-40bb-ab70-b652e88cde9d	cb7a888c-29ed-478e-9c32-4e392d00f7c9	interface	bridge	{bus=0x00, domain=0x0000, type=pci, slot=0x03, function=0x0}	0	{\n}	t	t	f	2014-02-28 16:41:19.069984+01	2014-03-01 12:00:33.754193+01	net0	\N	\N
54b4e759-f811-424d-9aca-5da6958e9e74	c124be96-7cd5-4199-98d3-00b8993c5e1f	disk	cdrom	{unit=0, bus=1, target=0, controller=0, type=drive}	0	{\n  "path" : ""\n}	t	t	t	2014-02-26 14:02:16.083784+01	2014-02-28 18:36:01.947012+01	ide0-1-0	\N	\N
b9e4f312-486d-4e45-81fd-cb89a3af7be3	cb7a888c-29ed-478e-9c32-4e392d00f7c9	balloon	memballoon	{bus=0x00, domain=0x0000, type=pci, slot=0x09, function=0x0}	0	{\n  "model" : "virtio"\n}	t	t	t	2014-02-28 16:41:18.739437+01	2014-03-01 12:00:33.754193+01	balloon0	\N	\N
33ddefc6-e78c-4d5e-b1af-bcf6ae88b6b4	cb7a888c-29ed-478e-9c32-4e392d00f7c9	controller	virtio-scsi	{bus=0x00, domain=0x0000, type=pci, slot=0x05, function=0x0}	0	{\n}	t	t	f	2014-02-28 16:41:18.739437+01	2014-03-01 12:00:33.754193+01	scsi0	\N	\N
5147580f-fe0b-4a59-9591-579322ddd9da	cb7a888c-29ed-478e-9c32-4e392d00f7c9	disk	disk	{bus=0x00, domain=0x0000, type=pci, slot=0x08, function=0x0}	0	{\n}	t	t	f	2014-02-28 16:43:39.900839+01	2014-03-01 12:00:33.754193+01	virtio-disk1	\N	\N
f8a2f53e-4455-469f-87f4-11e0566b03b0	cb7a888c-29ed-478e-9c32-4e392d00f7c9	interface	bridge	{bus=0x00, domain=0x0000, type=pci, slot=0x04, function=0x0}	0	{\n}	t	t	f	2014-02-28 16:41:19.323514+01	2014-03-01 12:00:33.754193+01	net1	\N	\N
74840c6f-b1ac-4b96-ba75-98a957a6e2b2	cb7a888c-29ed-478e-9c32-4e392d00f7c9	controller	usb	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x2}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	usb0	\N	\N
93af204e-5dfa-49b0-9ebc-d238939ea18d	cb7a888c-29ed-478e-9c32-4e392d00f7c9	controller	ide	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x1}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	ide0	\N	\N
3943cdf1-63bd-43bb-a96e-9ab6ae45b622	cb7a888c-29ed-478e-9c32-4e392d00f7c9	controller	virtio-serial	{bus=0x00, domain=0x0000, type=pci, slot=0x06, function=0x0}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	virtio-serial0	\N	\N
c409946d-4b11-4346-b79e-c191b1757f53	cb7a888c-29ed-478e-9c32-4e392d00f7c9	channel	unix	{port=1, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	channel0	\N	\N
5e32b6ab-0d43-4a17-a1bc-023e8dc7830a	cb7a888c-29ed-478e-9c32-4e392d00f7c9	channel	unix	{port=2, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	channel1	\N	\N
e6647e15-dccd-4d02-b0c7-403b95949156	cb7a888c-29ed-478e-9c32-4e392d00f7c9	channel	spicevmc	{port=3, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-03-01 12:00:33.761732+01	\N	channel2	\N	\N
ac399233-9e49-4c7a-a6b9-468cfbe46d24	1a5142e6-47cd-4193-b446-c62e05bc5df6	video	qxl	{bus=0x00, domain=0x0000, type=pci, slot=0x02, function=0x0}	0	{\n  "ram" : "65536",\n  "vram" : "32768",\n  "heads" : "1"\n}	t	t	f	2014-02-27 15:46:10.727912+01	2014-02-28 18:36:05.128122+01	video0	\N	\N
6fec6260-e8b5-47cd-9474-1260ef0589a1	1a5142e6-47cd-4193-b446-c62e05bc5df6	channel	unix	{port=1, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	channel0	\N	\N
91fa42ff-a1b6-467b-975f-f91a41bc0428	1a5142e6-47cd-4193-b446-c62e05bc5df6	channel	unix	{port=2, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	channel1	\N	\N
8f6956d3-bc07-4f5c-a705-f62002e0aa66	1a5142e6-47cd-4193-b446-c62e05bc5df6	channel	spicevmc	{port=3, bus=0, controller=0, type=virtio-serial}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	channel2	\N	\N
9fc0ac2d-1b11-467f-a71b-e4eded5ee69a	1a5142e6-47cd-4193-b446-c62e05bc5df6	controller	usb	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x2}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	usb0	\N	\N
00d3ebd5-2e5f-451c-8d9e-0aeb104f902b	1a5142e6-47cd-4193-b446-c62e05bc5df6	controller	ide	{bus=0x00, domain=0x0000, type=pci, slot=0x01, function=0x1}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	ide0	\N	\N
75569f9e-c201-4545-ae8d-0050212f1bee	1a5142e6-47cd-4193-b446-c62e05bc5df6	controller	virtio-serial	{bus=0x00, domain=0x0000, type=pci, slot=0x04, function=0x0}	0	{\n}	f	t	f	2014-02-28 18:36:05.145771+01	\N	virtio-serial0	\N	\N
\.


--
-- Data for Name: vm_dynamic; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_dynamic (vm_guid, status, vm_ip, vm_host, vm_pid, last_start_time, guest_cur_user_name, guest_last_login_time, guest_last_logout_time, guest_os, run_on_vds, migrating_to_vds, app_list, display, acpi_enable, session, display_ip, display_type, kvm_enable, display_secure_port, utc_diff, last_vds_run_on, client_ip, guest_requested_memory, hibernation_vol_handle, boot_sequence, exit_status, pause_status, exit_message, hash, console_user_id, guest_agent_nics_hash, console_cur_user_name, last_watchdog_event, last_watchdog_action, is_run_once, vm_fqdn, cpu_name, last_stop_time, current_cd) FROM stdin;
cb7a888c-29ed-478e-9c32-4e392d00f7c9	0	\N	nfs02.priv7o	\N	2014-03-01 12:00:27.189+01	\N	\N	\N	\N	\N	\N	kernel-2.6.32-431.5.1.el6,ovirt-guest-agent-1.0.8-1.el6,kernel-2.6.32-431.el6	5900	t	0	vbox70.priv7o	1	t	5901	-3	\N		\N		0	0	0	User shut down	998292859962162093	\N	1324297825	\N	\N	\N	f	\N	\N	2014-03-03 10:38:08.113+01	\N
c124be96-7cd5-4199-98d3-00b8993c5e1f	0	\N	\N	\N	2014-02-26 14:49:33.601+01	\N	\N	\N	\N	\N	\N		5902	t	0	vbox60.priv7o	1	t	5903	-5	\N	192.168.124.242	\N		0	0	0	User shut down	8089729872340065868	\N	0	\N	\N	\N	f	\N	\N	2014-03-03 10:38:13.311+01	\N
1a5142e6-47cd-4193-b446-c62e05bc5df6	0	\N	\N	\N	2014-02-27 15:47:13.053+01	\N	\N	\N	\N	\N	\N		5900	t	0	vbox60.priv7o	1	t	5901	-1	\N	192.168.124.242	\N		0	0	0	User shut down	1549346168572491657	\N	0	\N	\N	\N	f	\N	\N	2014-03-03 10:37:51.501+01	\N
63263ab7-b153-401d-98bf-baf0ee99d49b	0	\N	\N	\N	2014-02-24 15:10:26.051+01	\N	\N	\N	\N	\N	\N		5906	t	0	vbox60.priv7o	1	t	5907	0	\N	192.168.124.242	\N		0	0	0	User shut down	-4956845826274849249	\N	0	\N	\N	\N	f	\N	\N	2014-03-03 10:38:41.198+01	\N
\.


--
-- Data for Name: vm_guest_agent_interfaces; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_guest_agent_interfaces (vm_id, interface_name, mac_address, ipv4_addresses, ipv6_addresses) FROM stdin;
cb7a888c-29ed-478e-9c32-4e392d00f7c9	eth0	00:1a:4a:d6:ee:18	192.168.248.37	fe80::21a:4aff:fed6:ee18
cb7a888c-29ed-478e-9c32-4e392d00f7c9	eth1	00:1a:4a:d6:ee:19	192.168.244.12	fe80::21a:4aff:fed6:ee19
\.


--
-- Data for Name: vm_init; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_init (vm_id, host_name, domain, authorized_keys, regenerate_keys, time_zone, dns_servers, dns_search_domains, networks, password, winkey, custom_script) FROM stdin;
00000000-0000-0000-0000-000000000000	\N		\N	f	\N	\N	\N	\N	\N	\N	\N
\.


--
-- Data for Name: vm_interface; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_interface (id, vm_guid, vmt_guid, mac_addr, name, speed, type, _create_date, _update_date, linked, vnic_profile_id) FROM stdin;
4c8ef654-f151-4412-a064-19fdf1ab287f	63263ab7-b153-401d-98bf-baf0ee99d49b	\N	00:1a:4a:d6:ee:ef	nic1	1000	3	2014-02-24 14:51:37.778917+01	\N	t	506a337e-cefe-460b-8d48-245651383b37
3f7c2c60-ae86-48f8-87ec-9ce85d6366c7	c124be96-7cd5-4199-98d3-00b8993c5e1f	\N	52:54:00:9c:3e:b7	eth0	100	1	2014-02-26 14:02:16.049356+01	2014-02-26 18:14:12.795859+01	t	a0fd075f-3d5b-41d2-b21a-528b0fe1ac72
807b4e46-74e8-442d-ac97-7bd4bbefab01	1a5142e6-47cd-4193-b446-c62e05bc5df6	\N	52:54:00:9c:3e:b7	eth0	100	1	2014-02-27 15:25:53.037678+01	2014-02-27 15:46:11.025652+01	t	a0fd075f-3d5b-41d2-b21a-528b0fe1ac72
8d590258-cd56-40bb-ab70-b652e88cde9d	cb7a888c-29ed-478e-9c32-4e392d00f7c9	\N	00:1a:4a:d6:ee:18	nic1	1000	3	2014-02-28 16:41:19.069984+01	2014-02-28 16:41:19.510359+01	t	506a337e-cefe-460b-8d48-245651383b37
f8a2f53e-4455-469f-87f4-11e0566b03b0	cb7a888c-29ed-478e-9c32-4e392d00f7c9	\N	00:1a:4a:d6:ee:19	nic2	1000	3	2014-02-28 16:41:19.323514+01	2014-02-28 16:41:19.510359+01	t	0000000e-000e-000e-000e-0000000000c1
\.


--
-- Data for Name: vm_interface_statistics; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_interface_statistics (id, vm_id, rx_rate, tx_rate, rx_drop, tx_drop, iface_status, _update_date) FROM stdin;
4c8ef654-f151-4412-a064-19fdf1ab287f	63263ab7-b153-401d-98bf-baf0ee99d49b	0	0	0	0	0	2014-03-03 10:38:38.135926+01
807b4e46-74e8-442d-ac97-7bd4bbefab01	1a5142e6-47cd-4193-b446-c62e05bc5df6	0	0	0	0	0	2014-03-03 10:37:36.056761+01
8d590258-cd56-40bb-ab70-b652e88cde9d	cb7a888c-29ed-478e-9c32-4e392d00f7c9	0	0	0	0	0	2014-03-03 10:37:48.909491+01
f8a2f53e-4455-469f-87f4-11e0566b03b0	cb7a888c-29ed-478e-9c32-4e392d00f7c9	0	0	0	0	0	2014-03-03 10:37:48.909491+01
3f7c2c60-ae86-48f8-87ec-9ce85d6366c7	c124be96-7cd5-4199-98d3-00b8993c5e1f	0	0	0	0	0	2014-03-03 10:38:07.108016+01
\.


--
-- Data for Name: vm_ovf_generations; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_ovf_generations (vm_guid, storage_pool_id, ovf_generation) FROM stdin;
00000000-0000-0000-0000-000000000000	00000002-0002-0002-0002-000000000051	1
63263ab7-b153-401d-98bf-baf0ee99d49b	00000002-0002-0002-0002-000000000051	5
c124be96-7cd5-4199-98d3-00b8993c5e1f	00000002-0002-0002-0002-000000000051	7
1a5142e6-47cd-4193-b446-c62e05bc5df6	00000002-0002-0002-0002-000000000051	4
cb7a888c-29ed-478e-9c32-4e392d00f7c9	00000002-0002-0002-0002-000000000051	3
\.


--
-- Data for Name: vm_pool_map; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_pool_map (vm_pool_id, vm_guid) FROM stdin;
\.


--
-- Data for Name: vm_pools; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_pools (vm_pool_id, vm_pool_name, vm_pool_description, vm_pool_type, parameters, vds_group_id, prestarted_vms, max_assigned_vms_per_user, vm_pool_comment, spice_proxy) FROM stdin;
\.


--
-- Data for Name: vm_static; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_static (vm_guid, vm_name, mem_size_mb, vmt_guid, os, description, vds_group_id, creation_date, num_of_monitors, is_initialized, is_auto_suspend, num_of_sockets, cpu_per_socket, usb_policy, time_zone, is_stateless, fail_back, _create_date, _update_date, dedicated_vm_for_vds, auto_startup, vm_type, nice_level, default_boot_sequence, default_display_type, priority, iso_path, origin, initrd_url, kernel_url, kernel_params, migration_support, userdefined_properties, predefined_properties, min_allocated_mem, entity_type, child_count, template_status, quota_id, allow_console_reconnect, cpu_pinning, is_smartcard_enabled, host_cpu_flags, db_generation, is_delete_protected, is_disabled, is_run_and_pause, created_by_user_id, tunnel_migration, free_text_comment, single_qxl_pci, cpu_shares, vnc_keyboard_layout, instance_type_id, image_type_id, sso_method, original_template_id, original_template_name, migration_downtime, template_version_number, template_version_name) FROM stdin;
00000000-0000-0000-0000-000000000000	Blank	1024	00000000-0000-0000-0000-000000000000	0	Blank template	00000001-0001-0001-0001-00000000031e	2008-03-31 23:00:00+02	1	\N	f	1	1	1	\N	\N	f	2013-12-25 14:31:54.367179+01	2013-12-25 14:31:53.239308+01	\N	\N	0	0	0	1	0		0	\N	\N	\N	0	\N	\N	0	TEMPLATE	0	0	\N	f	\N	f	f	1	f	f	f	\N	\N	\N	f	0	\N	\N	\N	guest_agent	\N	\N	\N	1	base version
cb7a888c-29ed-478e-9c32-4e392d00f7c9	C6_nfs02	2024	00000000-0000-0000-0000-000000000000	19	\N	00000001-0001-0001-0001-00000000031e	2014-02-28 16:41:18.666+01	1	t	f	2	1	1	\N	f	f	2014-02-28 16:41:18.667332+01	\N	\N	t	1	0	0	1	1		3	\N	\N	\N	0			1024	VM	0	\N	\N	t		f	f	3	f	f	f	fdfc627c-d875-11e0-90f0-83df133b58cc	\N	\N	t	0	\N	\N	\N	guest_agent	00000000-0000-0000-0000-000000000000	Blank	\N	1	\N
c124be96-7cd5-4199-98d3-00b8993c5e1f	ayllok1	3024	00000000-0000-0000-0000-000000000000	5	Imported with virt-v2v	00000001-0001-0001-0001-00000000031e	2014-02-26 14:02:16.048+01	1	t	f	3	1	1	\N	f	f	2014-02-26 14:02:16.049356+01	2014-02-26 18:14:12.504809+01	\N	f	1	0	0	1	1		0	\N	\N	\N	0			2024	VM	0	\N	\N	f	\N	f	f	7	f	f	t	\N	\N	\N	t	0	\N	\N	\N	guest_agent	\N	\N	\N	1	\N
63263ab7-b153-401d-98bf-baf0ee99d49b	rh6prova1	2024	00000000-0000-0000-0000-000000000000	19	\N	00000001-0001-0001-0001-00000000031e	2014-02-24 14:44:21.164+01	1	t	f	2	1	1	\N	f	f	2014-02-24 14:44:21.16511+01	2014-02-24 14:52:08.235653+01	\N	t	1	0	0	1	1		3	\N	\N	\N	0			2024	VM	0	\N	\N	t		f	f	5	f	f	f	fdfc627c-d875-11e0-90f0-83df133b58cc	\N	\N	t	0	it	\N	\N	guest_agent	00000000-0000-0000-0000-000000000000	Blank	\N	1	\N
1a5142e6-47cd-4193-b446-c62e05bc5df6	ayllok2	3024	00000000-0000-0000-0000-000000000000	5	Imported with virt-v2v from raw-disk	00000001-0001-0001-0001-00000000031e	2014-02-27 15:25:53.031+01	1	t	f	3	1	1	\N	f	f	2014-02-27 15:25:53.037678+01	2014-02-27 15:46:58.116948+01	\N	f	1	0	0	1	1		0	\N	\N	\N	0			2024	VM	0	\N	\N	f	\N	f	f	4	f	f	t	\N	\N	\N	t	0	\N	\N	\N	guest_agent	\N	\N	\N	1	\N
\.


--
-- Data for Name: vm_statistics; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vm_statistics (vm_guid, cpu_user, cpu_sys, elapsed_time, usage_network_percent, usage_mem_percent, usage_cpu_percent, disks_usage, _update_date) FROM stdin;
1a5142e6-47cd-4193-b446-c62e05bc5df6	0	0	0	0	0	0	\N	2014-03-03 10:37:51.638178+01
cb7a888c-29ed-478e-9c32-4e392d00f7c9	0	0	0	0	0	0	\N	2014-03-03 10:38:08.21191+01
c124be96-7cd5-4199-98d3-00b8993c5e1f	0	0	0	0	0	0	\N	2014-03-03 10:38:13.433486+01
63263ab7-b153-401d-98bf-baf0ee99d49b	0	0	0	0	0	0	\N	2014-03-03 10:38:41.308501+01
\.


--
-- Data for Name: vnic_profiles; Type: TABLE DATA; Schema: public; Owner: engine
--

COPY vnic_profiles (id, name, network_id, port_mirroring, custom_properties, description, _create_date, _update_date, network_qos_id) FROM stdin;
0000000e-000e-000e-000e-0000000000c1	ovirtmgmt	00000000-0000-0000-0000-000000000009	f	\N	\N	2014-02-23 15:41:09.25577+01	\N	\N
506a337e-cefe-460b-8d48-245651383b37	b0br1	e3ea893b-1f4e-4697-9b27-756b7d4f3c47	f	\N	\N	2014-02-23 18:37:11.565135+01	\N	\N
f78c64c4-31ff-4e97-a93f-406c394ebfca	vlan1_100mb	e3ea893b-1f4e-4697-9b27-756b7d4f3c47	f	{\n}	\N	2014-02-23 21:25:04.263059+01	\N	ee8ad8b8-6b4e-4cf5-85af-14f00c4b622d
80d975fa-9138-49a7-8ef2-f27053b23ff4	b0br3300	3aa34709-4cf0-4cad-9f2d-7ded9f79f544	f	\N	\N	2014-02-24 16:01:23.391608+01	\N	\N
a0fd075f-3d5b-41d2-b21a-528b0fe1ac72	b0br48	74987b9e-82ce-4f67-a70a-c3a52bfb86d6	f	\N	\N	2014-02-26 18:06:14.271648+01	\N	\N
\.


--
-- Name: affinity_group_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY affinity_groups
    ADD CONSTRAINT affinity_group_pk PRIMARY KEY (id);


--
-- Name: cluster_policy_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY cluster_policies
    ADD CONSTRAINT cluster_policy_pk PRIMARY KEY (id);


--
-- Name: disk_lun_map_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_map_pk PRIMARY KEY (disk_id, lun_id);


--
-- Name: gluster_volumes_name_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT gluster_volumes_name_unique UNIQUE (cluster_id, vol_name);


--
-- Name: groups_domain_external_id_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY ad_groups
    ADD CONSTRAINT groups_domain_external_id_unique UNIQUE (domain, external_id);


--
-- Name: idx_gluster_volume_bricks_volume_server_brickdir; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT idx_gluster_volume_bricks_volume_server_brickdir UNIQUE (volume_id, server_id, brick_dir);


--
-- Name: idx_gluster_volume_options_volume_id_option_key; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT idx_gluster_volume_options_volume_id_option_key UNIQUE (volume_id, option_key);


--
-- Name: materialized_views_pkey; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY materialized_views
    ADD CONSTRAINT materialized_views_pkey PRIMARY KEY (mv_name);


--
-- Name: pk_action_version_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY action_version_map
    ADD CONSTRAINT pk_action_version_map PRIMARY KEY (action_type);


--
-- Name: pk_ad_group_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY ad_groups
    ADD CONSTRAINT pk_ad_group_id PRIMARY KEY (id);


--
-- Name: pk_async_tasks; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY async_tasks
    ADD CONSTRAINT pk_async_tasks PRIMARY KEY (task_id);


--
-- Name: pk_audit_log; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY audit_log
    ADD CONSTRAINT pk_audit_log PRIMARY KEY (audit_log_id);


--
-- Name: pk_bookmarks; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY bookmarks
    ADD CONSTRAINT pk_bookmarks PRIMARY KEY (bookmark_id);


--
-- Name: pk_custom_actions; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY custom_actions
    ADD CONSTRAINT pk_custom_actions PRIMARY KEY (action_name, tab);


--
-- Name: pk_disk_image_dynamic; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY disk_image_dynamic
    ADD CONSTRAINT pk_disk_image_dynamic PRIMARY KEY (image_id);


--
-- Name: pk_disks; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY base_disks
    ADD CONSTRAINT pk_disks PRIMARY KEY (disk_id);


--
-- Name: pk_event_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY event_map
    ADD CONSTRAINT pk_event_map PRIMARY KEY (event_up_name);


--
-- Name: pk_event_notification_methods; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY event_notification_methods
    ADD CONSTRAINT pk_event_notification_methods PRIMARY KEY (method_id);


--
-- Name: pk_event_subscriber; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT pk_event_subscriber PRIMARY KEY (subscriber_id, event_up_name, method_id, tag_name);


--
-- Name: pk_gluster_cluster_services; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_cluster_services
    ADD CONSTRAINT pk_gluster_cluster_services PRIMARY KEY (cluster_id, service_type);


--
-- Name: pk_gluster_hooks; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_hooks
    ADD CONSTRAINT pk_gluster_hooks PRIMARY KEY (id);


--
-- Name: pk_gluster_server; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_server
    ADD CONSTRAINT pk_gluster_server PRIMARY KEY (server_id);


--
-- Name: pk_gluster_server_services; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_server_services
    ADD CONSTRAINT pk_gluster_server_services PRIMARY KEY (id);


--
-- Name: pk_gluster_service_types; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_service_types
    ADD CONSTRAINT pk_gluster_service_types PRIMARY KEY (service_type);


--
-- Name: pk_gluster_services; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_services
    ADD CONSTRAINT pk_gluster_services PRIMARY KEY (id);


--
-- Name: pk_gluster_volume_access_protocols; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_access_protocols
    ADD CONSTRAINT pk_gluster_volume_access_protocols PRIMARY KEY (volume_id, access_protocol);


--
-- Name: pk_gluster_volume_bricks; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT pk_gluster_volume_bricks PRIMARY KEY (id);


--
-- Name: pk_gluster_volume_options; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT pk_gluster_volume_options PRIMARY KEY (id);


--
-- Name: pk_gluster_volume_transport_types; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volume_transport_types
    ADD CONSTRAINT pk_gluster_volume_transport_types PRIMARY KEY (volume_id, transport_type);


--
-- Name: pk_gluster_volumes; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT pk_gluster_volumes PRIMARY KEY (id);


--
-- Name: pk_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY business_entity_snapshot
    ADD CONSTRAINT pk_id PRIMARY KEY (id);


--
-- Name: pk_image_storage_domain_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT pk_image_storage_domain_map PRIMARY KEY (image_id, storage_domain_id);


--
-- Name: pk_images; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY images
    ADD CONSTRAINT pk_images PRIMARY KEY (image_guid);


--
-- Name: pk_iscsi_bonds; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY iscsi_bonds
    ADD CONSTRAINT pk_iscsi_bonds PRIMARY KEY (id);


--
-- Name: pk_iscsi_bonds_networks_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY iscsi_bonds_networks_map
    ADD CONSTRAINT pk_iscsi_bonds_networks_map PRIMARY KEY (iscsi_bond_id, network_id);


--
-- Name: pk_iscsi_bonds_storage_connections_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY iscsi_bonds_storage_connections_map
    ADD CONSTRAINT pk_iscsi_bonds_storage_connections_map PRIMARY KEY (iscsi_bond_id, connection_id);


--
-- Name: pk_jobs; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY job
    ADD CONSTRAINT pk_jobs PRIMARY KEY (job_id);


--
-- Name: pk_jobs_subject_entity; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY job_subject_entity
    ADD CONSTRAINT pk_jobs_subject_entity PRIMARY KEY (job_id, entity_id);


--
-- Name: pk_lun_storage_server_connection_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT pk_lun_storage_server_connection_map PRIMARY KEY (lun_id, storage_server_connection);


--
-- Name: pk_luns; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY luns
    ADD CONSTRAINT pk_luns PRIMARY KEY (lun_id);


--
-- Name: pk_network; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY network
    ADD CONSTRAINT pk_network PRIMARY KEY (id);


--
-- Name: pk_network_cluster; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT pk_network_cluster PRIMARY KEY (network_id, cluster_id);


--
-- Name: pk_network_qos_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY network_qos
    ADD CONSTRAINT pk_network_qos_id PRIMARY KEY (id);


--
-- Name: pk_object_column_white_list; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY object_column_white_list
    ADD CONSTRAINT pk_object_column_white_list PRIMARY KEY (object_name, column_name);


--
-- Name: pk_object_column_white_list_sql; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY object_column_white_list_sql
    ADD CONSTRAINT pk_object_column_white_list_sql PRIMARY KEY (object_name);


--
-- Name: pk_os_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY dwh_osinfo
    ADD CONSTRAINT pk_os_id PRIMARY KEY (os_id);


--
-- Name: pk_permissions_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY permissions
    ADD CONSTRAINT pk_permissions_id PRIMARY KEY (id);


--
-- Name: pk_quota; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY quota
    ADD CONSTRAINT pk_quota PRIMARY KEY (id);


--
-- Name: pk_quota_limitation; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT pk_quota_limitation PRIMARY KEY (id);


--
-- Name: pk_repo_file_meta_data; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY repo_file_meta_data
    ADD CONSTRAINT pk_repo_file_meta_data PRIMARY KEY (repo_domain_id, repo_image_id);


--
-- Name: pk_roles_groups; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY roles_groups
    ADD CONSTRAINT pk_roles_groups PRIMARY KEY (role_id, action_group_id);


--
-- Name: pk_roles_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY roles
    ADD CONSTRAINT pk_roles_id PRIMARY KEY (id);


--
-- Name: pk_snapshots; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY snapshots
    ADD CONSTRAINT pk_snapshots PRIMARY KEY (snapshot_id);


--
-- Name: pk_steps; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY step
    ADD CONSTRAINT pk_steps PRIMARY KEY (step_id);


--
-- Name: pk_storage; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY storage_domain_static
    ADD CONSTRAINT pk_storage PRIMARY KEY (id);


--
-- Name: pk_storage_domain_dynamic; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY storage_domain_dynamic
    ADD CONSTRAINT pk_storage_domain_dynamic PRIMARY KEY (id);


--
-- Name: pk_storage_domain_pool_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT pk_storage_domain_pool_map PRIMARY KEY (storage_id, storage_pool_id);


--
-- Name: pk_storage_pool; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY storage_pool
    ADD CONSTRAINT pk_storage_pool PRIMARY KEY (id);


--
-- Name: pk_storage_server; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY storage_server_connections
    ADD CONSTRAINT pk_storage_server PRIMARY KEY (id);


--
-- Name: pk_tags_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags
    ADD CONSTRAINT pk_tags_id PRIMARY KEY (tag_id);


--
-- Name: pk_tags_user_group_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT pk_tags_user_group_map PRIMARY KEY (tag_id, group_id);


--
-- Name: pk_tags_user_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT pk_tags_user_map PRIMARY KEY (tag_id, user_id);


--
-- Name: pk_tags_vds_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT pk_tags_vds_map PRIMARY KEY (tag_id, vds_id);


--
-- Name: pk_tags_vm_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT pk_tags_vm_map PRIMARY KEY (tag_id, vm_id);


--
-- Name: pk_tags_vm_pool_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT pk_tags_vm_pool_map PRIMARY KEY (tag_id, vm_pool_id);


--
-- Name: pk_users; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT pk_users PRIMARY KEY (user_id);


--
-- Name: pk_vdc_db_log; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vdc_db_log
    ADD CONSTRAINT pk_vdc_db_log PRIMARY KEY (error_id);


--
-- Name: pk_vdc_options; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vdc_options
    ADD CONSTRAINT pk_vdc_options PRIMARY KEY (option_id);


--
-- Name: pk_vds_dynamic; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_dynamic
    ADD CONSTRAINT pk_vds_dynamic PRIMARY KEY (vds_id);


--
-- Name: pk_vds_groups; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_groups
    ADD CONSTRAINT pk_vds_groups PRIMARY KEY (vds_group_id);


--
-- Name: pk_vds_interface; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_interface
    ADD CONSTRAINT pk_vds_interface PRIMARY KEY (id);


--
-- Name: pk_vds_interface_statistics; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_interface_statistics
    ADD CONSTRAINT pk_vds_interface_statistics PRIMARY KEY (id);


--
-- Name: pk_vds_spm_id_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT pk_vds_spm_id_map PRIMARY KEY (storage_pool_id, vds_spm_id);


--
-- Name: pk_vds_static; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_static
    ADD CONSTRAINT pk_vds_static PRIMARY KEY (vds_id);


--
-- Name: pk_vds_statistics; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_statistics
    ADD CONSTRAINT pk_vds_statistics PRIMARY KEY (vds_id);


--
-- Name: pk_vm_device; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_device
    ADD CONSTRAINT pk_vm_device PRIMARY KEY (device_id, vm_id);


--
-- Name: pk_vm_dynamic; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT pk_vm_dynamic PRIMARY KEY (vm_guid);


--
-- Name: pk_vm_init; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_init
    ADD CONSTRAINT pk_vm_init PRIMARY KEY (vm_id);


--
-- Name: pk_vm_interface; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT pk_vm_interface PRIMARY KEY (id);


--
-- Name: pk_vm_interface_statistics; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_interface_statistics
    ADD CONSTRAINT pk_vm_interface_statistics PRIMARY KEY (id);


--
-- Name: pk_vm_pool_map; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT pk_vm_pool_map PRIMARY KEY (vm_guid);


--
-- Name: pk_vm_pools; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_pools
    ADD CONSTRAINT pk_vm_pools PRIMARY KEY (vm_pool_id);


--
-- Name: pk_vm_static; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_static
    ADD CONSTRAINT pk_vm_static PRIMARY KEY (vm_guid);


--
-- Name: pk_vm_statistics; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_statistics
    ADD CONSTRAINT pk_vm_statistics PRIMARY KEY (vm_guid);


--
-- Name: pk_vnic_profiles_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vnic_profiles
    ADD CONSTRAINT pk_vnic_profiles_id PRIMARY KEY (id);


--
-- Name: policy_unit_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY policy_units
    ADD CONSTRAINT policy_unit_pk PRIMARY KEY (id);


--
-- Name: providers_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY providers
    ADD CONSTRAINT providers_pk PRIMARY KEY (id);


--
-- Name: quota_quota_name_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY quota
    ADD CONSTRAINT quota_quota_name_unique UNIQUE (quota_name);


--
-- Name: schema_version_primary_key; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY schema_version
    ADD CONSTRAINT schema_version_primary_key PRIMARY KEY (id);


--
-- Name: unique_gluster_server_services_server_service; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_server_services
    ADD CONSTRAINT unique_gluster_server_services_server_service UNIQUE (server_id, service_id);


--
-- Name: unique_gluster_services_type_name; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY gluster_services
    ADD CONSTRAINT unique_gluster_services_type_name UNIQUE (service_type, service_name);


--
-- Name: uq_command_id_entity_id; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY business_entity_snapshot
    ADD CONSTRAINT uq_command_id_entity_id UNIQUE (command_id, entity_id, entity_type, snapshot_type);


--
-- Name: users_domain_external_id_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_domain_external_id_unique UNIQUE (domain, external_id);


--
-- Name: vds_static_host_name_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_static_host_name_unique UNIQUE (host_name);


--
-- Name: vds_static_vds_name_unique; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_static_vds_name_unique UNIQUE (vds_name);


--
-- Name: vm_ovf_generations_pkey; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: 
--

ALTER TABLE ONLY vm_ovf_generations
    ADD CONSTRAINT vm_ovf_generations_pkey PRIMARY KEY (vm_guid);


--
-- Name: audit_log_origin_custom_event_id_idx; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE UNIQUE INDEX audit_log_origin_custom_event_id_idx ON audit_log USING btree (origin, custom_event_id) WHERE ((origin)::text !~~* 'ovirt'::text);


--
-- Name: idx_affinity_group_cluster_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_affinity_group_cluster_id ON affinity_groups USING btree (cluster_id);


--
-- Name: idx_audit_correlation_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_correlation_id ON audit_log USING btree (correlation_id);


--
-- Name: idx_audit_log_job_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_job_id ON audit_log USING btree (job_id);


--
-- Name: idx_audit_log_log_time; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_log_time ON audit_log USING btree (log_time);


--
-- Name: idx_audit_log_storage_domain_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_storage_domain_name ON audit_log USING btree (storage_domain_name);


--
-- Name: idx_audit_log_storage_pool_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_storage_pool_name ON audit_log USING btree (storage_pool_name);


--
-- Name: idx_audit_log_user_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_user_name ON audit_log USING btree (user_name);


--
-- Name: idx_audit_log_vds_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_vds_name ON audit_log USING btree (vds_name);


--
-- Name: idx_audit_log_vm_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_vm_name ON audit_log USING btree (vm_name);


--
-- Name: idx_audit_log_vm_template_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_audit_log_vm_template_name ON audit_log USING btree (vm_template_name);


--
-- Name: idx_business_entity_snapshot_command_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_business_entity_snapshot_command_id ON business_entity_snapshot USING btree (command_id);


--
-- Name: idx_combined_ad_role_object; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE UNIQUE INDEX idx_combined_ad_role_object ON permissions USING btree (ad_element_id, role_id, object_id);


--
-- Name: idx_gluster_bricks_task_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_bricks_task_id ON gluster_volume_bricks USING btree (task_id);


--
-- Name: idx_gluster_cluster_services_cluster_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_cluster_services_cluster_id ON gluster_cluster_services USING btree (cluster_id);


--
-- Name: idx_gluster_hooks_cluster_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_hooks_cluster_id ON gluster_hooks USING btree (cluster_id);


--
-- Name: idx_gluster_hooks_unique; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE UNIQUE INDEX idx_gluster_hooks_unique ON gluster_hooks USING btree (cluster_id, gluster_command, stage, name);


--
-- Name: idx_gluster_server_hooks_unique; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE UNIQUE INDEX idx_gluster_server_hooks_unique ON gluster_server_hooks USING btree (hook_id, server_id);


--
-- Name: idx_gluster_server_services_server_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_server_services_server_id ON gluster_server_services USING btree (server_id);


--
-- Name: idx_gluster_server_unique; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE UNIQUE INDEX idx_gluster_server_unique ON gluster_server USING btree (server_id, gluster_server_uuid);


--
-- Name: idx_gluster_volume_access_protocols_volume_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_volume_access_protocols_volume_id ON gluster_volume_access_protocols USING btree (volume_id);


--
-- Name: idx_gluster_volume_bricks_volume_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_volume_bricks_volume_id ON gluster_volume_bricks USING btree (volume_id);


--
-- Name: idx_gluster_volume_options_volume_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_volume_options_volume_id ON gluster_volume_options USING btree (volume_id);


--
-- Name: idx_gluster_volume_transport_types_volume_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_volume_transport_types_volume_id ON gluster_volume_transport_types USING btree (volume_id);


--
-- Name: idx_gluster_volumes_cluster_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_gluster_volumes_cluster_id ON gluster_volumes USING btree (cluster_id);


--
-- Name: idx_job_start_time; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_job_start_time ON job USING btree (start_time);


--
-- Name: idx_job_subject_entity_entity_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_job_subject_entity_entity_id ON job_subject_entity USING btree (entity_id);


--
-- Name: idx_network_external_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_network_external_id ON network USING btree (provider_network_external_id) WHERE (provider_network_external_id IS NOT NULL);


--
-- Name: idx_network_qos_storage_pool_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_network_qos_storage_pool_id ON network_qos USING btree (storage_pool_id);


--
-- Name: idx_network_storage_pool_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_network_storage_pool_id ON network USING btree (storage_pool_id);


--
-- Name: idx_permissions_ad_element_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_permissions_ad_element_id ON permissions USING btree (ad_element_id);


--
-- Name: idx_permissions_object_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_permissions_object_id ON permissions USING btree (object_id);


--
-- Name: idx_permissions_role_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_permissions_role_id ON permissions USING btree (role_id);


--
-- Name: idx_quota_limitation_quota_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_quota_limitation_quota_id ON quota_limitation USING btree (quota_id);


--
-- Name: idx_quota_limitation_storage_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_quota_limitation_storage_id ON quota_limitation USING btree (storage_id) WHERE (storage_id IS NOT NULL);


--
-- Name: idx_quota_limitation_vds_group_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_quota_limitation_vds_group_id ON quota_limitation USING btree (vds_group_id) WHERE (vds_group_id IS NOT NULL);


--
-- Name: idx_repo_file_file_type; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_repo_file_file_type ON repo_file_meta_data USING btree (file_type);


--
-- Name: idx_roles__app_mode; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_roles__app_mode ON roles USING btree (app_mode);


--
-- Name: idx_roles_groups_action_group_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_roles_groups_action_group_id ON roles_groups USING btree (action_group_id);


--
-- Name: idx_step_external_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_step_external_id ON step USING btree (external_id);


--
-- Name: idx_step_job_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_step_job_id ON step USING btree (job_id);


--
-- Name: idx_step_parent_step_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_step_parent_step_id ON step USING btree (parent_step_id);


--
-- Name: idx_storage_pool_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_storage_pool_id ON quota USING btree (storage_pool_id) WHERE (storage_pool_id IS NOT NULL);


--
-- Name: idx_vds_interface_vds_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vds_interface_vds_id ON vds_interface USING btree (vds_id);


--
-- Name: idx_vdsm_task_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vdsm_task_id ON async_tasks USING btree (vdsm_task_id);


--
-- Name: idx_vm_dynamic_run_on_vds; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_dynamic_run_on_vds ON vm_dynamic USING btree (run_on_vds);


--
-- Name: idx_vm_guest_agent_interfaces_vm_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_guest_agent_interfaces_vm_id ON vm_guest_agent_interfaces USING btree (vm_id);


--
-- Name: idx_vm_interface_vm_vmt_guid; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_interface_vm_vmt_guid ON vm_interface USING btree (vm_guid, vmt_guid);


--
-- Name: idx_vm_interface_vnic_profile_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_interface_vnic_profile_id ON vm_interface USING btree (vnic_profile_id);


--
-- Name: idx_vm_ovf_generations_storage_pool_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_ovf_generations_storage_pool_id ON vm_ovf_generations USING btree (storage_pool_id);


--
-- Name: idx_vm_ovf_generations_vm_guid; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_ovf_generations_vm_guid ON vm_ovf_generations USING btree (vm_guid);


--
-- Name: idx_vm_static_vm_name; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vm_static_vm_name ON vm_static USING btree (vm_name);


--
-- Name: idx_vnic_profiles_network_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vnic_profiles_network_id ON vnic_profiles USING btree (network_id);


--
-- Name: idx_vnic_profiles_network_qos_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX idx_vnic_profiles_network_qos_id ON vnic_profiles USING btree (network_qos_id);


--
-- Name: ix_vdc_options; Type: INDEX; Schema: public; Owner: engine; Tablespace: 
--

CREATE INDEX ix_vdc_options ON vdc_options USING btree (option_name);


--
-- Name: affinity_group_cluster_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY affinity_groups
    ADD CONSTRAINT affinity_group_cluster_id_fk FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: affinity_group_member_affinity_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY affinity_group_members
    ADD CONSTRAINT affinity_group_member_affinity_id_fk FOREIGN KEY (affinity_group_id) REFERENCES affinity_groups(id) ON DELETE CASCADE;


--
-- Name: affinity_group_member_vm_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY affinity_group_members
    ADD CONSTRAINT affinity_group_member_vm_id_fk FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: disk_lun_to_disk_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_to_disk_fk FOREIGN KEY (disk_id) REFERENCES base_disks(disk_id);


--
-- Name: disk_lun_to_lun_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_to_lun_fk FOREIGN KEY (lun_id) REFERENCES luns(lun_id);


--
-- Name: fk_async_task_entity; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY async_tasks_entities
    ADD CONSTRAINT fk_async_task_entity FOREIGN KEY (async_task_id) REFERENCES async_tasks(task_id) ON DELETE CASCADE;


--
-- Name: fk_cluster_policy_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY cluster_policy_units
    ADD CONSTRAINT fk_cluster_policy_id FOREIGN KEY (cluster_policy_id) REFERENCES cluster_policies(id) ON DELETE CASCADE;


--
-- Name: fk_disk_image_dynamic_images; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY disk_image_dynamic
    ADD CONSTRAINT fk_disk_image_dynamic_images FOREIGN KEY (image_id) REFERENCES images(image_guid) ON DELETE CASCADE;


--
-- Name: fk_event_notification_hist_audit_log; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY event_notification_hist
    ADD CONSTRAINT fk_event_notification_hist_audit_log FOREIGN KEY (audit_log_id) REFERENCES audit_log(audit_log_id) ON DELETE CASCADE;


--
-- Name: fk_event_notification_users; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY event_notification_hist
    ADD CONSTRAINT fk_event_notification_users FOREIGN KEY (subscriber_id) REFERENCES users(user_id) ON DELETE CASCADE;


--
-- Name: fk_event_subscriber_event_map; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_event_map FOREIGN KEY (event_up_name) REFERENCES event_map(event_up_name) ON DELETE CASCADE;


--
-- Name: fk_event_subscriber_event_notification_methods; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_event_notification_methods FOREIGN KEY (method_id) REFERENCES event_notification_methods(method_id) ON DELETE CASCADE;


--
-- Name: fk_event_subscriber_users; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_users FOREIGN KEY (subscriber_id) REFERENCES users(user_id) ON DELETE CASCADE;


--
-- Name: fk_image_storage_domain_map_images; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT fk_image_storage_domain_map_images FOREIGN KEY (image_id) REFERENCES images(image_guid) ON DELETE CASCADE;


--
-- Name: fk_image_storage_domain_map_quota; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT fk_image_storage_domain_map_quota FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE SET NULL;


--
-- Name: fk_image_storage_domain_map_storage_domain_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT fk_image_storage_domain_map_storage_domain_static FOREIGN KEY (storage_domain_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;


--
-- Name: fk_iscsi_bonds_networks_map_iscsi_bond_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY iscsi_bonds_networks_map
    ADD CONSTRAINT fk_iscsi_bonds_networks_map_iscsi_bond_id FOREIGN KEY (iscsi_bond_id) REFERENCES iscsi_bonds(id) ON DELETE CASCADE;


--
-- Name: fk_iscsi_bonds_networks_map_network_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY iscsi_bonds_networks_map
    ADD CONSTRAINT fk_iscsi_bonds_networks_map_network_id FOREIGN KEY (network_id) REFERENCES network(id) ON DELETE CASCADE;


--
-- Name: fk_iscsi_bonds_storage_connections_map_connection_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY iscsi_bonds_storage_connections_map
    ADD CONSTRAINT fk_iscsi_bonds_storage_connections_map_connection_id FOREIGN KEY (connection_id) REFERENCES storage_server_connections(id) ON DELETE CASCADE;


--
-- Name: fk_iscsi_bonds_storage_connections_map_iscsi_bond_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY iscsi_bonds_storage_connections_map
    ADD CONSTRAINT fk_iscsi_bonds_storage_connections_map_iscsi_bond_id FOREIGN KEY (iscsi_bond_id) REFERENCES iscsi_bonds(id) ON DELETE CASCADE;


--
-- Name: fk_iscsi_bonds_storage_pool; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY iscsi_bonds
    ADD CONSTRAINT fk_iscsi_bonds_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: fk_job_subject_entity_job; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY job_subject_entity
    ADD CONSTRAINT fk_job_subject_entity_job FOREIGN KEY (job_id) REFERENCES job(job_id) ON DELETE CASCADE;


--
-- Name: fk_lun_storage_server_connection_map_luns; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT fk_lun_storage_server_connection_map_luns FOREIGN KEY (lun_id) REFERENCES luns(lun_id) ON DELETE CASCADE;


--
-- Name: fk_lun_storage_server_connection_map_storage_server_connections; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT fk_lun_storage_server_connection_map_storage_server_connections FOREIGN KEY (storage_server_connection) REFERENCES storage_server_connections(id) ON DELETE CASCADE;


--
-- Name: fk_network_cluster_network; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT fk_network_cluster_network FOREIGN KEY (network_id) REFERENCES network(id) ON DELETE CASCADE;


--
-- Name: fk_network_cluster_vds_groups; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT fk_network_cluster_vds_groups FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: fk_network_provided_by; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network
    ADD CONSTRAINT fk_network_provided_by FOREIGN KEY (provider_network_provider_id) REFERENCES providers(id) ON DELETE CASCADE;


--
-- Name: fk_network_qos_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network
    ADD CONSTRAINT fk_network_qos_id FOREIGN KEY (qos_id) REFERENCES network_qos(id) ON DELETE SET NULL;


--
-- Name: fk_network_storage_pool; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network
    ADD CONSTRAINT fk_network_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE SET NULL;


--
-- Name: fk_permissions_roles; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY permissions
    ADD CONSTRAINT fk_permissions_roles FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;


--
-- Name: fk_policy_unit_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY cluster_policy_units
    ADD CONSTRAINT fk_policy_unit_id FOREIGN KEY (policy_unit_id) REFERENCES policy_units(id) ON DELETE CASCADE;


--
-- Name: fk_repo_file_meta_data_storage_domain_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY repo_file_meta_data
    ADD CONSTRAINT fk_repo_file_meta_data_storage_domain_static FOREIGN KEY (repo_domain_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;


--
-- Name: fk_roles_groups_action_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY roles_groups
    ADD CONSTRAINT fk_roles_groups_action_id FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;


--
-- Name: fk_snapshot_vm; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY snapshots
    ADD CONSTRAINT fk_snapshot_vm FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid);


--
-- Name: fk_step_job; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY step
    ADD CONSTRAINT fk_step_job FOREIGN KEY (job_id) REFERENCES job(job_id) ON DELETE CASCADE;


--
-- Name: fk_storage_domain_dynamic_storage_domain_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY storage_domain_dynamic
    ADD CONSTRAINT fk_storage_domain_dynamic_storage_domain_static FOREIGN KEY (id) REFERENCES storage_domain_static(id);


--
-- Name: fk_storage_domain_pool_map_storage_domain_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT fk_storage_domain_pool_map_storage_domain_static FOREIGN KEY (storage_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;


--
-- Name: fk_storage_domain_pool_map_storage_pool; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT fk_storage_domain_pool_map_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: fk_tags_vm_pool_map_tag; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT fk_tags_vm_pool_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id) ON DELETE CASCADE;


--
-- Name: fk_tags_vm_pool_map_vm_pool; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT fk_tags_vm_pool_map_vm_pool FOREIGN KEY (vm_pool_id) REFERENCES vm_pools(vm_pool_id) ON DELETE CASCADE;


--
-- Name: fk_vds_groups_storage_pool_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_groups
    ADD CONSTRAINT fk_vds_groups_storage_pool_id FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE SET NULL;


--
-- Name: fk_vds_groups_vm_pools; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_pools
    ADD CONSTRAINT fk_vds_groups_vm_pools FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);


--
-- Name: fk_vds_interface_statistics_vds_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_interface_statistics
    ADD CONSTRAINT fk_vds_interface_statistics_vds_static FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: fk_vds_interface_vds_interface; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_interface
    ADD CONSTRAINT fk_vds_interface_vds_interface FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: fk_vds_spm_id_map_storage_pool; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT fk_vds_spm_id_map_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: fk_vds_spm_id_map_vds_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT fk_vds_spm_id_map_vds_id FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: fk_vds_static_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_static
    ADD CONSTRAINT fk_vds_static_vm_static FOREIGN KEY (dedicated_vm_for_vds) REFERENCES vds_static(vds_id);


--
-- Name: fk_vm_device_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_device
    ADD CONSTRAINT fk_vm_device_vm_static FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: fk_vm_guest_agent_interfaces; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_guest_agent_interfaces
    ADD CONSTRAINT fk_vm_guest_agent_interfaces FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: fk_vm_interface_statistics_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_interface_statistics
    ADD CONSTRAINT fk_vm_interface_statistics_vm_static FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: fk_vm_interface_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT fk_vm_interface_vm_static FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: fk_vm_interface_vm_static_template; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT fk_vm_interface_vm_static_template FOREIGN KEY (vmt_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: fk_vm_interface_vnic_profile_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT fk_vm_interface_vnic_profile_id FOREIGN KEY (vnic_profile_id) REFERENCES vnic_profiles(id) ON DELETE SET NULL;


--
-- Name: fk_vm_static_quota; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_static
    ADD CONSTRAINT fk_vm_static_quota FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE SET NULL;


--
-- Name: fk_vnic_profiles_network_qos_id; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vnic_profiles
    ADD CONSTRAINT fk_vnic_profiles_network_qos_id FOREIGN KEY (network_qos_id) REFERENCES network_qos(id) ON DELETE SET NULL;


--
-- Name: gluster_cluster_services_cluster_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_cluster_services
    ADD CONSTRAINT gluster_cluster_services_cluster_id_fkey FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: gluster_cluster_services_service_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_cluster_services
    ADD CONSTRAINT gluster_cluster_services_service_type_fkey FOREIGN KEY (service_type) REFERENCES gluster_service_types(service_type) ON DELETE CASCADE;


--
-- Name: gluster_hooks_cluster_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_hooks
    ADD CONSTRAINT gluster_hooks_cluster_id_fkey FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: gluster_server_hooks_hook_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_server_hooks
    ADD CONSTRAINT gluster_server_hooks_hook_id_fkey FOREIGN KEY (hook_id) REFERENCES gluster_hooks(id) ON DELETE CASCADE;


--
-- Name: gluster_server_hooks_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_server_hooks
    ADD CONSTRAINT gluster_server_hooks_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: gluster_server_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_server
    ADD CONSTRAINT gluster_server_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: gluster_server_services_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_server_services
    ADD CONSTRAINT gluster_server_services_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: gluster_server_services_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_server_services
    ADD CONSTRAINT gluster_server_services_service_id_fkey FOREIGN KEY (service_id) REFERENCES gluster_services(id) ON DELETE CASCADE;


--
-- Name: gluster_services_service_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_services
    ADD CONSTRAINT gluster_services_service_type_fkey FOREIGN KEY (service_type) REFERENCES gluster_service_types(service_type) ON DELETE CASCADE;


--
-- Name: gluster_volume_access_protocols_volume_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volume_access_protocols
    ADD CONSTRAINT gluster_volume_access_protocols_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;


--
-- Name: gluster_volume_bricks_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT gluster_volume_bricks_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;


--
-- Name: gluster_volume_bricks_volume_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT gluster_volume_bricks_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;


--
-- Name: gluster_volume_options_volume_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT gluster_volume_options_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;


--
-- Name: gluster_volume_transport_types_volume_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volume_transport_types
    ADD CONSTRAINT gluster_volume_transport_types_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;


--
-- Name: gluster_volumes_cluster_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT gluster_volumes_cluster_id_fkey FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: image_templates_images; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY images
    ADD CONSTRAINT image_templates_images FOREIGN KEY (it_guid) REFERENCES images(image_guid);


--
-- Name: network_qos_storage_pool_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY network_qos
    ADD CONSTRAINT network_qos_storage_pool_fk FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: quota_limitation_quota_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_quota_id_fkey FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE CASCADE;


--
-- Name: quota_limitation_storage_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_storage_id_fkey FOREIGN KEY (storage_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;


--
-- Name: quota_limitation_vds_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_vds_group_id_fkey FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;


--
-- Name: quota_storage_pool_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY quota
    ADD CONSTRAINT quota_storage_pool_id_fkey FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: tags_user_group_map_tag; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT tags_user_group_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);


--
-- Name: tags_user_map_tag; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT tags_user_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);


--
-- Name: tags_user_map_user; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT tags_user_map_user FOREIGN KEY (user_id) REFERENCES users(user_id);


--
-- Name: tags_user_map_user_group; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT tags_user_map_user_group FOREIGN KEY (group_id) REFERENCES ad_groups(id);


--
-- Name: tags_vds_map_tag; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT tags_vds_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);


--
-- Name: tags_vds_map_vds; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT tags_vds_map_vds FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);


--
-- Name: tags_vm_map_tag; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT tags_vm_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);


--
-- Name: tags_vm_map_vm; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT tags_vm_map_vm FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: vds_groups_cluster_policy; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_groups
    ADD CONSTRAINT vds_groups_cluster_policy FOREIGN KEY (cluster_policy_id) REFERENCES cluster_policies(id);


--
-- Name: vds_groups_vds_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_groups_vds_static FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);


--
-- Name: vds_groups_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_static
    ADD CONSTRAINT vds_groups_vm_static FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);


--
-- Name: vds_static_vds_dynamic; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_dynamic
    ADD CONSTRAINT vds_static_vds_dynamic FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);


--
-- Name: vds_static_vds_statistics; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vds_statistics
    ADD CONSTRAINT vds_static_vds_statistics FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);


--
-- Name: vds_static_vm_dynamic_m; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vds_static_vm_dynamic_m FOREIGN KEY (migrating_to_vds) REFERENCES vds_static(vds_id);


--
-- Name: vds_static_vm_dynamic_r; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vds_static_vm_dynamic_r FOREIGN KEY (run_on_vds) REFERENCES vds_static(vds_id);


--
-- Name: vm_device_snapshot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_device
    ADD CONSTRAINT vm_device_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id) ON DELETE CASCADE;


--
-- Name: vm_guid_pools; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT vm_guid_pools FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: vm_ovf_generations_storage_pool_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_ovf_generations
    ADD CONSTRAINT vm_ovf_generations_storage_pool_id_fkey FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;


--
-- Name: vm_pools_vm; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT vm_pools_vm FOREIGN KEY (vm_pool_id) REFERENCES vm_pools(vm_pool_id);


--
-- Name: vm_static_vm_dynamic; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vm_static_vm_dynamic FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: vm_static_vm_init; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_init
    ADD CONSTRAINT vm_static_vm_init FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: vm_static_vm_statistics; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_statistics
    ADD CONSTRAINT vm_static_vm_statistics FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
-- Name: vm_templates_vm_static; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vm_static
    ADD CONSTRAINT vm_templates_vm_static FOREIGN KEY (vmt_guid) REFERENCES vm_static(vm_guid);


--
-- Name: vnic_profiles_network_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: engine
--

ALTER TABLE ONLY vnic_profiles
    ADD CONSTRAINT vnic_profiles_network_id_fkey FOREIGN KEY (network_id) REFERENCES network(id) ON DELETE CASCADE;


--
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


--
-- PostgreSQL database dump complete
--

