Changes to 'refs/tags/spacecmd-1.6.4-1'
by aparsons
Tag 'spacecmd-1.6.4-1' created by Aron Parsons <parsonsa(a)bit-sys.com> at 2011-09-23 13:50 +0000
Tagging package [spacecmd] version [1.6.4-1] in directory [spacecmd/].
Changes since spacewalk-backend-1.6.21-1:
Aron Parsons (2):
spacecmd: added softwarechannel_regenerateyumcache
Automatic commit of package [spacecmd] release [1.6.4-1].
---
rel-eng/packages/spacecmd | 2 +-
spacecmd/spacecmd.spec | 5 ++++-
spacecmd/src/lib/softwarechannel.py | 25 +++++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
---
12 years, 6 months
2 commits - rel-eng/packages spacecmd/spacecmd.spec spacecmd/src
by aparsons
rel-eng/packages/spacecmd | 2 +-
spacecmd/spacecmd.spec | 5 ++++-
spacecmd/src/lib/softwarechannel.py | 25 +++++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
New commits:
commit 22f26b19383f1429ed0603ebdfb11d510308b900
Author: Aron Parsons <parsonsa(a)bit-sys.com>
Date: Fri Sep 23 09:50:41 2011 -0400
Automatic commit of package [spacecmd] release [1.6.4-1].
diff --git a/rel-eng/packages/spacecmd b/rel-eng/packages/spacecmd
index 9626e37..0f0cfd7 100644
--- a/rel-eng/packages/spacecmd
+++ b/rel-eng/packages/spacecmd
@@ -1 +1 @@
-1.6.3-1 spacecmd/
+1.6.4-1 spacecmd/
diff --git a/spacecmd/spacecmd.spec b/spacecmd/spacecmd.spec
index b1bd2dc..3a5e057 100644
--- a/spacecmd/spacecmd.spec
+++ b/spacecmd/spacecmd.spec
@@ -4,7 +4,7 @@
%endif
Name: spacecmd
-Version: 1.6.3
+Version: 1.6.4
Release: 1%{?dist}
Summary: Command-line interface to Spacewalk and Satellite servers
@@ -61,6 +61,9 @@ touch %{buildroot}/%{python_sitelib}/spacecmd/__init__.py
%doc %{_mandir}/man1/spacecmd.1.gz
%changelog
+* Fri Sep 23 2011 Aron Parsons <parsonsa(a)bit-sys.com> 1.6.4-1
+- spacecmd: added softwarechannel_regenerateyumcache (parsonsa(a)bit-sys.com)
+
* Thu Aug 11 2011 Miroslav Suchý 1.6.3-1
- do not mask original error by raise in execption
commit 653b46296278e93ce28d3ecb512fcd2eef4d22f7
Author: Aron Parsons <parsonsa(a)bit-sys.com>
Date: Fri Sep 23 09:50:14 2011 -0400
spacecmd: added softwarechannel_regenerateyumcache
diff --git a/spacecmd/src/lib/softwarechannel.py b/spacecmd/src/lib/softwarechannel.py
index 394f53a..7aa4d38 100644
--- a/spacecmd/src/lib/softwarechannel.py
+++ b/spacecmd/src/lib/softwarechannel.py
@@ -880,4 +880,29 @@ def do_softwarechannel_regenerateneededcache(self, args):
if self.user_confirm('Are you sure [y/N]: '):
self.client.channel.software.regenerateNeededCache(self.session)
+####################
+
+def help_softwarechannel_regenerateyumcache(self):
+ print 'softwarechannel_regenerateyumcache: '
+ print 'Regenerate the YUM cache for a software channel'
+ print
+ print 'usage: softwarechannel_regnerateyumcache <CHANNEL ...>'
+
+def complete_softwarechannel_regenerateyumcache(self, text, line, beg, end):
+ return tab_completer(self.do_softwarechannel_list('', True), text)
+
+def do_softwarechannel_regenerateyumcache(self, args):
+ (args, options) = parse_arguments(args)
+
+ if not len(args):
+ self.help_softwarechannel_regenerateyumcache()
+ return
+
+ # allow globbing of software channel names
+ channels = filter_results(self.do_softwarechannel_list('', True), args)
+
+ for channel in channels:
+ logging.debug('Regenerating YUM cache for %s' % channel)
+ self.client.channel.software.regenerateYumCache(self.session, channel)
+
# vim:ts=4:expandtab:
12 years, 6 months
Changes to 'refs/tags/rhncfg-5.10.15-1'
by Martin Minar
Tag 'rhncfg-5.10.15-1' created by Martin Minar <mminar(a)redhat.com> at 2011-09-23 12:47 +0000
Tagging package [rhncfg] version [5.10.15-1] in directory [client/tools/rhncfg/].
Changes since spacewalk-schema-1.6.17-1:
Martin Minar (1):
Automatic commit of package [rhncfg] release [5.10.15-1].
---
client/tools/rhncfg/rhncfg.spec | 6 +++++-
rel-eng/packages/rhncfg | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
---
12 years, 6 months
client/tools rel-eng/packages
by Martin Minar
client/tools/rhncfg/rhncfg.spec | 6 +++++-
rel-eng/packages/rhncfg | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit c8759548af8e540a2f6e66108c1361b91a309277
Author: Martin Minar <mminar(a)redhat.com>
Date: Fri Sep 23 14:47:52 2011 +0200
Automatic commit of package [rhncfg] release [5.10.15-1].
diff --git a/client/tools/rhncfg/rhncfg.spec b/client/tools/rhncfg/rhncfg.spec
index da29649..1241521 100644
--- a/client/tools/rhncfg/rhncfg.spec
+++ b/client/tools/rhncfg/rhncfg.spec
@@ -8,7 +8,7 @@ Group: Applications/System
License: GPLv2 and Python
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
-Version: 5.10.14
+Version: 5.10.15
Release: 1%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
@@ -106,6 +106,10 @@ rm -rf $RPM_BUILD_ROOT
# $Id$
%changelog
+* Fri Sep 23 2011 Martin Minar <mminar(a)redhat.com> 5.10.15-1
+- Fix `rhncfg-client verify' traceback for missing symlinks
+ (Joshua.Roys(a)gtri.gatech.edu)
+
* Thu Aug 18 2011 Michael Mraka <michael.mraka(a)redhat.com> 5.10.14-1
- 731284 - is_selinux_enabled is not defined on RHEL4
diff --git a/rel-eng/packages/rhncfg b/rel-eng/packages/rhncfg
index a955a63..f7a172f 100644
--- a/rel-eng/packages/rhncfg
+++ b/rel-eng/packages/rhncfg
@@ -1 +1 @@
-5.10.14-1 client/tools/rhncfg/
+5.10.15-1 client/tools/rhncfg/
12 years, 6 months
Changes to 'refs/tags/spacewalk-schema-1.6.17-1'
by Michael Mraka
Tag 'spacewalk-schema-1.6.17-1' created by Michael Mraka <michael.mraka(a)redhat.com> at 2011-09-23 09:49 +0000
Tagging package [spacewalk-schema] version [1.6.17-1] in directory [schema/spacewalk/].
Changes since spacewalk-web-1.6.23-1:
Michael Mraka (20):
synced rhn_entitlement.repoll_virt_guest_entitlements() with oracle
synced rhn_entitlement.assign_channel_entitlement() with oracle
synced rhn_entitlement.activate_system_entitlement() with oracle
synced rhn_entitlement.activate_channel_entitlement() with oracle
synced rhn_entitlement.prune_family() with oracle
rhn_entitlements.pkb are now equivalent
removed dead get_license_path() and license_consent()
changed function order so it's easier to diff sources
synced rhn_channel.subscribe_server() with oracle
ported can_convert_to_fve() and convert_to_fve() from oracle
synced rhn_channel.clear_subscriptions() with oracle
synced rhn_channel.channel_family_current_members() with oracle
ported rhn_channel.cfam_curr_fve_members() from oracle
synced rhn_channel.update_family_counts() with oracle
ported rhn_channel.update_group_family_counts() from oracle
upgrade for rhn_entitlements
upgrade for rhn_channel
fixed couple of syntax errors
don't drop other stuff depending on this
Automatic commit of package [spacewalk-schema] release [1.6.17-1].
---
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/postgres/packages/rhn_channel.pkb | 248 -
schema/spacewalk/postgres/packages/rhn_entitlements.pkb | 105
schema/spacewalk/spacewalk-schema.spec | 6
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.oracle | 1
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql | 1843 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.oracle | 1
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql | 1225 ++++++
8 files changed, 3332 insertions(+), 99 deletions(-)
---
12 years, 6 months
rel-eng/packages schema/spacewalk
by Michael Mraka
rel-eng/packages/spacewalk-schema | 2 +-
schema/spacewalk/spacewalk-schema.spec | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 60261a629bb6a7505abdafd09768e83962369ca2
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Sep 23 11:49:03 2011 +0200
Automatic commit of package [spacewalk-schema] release [1.6.17-1].
diff --git a/rel-eng/packages/spacewalk-schema b/rel-eng/packages/spacewalk-schema
index 3b5207c..46642cf 100644
--- a/rel-eng/packages/spacewalk-schema
+++ b/rel-eng/packages/spacewalk-schema
@@ -1 +1 @@
-1.6.16-1 schema/spacewalk/
+1.6.17-1 schema/spacewalk/
diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec
index d7b3830..d9d656e 100644
--- a/schema/spacewalk/spacewalk-schema.spec
+++ b/schema/spacewalk/spacewalk-schema.spec
@@ -2,7 +2,7 @@ Name: spacewalk-schema
Group: Applications/Internet
Summary: Oracle SQL schema for Spacewalk server
-Version: 1.6.16
+Version: 1.6.17
Release: 1%{?dist}
Source0: %{name}-%{version}.tar.gz
@@ -66,6 +66,10 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/spacewalk-sql*
%changelog
+* Fri Sep 23 2011 Michael Mraka <michael.mraka(a)redhat.com> 1.6.17-1
+- synced rhn_channel with oracle
+- synced rhn_entitlement with oracle
+
* Thu Sep 15 2011 Michael Mraka <michael.mraka(a)redhat.com> 1.6.16-1
- 529064 - fixed update_needed_cache which wrongly updated cache if a package
was in more erratas
12 years, 6 months
19 commits - schema/spacewalk
by Michael Mraka
schema/spacewalk/postgres/packages/rhn_channel.pkb | 248 -
schema/spacewalk/postgres/packages/rhn_entitlements.pkb | 105
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.oracle | 1
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql | 1843 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.oracle | 1
schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql | 1225 ++++++
6 files changed, 3326 insertions(+), 97 deletions(-)
New commits:
commit ae137fd175dafda9fba2aa0b38b1b6c99e529562
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Sep 21 13:10:30 2011 +0200
don't drop other stuff depending on this
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql
index 2ef2291..1c6f509 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql
@@ -1,316 +1,5 @@
-- oracle equivalent source sha1 b14267384bc104605623a41b755e68e0103b5aa8
-drop schema if exists rhn_entitlements cascade ;
-
---
--- Copyright (c) 2008--2010 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
-
-create schema rhn_entitlements;
-
--- setup search_path so that these functions are created in appropriate schema.
-update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path';
-
- create or replace function remove_org_entitlements (
- org_id_in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function entitlement_grants_service (
- entitlement_in in varchar,
- service_level_in in varchar
- ) returns numeric
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function lookup_entitlement_group (
- org_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns numeric
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function create_entitlement_group (
- org_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns numeric
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function can_entitle_server (
- server_id_in in numeric,
- type_label_in in varchar
- )
- returns numeric
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar
- )
- returns numeric
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function entitle_server (
- server_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled'
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function remove_server_entitlement (
- server_id_in in numeric,
- type_label_in in varchar default 'sw_mgr_entitled',
- repoll_virt_guests in numeric default 1
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function unentitle_server (
- server_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function repoll_virt_guest_entitlements(
- server_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function get_server_entitlement (
- server_id_in in numeric
- ) returns varchar[]
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function modify_org_service (
- org_id_in in numeric,
- service_label_in in varchar,
- enable_in in char
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function set_customer_enterprise (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function set_customer_provisioning (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function set_customer_nonlinux (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function unset_customer_enterprise (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function unset_customer_provisioning (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function unset_customer_nonlinux (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function assign_system_entitlement(
- group_label_in in varchar,
- from_org_id_in in numeric,
- to_org_id_in in numeric,
- quantity_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function assign_channel_entitlement(
- channel_family_label_in in varchar,
- from_org_id_in in numeric,
- to_org_id_in in numeric,
- quantity_in in numeric,
- flex_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function activate_system_entitlement(
- org_id_in in numeric,
- group_label_in in varchar,
- quantity_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function activate_channel_entitlement(
- org_id_in in numeric,
- channel_family_label_in in varchar,
- quantity_in in numeric,
- flex_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function set_group_count (
- customer_id_in in numeric, -- customer_id
- type_in in char, -- 'U' or 'S'
- group_type_in in numeric, -- rhn[User|Server]GroupType.id
- quantity_in in numeric, -- quantity
- update_family_countsYN in numeric default 1 -- call update_family_counts inside
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function set_family_count (
- customer_id_in in numeric, -- customer_id
- channel_family_id_in in numeric, -- 246
- quantity_in in numeric, -- 3
- flex_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- -- this makes NO checks that the quantity is within max,
- -- so we should NEVER run this unless we KNOW that we won't be
- -- violating the max
- create or replace function entitle_last_modified_servers (
- customer_id_in in numeric, -- customer_id
- type_label_in in varchar, -- 'enterprise_entitled'
- quantity_in in numeric -- 3
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
- create or replace function subscribe_newest_servers (
- customer_id_in in numeric
- ) returns void
-as $$
-BEGIN
- RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
-END;
-$$ language plpgsql;
-
--- restore the original setting
-update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path';
-
-
---
--- Copyright (c) 2008--2011 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
-
-- create schema rhn_entitlements;
-- setup search_path so that these functions are created in appropriate schema.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
index 493c0a4..f7e37ad 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
@@ -1,26 +1,8 @@
-- oracle equivalent source sha1 b14267384bc104605623a41b755e68e0103b5aa8
-drop schema if exists rhn_channel cascade ;
-
---
--- Copyright (c) 2008--2010 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
---
---
---
-
-create schema rhn_channel;
+drop function get_license_path(channel_id_in in numeric);
+drop function license_consent(channel_id_in in numeric, user_id_in in numeric, server_id_in in numeric);
+drop function clear_subscriptions(server_id_in in numeric, deleting_server in numeric);
--update pg_setting
update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path';
commit 586ee0dd83a5240d332eb6146ea8e6b2a0975688
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Sep 20 16:52:55 2011 +0200
fixed couple of syntax errors
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 6803946..e73fbb5 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -1,9 +1,5 @@
-- oracle equivalent source sha1 57ec75b0aacf78d2bba70e5ad4158bccacccf265
--
--- This file is not yet in sync with Oracle. Synced functions are:
--- subscribe_server + all subfunctions
--- unsubscribe_server + all subfunctions
---
-- Copyright (c) 2008--2010 Red Hat, Inc.
--
-- This software is licensed to you under the GNU General Public License,
@@ -180,7 +176,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
return 1;
END LOOP;
RETURN 0;
- END can_convert_to_fve;
+ END$$ language plpgsql;
@@ -188,6 +184,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
returns void
as $$
+ declare
available_fve_subs NUMERIC;
server_org_id_val NUMERIC;
BEGIN
@@ -202,7 +199,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
WHERE id = server_id_in;
- obtain_read_lock(channel_family_id_val, server_org_id_val);
+ perform obtain_read_lock(channel_family_id_val, server_org_id_val);
if not found then
perform rhn_exception.raise_exception('channel_family_no_subscriptions');
end if;
@@ -676,7 +673,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
declare
current_members_count numeric := 0;
begin
- select count(distinct sc.server_id)
+ select count(distinct server_id)
into current_members_count
from rhnChannelFamilyServerPhysical cfsp
where cfsp.channel_family_id = channel_family_id_in
@@ -691,7 +688,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
returns numeric
as $$
declare
- current_members_count number := 0;
+ current_members_count numeric := 0;
begin
select count(sc.server_id)
@@ -717,7 +714,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
AS $$
BEGIN
update rhnPrivateChannelFamily
- set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in)
+ set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in),
fve_current_members = rhn_channel.cfam_curr_fve_members(channel_family_id_in,org_id_in)
where org_id = org_id_in
and channel_family_id = channel_family_id_in;
@@ -727,6 +724,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
org_id_in IN NUMERIC)
returns void
as $$
+ declare
+ i record;
BEGIN
FOR i IN (
SELECT DISTINCT CFM.channel_family_id, SG.org_id
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
index 1a1580f..493c0a4 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
@@ -3,10 +3,6 @@
drop schema if exists rhn_channel cascade ;
--
--- This file is not yet in sync with Oracle. Synced functions are:
--- subscribe_server + all subfunctions
--- unsubscribe_server + all subfunctions
---
-- Copyright (c) 2008--2010 Red Hat, Inc.
--
-- This software is licensed to you under the GNU General Public License,
@@ -183,7 +179,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
return 1;
END LOOP;
RETURN 0;
- END can_convert_to_fve;
+ END$$ language plpgsql;
@@ -191,6 +187,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
returns void
as $$
+ declare
available_fve_subs NUMERIC;
server_org_id_val NUMERIC;
BEGIN
@@ -205,7 +202,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
WHERE id = server_id_in;
- obtain_read_lock(channel_family_id_val, server_org_id_val);
+ perform obtain_read_lock(channel_family_id_val, server_org_id_val);
if not found then
perform rhn_exception.raise_exception('channel_family_no_subscriptions');
end if;
@@ -679,7 +676,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
declare
current_members_count numeric := 0;
begin
- select count(distinct sc.server_id)
+ select count(distinct server_id)
into current_members_count
from rhnChannelFamilyServerPhysical cfsp
where cfsp.channel_family_id = channel_family_id_in
@@ -694,7 +691,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
returns numeric
as $$
declare
- current_members_count number := 0;
+ current_members_count numeric := 0;
begin
select count(sc.server_id)
@@ -720,7 +717,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
AS $$
BEGIN
update rhnPrivateChannelFamily
- set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in)
+ set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in),
fve_current_members = rhn_channel.cfam_curr_fve_members(channel_family_id_in,org_id_in)
where org_id = org_id_in
and channel_family_id = channel_family_id_in;
@@ -730,6 +727,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
org_id_in IN NUMERIC)
returns void
as $$
+ declare
+ i record;
BEGIN
FOR i IN (
SELECT DISTINCT CFM.channel_family_id, SG.org_id
commit 46cbc369ce2a13d78aec45a1e7012e7d88749991
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Sep 20 16:15:55 2011 +0200
upgrade for rhn_channel
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.oracle
new file mode 100644
index 0000000..b7b00b1
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.oracle
@@ -0,0 +1 @@
+-- This file is intentionally left empty.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
new file mode 100644
index 0000000..1a1580f
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/091-rhn_channel.sql.postgresql
@@ -0,0 +1,1244 @@
+-- oracle equivalent source sha1 b14267384bc104605623a41b755e68e0103b5aa8
+
+drop schema if exists rhn_channel cascade ;
+
+--
+-- This file is not yet in sync with Oracle. Synced functions are:
+-- subscribe_server + all subfunctions
+-- unsubscribe_server + all subfunctions
+--
+-- Copyright (c) 2008--2010 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+--
+--
+--
+
+create schema rhn_channel;
+
+--update pg_setting
+update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path';
+
+ create or replace function obtain_read_lock(channel_family_id_in in numeric, org_id_in in numeric)
+ returns void as $$
+ declare
+ read_lock date;
+ begin
+ select created into read_lock
+ from rhnPrivateChannelFamily
+ where channel_family_id = channel_family_id_in and org_id = org_id_in
+ for update;
+ end$$ language plpgsql;
+
+ -- this "emulates" cursor server_base_subscriptions defined in oracle/rhn_channel.pks
+ create or replace function server_base_subscriptions(server_id_in NUMERIC)
+ returns boolean as $$
+ begin
+ return exists(SELECT C.id FROM rhnChannel C, rhnServerChannel SC
+ WHERE C.id = SC.channel_id
+ AND SC.server_id = server_id_in
+ AND C.parent_channel IS NULL);
+ end$$ language plpgsql;
+
+ -- this "emulates" cursor server_base_subscriptions defined in oracle/rhn_channel.pks
+ create or replace function check_server_subscription(server_id_in NUMERIC, channel_id_in NUMERIC)
+ returns boolean as $$
+ begin
+ return exists(SELECT channel_id FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in);
+ end$$ language plpgsql;
+
+
+ CREATE OR REPLACE FUNCTION subscribe_server(server_id_in IN NUMERIC, channel_id_in NUMERIC, immediate_in NUMERIC default 1, user_id_in in numeric default null, recalcfamily_in NUMERIC default 1) returns void
+ AS $$
+ declare
+ channel_parent_val rhnChannel.parent_channel%TYPE;
+ parent_subscribed BOOLEAN;
+ server_has_base_chan BOOLEAN;
+ server_already_in_chan BOOLEAN;
+ channel_family_id_val NUMERIC;
+ server_org_id_val NUMERIC;
+ available_subscriptions NUMERIC;
+ available_fve_subs numeric;
+ consenting_user NUMERIC;
+ allowed numeric;
+ is_fve_char char(1) := 'N';
+ BEGIN
+ if user_id_in is not null then
+ allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
+ else
+ allowed := 1;
+ end if;
+
+ if allowed = 0 then
+ perform rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+
+
+ SELECT parent_channel INTO channel_parent_val FROM rhnChannel WHERE id = channel_id_in;
+
+ IF channel_parent_val IS NOT NULL
+ THEN
+ -- child channel; if attempting to cross-subscribe a child to the wrong base, silently ignore
+ parent_subscribed := rhn_channel.check_server_subscription(server_id_in, channel_parent_val);
+
+ IF NOT parent_subscribed
+ THEN
+ RETURN;
+ END IF;
+ ELSE
+ -- base channel
+ server_has_base_chan := rhn_channel.server_base_subscriptions(server_id_in);
+
+ IF server_has_base_chan
+ THEN
+ perform rhn_exception.raise_exception('channel_server_one_base');
+ END IF;
+ END IF;
+
+ server_already_in_chan := rhn_channel.check_server_subscription(server_id_in, channel_id_in);
+
+ IF server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ perform rhn_exception.raise_exception('channel_subscribe_no_family');
+ END IF;
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT COALESCE(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
+ INTO server_org_id_val
+ FROM rhnChannel
+ WHERE id = channel_id_in;
+
+ begin
+ perform rhn_channel.obtain_read_lock(channel_family_id_val, server_org_id_val);
+ exception
+ when no_data_found then
+ perform rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end;
+
+ available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF available_subscriptions IS NULL OR
+ available_subscriptions > 0 or
+ rhn_channel.can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
+ (available_fve_subs > 0 AND rhn_channel.can_server_consume_fve(server_id_in) = 1)
+ THEN
+ if rhn_channel.can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND rhn_channel.can_server_consume_fve(server_id_in) = 1 THEN
+ is_fve_char := 'Y';
+ end if;
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select nextval('rhn_event_id_seq'),
+ server_id_in,
+ 'subscribed to channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+ UPDATE rhnServer SET channels_changed = current_timestamp WHERE id = server_id_in;
+ INSERT INTO rhnServerChannel (server_id, channel_id, is_fve) VALUES (server_id_in, channel_id_in, is_fve_char);
+ IF recalcfamily_in > 0
+ THEN
+ perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ END IF;
+ perform queue_server(server_id_in, immediate_in);
+ ELSE
+ perform rhn_exception.raise_exception('channel_family_no_subscriptions');
+ END IF;
+
+ END$$ language plpgsql;
+
+
+
+ create or replace function can_convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
+ RETURNS NUMERIC
+ as $$
+ declare
+ fve_convertible_entries cursor for
+ select 1 from
+ rhnServerFveCapable cap
+ where cap.server_id = server_id_in
+ AND cap.channel_family_id = channel_family_id_val;
+ BEGIN
+ FOR entry IN fve_convertible_entries LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END can_convert_to_fve;
+
+
+
+ -- Converts server channel_family to use a flex entitlement
+ create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
+ returns void
+ as $$
+ available_fve_subs NUMERIC;
+ server_org_id_val NUMERIC;
+ BEGIN
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT org_id
+ INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ if not found then
+ perform rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end if;
+ IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
+ THEN
+ perform rhn_exception.raise_exception('server_cannot_convert_to_flex');
+ END IF;
+
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF (available_fve_subs > 0)
+ THEN
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select nextval('rhn_event_id_seq'),
+ server_id_in,
+ 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
+ cf.label
+ from rhnChannelFamily cf
+ where cf.id = channel_family_id_val
+ );
+
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = server_id_in and
+ sc.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
+
+ perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ ELSE
+ perform rhn_exception.raise_exception('not_enough_flex_entitlements');
+ END IF;
+
+ END$$ language plpgsql;
+
+ create or replace function can_server_consume_virt_channl(
+ server_id_in in numeric,
+ family_id_in in numeric )
+ returns numeric
+ as $$
+ begin
+ if exists(
+ select 1
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnVirtualInstance vi
+ where
+ vi.virtual_system_id = server_id_in
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ and cfvsl.channel_family_id = family_id_in
+ and exists (
+ select 1
+ from rhnServerEntitlementView sev
+ where vi.host_system_id = sev.server_id
+ and sev.server_group_type_id = sgtvsl.server_group_type_id ))
+ then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$ language plpgsql;
+
+ create or replace function can_server_consume_fve(server_id_in in numeric) returns numeric
+ as $$
+ declare
+ vi_entries cursor for
+ SELECT 1
+ FROM rhnVirtualInstance vi
+ WHERE vi.virtual_system_id = server_id_in;
+ vi_count numeric;
+
+ begin
+ FOR vi_entry IN VI_ENTRIES LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ end$$ language plpgsql;
+
+ create or replace function guess_server_base(
+ server_id_in in numeric
+ ) RETURNS numeric as $$
+ declare
+ server_cursor cursor for
+ select s.server_arch_id, s.release, s.org_id
+ from rhnServer s
+ where s.id = server_id_in;
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ base_channel_cursor cursor(
+ release_in varchar,
+ server_arch_id_in numeric,
+ org_id_in numeric
+ ) for
+ select distinct c.*
+ from rhnDistChannelMap dcm,
+ rhnServerChannelArchCompat scac,
+ rhnChannel c,
+ rhnChannelPermissions cp
+ where cp.org_id = org_id_in
+ and cp.channel_id = c.id
+ and c.parent_channel is null
+ and c.id = dcm.channel_id
+ and c.channel_arch_id = dcm.channel_arch_id
+ and dcm.release = release_in
+ and scac.server_arch_id = server_arch_id_in
+ and scac.channel_arch_id = c.channel_arch_id;
+
+ begin
+ for s in server_cursor loop
+ for channel in base_channel_cursor(s.release,
+ s.server_arch_id, s.org_id)
+ loop
+ return channel.id;
+ end loop;
+ end loop;
+ -- Server not found, or no base channel applies to it
+ return null;
+ end$$ language plpgsql;
+
+ -- Private function
+ create or replace function normalize_server_arch(server_arch_in in varchar)
+ returns varchar
+ as $$
+ declare
+ suffix VARCHAR(128) := '-redhat-linux';
+ begin
+ if server_arch_in is NULL then
+ return NULL;
+ end if;
+ if position('-' IN server_arch_in) > 0
+ then
+ -- Suffix already present
+ return server_arch_in;
+ end if;
+ return server_arch_in || suffix;
+ end$$ language plpgsql;
+
+ --
+ -- Raises:
+ -- server_arch_not_found
+ -- no_subscribe_permissions
+ create or replace function base_channel_for_release_arch(
+ release_in in varchar,
+ server_arch_in in varchar,
+ org_id_in in numeric default -1,
+ user_id_in in numeric default null
+ ) returns numeric as $$
+ declare
+ server_arch varchar(256) := rhn_channel.normalize_server_arch(server_arch_in);
+ server_arch_id numeric;
+ begin
+ -- Look up the server arch
+ select id
+ into server_arch_id
+ from rhnServerArch
+ where label = server_arch;
+ if not found then
+ perform rhn_exception.raise_exception('server_arch_not_found');
+ end if;
+
+ return rhn_channel.base_channel_rel_archid(release_in, server_arch_id,
+ org_id_in, user_id_in);
+ end$$ language plpgsql;
+
+ create or replace function base_channel_rel_archid(
+ release_in in varchar,
+ server_arch_id_in in numeric,
+ org_id_in in numeric default -1,
+ user_id_in in numeric default null
+ ) returns numeric as $$
+ declare
+ denied_channel_id numeric := null;
+ valid_org_id numeric := org_id_in;
+ valid_user_id numeric := user_id_in;
+ channel_subscribable numeric;
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ base_channel_cursor cursor(
+ release_in varchar,
+ server_arch_id_in numeric,
+ org_id_in numeric
+ ) for
+ select distinct c.*
+ from rhnDistChannelMap dcm,
+ rhnServerChannelArchCompat scac,
+ rhnChannel c,
+ rhnChannelPermissions cp
+ where cp.org_id = org_id_in
+ and cp.channel_id = c.id
+ and c.parent_channel is null
+ and c.id = dcm.channel_id
+ and c.channel_arch_id = dcm.channel_arch_id
+ and dcm.release = release_in
+ and scac.server_arch_id = server_arch_id_in
+ and scac.channel_arch_id = c.channel_arch_id;
+
+ begin
+ if org_id_in = -1 and user_id_in is not null then
+ -- Get the org id from the user id
+
+ select org_id
+ into valid_org_id
+ from web_contact
+ where id = user_id_in;
+
+ if not found then
+ -- User doesn't exist
+ -- XXX Only list public stuff for now
+ valid_user_id := null;
+ valid_org_id := -1;
+ end if;
+ end if;
+
+ for c in base_channel_cursor(release_in, server_arch_id_in, valid_org_id)
+ loop
+ -- This row is a possible match
+ if valid_user_id is null then
+ -- User ID not specified, so no user to channel permissions to
+ -- check
+ return c.id;
+ end if;
+
+ -- Check user to channel permissions
+ select rhn_channel.loose_user_role_check(c.id, user_id_in, 'subscribe')
+ into channel_subscribable;
+
+ if channel_subscribable = 1 then
+ return c.id;
+ end if;
+
+ -- Base channel exists, but is not subscribable; keep trying
+ denied_channel_id := c.id;
+ end loop;
+
+ if denied_channel_id is not null then
+ perform rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+ -- No base channel applies
+ return NULL;
+ end$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION clear_subscriptions(server_id_in IN NUMERIC, deleting_server IN NUMERIC default 0,
+ update_family_countsYN IN NUMERIC default 1 ) returns void
+ AS $$
+ declare
+ server_channels cursor(server_id_in numeric) for
+ select s.org_id, sc.channel_id, cfm.channel_family_id
+ from rhnServer s,
+ rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where s.id = server_id_in
+ and s.id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ order by cfm.channel_family_id;
+ last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
+ last_channel_org_id rhnServer.org_id%type := -1;
+ BEGIN
+ for channel in server_channels(server_id_in)
+ loop
+ perform rhn_channel.unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
+ if update_family_countsYN > 0
+ and channel.channel_family_id != last_channel_family_id then
+ -- update family counts only once
+ -- after all channels with same family has been fetched
+ if last_channel_family_id != -1 then
+ perform rhn_channel.update_family_counts(channel.channel_family_id, channel.org_id);
+ end if;
+ last_channel_family_id := channel.channel_family_id;
+ last_channel_org_id := channel.org_id;
+ end if;
+ end loop;
+ if update_family_countsYN > 0 and last_channel_family_id != -1 then
+ -- update the last family fetched
+ perform rhn_channel.update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION unsubscribe_server(server_id_in IN NUMERIC, channel_id_in NUMERIC, immediate_in NUMERIC default 1, unsubscribe_children_in numeric default 0,
+ deleting_server in numeric default 0,
+ update_family_countsYN in numeric default 1) returns void
+ AS $$
+ declare
+ channel_family_id_val NUMERIC;
+ server_org_id_val NUMERIC;
+ available_subscriptions NUMERIC;
+ server_already_in_chan BOOLEAN;
+ channel_family_is_proxy cursor(channel_family_id_in numeric) for
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-proxy';
+ channel_family_is_satellite cursor(channel_family_id_in numeric) for
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-satellite';
+ child record;
+ BEGIN
+ -- In PostgreSQL recursion with opened cursors is not allowed so we use
+ -- FOR IN SELECT form which is ok.
+ FOR child IN select c.id
+ from rhnChannel c,
+ rhnServerChannel sc
+ where 1=1
+ and c.parent_channel = channel_id_in
+ and c.id = sc.channel_id
+ and sc.server_id = server_id_in
+ LOOP
+ if unsubscribe_children_in = 1 then
+ perform rhn_channel.unsubscribe_server(server_id_in,
+ child.id,
+ immediate_in,
+ unsubscribe_children_in,
+ deleting_server,
+ update_family_countsYN);
+ else
+ perform rhn_exception.raise_exception('channel_unsubscribe_child_exists');
+ end if;
+ END LOOP;
+
+ server_already_in_chan := rhn_channel.check_server_subscription(server_id_in, channel_id_in);
+
+ IF NOT server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ if deleting_server = 0 then
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select nextval('rhn_event_id_seq'),
+ server_id_in,
+ 'unsubscribed from channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+
+ UPDATE rhnServer SET channels_changed = current_timestamp WHERE id = server_id_in;
+ end if;
+
+ DELETE FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in;
+
+ if deleting_server = 0 then
+ perform queue_server(server_id_in, immediate_in);
+ end if;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ perform rhn_exception.raise_exception('channel_unsubscribe_no_family');
+ END IF;
+
+ for ignore in channel_family_is_satellite(channel_family_id_val) loop
+ delete from rhnSatelliteInfo where server_id = server_id_in;
+ end loop;
+
+ for ignore in channel_family_is_proxy(channel_family_id_val) loop
+ delete from rhnProxyInfo where server_id = server_id_in;
+ end loop;
+ SELECT org_id INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ if update_family_countsYN = 1 then
+ perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ end if;
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION family_for_channel(channel_id_in IN NUMERIC)
+ RETURNS NUMERIC
+ AS $$
+ declare
+ channel_family_id_val NUMERIC;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ IF NOT FOUND THEN
+ RETURN NULL;
+ END IF;
+
+ RETURN channel_family_id_val;
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION available_family_subscriptions(channel_family_id_in IN NUMERIC, org_id_in IN NUMERIC)
+ RETURNS NUMERIC
+ AS $$
+ declare
+ cfp record;
+ current_members_val NUMERIC;
+ max_members_val NUMERIC;
+ found NUMERIC;
+ BEGIN
+ for cfp in SELECT * FROM rhnOrgChannelFamilyPermissions
+ WHERE channel_family_id = channel_family_id_in
+ AND org_id = org_id_in
+ LOOP
+ found := 1;
+ current_members_val := cfp.current_members;
+ max_members_val := cfp.max_members;
+ END LOOP;
+
+ -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
+ -- either way, there are no available subscriptions
+
+ IF found IS NULL
+ THEN
+ RETURN 0;
+ END IF;
+
+ -- null max members? in that case, pass it on; NULL means infinite
+ IF max_members_val IS NULL
+ THEN
+ RETURN NULL;
+ END IF;
+
+ -- otherwise, return the delta
+ RETURN max_members_val - current_members_val;
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION available_fve_family_subs(channel_family_id_in IN NUMERIC, org_id_in IN NUMERIC)
+ RETURNS NUMERIC
+ AS $$
+ declare
+ cfp record;
+ fve_current_members_val NUMERIC;
+ fve_max_members_val NUMERIC;
+ found NUMERIC;
+ BEGIN
+ for cfp in SELECT * FROM rhnOrgChannelFamilyPermissions
+ WHERE channel_family_id = channel_family_id_in
+ AND org_id = org_id_in
+ LOOP
+ found := 1;
+ fve_current_members_val := cfp.fve_current_members;
+ fve_max_members_val := cfp.fve_max_members;
+ END LOOP;
+
+ -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
+ -- either way, there are no available subscriptions
+
+ IF found IS NULL
+ THEN
+ RETURN 0;
+ END IF;
+
+ -- null max members? in that case, pass it on; NULL means infinite
+ IF fve_max_members_val IS NULL
+ THEN
+ RETURN NULL;
+ END IF;
+
+ -- otherwise, return the delta
+ RETURN fve_max_members_val - fve_current_members_val;
+ END$$ language plpgsql;
+
+ -- *******************************************************************
+ -- FUNCTION: channel_family_current_members
+ -- Calculates and returns the actual count of systems consuming
+ -- physical channel subscriptions.
+ -- Called by: update_family_counts
+ -- rhn_entitlements.repoll_virt_guest_entitlements
+ -- *******************************************************************
+ create or replace function channel_family_current_members(channel_family_id_in IN NUMERIC,
+ org_id_in IN NUMERIC)
+ returns numeric
+ as $$
+ declare
+ current_members_count numeric := 0;
+ begin
+ select count(distinct sc.server_id)
+ into current_members_count
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.channel_family_id = channel_family_id_in
+ and cfsp.customer_id = org_id_in;
+ return current_members_count;
+ end$$ language plpgsql;
+
+
+ create or replace function cfam_curr_fve_members(
+ channel_family_id_in IN NUMERIC,
+ org_id_in IN NUMERIC)
+ returns numeric
+ as $$
+ declare
+ current_members_count number := 0;
+
+ begin
+ select count(sc.server_id)
+ into current_members_count
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm,
+ rhnServer s
+ where s.org_id = org_id_in
+ and s.id = sc.server_id
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and exists (
+ select 1
+ from rhnChannelFamilyServerFve cfsp
+ where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
+ and cfsp.server_id = s.id
+ );
+
+ return current_members_count;
+ end$$ language plpgsql;
+ CREATE OR REPLACE FUNCTION update_family_counts(channel_family_id_in IN NUMERIC,
+ org_id_in IN NUMERIC) returns void
+ AS $$
+ BEGIN
+ update rhnPrivateChannelFamily
+ set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in)
+ fve_current_members = rhn_channel.cfam_curr_fve_members(channel_family_id_in,org_id_in)
+ where org_id = org_id_in
+ and channel_family_id = channel_family_id_in;
+ END$$ language plpgsql;
+
+ create or replace function update_group_family_counts(group_label_in IN VARCHAR,
+ org_id_in IN NUMERIC)
+ returns void
+ as $$
+ BEGIN
+ FOR i IN (
+ SELECT DISTINCT CFM.channel_family_id, SG.org_id
+ FROM rhnChannelFamilyMembers CFM
+ JOIN rhnServerChannel SC
+ ON SC.channel_id = CFM.channel_id
+ JOIN rhnServerGroupMembers SGM
+ ON SC.server_id = SGM.server_id
+ JOIN rhnServerGroup SG
+ ON SGM.server_group_id = SG.id
+ JOIN rhnServerGroupType SGT
+ ON SG.group_type = SGT.id
+ WHERE SGT.label = group_label_in
+ AND SG.org_id = org_id_in
+ AND SGT.is_base = 'Y'
+ ) LOOP
+ perform rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION available_chan_subscriptions(channel_id_in IN NUMERIC,
+ org_id_in IN NUMERIC)
+ RETURNS NUMERIC
+ AS $$
+ declare
+ channel_family_id_val NUMERIC;
+ BEGIN
+ SELECT channel_family_id INTO STRICT channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_family_subscriptions(
+ channel_family_id_val, org_id_in);
+ END$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION available_fve_chan_subs(channel_id_in IN NUMERIC,
+ org_id_in IN NUMERIC)
+ RETURNS NUMERIC
+ AS $$
+ declare
+ channel_family_id_val NUMERIC;
+ BEGIN
+ SELECT channel_family_id INTO STRICT channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_fve_family_subs(
+ channel_family_id_val, org_id_in);
+ END$$ language plpgsql;
+
+ create or replace function unsubscribe_server_from_family(server_id_in in numeric,
+ channel_family_id_in in numeric)
+ returns void
+ as $$
+ begin
+ delete
+ from rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and channel_id in (
+ select rcfm.channel_id
+ from rhnChannelFamilyMembers rcfm
+ where rcfm.channel_family_id = channel_family_id_in);
+ end$$ language plpgsql;
+
+ create or replace function get_org_id(channel_id_in in numeric)
+ returns numeric
+ as $$
+ declare
+ org_id_out numeric;
+ begin
+ select org_id into strict org_id_out
+ from rhnChannel
+ where id = channel_id_in;
+
+ return org_id_out;
+ end$$ language plpgsql;
+
+ create or replace function get_cfam_org_access(cfam_id_in in numeric, org_id_in in numeric)
+ returns numeric
+ as $$
+ begin
+ if exists(
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = org_id_in
+ ) then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$ language plpgsql;
+
+ create or replace function get_org_access(channel_id_in in numeric, org_id_in in numeric)
+ returns integer
+ as $$
+ begin
+ -- the idea: if we get past this query,
+ -- the org has access to the channel, else not
+ if exists(
+ select 1
+ from rhnChannelFamilyMembers CFM,
+ rhnOrgChannelFamilyPermissions CFP
+ where cfp.org_id = org_id_in
+ and CFM.channel_family_id = CFP.channel_family_id
+ and CFM.channel_id = channel_id_in
+ and (CFP.max_members > 0 or CFP.max_members is null or CFP.org_id = 1) )
+ then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$ language plpgsql;
+
+ -- check if a user has a given role, or if such a role is inferrable
+ create or replace function user_role_check_debug(channel_id_in in numeric,
+ user_id_in in numeric,
+ role_in in varchar,
+ status out numeric,
+ reason_out out varchar)
+ as $$
+ declare
+ org_id numeric;
+ begin
+ org_id := rhn_user.get_org_id(user_id_in);
+
+ -- channel might be shared
+ if role_in = 'subscribe' and
+ rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
+ status := 1;
+ return;
+ end if;
+
+ if role_in = 'manage' and
+ COALESCE(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ reason_out := 'channel_not_owned';
+ status := 0;
+ return;
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ reason_out := 'channel_not_available';
+ status := 0;
+ return;
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ reason_out := 'channel_admin';
+ status := 1;
+ return;
+ end if;
+
+ -- the subscribe permission is inferred
+ -- UNLESS the not_globally_subscribable flag is set
+ if role_in = 'subscribe'
+ then
+ if rhn_channel.org_channel_setting(channel_id_in,
+ org_id,
+ 'not_globally_subscribable') = 0 then
+ reason_out := 'globally_subscribable';
+ status := 1;
+ return;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ reason_out := 'direct_permission';
+ status := rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in);
+ return;
+ end$$ language plpgsql;
+
+ -- same as above, but with no OUT param; useful in views, etc
+ create or replace function user_role_check(channel_id_in in numeric, user_id_in in numeric, role_in in varchar)
+ returns numeric
+ as $$
+ declare
+ throwaway record;
+ begin
+ throwaway := rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in);
+ return throwaway.status;
+ end$$ language plpgsql;
+
+ --
+ -- For multiorg phase II, this function simply checks to see if the user's
+ -- has a trust relationship that includes this channel by id.
+ --
+ create or replace function shared_user_role_check(channel_id in numeric, user_id in numeric, role in varchar)
+ returns numeric
+ as $$
+ declare
+ n numeric;
+ oid numeric;
+ begin
+ oid := rhn_user.get_org_id(user_id);
+ select 1 into n
+ from rhnSharedChannelView s
+ where s.id = channel_id and s.org_trust_id = oid;
+
+ if not found then
+ return 0;
+ end if;
+
+ return 1;
+ end$$ language plpgsql;
+
+ -- same as above, but returns 1 if user_id_in is null
+ -- This is useful in queries where user_id is not specified
+ create or replace function loose_user_role_check(channel_id_in in numeric, user_id_in in numeric, role_in in varchar)
+ returns numeric
+ as $$
+ begin
+ if user_id_in is null then
+ return 1;
+ end if;
+ return rhn_channel.user_role_check(channel_id_in, user_id_in, role_in);
+ end$$ language plpgsql;
+
+ -- directly checks the table, no inferred permissions
+ create or replace function direct_user_role_check(channel_id_in in numeric, user_id_in in numeric, role_in in varchar)
+ returns numeric
+ as $$
+ declare
+ throwaway numeric;
+ begin
+ -- the idea: if we get past this query, the user has the role, else no
+ select 1 into throwaway
+ from rhnChannelPermissionRole CPR,
+ rhnChannelPermission CP
+ where CP.user_id = user_id_in
+ and CP.channel_id = channel_id_in
+ and CPR.label = role_in
+ and CP.role_id = CPR.id;
+
+ if not found then
+ return 0;
+ end if;
+
+ return 1;
+ end$$ language plpgsql;
+
+ -- check if an org has a certain setting
+ create or replace function org_channel_setting(channel_id_in in numeric, org_id_in in numeric, setting_in in varchar)
+ returns numeric
+ as $$
+ declare
+ throwaway numeric;
+ begin
+ -- the idea: if we get past this query, the org has the setting
+ select 1 into throwaway
+ from rhnOrgChannelSettingsType OCST,
+ rhnOrgChannelSettings OCS
+ where OCS.org_id = org_id_in
+ and OCS.channel_id = channel_id_in
+ and OCST.label = setting_in
+ and OCS.setting_id = OCST.id;
+
+ if not found then
+ return 0;
+ end if;
+
+ return 1;
+ end$$ language plpgsql;
+
+ CREATE OR REPLACE FUNCTION channel_priority(channel_id_in IN numeric)
+ RETURNS numeric
+ AS $$
+ declare
+ channel_name varchar(256);
+ priority numeric;
+ end_of_life_val timestamptz;
+ org_id_val numeric;
+ BEGIN
+
+ select name, end_of_life, org_id
+ into channel_name, end_of_life_val, org_id_val
+ from rhnChannel
+ where id = channel_id_in;
+
+ if end_of_life_val is not null then
+ return -400;
+ end if;
+
+ if channel_name like 'Red Hat Enterprise Linux%' or channel_name like 'RHEL%' then
+ priority := 1000;
+ if channel_name not like '%Beta%' then
+ priority := priority + 1000;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 5%' then 600
+ when channel_name like '%v. 4%' then 500
+ when channel_name like '%v. 3%' then 400
+ when channel_name like '%v. 2%' then 300
+ when channel_name like '%v. 1%' then 200
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like 'Red Hat Enterprise Linux (v. 5%' then 60
+ when (channel_name like '%AS%' and channel_name not like '%Extras%') then 50
+ when (channel_name like '%ES%' and channel_name not like '%Extras%') then 40
+ when (channel_name like '%WS%' and channel_name not like '%Extras%') then 30
+ when (channel_name like '%Desktop%' and channel_name not like '%Extras%') then 20
+ when channel_name like '%Extras%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%)' then 5
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+ elsif channel_name like 'Red Hat Desktop%' then
+ priority := 900;
+
+ if channel_name not like '%Beta%' then
+ priority := priority + 50;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 4%' then 40
+ when channel_name like '%v. 3%' then 30
+ when channel_name like '%v. 2%' then 20
+ when channel_name like '%v. 1%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+
+ elsif org_id_val is not null then
+ priority := 600;
+ else
+ priority := 500;
+ end if;
+
+ return -priority;
+
+ end$$ language plpgsql;
+
+ -- right now this only does the accounting changes; the cascade
+ -- actually does the rhnServerChannel delete.
+ create or replace function delete_server_channels(server_id_in in numeric) returns void
+ as $$
+ begin
+ update rhnPrivateChannelFamily
+ set current_members = current_members -1
+ where org_id in (
+ select org_id
+ from rhnServer
+ where id = server_id_in
+ )
+ and channel_family_id in (
+ select rcfm.channel_family_id
+ from rhnChannelFamilyMembers rcfm,
+ rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and rsc.channel_id = rcfm.channel_id
+ and not exists (
+ select 1
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnServerEntitlementView sev,
+ rhnVirtualInstance vi
+ where
+ -- system is a virtual instance
+ vi.virtual_system_id = server_id_in
+ and vi.host_system_id = sev.server_id
+ -- system's host has a virt ent
+ and sev.label in ('virtualization_host',
+ 'virtualization_host_platform')
+ and sev.server_group_type_id =
+ sgtvsl.server_group_type_id
+ -- the host's virt ent grants a cf virt sub level
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ -- the cf is in that virt sub level
+ and cfvsl.channel_family_id = rcfm.channel_family_id
+ )
+ );
+ end$$ language plpgsql;
+
+ -- this could certainly be optimized to do updates if needs be
+ create or replace function refresh_newest_package(channel_id_in in numeric, caller_in in varchar default '(unknown)') returns void
+ as $$
+ begin
+ delete from rhnChannelNewestPackage where channel_id = channel_id_in;
+ insert into rhnChannelNewestPackage
+ ( channel_id, name_id, evr_id, package_id, package_arch_id )
+ ( select channel_id,
+ name_id, evr_id,
+ package_id, package_arch_id
+ from rhnChannelNewestPackageView
+ where channel_id = channel_id_in
+ );
+ insert into rhnChannelNewestPackageAudit (channel_id, caller)
+ values (channel_id_in, caller_in);
+ update rhnChannel
+ set last_modified = greatest(current_timestamp, last_modified + interval '1 second')
+ where id = channel_id_in;
+ end$$ language plpgsql;
+
+ create or replace function update_channel ( channel_id_in in numeric, invalidate_ss in numeric default 0,
+ date_to_use in timestamptz default current_timestamp ) returns void
+ as $$
+ declare
+ channel_last_modified timestamptz;
+ last_modified_value timestamptz;
+
+ snapshots cursor for
+ select snapshot_id id
+ from rhnSnapshotChannel
+ where channel_id = channel_id_in;
+
+ begin
+
+ select last_modified
+ into channel_last_modified
+ from rhnChannel
+ where id = channel_id_in;
+
+ last_modified_value := date_to_use;
+
+ if last_modified_value <= channel_last_modified then
+ last_modified_value := last_modified_value + interval '1 second';
+ end if;
+
+ update rhnChannel set last_modified = last_modified_value
+ where id = channel_id_in;
+
+ if invalidate_ss = 1 then
+ for snapshot in snapshots loop
+ update rhnSnapshot
+ set invalid = lookup_snapshot_invalid_reason('channel_modified')
+ where id = snapshot.id;
+ end loop;
+ end if;
+
+ end$$ language plpgsql;
+
+ create or replace function update_channels_by_package ( package_id_in in numeric, date_to_use in timestamptz default current_timestamp ) returns void
+ as $$
+ declare
+ channels cursor for
+ select channel_id
+ from rhnChannelPackage
+ where package_id = package_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we want to invalidate the snapshot assocated with the channel when we
+ -- do this b/c we know we've added or removed or packages
+ perform rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
+ end loop;
+ end$$ language plpgsql;
+
+
+ create or replace function update_channels_by_errata ( errata_id_in numeric, date_to_use in timestamptz default current_timestamp ) returns void
+ as $$
+ declare
+ channels cursor for
+ select channel_id
+ from rhnChannelErrata
+ where errata_id = errata_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we won't invalidate snapshots, b/c just changing the errata associated with
+ -- a channel shouldn't invalidate snapshots
+ perform rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
+ end loop;
+ end$$ language plpgsql;
+
+ create or replace function update_needed_cache(channel_id_in in numeric) returns void
+ as $$
+ declare
+ server record;
+ begin
+ -- we intentionaly do a loop here instead of one huge select
+ -- b/c we want to break update into smaller transaction to unblock other sessions
+ -- querying rhnServerNeededCache
+ for server in (
+ select sc.server_id as id
+ from rhnServerChannel sc
+ where sc.channel_id = channel_id_in
+ ) loop
+ perform rhn_server.update_needed_cache(server.id);
+ end loop;
+ end$$ language plpgsql;
+
+-- restore the original setting
+update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_channel')+1) ) where name = 'search_path';
commit 08931b0b2f8d7f49325e4288dbe6e8e202c535c9
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Sep 20 16:10:47 2011 +0200
upgrade for rhn_entitlements
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.oracle
new file mode 100644
index 0000000..b7b00b1
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.oracle
@@ -0,0 +1 @@
+-- This file is intentionally left empty.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql
new file mode 100644
index 0000000..2ef2291
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.5-to-spacewalk-schema-1.6/090-rhn_entitlements.sql.postgresql
@@ -0,0 +1,2154 @@
+-- oracle equivalent source sha1 b14267384bc104605623a41b755e68e0103b5aa8
+
+drop schema if exists rhn_entitlements cascade ;
+
+--
+-- Copyright (c) 2008--2010 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+create schema rhn_entitlements;
+
+-- setup search_path so that these functions are created in appropriate schema.
+update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path';
+
+ create or replace function remove_org_entitlements (
+ org_id_in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function entitlement_grants_service (
+ entitlement_in in varchar,
+ service_level_in in varchar
+ ) returns numeric
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function lookup_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function create_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function can_entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function remove_server_entitlement (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled',
+ repoll_virt_guests in numeric default 1
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function unentitle_server (
+ server_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function repoll_virt_guest_entitlements(
+ server_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function get_server_entitlement (
+ server_id_in in numeric
+ ) returns varchar[]
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function modify_org_service (
+ org_id_in in numeric,
+ service_label_in in varchar,
+ enable_in in char
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function set_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function set_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function set_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function unset_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function unset_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function unset_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function assign_system_entitlement(
+ group_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function assign_channel_entitlement(
+ channel_family_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function activate_system_entitlement(
+ org_id_in in numeric,
+ group_label_in in varchar,
+ quantity_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function activate_channel_entitlement(
+ org_id_in in numeric,
+ channel_family_label_in in varchar,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function set_group_count (
+ customer_id_in in numeric, -- customer_id
+ type_in in char, -- 'U' or 'S'
+ group_type_in in numeric, -- rhn[User|Server]GroupType.id
+ quantity_in in numeric, -- quantity
+ update_family_countsYN in numeric default 1 -- call update_family_counts inside
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function set_family_count (
+ customer_id_in in numeric, -- customer_id
+ channel_family_id_in in numeric, -- 246
+ quantity_in in numeric, -- 3
+ flex_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ -- this makes NO checks that the quantity is within max,
+ -- so we should NEVER run this unless we KNOW that we won't be
+ -- violating the max
+ create or replace function entitle_last_modified_servers (
+ customer_id_in in numeric, -- customer_id
+ type_label_in in varchar, -- 'enterprise_entitled'
+ quantity_in in numeric -- 3
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+ create or replace function subscribe_newest_servers (
+ customer_id_in in numeric
+ ) returns void
+as $$
+BEGIN
+ RAISE EXCEPTION 'Stub called, must be replaced by .pkb';
+END;
+$$ language plpgsql;
+
+-- restore the original setting
+update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path';
+
+
+--
+-- Copyright (c) 2008--2011 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+-- create schema rhn_entitlements;
+
+-- setup search_path so that these functions are created in appropriate schema.
+update pg_settings set setting = 'rhn_entitlements,' || setting where name = 'search_path';
+
+ create or replace function find_compatible_sg (
+ server_id_in in numeric,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ servergroups cursor for
+ select sg.id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerServerGroupArchCompat ssgac
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sgt.label = type_label_in
+ and sg.group_type = sgt.id
+ and ssgac.server_group_type = sgt.id
+ and ssgac.server_arch_id = s.server_arch_id
+ and not exists (
+ select 1
+ from rhnServerGroupMembers sgm
+ where sgm.server_group_id = sg.id
+ and sgm.server_id = s.id);
+
+
+ begin
+ for servergroup in servergroups loop
+ return servergroup.id;
+ end loop;
+
+ --no servergroup found
+ return NULL;
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: remove_org_entitlements
+ --
+ -- Removes both system entitlements and channel subscriptions
+ -- that are currently assigned to an org and re-assigns to the
+ -- master org (org_id = 1).
+ --
+ -- When we call this we expect everything to already be unentitled
+ -- which shoul be handled by delete_org.
+ --
+ -- Called by: delete_org
+ -- *******************************************************************
+ create or replace function remove_org_entitlements (
+ org_id_in numeric
+ ) returns void
+as $$
+ declare
+ system_ents cursor for
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ channel_subs cursor for
+ select pcf.channel_family_id, pcf.max_members
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.org_id is null;
+
+ begin
+
+ for system_ent in system_ents loop
+ update rhnServerGroup
+ set max_members = max_members + system_ent.max_members
+ where org_id = 1
+ and group_type = system_ent.group_type;
+ end loop;
+
+ update rhnServerGroup
+ set max_members = 0
+ where org_id = org_id_in;
+
+ for channel_sub in channel_subs loop
+ update rhnPrivateChannelFamily
+ set max_members = max_members + channel_sub.max_members
+ where org_id = 1
+ and channel_family_id = channel_sub.channel_family_id;
+ end loop;
+
+ update rhnPrivateChannelFamily
+ set max_members = 0
+ where org_id = org_id_in;
+
+ end$$
+language plpgsql;
+
+ create or replace function entitlement_grants_service (
+ entitlement_in in varchar,
+ service_level_in in varchar
+ ) returns numeric
+as $$
+ begin
+ if service_level_in = 'provisioning' then
+ if entitlement_in = 'provisioning_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'management' then
+ if entitlement_in = 'enterprise_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'monitoring' then
+ if entitlement_in = 'monitoring_entitled' then
+ return 1;
+ end if;
+ elsif service_level_in = 'updates' then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function lookup_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+ declare
+ server_groups cursor for
+ select sg.id server_group_id
+ from rhnServerGroup sg,
+ rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ and sgt.id = sg.group_type
+ and sg.org_id = org_id_in;
+ begin
+ for sg in server_groups loop
+ return sg.server_group_id;
+ end loop;
+ return rhn_entitlements.create_entitlement_group(
+ org_id_in,
+ type_label_in
+ );
+ end$$
+language plpgsql;
+
+ create or replace function create_entitlement_group (
+ org_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns numeric
+as $$
+ declare
+ sg_id_val numeric;
+ begin
+ select nextval('rhn_server_group_id_seq')
+ into sg_id_val;
+
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id
+ ) (
+ select sg_id_val, sgt.label, sgt.label,
+ 0, 0, sgt.id, org_id_in
+ from rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ );
+
+ return sg_id_val;
+ end$$
+language plpgsql;
+
+ create or replace function can_entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ addon_servergroups cursor (base_label_in varchar,
+ addon_label_in varchar) for
+ select
+ addon_id
+ from
+ rhnSGTypeBaseAddonCompat
+ where base_id = lookup_sg_type (base_label_in)
+ and addon_id = lookup_sg_type (addon_label_in);
+
+ previous_ent varchar[];
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i numeric := 0;
+ sgid numeric := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
+
+ select distinct is_base
+ into is_base_in
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if array_upper(previous_ent, 1) is null or array_upper(previous_ent, 1) = 0 then
+ if is_base_in = 'Y' then
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- there are previous ents, first make sure we're not trying to entitle a base ent
+ elsif is_base_in = 'Y' then
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+
+ -- it must be an addon, so proceed with the entitlement
+ else
+
+ -- find the servers base ent
+ is_base_current := 'N';
+ i := 0;
+ while is_base_current = 'N' and i < array_upper(previous_ent, 1)
+ loop
+ i := i + 1;
+ select is_base
+ into is_base_current
+ from rhnServerGroupType
+ where label = previous_ent[i];
+ end loop;
+
+ -- never found a base ent, that would be strange
+ if is_base_current = 'N' then
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- this for loop verifies the validity of the addon path
+ for addon_servergroup in addon_servergroups (previous_ent[i], type_label_in) loop
+ -- find an appropriate sgid for the addon and entitle the server
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+ end if;
+ end loop;
+
+ end if;
+
+ return 0;
+
+ end$$
+language plpgsql;
+
+ create or replace function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar
+ )
+ returns numeric
+as $$
+ declare
+ type_label_in_is_base char(1);
+ sgid numeric;
+
+ begin
+
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end if;
+
+ if type_label_in_is_base = 'N' then
+ perform rhn_exception.raise_exception ( 'invalid_entitlement' );
+ else
+ sgid := rhn_entitlements.find_compatible_sg ( server_id_in,
+ type_label_in );
+ if sgid is not null then
+ return 1;
+ else
+ return 0;
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function entitle_server (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled'
+ ) returns void
+as $$
+ declare
+ sgid numeric := 0;
+ is_virt numeric := 0;
+
+ begin
+
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ if is_virt = 0 and (type_label_in = 'virtualization_host' or
+ type_label_in = 'virtualization_host_platform') then
+
+ is_virt := 1;
+ end if;
+
+ if rhn_entitlements.can_entitle_server(server_id_in,
+ type_label_in) = 1 then
+ sgid := rhn_entitlements.find_compatible_sg (server_id_in,
+ type_label_in);
+ if sgid is not null then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'added system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ perform rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ perform rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ perform rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function remove_server_entitlement (
+ server_id_in in numeric,
+ type_label_in in varchar default 'sw_mgr_entitled',
+ repoll_virt_guests in numeric default 1
+ ) returns void
+as $$
+ declare
+ group_id numeric;
+ type_is_base char;
+ is_virt numeric := 0;
+ begin
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ if not found then
+ is_virt := 0;
+ end if;
+
+ select sg.id, sgt.is_base
+ into group_id, type_is_base
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnServer s
+ where s.id = server_id_in
+ and s.id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.org_id = s.org_id
+ and sgt.label = type_label_in
+ and sgt.id = sg.group_type;
+
+ if not found then
+ perform rhn_exception.raise_exception('invalid_server_group_member');
+ end if;
+
+ if ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ perform rhn_entitlements.unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'removed system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platforrm' end );
+
+ perform rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ -- special case: clean up related monitoring data
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM state_change
+ WHERE o_id IN (SELECT probe_id::varchar
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE
+ FROM time_series
+ WHERE substring(o_id FROM position('-' IN o_id) + 1
+ FOR position('-' IN substring(o_id FROM position('-' IN o_id) + 1)) - 1)
+ IN (SELECT probe_id::text
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE
+ FROM rhn_probe
+ WHERE recid IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ end if;
+
+ if is_virt = 1 and repoll_virt_guests = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function unentitle_server (
+ server_id_in in numeric
+ ) returns void
+as $$
+ declare
+ servergroups cursor for
+ select distinct sgt.label, sg.id server_group_id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerGroupMembers sgm
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sg.group_type = sgt.id
+ and sgm.server_group_id = sg.id
+ and sgm.server_id = s.id;
+
+ is_virt numeric := 0;
+
+ begin
+
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( nextval('rhn_event_id_seq'), server_id_in,
+ 'removed system entitlement ',
+ case servergroup.label
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ perform rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ perform rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: repoll_virt_guest_entitlements
+ --
+ -- Whenever we add/remove a virtualization_host* entitlement from
+ -- a host, we can call this procedure to update what type of slots
+ -- the guests are consuming.
+ --
+ -- If you're removing the entitlement, it's
+ -- possible the guests will become unentitled if you don't have enough
+ -- physical slots to cover them.
+ --
+ -- If you're adding the entitlement, you end up freeing up physical
+ -- slots for other systems.
+ --
+ -- *******************************************************************
+ create or replace function repoll_virt_guest_entitlements(
+ server_id_in in numeric
+ ) returns void
+as $$
+ declare
+ -- All channel families associated with the guests of server_id_in
+ families cursor for
+ select distinct cfs.channel_family_id
+ from
+ rhnChannelFamilyServers cfs,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = cfs.server_id;
+
+ -- All of server group types associated with the guests of
+ -- server_id_in
+ group_types cursor for
+ select distinct sg.group_type, sgt.label
+ from
+ rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+
+ -- Virtual servers from a certain family belonging to a specific
+ -- host that are consuming physical channel slots over the limit.
+ virt_servers_cfam cursor(family_id_in numeric, quantity_in numeric) for
+ select vi.virtual_system_id
+ from
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = family_id_in
+ order by sc.modified desc
+ limit quantity_in;
+
+ -- Virtual servers from a certain family belonging to a specific
+ -- host that are consuming physical system slots over the limit.
+ virt_servers_sgt cursor(group_type_in numeric, quantity_in numeric) for
+ select vi.virtual_system_id
+ from
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = group_type_in
+ order by sgm.modified desc
+ limit quantity_in;
+
+ -- Get the orgs of Virtual guests
+ -- Since they may belong to different orgs
+ virt_guest_orgs cursor for
+ select distinct (s.org_id)
+ from rhnServer s
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
+ where
+ vi.host_system_id = server_id_in
+ and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
+
+ org_id_val numeric;
+ max_members_val numeric;
+ max_flex_val numeric;
+ current_members_calc numeric;
+ sg_id numeric;
+ is_virt numeric := 0;
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id in (
+ select vi.virtual_system_id
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ limit free_slots
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
+ -- get the current (physical) members of the family
+ current_members_calc :=
+ rhn_channel.channel_family_current_members(family.channel_family_id,
+ org_id_val); -- fixed transposed args
+
+ -- get the max members of the family
+ select max_members
+ into max_members_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ select fve_max_members
+ into max_flex_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, so we'll
+ -- unsubscribe guests from the host first.
+
+ -- hm, i don't think max_members - current_members_calc yielding a negative number
+ -- will work w/ rownum, swaping 'em in the body of this if...
+ for virt_server in virt_servers_cfam(family.channel_family_id,
+ current_members_calc - max_members_val) loop
+
+ perform rhn_channel.unsubscribe_server_from_family(
+ virt_server.virtual_system_id,
+ family.channel_family_id);
+ end loop;
+
+ -- if we're still over the limit, which would be odd,
+ -- just prune the group to max_members
+ --
+ -- er... wouldn't we actually have to refresh the values of
+ -- current_members_calc and max_members_val to actually ever
+ -- *skip this??
+ if current_members_calc > max_members_val then
+ -- argh, transposed again?!
+ perform rhn_entitlements.set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val, max_flex_val);
+ --TODO calculate this correctly
+ end if;
+
+ end if;
+
+ -- update current_members for the family. This will set the value
+ -- to reflect adding/removing the entitlement.
+ --
+ -- what's the difference of doing this vs the unavoidable set_family_count above?
+ perform rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+
+ -- It is possible that the guests belong to a different org than the host
+ -- so we are going to update the family counts in the guests orgs also
+ for org in virt_guest_orgs loop
+ perform rhn_channel.update_family_counts(family.channel_family_id,
+ org.org_id);
+ end loop;
+ end loop;
+
+ for a_group_type in group_types loop
+ -- get the current *physical* members of the system entitlement type for the org...
+ --
+ -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
+ -- *physical* slots, vs physical+virt ... boy that's confusing...
+
+ select max_members, id
+ into max_members_val, sg_id
+ from rhnServerGroup
+ where group_type = a_group_type.group_type
+ and org_id = org_id_val;
+
+
+ select count(sep.server_id) into current_members_calc
+ from rhnServerEntitlementPhysical sep
+ where sep.server_group_id = sg_id
+ and sep.server_group_type_id = a_group_type.group_type;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
+ for virt_server in virt_servers_sgt(a_group_type.group_type,
+ current_members_calc - max_members_val) loop
+ perform rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
+
+ -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
+ current_members_calc := current_members_calc - 1;
+ end loop;
+
+ end if;
+
+ update rhnServerGroup set current_members = current_members_calc
+ where org_id = org_id_val
+ and group_type = a_group_type.group_type;
+
+ -- I think that's all the house-keeping we have to do...
+ end loop;
+
+ end$$
+language plpgsql;
+
+ create or replace function get_server_entitlement (
+ server_id_in in numeric
+ ) returns varchar[]
+as $$
+ declare
+ server_groups cursor for
+ select sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_id = server_id_in
+ and sg.id = sgm.server_group_id
+ and sgt.id = sg.group_type
+ and sgt.label in (
+ 'sw_mgr_entitled','enterprise_entitled',
+ 'provisioning_entitled', 'nonlinux_entitled',
+ 'monitoring_entitled', 'virtualization_host',
+ 'virtualization_host_platform'
+ );
+
+ ent_array varchar[];
+
+ begin
+
+ ent_array := '{}';
+
+ for sg in server_groups loop
+ ent_array := ent_array || sg.label;
+ end loop;
+
+ return ent_array;
+
+ end$$
+language plpgsql;
+
+ -- this desperately needs to be table driven.
+ create or replace function modify_org_service (
+ org_id_in in numeric,
+ service_label_in in varchar,
+ enable_in in char
+ ) returns void
+as $$
+ declare
+ roles_to_process varchar[];
+ roles cursor(role_label_in varchar) for
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ org_roles cursor(role_label_in varchar) for
+ select 1
+ from rhnUserGroup ug,
+ rhnUserGroupType ugt
+ where ugt.label = role_label_in
+ and ug.org_id = org_id_in
+ and ugt.id = ug.group_type;
+
+ ents_to_process varchar[];
+ ents cursor(ent_label_in varchar) for
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ org_ents cursor(ent_label_in varchar) for
+ select 1
+ from rhnOrgEntitlements oe,
+ rhnOrgEntitlementType oet
+ where oet.label = ent_label_in
+ and oe.org_id = org_id_in
+ and oet.id = oe.entitlement_id;
+ create_row char(1);
+ begin
+ ents_to_process := '{}';
+ roles_to_process := '{}';
+ -- a bit kludgy, but only for 3.4 really. Certainly no
+ -- worse than the old code...
+ if service_label_in = 'enterprise' or
+ service_label_in = 'management' then
+ ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
+
+ roles_to_process := array_append(roles_to_process, 'org_admin');
+
+ roles_to_process := array_append(roles_to_process, 'system_group_admin');
+
+ roles_to_process := array_append(roles_to_process, 'activation_key_admin');
+
+ roles_to_process := array_append(roles_to_process, 'org_applicant');
+ elsif service_label_in = 'provisioning' then
+ ents_to_process := array_append(ents_to_process, 'rhn_provisioning');
+
+ roles_to_process := array_append(roles_to_process, 'system_group_admin');
+
+ roles_to_process := array_append(roles_to_process, 'activation_key_admin');
+
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process := array_append(ents_to_process, 'sw_mgr_enterprise');
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process := array_append(ents_to_process, 'rhn_monitor');
+
+ roles_to_process := array_append(roles_to_process, 'monitoring_admin');
+ elsif service_label_in = 'virtualization' then
+ ents_to_process := array_append(ents_to_process, 'rhn_virtualization');
+
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process := array_append(ents_to_process, 'rhn_virtualization_platform');
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process := array_append(ents_to_process, 'rhn_nonlinux');
+ roles_to_process := array_append(roles_to_process, 'config_admin');
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..array_upper(ents_to_process, 1) loop
+ for ent in ents(ents_to_process[i]) loop
+ create_row := 'Y';
+ for oe in org_ents(ent.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnOrgEntitlements(org_id, entitlement_id)
+ values (org_id_in, ent.id);
+ end if;
+ end loop;
+ end loop;
+ for i in 1..array_upper(roles_to_process, 1) loop
+ for role in roles(roles_to_process[i]) loop
+ create_row := 'Y';
+ for o_r in org_roles(role.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnUserGroup(
+ id, name, description, current_members,
+ group_type, org_id
+ ) (
+ select nextval('rhn_user_group_id_seq'),
+ ugt.name || 's',
+ ugt.name || 's for Org ' ||
+ o.name || ' ('|| o.id ||')',
+ 0, ugt.id, o.id
+ from rhnUserGroupType ugt,
+ web_customer o
+ where o.id = org_id_in
+ and ugt.id = role.id
+ );
+ end if;
+ end loop;
+ end loop;
+ else
+ for i in 1..coalesce(array_upper(ents_to_process, 1), 0) loop
+ for ent in ents(ents_to_process[i]) loop
+ delete from rhnOrgEntitlements
+ where org_id = org_id_in
+ and entitlement_id = ent.id;
+ end loop;
+ end loop;
+ end if;
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_monitoring (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function set_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_enterprise (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'enterprise', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_provisioning (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'provisioning', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_monitoring (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'monitoring', 'N');
+ end$$
+language plpgsql;
+
+ create or replace function unset_customer_nonlinux (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ begin
+ perform rhn_entitlements.modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_group_count, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ create or replace function prune_group (
+ group_id_in in numeric,
+ type_in in char,
+ quantity_in in numeric,
+ update_family_countsYN in numeric default 1
+ ) returns void
+as $$
+ declare
+ ugrecord record;
+ sgrecord record;
+ type_is_base char;
+ begin
+ if type_in = 'U' then
+ update rhnUserGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for ugrecord in (
+ select user_id, user_group_id, ugt.label
+ from rhnUserGroupType ugt,
+ rhnUserGroup ug,
+ rhnUserGroupMembers ugm
+ where 1=1
+ and ugm.user_group_id = group_id_in
+ and ugm.user_id in (
+ select user_id
+ from rhnUserGroupMembers
+ where user_group_id = group_id_in
+ order by modified asc
+ offset quantity_in
+ )
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id
+ ) loop
+ perform rhn_user.remove_from_usergroup(ugrecord.user_id, ugrecord.user_group_id);
+ end loop;
+ elsif type_in = 'S' then
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sgrecord in (
+ select server_id, server_group_id, sgt.id as group_type_id, sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_group_id = group_id_in
+ and sgm.server_id in (
+ select sep.server_id
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by sep.modified asc
+ offset quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id
+ ) loop
+ perform rhn_entitlements.remove_server_entitlement(sgrecord.server_id, sgrecord.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sgrecord.group_type_id;
+
+ -- if we're removing a base ent, then be sure to
+ -- remove the server's channel subscriptions.
+ if ( type_is_base = 'Y' ) then
+ perform rhn_channel.clear_subscriptions(sgrecord.server_id, update_family_countsYN);
+ end if;
+
+ end loop;
+ end if;
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_system_entitlement
+ --
+ -- Moves system entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_group_count
+ -- *******************************************************************
+ create or replace function assign_system_entitlement(
+ group_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ to_org_prev_ent_count numeric;
+ new_ent_count numeric;
+ new_quantity numeric;
+ group_type numeric;
+ begin
+
+ select max_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = from_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ select max_members
+ into to_org_prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = to_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+
+ if not found then
+ to_org_prev_ent_count := 0;
+ end if;
+
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end if;
+
+ new_ent_count := prev_ent_count - quantity_in;
+
+ if prev_ent_count > new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if new_ent_count < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ perform rhn_entitlements.set_group_count(from_org_id_in,
+ 'S',
+ group_type,
+ new_ent_count);
+
+ perform rhn_entitlements.set_group_count(to_org_id_in,
+ 'S',
+ group_type,
+ new_quantity);
+
+ -- Create or delete the entries in rhnOrgEntitlementType
+ if group_label_in = 'enterprise_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_enterprise(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_provisioning(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ perform rhn_entitlements.set_customer_monitoring(to_org_id_in);
+ else
+ perform rhn_entitlements.unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_channel_entitlement
+ --
+ -- Moves channel entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_family_count
+ -- *******************************************************************
+ create or replace function assign_channel_entitlement(
+ channel_family_label_in in varchar,
+ from_org_id_in in numeric,
+ to_org_id_in in numeric,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ from_org_prev_ent_count numeric;
+ from_org_prev_ent_count_flex numeric;
+ new_ent_count numeric;
+ new_ent_count_flex numeric;
+ to_org_prev_ent_count numeric;
+ to_org_prev_ent_count_flex numeric;
+ new_quantity numeric;
+ new_flex numeric;
+ cfam_id numeric;
+ begin
+
+ select max_members
+ into from_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ select max_members
+ into to_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ to_org_prev_ent_count := 0;
+ end if;
+
+ select fve_max_members
+ into from_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+ select fve_max_members
+ into to_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ to_org_prev_ent_count_flex := 0;
+ end if;
+
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end if;
+
+ new_ent_count := from_org_prev_ent_count - quantity_in;
+ new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
+
+ if from_org_prev_ent_count >= new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if from_org_prev_ent_count_flex >= new_ent_count_flex then
+ new_flex := to_org_prev_ent_count_flex + flex_in;
+ end if;
+
+ if new_ent_count < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ if new_ent_count_flex < 0 then
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+
+
+ perform rhn_entitlements.set_family_count(from_org_id_in,
+ cfam_id,
+ new_ent_count,
+ new_ent_count_flex);
+
+ perform rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity,
+ new_flex);
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_system_entitlement
+ --
+ -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
+ --
+ -- Calls: set_group_count to update, prune, or create the group.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if all entitlements
+ -- in the org are used so the free entitlements would not cover
+ -- the difference when descreasing the number of entitlements.
+ -- *******************************************************************
+ create or replace function activate_system_entitlement(
+ org_id_in in numeric,
+ group_label_in in varchar,
+ quantity_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ prev_ent_count_sum numeric;
+ group_type numeric;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+
+ select current_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.group_type = sgt.id
+ and sgt.label = group_label_in
+ and sg.org_id = org_id_in;
+
+ if not found then
+ prev_ent_count := 0;
+ end if;
+
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end if;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the allocated count in this org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ perform rhn_entitlements.set_group_count(org_id_in,
+ 'S',
+ group_type,
+ quantity_in,
+ 0);
+ -- bulk update family counts
+ perform rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_channel_entitlement
+ --
+ -- Calls: set_family_count to update, prune, or create the family
+ -- permission bucket.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if there are not enough
+ -- entitlements in the org to cover the difference when you are
+ -- descreasing the number of entitlements.
+ --
+ -- The backend code in Python is expected to do whatever arithmetics
+ -- is needed.
+ -- *******************************************************************
+ create or replace function activate_channel_entitlement(
+ org_id_in in numeric,
+ channel_family_label_in in varchar,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ prev_ent_count numeric;
+ prev_flex_count numeric;
+ prev_ent_count_sum numeric;
+ cfam_id numeric;
+ reduce_quantity numeric;
+ total_flex_capable numeric;
+ to_convert_reg cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
+ select SC.server_id
+ from rhnServerChannel SC inner join
+ rhnServer S on S.id = SC.server_id
+ where
+ is_fve = 'Y'
+ and S.org_id = org_id_in
+ and SC.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
+ limit quantity;
+ to_convert_flex cursor (channel_family_id_val numeric, org_id_in numeric, quantity numeric) for
+ select server_id
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id
+ limit quantity;
+
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ select current_members
+ into prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ prev_ent_count := 0;
+ end if;
+
+ select pcf.fve_current_members
+ into prev_flex_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+
+ if not found then
+ prev_flex_count := 0;
+ end if;
+
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+
+ if not found then
+ perform rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end if;
+
+ -- if there are too few flex entitlements
+ if flex_in < prev_flex_count then
+ -- and if the extra we need is less than or equal to our extra regular entitlements
+ if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
+ reduce_quantity := prev_flex_count - flex_in;
+ -- We need to convert some systems from flex guest to regular
+ for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
+ --rhn_channel.convert_to_regular(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+
+ --reset previous counts
+ prev_ent_count := prev_ent_count + reduce_quantity;
+ prev_flex_count := prev_flex_count - reduce_quantity;
+ else
+ perform rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+ end if;
+
+ -- if there are too few regular entitlements, and extra flex entitlements
+ if quantity_in < prev_ent_count and prev_flex_count < flex_in then
+ -- how many flex-capable systems (that aren't using flex) do we have
+ select count(*)
+ into total_flex_capable
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id;
+ -- if we have enough flex capable machines that is at least
+ -- as many as what we are over on
+ if total_flex_capable >= prev_ent_count - quantity_in then
+ reduce_quantity := prev_ent_count - quantity_in;
+ for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
+-- rhn_channel.convert_to_fve(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+ prev_ent_count := prev_ent_count - reduce_quantity;
+ prev_flex_count := prev_flex_count + reduce_quantity;
+ end if;
+ end if;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the count in that one org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ perform rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- even if we've manually converted systems to/from flex above
+ -- set_family_count should call update_family_counts, to reset
+ -- current used slots
+ perform rhn_entitlements.set_family_count(org_id_in, cfam_id,
+ quantity_in, flex_in);
+ end if;
+
+ end$$
+language plpgsql;
+
+ create or replace function set_group_count (
+ customer_id_in in numeric, -- customer_id
+ type_in in char, -- 'U' or 'S'
+ group_type_in in numeric, -- rhn[User|Server]GroupType.id
+ quantity_in in numeric, -- quantity
+ update_family_countsYN in numeric default 1
+ ) returns void
+as $$
+ declare
+ group_id numeric;
+ quantity numeric;
+ wasfound boolean;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ if type_in = 'U' then
+ select rug.id
+ into group_id
+ from rhnUserGroup rug
+ where 1=1
+ and rug.org_id = customer_id_in
+ and rug.group_type = group_type_in;
+ elsif type_in = 'S' then
+ select rsg.id
+ into group_id
+ from rhnServerGroup rsg
+ where 1=1
+ and rsg.org_id = customer_id_in
+ and rsg.group_type = group_type_in;
+ end if;
+
+ -- preserve the not found status across the rhn_entitlements.prune_group invocation
+ wasfound := true;
+ if not found then
+ wasfound := false;
+ end if;
+
+ perform rhn_entitlements.prune_group(
+ group_id,
+ type_in,
+ quantity,
+ update_family_countsYN
+ );
+
+ if not wasfound then
+ if type_in = 'U' then
+ insert into rhnUserGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select nextval('rhn_user_group_id_seq'), name, name,
+ quantity, 0, id, customer_id_in,
+ current_timestamp, current_timestamp
+ from rhnUserGroupType
+ where id = group_type_in
+ );
+ elsif type_in = 'S' then
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select nextval('rhn_server_group_id_seq'), name, name,
+ quantity, 0, id, customer_id_in,
+ current_timestamp, current_timestamp
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end if;
+ end if;
+
+ end$$
+language plpgsql;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count
+ -- *******************************************************************
+ create or replace function prune_family (
+ customer_id_in in numeric,
+ channel_family_id_in in numeric,
+ quantity_in in numeric,
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ is_fve_in char;
+ tmp_quantity numeric;
+
+ serverchannels cursor for
+ select sc.server_id,
+ sc.channel_id
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where 1=1
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and server_id in (
+ select rs.id as server_id
+ from
+ rhnServerChannel rsc,
+ rhnChannelFamilyMembers rcfm,
+ rhnServer rs
+ where 1=1
+ and rs.org_id = customer_id_in
+ and rs.id = rsc.server_id
+ and rsc.channel_id = rcfm.channel_id
+ and rcfm.channel_family_id = channel_family_id_in
+ and rsc.is_fve = is_fve_in
+ -- we only want to grab servers consuming
+ -- physical slots.
+ and exists (
+ select 1
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.server_id = rs.id
+ and cfsp.channel_family_id =
+ channel_family_id_in
+ )
+ order by rcfm.modified asc
+ offset quantity_in
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ tmp_quantity := quantity_in;
+ is_fve_in := 'N';
+
+ for sc in serverchannels loop
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1, 0, 0);
+
+ tmp_quantity := flex_in;
+ is_fve_in := 'Y';
+ for sc in serverchannels loop
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1, 0, 0);
+ end loop;
+ end loop;
+ perform rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end$$
+language plpgsql;
+
+ create or replace function set_family_count (
+ customer_id_in in numeric, -- customer_id
+ channel_family_id_in in numeric, -- 246
+ quantity_in in numeric, -- 3
+ flex_in in numeric
+ ) returns void
+as $$
+ declare
+ privperms cursor for
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ pubperms cursor for
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity numeric;
+ done numeric := 0;
+ flex numeric;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+ flex := flex_in;
+ if flex is not null and flex < 0 then
+ flex := 0;
+ end if;
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ perform rhn_entitlements.prune_family(
+ customer_id_in,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+
+ if quantity is null and flex is null then
+ delete from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ else
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ update rhnPrivateChannelFamily
+ set fve_max_members = flex
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ end if;
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ perform rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+ if done = 0 then
+ delete from rhnPublicChannelFamily
+ where channel_family_id = channel_family_id_in;
+ end if;
+ end if;
+ done := 1;
+ end loop;
+ -- if done's not 1, then we don't have any entitlements
+ if done != 1 then
+ insert into rhnPublicChannelFamily (
+ channel_family_id
+ ) values (
+ channel_family_id_in
+ );
+ end if;
+ end$$
+language plpgsql;
+
+ -- this expects quantity_in to be the number of available slots, not the
+ -- max_members of the server group. If you give it too many, it'll fail
+ -- and raise servergroup_max_members.
+ -- We should NEVER run this unless we're SURE that we won't
+ -- be violating the max.
+ create or replace function entitle_last_modified_servers (
+ customer_id_in in numeric, -- customer_id
+ type_label_in in varchar, -- 'enterprise_entitled'
+ quantity_in in numeric -- 3
+ ) returns void
+as $$
+ declare
+ -- find the servers that aren't currently in slots
+ servers cursor(cid_in numeric, quant_in numeric) for
+ select rs.id as server_id
+ from rhnServer rs
+ where 1=1
+ and rs.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnServerGroup sg,
+ rhnServerGroupMembers rsgm
+ where rsgm.server_id = rs.id
+ and rsgm.server_group_id = sg.id
+ and sg.group_type is not null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id =
+ rs.id
+ )
+ order by modified desc
+ limit quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ perform rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end$$
+language plpgsql;
+
+ create or replace function subscribe_newest_servers (
+ customer_id_in in numeric
+ ) returns void
+as $$
+ declare
+ -- find servers without base channels
+ servers cursor(cid_in numeric) for
+ select s.id
+ from rhnServer s
+ where 1=1
+ and s.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnChannel c,
+ rhnServerChannel sc
+ where sc.server_id = s.id
+ and sc.channel_id = c.id
+ and c.parent_channel is null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id = s.id
+ )
+ order by s.modified desc;
+ channel_id numeric;
+ begin
+ for server in servers(customer_id_in) loop
+ channel_id := rhn_channel.guess_server_base(server.id);
+ if channel_id is not null then
+ begin
+ perform rhn_channel.subscribe_server(server.id, channel_id);
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end$$
+language plpgsql;
+
+
+-- restore the original setting
+update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_entitlements')+1) ) where name = 'search_path';
commit c47f7060a0b833b7d386801f61a436352cf40741
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
ported rhn_channel.update_group_family_counts() from oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 19300a4..6803946 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -723,6 +723,30 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
and channel_family_id = channel_family_id_in;
END$$ language plpgsql;
+ create or replace function update_group_family_counts(group_label_in IN VARCHAR,
+ org_id_in IN NUMERIC)
+ returns void
+ as $$
+ BEGIN
+ FOR i IN (
+ SELECT DISTINCT CFM.channel_family_id, SG.org_id
+ FROM rhnChannelFamilyMembers CFM
+ JOIN rhnServerChannel SC
+ ON SC.channel_id = CFM.channel_id
+ JOIN rhnServerGroupMembers SGM
+ ON SC.server_id = SGM.server_id
+ JOIN rhnServerGroup SG
+ ON SGM.server_group_id = SG.id
+ JOIN rhnServerGroupType SGT
+ ON SG.group_type = SGT.id
+ WHERE SGT.label = group_label_in
+ AND SG.org_id = org_id_in
+ AND SGT.is_base = 'Y'
+ ) LOOP
+ perform rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END$$ language plpgsql;
+
CREATE OR REPLACE FUNCTION available_chan_subscriptions(channel_id_in IN NUMERIC,
org_id_in IN NUMERIC)
RETURNS NUMERIC
commit 49891a9497d01850afdc5feb69cbf9e9fc248743
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
synced rhn_channel.update_family_counts() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 4dd1e16..19300a4 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -716,11 +716,11 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
org_id_in IN NUMERIC) returns void
AS $$
BEGIN
- update rhnPrivateChannelFamily
- set current_members =
- rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in)
- where org_id = org_id_in
- and channel_family_id = channel_family_id_in;
+ update rhnPrivateChannelFamily
+ set current_members = rhn_channel.channel_family_current_members(channel_family_id_in, org_id_in)
+ fve_current_members = rhn_channel.cfam_curr_fve_members(channel_family_id_in,org_id_in)
+ where org_id = org_id_in
+ and channel_family_id = channel_family_id_in;
END$$ language plpgsql;
CREATE OR REPLACE FUNCTION available_chan_subscriptions(channel_id_in IN NUMERIC,
commit 4dd5b485dff59e77a6d23938366f86867e3d7848
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
ported rhn_channel.cfam_curr_fve_members() from oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index b90f999..4dd1e16 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -684,6 +684,34 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
return current_members_count;
end$$ language plpgsql;
+
+ create or replace function cfam_curr_fve_members(
+ channel_family_id_in IN NUMERIC,
+ org_id_in IN NUMERIC)
+ returns numeric
+ as $$
+ declare
+ current_members_count number := 0;
+
+ begin
+ select count(sc.server_id)
+ into current_members_count
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm,
+ rhnServer s
+ where s.org_id = org_id_in
+ and s.id = sc.server_id
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and exists (
+ select 1
+ from rhnChannelFamilyServerFve cfsp
+ where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
+ and cfsp.server_id = s.id
+ );
+
+ return current_members_count;
+ end$$ language plpgsql;
CREATE OR REPLACE FUNCTION update_family_counts(channel_family_id_in IN NUMERIC,
org_id_in IN NUMERIC) returns void
AS $$
commit aa4de9398bf70f0905fba885bf4fcd3784f58c8c
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
synced rhn_channel.channel_family_current_members() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 05c8637..b90f999 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -678,20 +678,9 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
begin
select count(distinct sc.server_id)
into current_members_count
- from rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnServer s
- where s.org_id = org_id_in
- and s.id = sc.server_id
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and exists (
- select 1
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
- and cfsp.server_id = s.id
- );
-
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.channel_family_id = channel_family_id_in
+ and cfsp.customer_id = org_id_in;
return current_members_count;
end$$ language plpgsql;
commit 112d3af2597435476f9a2c6d80eba78e6fb1543f
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
synced rhn_channel.clear_subscriptions() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index b8bae7e..05c8637 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -445,7 +445,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
return NULL;
end$$ language plpgsql;
- CREATE OR REPLACE FUNCTION clear_subscriptions(server_id_in IN NUMERIC, deleting_server IN NUMERIC default 0 ) returns void
+ CREATE OR REPLACE FUNCTION clear_subscriptions(server_id_in IN NUMERIC, deleting_server IN NUMERIC default 0,
+ update_family_countsYN IN NUMERIC default 1 ) returns void
AS $$
declare
server_channels cursor(server_id_in numeric) for
@@ -455,13 +456,29 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
rhnChannelFamilyMembers cfm
where s.id = server_id_in
and s.id = sc.server_id
- and sc.channel_id = cfm.channel_id;
+ and sc.channel_id = cfm.channel_id
+ order by cfm.channel_family_id;
+ last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
+ last_channel_org_id rhnServer.org_id%type := -1;
BEGIN
for channel in server_channels(server_id_in)
loop
- perform rhn_channel.unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server);
- perform rhn_channel.update_family_counts(channel.channel_family_id, channel.org_id);
+ perform rhn_channel.unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
+ if update_family_countsYN > 0
+ and channel.channel_family_id != last_channel_family_id then
+ -- update family counts only once
+ -- after all channels with same family has been fetched
+ if last_channel_family_id != -1 then
+ perform rhn_channel.update_family_counts(channel.channel_family_id, channel.org_id);
+ end if;
+ last_channel_family_id := channel.channel_family_id;
+ last_channel_org_id := channel.org_id;
+ end if;
end loop;
+ if update_family_countsYN > 0 and last_channel_family_id != -1 then
+ -- update the last family fetched
+ perform rhn_channel.update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
END$$ language plpgsql;
CREATE OR REPLACE FUNCTION unsubscribe_server(server_id_in IN NUMERIC, channel_id_in NUMERIC, immediate_in NUMERIC default 1, unsubscribe_children_in numeric default 0,
commit ba06521ddd52b5bc1d593d6511636e09edf1f0e1
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
ported can_convert_to_fve() and convert_to_fve() from oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 5437720..b8bae7e 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -163,6 +163,80 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
END IF;
END$$ language plpgsql;
+
+
+
+ create or replace function can_convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
+ RETURNS NUMERIC
+ as $$
+ declare
+ fve_convertible_entries cursor for
+ select 1 from
+ rhnServerFveCapable cap
+ where cap.server_id = server_id_in
+ AND cap.channel_family_id = channel_family_id_val;
+ BEGIN
+ FOR entry IN fve_convertible_entries LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END can_convert_to_fve;
+
+
+
+ -- Converts server channel_family to use a flex entitlement
+ create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
+ returns void
+ as $$
+ available_fve_subs NUMERIC;
+ server_org_id_val NUMERIC;
+ BEGIN
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT org_id
+ INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ if not found then
+ perform rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end if;
+ IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
+ THEN
+ perform rhn_exception.raise_exception('server_cannot_convert_to_flex');
+ END IF;
+
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF (available_fve_subs > 0)
+ THEN
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select nextval('rhn_event_id_seq'),
+ server_id_in,
+ 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
+ cf.label
+ from rhnChannelFamily cf
+ where cf.id = channel_family_id_val
+ );
+
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = server_id_in and
+ sc.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
+
+ perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ ELSE
+ perform rhn_exception.raise_exception('not_enough_flex_entitlements');
+ END IF;
+
+ END$$ language plpgsql;
create or replace function can_server_consume_virt_channl(
server_id_in in numeric,
commit 8bdb6dfeb8ef5ff4348db047cf263f101b7e1f6a
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 13:25:19 2011 +0200
synced rhn_channel.subscribe_server() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 48dd97a..5437720 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -139,8 +139,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
rhn_channel.can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
(available_fve_subs > 0 AND rhn_channel.can_server_consume_fve(server_id_in) = 1)
THEN
- if rhn_channel.can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0
- AND available_subscriptions> 0 AND rhn_channel.can_server_consume_fve(server_id_in) = 1 THEN
+ if rhn_channel.can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND rhn_channel.can_server_consume_fve(server_id_in) = 1 THEN
is_fve_char := 'Y';
end if;
commit ec1bdded19187d6162f65d8f593fef45a83b0ebd
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 11:44:01 2011 +0200
changed function order so it's easier to diff sources
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 5a59139..48dd97a 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -26,6 +26,18 @@ create schema rhn_channel;
--update pg_setting
update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path';
+ create or replace function obtain_read_lock(channel_family_id_in in numeric, org_id_in in numeric)
+ returns void as $$
+ declare
+ read_lock date;
+ begin
+ select created into read_lock
+ from rhnPrivateChannelFamily
+ where channel_family_id = channel_family_id_in and org_id = org_id_in
+ for update;
+ end$$ language plpgsql;
+
+ -- this "emulates" cursor server_base_subscriptions defined in oracle/rhn_channel.pks
create or replace function server_base_subscriptions(server_id_in NUMERIC)
returns boolean as $$
begin
@@ -35,6 +47,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
AND C.parent_channel IS NULL);
end$$ language plpgsql;
+ -- this "emulates" cursor server_base_subscriptions defined in oracle/rhn_channel.pks
create or replace function check_server_subscription(server_id_in NUMERIC, channel_id_in NUMERIC)
returns boolean as $$
begin
@@ -42,17 +55,6 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
end$$ language plpgsql;
- create or replace function obtain_read_lock(channel_family_id_in in numeric, org_id_in in numeric)
- returns void as $$
- declare
- read_lock date;
- begin
- select created into read_lock
- from rhnPrivateChannelFamily
- where channel_family_id = channel_family_id_in and org_id = org_id_in
- for update;
- end$$ language plpgsql;
-
CREATE OR REPLACE FUNCTION subscribe_server(server_id_in IN NUMERIC, channel_id_in NUMERIC, immediate_in NUMERIC default 1, user_id_in in numeric default null, recalcfamily_in NUMERIC default 1) returns void
AS $$
declare
commit 551af592978aacdd746627d3a818b326080bddd4
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 11:27:46 2011 +0200
removed dead get_license_path() and license_consent()
they've been removed from oracle by 20841b237216bccc459b6aae224c0a69dd16329b
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index ab6deba..5a59139 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -41,44 +41,6 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
return exists(SELECT channel_id FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in);
end$$ language plpgsql;
- CREATE OR REPLACE FUNCTION get_license_path(channel_id_in IN NUMERIC)
- RETURNS VARCHAR
- AS $$
- declare
- license_val VARCHAR(1000);
- BEGIN
- SELECT CFL.license_path INTO license_val
- FROM rhnChannelFamilyLicense CFL, rhnChannelFamilyMembers CFM
- WHERE CFM.channel_id = channel_id_in
- AND CFM.channel_family_id = CFL.channel_family_id;
-
- IF NOT FOUND THEN
- RETURN NULL;
- END IF;
-
- RETURN license_val;
- END$$ language plpgsql;
-
-
- CREATE OR REPLACE FUNCTION license_consent(channel_id_in IN NUMERIC, user_id_in IN NUMERIC, server_id_in IN NUMERIC) returns void
- AS $$
- declare
- channel_family_id_val NUMERIC;
- BEGIN
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- perform rhn_exception.raise_exception('channel_subscribe_no_family');
- END IF;
-
- IF rhn_channel.get_license_path(channel_id_in) IS NULL
- THEN
- perform rhn_exception.raise_exception('channel_consent_no_license');
- END IF;
-
- INSERT INTO rhnChannelFamilyLicenseConsent (channel_family_id, user_id, server_id)
- VALUES (channel_family_id_val, user_id_in, server_id_in);
- END$$ language plpgsql;
create or replace function obtain_read_lock(channel_family_id_in in numeric, org_id_in in numeric)
returns void as $$
commit 2df9a2a955a45537c497d702611e27863a2ce0ab
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 11:09:45 2011 +0200
rhn_entitlements.pkb are now equivalent
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index cfe0d6d..13bfdf2 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -1,11 +1,4 @@
--- Note: this file is not a full equivalent of the Oracle sources.
--- Neither the flex stuff nor the update_family_countsYN was fully migrated.
--- Migrated functions or code paths:
---
--- can_entitle_server
--- entitle_server
--- (code path of simple rhn-satellite-activate)
--- assign_channel_entitlement
+-- oracle equivalent source sha1 8fcbc1336a4b7f715fb1304875a38ebd0ae53565
--
-- Copyright (c) 2008--2011 Red Hat, Inc.
--
commit 608bee1d5cf46ab64bf31f8781bfd4ea8471cea8
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 10:14:56 2011 +0200
synced rhn_entitlement.prune_family() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index 57efbfd..cfe0d6d 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -1649,8 +1649,8 @@ as $$
and rs.org_id = customer_id_in
and rs.id = rsc.server_id
and rsc.channel_id = rcfm.channel_id
- and rcfm.channel_family_id =
- channel_family_id_in
+ and rcfm.channel_family_id = channel_family_id_in
+ and rsc.is_fve = is_fve_in
-- we only want to grab servers consuming
-- physical slots.
and exists (
@@ -1673,12 +1673,12 @@ as $$
is_fve_in := 'N';
for sc in serverchannels loop
- perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1);
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1, 0, 0);
tmp_quantity := flex_in;
is_fve_in := 'Y';
for sc in serverchannels loop
- perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1);
+ perform rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1, 0, 0);
end loop;
end loop;
perform rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
commit 82714376e3915638d85ea776e90f301be4c1e0f7
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 10:14:56 2011 +0200
synced rhn_entitlement.activate_channel_entitlement() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index b0e0abb..57efbfd 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -1431,7 +1431,8 @@ as $$
select server_id
from rhnServerFveCapable
where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id;
+ channel_family_id = cfam_id
+ limit quantity;
begin
@@ -1480,7 +1481,10 @@ as $$
for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
--rhn_channel.convert_to_regular(system.server_id, cfam_id);
UPDATE rhnServerChannel sc set sc.is_fve = 'N'
- where sc.server_id = system.server_id;
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
end loop;
--reset previous counts
@@ -1507,7 +1511,10 @@ as $$
for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
-- rhn_channel.convert_to_fve(system.server_id, cfam_id);
UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id = system.server_id;
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
end loop;
prev_ent_count := prev_ent_count - reduce_quantity;
prev_flex_count := prev_flex_count + reduce_quantity;
commit c8ad2d5dc5bd2eeb6ba22b51abc43956a661f7c3
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 10:14:56 2011 +0200
synced rhn_entitlement.activate_system_entitlement() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index 07693e7..b0e0abb 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -1374,10 +1374,15 @@ as $$
perform rhn_exception.raise_exception(
'not_enough_entitlements_in_base_org');
else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
perform rhn_entitlements.set_group_count(org_id_in,
'S',
group_type,
- quantity_in);
+ quantity_in,
+ 0);
+ -- bulk update family counts
+ perform rhn_channel.update_group_family_counts(group_label_in, org_id_in);
end if;
end$$
commit cdc3418dba1caca78b4a3dc7d3ff9e1a29e617a8
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Sep 19 10:14:56 2011 +0200
synced rhn_entitlement.assign_channel_entitlement() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index 78ff0d8..07693e7 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -1285,7 +1285,7 @@ as $$
new_ent_count := from_org_prev_ent_count - quantity_in;
new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
- if from_org_prev_ent_count > new_ent_count then
+ if from_org_prev_ent_count >= new_ent_count then
new_quantity := to_org_prev_ent_count + quantity_in;
end if;
commit 3a6af5f11d21b9eb3019249a2162a14c99f34403
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Sep 15 14:03:46 2011 +0200
synced rhn_entitlement.repoll_virt_guest_entitlements() with oracle
diff --git a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
index 12916b5..78ff0d8 100644
--- a/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_entitlements.pkb
@@ -7,7 +7,7 @@
-- (code path of simple rhn-satellite-activate)
-- assign_channel_entitlement
--
--- Copyright (c) 2008--2010 Red Hat, Inc.
+-- Copyright (c) 2008--2011 Red Hat, Inc.
--
-- This software is licensed to you under the GNU General Public License,
-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -602,12 +602,31 @@ as $$
order by sgm.modified desc
limit quantity_in;
+ -- Get the orgs of Virtual guests
+ -- Since they may belong to different orgs
+ virt_guest_orgs cursor for
+ select distinct (s.org_id)
+ from rhnServer s
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
+ where
+ vi.host_system_id = server_id_in
+ and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
+
org_id_val numeric;
max_members_val numeric;
+ max_flex_val numeric;
current_members_calc numeric;
sg_id numeric;
-
+ is_virt numeric := 0;
begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+
+ if not found then
+ is_virt := 0;
+ end if;
select org_id
into org_id_val
@@ -616,6 +635,33 @@ as $$
-- deal w/ channel entitlements first ...
for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id in (
+ select vi.virtual_system_id
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ limit free_slots
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
-- get the current (physical) members of the family
current_members_calc :=
rhn_channel.channel_family_current_members(family.channel_family_id,
@@ -628,6 +674,12 @@ as $$
where channel_family_id = family.channel_family_id
and org_id = org_id_val;
+ select fve_max_members
+ into max_flex_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
if current_members_calc > max_members_val then
-- A virtualization_host* ent must have been removed, so we'll
-- unsubscribe guests from the host first.
@@ -652,7 +704,8 @@ as $$
-- argh, transposed again?!
perform rhn_entitlements.set_family_count(org_id_val,
family.channel_family_id,
- max_members_val);
+ max_members_val, max_flex_val);
+ --TODO calculate this correctly
end if;
end if;
@@ -663,6 +716,13 @@ as $$
-- what's the difference of doing this vs the unavoidable set_family_count above?
perform rhn_channel.update_family_counts(family.channel_family_id,
org_id_val);
+
+ -- It is possible that the guests belong to a different org than the host
+ -- so we are going to update the family counts in the guests orgs also
+ for org in virt_guest_orgs loop
+ perform rhn_channel.update_family_counts(family.channel_family_id,
+ org.org_id);
+ end loop;
end loop;
for a_group_type in group_types loop
12 years, 6 months
Changes to 'refs/tags/spacewalk-web-1.6.23-1'
by Jan Pazdziora
Tag 'spacewalk-web-1.6.23-1' created by Jan Pazdziora <jpazdziora(a)redhat.com> at 2011-09-23 09:35 +0000
Tagging package [spacewalk-web] version [1.6.23-1] in directory [web/].
Changes since spacewalk-java-1.6.49-1:
Jan Pazdziora (2):
The /etc/rhn/default/rhn_web.conf does not need to be provided by -pxt since it is provided by -base-minimal.
Automatic commit of package [spacewalk-web] release [1.6.23-1].
---
rel-eng/packages/spacewalk-web | 2 +-
web/spacewalk-web.spec | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
---
12 years, 6 months
rel-eng/packages web/spacewalk-web.spec
by Jan Pazdziora
rel-eng/packages/spacewalk-web | 2 +-
web/spacewalk-web.spec | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 28051947ae492ef133b008aec540076fd45b146e
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Sep 23 11:35:47 2011 +0200
Automatic commit of package [spacewalk-web] release [1.6.23-1].
diff --git a/rel-eng/packages/spacewalk-web b/rel-eng/packages/spacewalk-web
index 4636813..651d084 100644
--- a/rel-eng/packages/spacewalk-web
+++ b/rel-eng/packages/spacewalk-web
@@ -1 +1 @@
-1.6.22-1 web/
+1.6.23-1 web/
diff --git a/web/spacewalk-web.spec b/web/spacewalk-web.spec
index 67a7ee6..f504a4e 100644
--- a/web/spacewalk-web.spec
+++ b/web/spacewalk-web.spec
@@ -2,7 +2,7 @@ Name: spacewalk-web
Summary: Spacewalk Web site - Perl modules
Group: Applications/Internet
License: GPLv2
-Version: 1.6.22
+Version: 1.6.23
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk/
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -256,6 +256,10 @@ rm -rf $RPM_BUILD_ROOT
# $Id$
%changelog
+* Fri Sep 23 2011 Jan Pazdziora 1.6.23-1
+- The /etc/rhn/default/rhn_web.conf does not need to be provided by -pxt since
+ it is provided by -base-minimal.
+
* Mon Sep 19 2011 Michael Mraka <michael.mraka(a)redhat.com> 1.6.22-1
- 723461 - let emails be sent to localhost by default
12 years, 6 months
web/spacewalk-web.spec
by Jan Pazdziora
web/spacewalk-web.spec | 1 -
1 file changed, 1 deletion(-)
New commits:
commit a5711c65c42e284d1bbedacf36be016d3f4ec7db
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Sep 23 11:19:37 2011 +0200
The /etc/rhn/default/rhn_web.conf does not need to be provided by -pxt since it is provided by -base-minimal.
Addressing
spacewalk-base-minimal-1.6.20-1.el5
spacewalk-pxt-1.6.20-1.el5
diff --git a/web/spacewalk-web.spec b/web/spacewalk-web.spec
index 684d842..67a7ee6 100644
--- a/web/spacewalk-web.spec
+++ b/web/spacewalk-web.spec
@@ -242,7 +242,6 @@ rm -rf $RPM_BUILD_ROOT
%files -n spacewalk-pxt
%{perl_vendorlib}/PXT.pm
-%attr(640,root,apache) %config %{_sysconfdir}/rhn/default/rhn_web.conf
%{perl_vendorlib}/PXT/
%exclude %{perl_vendorlib}/PXT/Config.pm
%{_mandir}/man3/PXT::ApacheHandler.3pm.gz
12 years, 6 months