Changes to 'refs/tags/osad-5.9.30-1'
by Michael Mraka
Tag 'osad-5.9.30-1' created by Michael Mraka <michael.mraka(a)redhat.com> at 2010-02-22 12:54 +0000
Tagging package [osad] version [5.9.30-1] in directory [client/tools/osad/].
Changes since rhn-client-tools-0.9.3-1:
Jan Pazdziora (1):
246480 - sync last_modified column for rhnKickstartableTree as well.
Michael Mraka (3):
fixed 0.7 -> 0.8 upgrade errors
hashlib is imported so it should be required
Automatic commit of package [osad] release [5.9.30-1].
---
backend/server/importlib/backendOracle.py | 1
client/tools/osad/osad.spec | 6
rel-eng/packages/osad | 2
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql | 2
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql | 253 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql | 1417 ++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql | 1417 --------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql | 253 -
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql | 226 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql | 1730 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql | 1730 ----------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql | 226 -
15 files changed, 3667 insertions(+), 3634 deletions(-)
---
13 years, 9 months
2 commits - client/tools rel-eng/packages
by Michael Mraka
client/tools/osad/osad.spec | 6 +++++-
rel-eng/packages/osad | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 0072a5c47385160b6de5f5cbcdc8142319c32e5d
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Feb 22 13:54:16 2010 +0100
Automatic commit of package [osad] release [5.9.30-1].
diff --git a/client/tools/osad/osad.spec b/client/tools/osad/osad.spec
index dc4f665..eb47063 100644
--- a/client/tools/osad/osad.spec
+++ b/client/tools/osad/osad.spec
@@ -9,7 +9,7 @@ Group: System Environment/Daemons
License: GPLv2
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
-Version: 5.9.29
+Version: 5.9.30
Release: 1%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
@@ -239,6 +239,9 @@ rpm -ql osa-dispatcher | xargs -n 1 /sbin/restorecon -rvvi {}
# $Id$
%changelog
+* Mon Feb 22 2010 Michael Mraka <michael.mraka(a)redhat.com> 5.9.30-1
+- fixed missing Requires: python-hashlib
+
* Thu Feb 04 2010 Michael Mraka <michael.mraka(a)redhat.com> 5.9.29-1
- updated copyrights
diff --git a/rel-eng/packages/osad b/rel-eng/packages/osad
index ece35ef..ee745cf 100644
--- a/rel-eng/packages/osad
+++ b/rel-eng/packages/osad
@@ -1 +1 @@
-5.9.29-1 client/tools/osad/
+5.9.30-1 client/tools/osad/
commit 607ed194b8df81b389653e520a306c21546c146d
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Feb 22 13:51:43 2010 +0100
hashlib is imported so it should be required
fixed
# service osad start
Starting osad: Unable to load module osad
No module named hashlib
[FAILED]
diff --git a/client/tools/osad/osad.spec b/client/tools/osad/osad.spec
index 589d28b..dc4f665 100644
--- a/client/tools/osad/osad.spec
+++ b/client/tools/osad/osad.spec
@@ -17,6 +17,7 @@ BuildRequires: python-devel
Requires: python
Requires: rhnlib >= 1.8-3
Requires: jabberpy
+Requires: python-hashlib
# This should have been required by rhnlib
Requires: PyXML
%if "%{pythongen}" == "1.5"
13 years, 9 months
schema/spacewalk
by Michael Mraka
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql | 2
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql | 253 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql | 1417 ++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql | 1417 --------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql | 253 -
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql | 226 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql | 1730 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql | 1730 ----------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql | 226 -
12 files changed, 3660 insertions(+), 3632 deletions(-)
New commits:
commit 35e5f0f431788d7617dec023aeb19069175e0cf5
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 14:40:49 2010 +0100
fixed 0.7 -> 0.8 upgrade errors
- rhnPackageFile-md5 - fix for runing out of UNDO
- rhnKickstartPackage - should fix unique keys before index creation
- rhn_channel & rhn_entitlements - fixed order of pks/pkb
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
index f8ad8db..cb46fc4 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
@@ -1 +1 @@
-alter table rhnPackageFile drop column md5;
+alter table rhnPackageFile set unused column md5;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql
new file mode 100644
index 0000000..bae9b4f
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql
@@ -0,0 +1,28 @@
+declare
+ i number;
+begin
+ for rec in (
+ select kickstart_id kid
+ from rhnKickstartPackage
+ where position = 0
+ group by kickstart_id
+ having count(*) > 1
+ ) loop
+ i := 0;
+ for erec in (
+ select rhnKickstartPackage.rowid rid
+ from rhnKickstartPackage, rhnPackageName
+ where rhnKickstartPackage.package_name_id = rhnPackageName.id
+ and rhnKickstartPackage.kickstart_id = rec.kid
+ order by rhnKickstartPackage.position, rhnPackageName.name
+ ) loop
+ update rhnKickstartPackage
+ set position = i
+ where rhnKickstartPackage.rowid = erec.rid;
+ i := i + 1;
+ end loop;
+ end loop;
+end;
+/
+
+commit;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql
new file mode 100644
index 0000000..c7d65f9
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql
@@ -0,0 +1,5 @@
+DROP INDEX rhn_kspackage_id_idx;
+
+ALTER TABLE rhnKickstartPackage
+ ADD CONSTRAINT rhn_kspackage_pos_uq UNIQUE (kickstart_id, position)
+ USING INDEX TABLESPACE [[4m_tbs]];
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql
deleted file mode 100644
index c7d65f9..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-DROP INDEX rhn_kspackage_id_idx;
-
-ALTER TABLE rhnKickstartPackage
- ADD CONSTRAINT rhn_kspackage_pos_uq UNIQUE (kickstart_id, position)
- USING INDEX TABLESPACE [[4m_tbs]];
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql
new file mode 100644
index 0000000..cac3093
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql
@@ -0,0 +1,253 @@
+--
+-- 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 OR REPLACE
+PACKAGE rhn_channel
+IS
+ version varchar2(100) := '';
+
+ CURSOR server_base_subscriptions(server_id_in NUMBER) IS
+ 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;
+
+ CURSOR check_server_subscription(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT channel_id
+ FROM rhnServerChannel
+ WHERE server_id = server_id_in
+ AND channel_id = channel_id_in;
+
+ CURSOR check_server_parent_membership(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT C.id
+ FROM rhnChannel C, rhnServerChannel SC
+ WHERE C.parent_channel = channel_id_in
+ AND C.id = SC.channel_id
+ AND SC.server_id = server_id_in;
+
+ CURSOR channel_family_perm_cursor(channel_family_id_in NUMBER, org_id_in NUMBER) IS
+ SELECT *
+ FROM rhnOrgChannelFamilyPermissions
+ WHERE channel_family_id = channel_family_id_in
+ AND org_id = org_id_in;
+
+ PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER);
+ FUNCTION get_license_path(channel_id_in IN NUMBER) RETURN VARCHAR2;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1);
+
+ function can_server_consume_virt_channl(
+ server_id_in IN NUMBER,
+ family_id_in in number)
+ return number;
+
+ FUNCTION guess_server_base(server_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION base_channel_for_release_arch(release_in in varchar2,
+ server_arch_in in varchar2, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION base_channel_rel_archid(release_in in varchar2,
+ server_arch_id_in in number, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION channel_priority(channel_id_in in number) RETURN number;
+
+ PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+ PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+
+ PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+ procedure bulk_server_basechange_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ old_channel_id_in in number,
+ new_channel_id_in in number);
+
+ procedure bulk_guess_server_base(
+ set_label_in in varchar2,
+ set_uid_in in number);
+
+ procedure bulk_guess_server_base_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ channel_id_in in number);
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number;
+
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER, org_id_in IN NUMBER);
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2, org_id_in IN NUMBER);
+ FUNCTION family_for_channel(channel_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ procedure entitle_customer(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
+ procedure set_family_maxmembers(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
+ procedure unsubscribe_server_from_family(server_id_in in number, channel_family_id_in in number);
+
+ procedure delete_server_channels(server_id_in in number);
+ procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)');
+
+ function get_org_id(channel_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
+
+ function get_org_access(channel_id_in in number, org_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_access, WNDS, RNPS, WNPS);
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
+
+ function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2, reason_out out varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
+
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(user_role_check, WNDS, RNPS, WNPS);
+
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(loose_user_role_check, WNDS, RNPS, WNPS);
+
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(direct_user_role_check, WNDS, RNPS, WNPS);
+
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(shared_user_role_check, WNDS, RNPS, WNPS);
+
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ RETURN NUMBER;
+
+ PROCEDURE update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate );
+
+
+ PRAGMA RESTRICT_REFERENCES(org_channel_setting, WNDS, RNPS, WNPS);
+
+END rhn_channel;
+/
+SHOW ERRORS
+
+--
+-- Revision 1.37 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.36 2004/03/26 18:11:32 rbb
+-- Bugzilla: 114057
+--
+-- Add a script to determine channel priority.
+--
+-- Revision 1.35 2004/02/17 20:16:52 pjones
+-- bugzilla: none -- add cvs tags into the package as long as we're touching
+-- it anyway
+--
+-- Revision 1.34 2003/11/13 18:13:09 cturner
+-- pragmas can now return now that rhn_user pragmas are fixed
+--
+-- Revision 1.32 2003/09/22 21:00:40 cturner
+-- add method for easy acl check
+--
+-- Revision 1.31 2003/09/17 22:14:11 misa
+-- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
+--
+-- Revision 1.30 2003/07/24 16:44:16 misa
+-- bugzilla: none A function more usable on the rhnapp side
+--
+-- Revision 1.29 2003/07/24 14:00:17 misa
+-- bugzilla: none PRAGMA RESTRICT_REFERENCES good
+--
+-- Revision 1.28 2003/07/23 21:59:19 cturner
+-- rework how rhnUserChannel works; move to plsql for speed and maintenance
+--
+-- Revision 1.27 2003/07/21 17:49:12 pjones
+-- bugzilla: none
+--
+-- add optional user for subscribe_server
+--
+-- Revision 1.26 2002/12/19 18:13:42 misa
+-- Added caller with a default value
+--
+-- Revision 1.25 2002/12/11 22:18:46 pjones
+-- rhnChannelNewestPackage
+--
+-- Revision 1.24 2002/11/21 22:08:11 pjones
+-- make unsubscribe_channels have a "unsubscribe_children_in number := 0"
+-- argument so that you can tell it to unsubscribe children.
+--
+-- Also, make it raise an exception instead of silent failure in the
+-- other case.
+--
+-- Revision 1.23 2002/11/18 17:20:50 pjones
+-- this should have gone back too
+--
+-- Revision 1.22 2002/11/13 23:16:18 pjones
+-- lookup_*_arch()
+--
+-- Revision 1.21 2002/10/07 20:01:59 rnorwood
+-- guess base channel for ssm and single system
+--
+-- Revision 1.20 2002/10/02 19:21:03 bretm
+-- o 3rd party channel schema changes, no more clobs...
+--
+-- Revision 1.19 2002/09/20 19:21:58 bretm
+-- o more 3rd party channel stuff...
+--
+-- Revision 1.18 2002/06/12 22:33:03 pjones
+-- procedure bulk_guess_server_base_from(
+-- set_label_in in varchar2,
+-- set_uid_in in number,
+-- channel_id_in in number);
+--
+-- for bretm
+--
+-- Revision 1.17 2002/06/12 22:12:25 pjones
+-- procedure bulk_guess_server_base(
+-- set_label_in in varchar2,
+-- set_uid_in in number);
+--
+-- for bretm
+--
+-- Revision 1.16 2002/06/12 19:37:55 pjones
+-- bulk_server_basechange_from(
+-- set_label_in in varchar2,
+-- set_uid_in in number,
+-- old_channel_id_in in number,
+-- new_channel_id_in in number
+-- );
+--
+-- for bretm
+--
+-- Revision 1.15 2002/05/10 22:08:22 pjones
+-- id/log
+--
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql
new file mode 100644
index 0000000..0f18b67
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql
@@ -0,0 +1,1417 @@
+--
+-- 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 OR REPLACE
+PACKAGE BODY rhn_channel
+IS
+ body_version varchar2(100) := '';
+
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ cursor base_channel_cursor(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number
+ ) return rhnChannel%ROWTYPE is
+ 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;
+
+ FUNCTION get_license_path(channel_id_in IN NUMBER)
+ RETURN VARCHAR2
+ IS
+ license_val VARCHAR2(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;
+
+ RETURN license_val;
+
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END get_license_path;
+
+
+ PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER)
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_subscribe_no_family');
+ END IF;
+
+ IF rhn_channel.get_license_path(channel_id_in) IS NULL
+ THEN
+ 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 license_consent;
+
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in NUMBER := 1)
+ IS
+ channel_parent_val rhnChannel.parent_channel%TYPE;
+ parent_subscribed BOOLEAN;
+ server_has_base_chan BOOLEAN;
+ server_already_in_chan BOOLEAN;
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ consenting_user NUMBER;
+ allowed number := 0;
+ current_members_val number;
+ 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
+ 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 := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
+ LOOP
+ parent_subscribed := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT parent_subscribed
+ THEN
+ RETURN;
+ END IF;
+ ELSE
+ -- base channel
+ server_has_base_chan := FALSE;
+ FOR base IN server_base_subscriptions(server_id_in)
+ LOOP
+ server_has_base_chan := TRUE;
+ END LOOP base;
+
+ IF server_has_base_chan
+ THEN
+ rhn_exception.raise_exception('channel_server_one_base');
+ END IF;
+ END IF;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ 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
+ 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 NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
+ INTO server_org_id_val
+ FROM rhnChannel
+ WHERE id = channel_id_in;
+
+ select current_members
+ into current_members_val
+ from rhnPrivateChannelFamily
+ where org_id = server_org_id_val and channel_family_id = channel_family_id_val
+ for update of current_members;
+
+ available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
+
+ IF available_subscriptions IS NULL OR
+ available_subscriptions > 0 or
+ can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1
+ THEN
+
+ IF rhn_channel.get_license_path(channel_id_in) IS NOT NULL
+ THEN
+ BEGIN
+
+ SELECT user_id INTO consenting_user
+ FROM rhnChannelFamilyLicenseConsent
+ WHERE channel_family_id = channel_family_id_val
+ AND server_id = server_id_in;
+
+ EXCEPTION
+ WHEN NO_DATA_FOUND THEN
+ rhn_exception.raise_exception('channel_subscribe_no_consent');
+ END;
+ END IF;
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ 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 = sysdate WHERE id = server_id_in;
+ INSERT INTO rhnServerChannel (server_id, channel_id) VALUES (server_id_in, channel_id_in);
+ IF recalcfamily_in > 0
+ THEN
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ END IF;
+ queue_server(server_id_in, immediate_in);
+ ELSE
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ END IF;
+
+ END subscribe_server;
+
+ function can_server_consume_virt_channl(
+ server_id_in in number,
+ family_id_in in number )
+ return number
+ is
+
+ cursor server_virt_families is
+ select vi.virtual_system_id, cfvsl.channel_family_id
+ 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 );
+ begin
+
+ for server_virt_family in server_virt_families loop
+ return 1;
+ end loop;
+
+ return 0;
+
+ end;
+
+
+ PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
+ END LOOP server;
+ END bulk_subscribe_server;
+
+ PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ IF rhn_server.can_change_base_channel(server.element) = 1
+ THEN
+ rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
+ rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
+ END IF;
+ END LOOP server;
+ END bulk_server_base_change;
+
+ procedure bulk_server_basechange_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ old_channel_id_in in number,
+ new_channel_id_in in number
+ ) is
+ cursor servers is
+ select sc.server_id id
+ from rhnChannel nc,
+ rhnServerChannelArchCompat scac,
+ rhnServer s,
+ rhnChannel oc,
+ rhnServerChannel sc,
+ rhnSet st
+ where 1=1
+ -- first, find the servers we're looking for.
+ and st.label = set_label_in
+ and st.user_id = set_uid_in
+ and st.element = sc.server_id
+ -- now, filter out anything that's not in the
+ -- old base channel.
+ and sc.channel_id = old_channel_id_in
+ and sc.channel_id = oc.id
+ and oc.parent_channel is null
+ -- now, see if it's compatible with the new base channel
+ and nc.id = new_channel_id_in
+ and nc.parent_channel is null
+ and sc.server_id = s.id
+ and s.server_arch_id = scac.server_arch_id
+ and scac.channel_arch_id = nc.channel_arch_id;
+ begin
+ for s in servers loop
+ insert into rhnSet (
+ user_id, label, element
+ ) values (
+ set_uid_in,
+ set_label_in || 'basechange',
+ s.id
+ );
+ end loop channel;
+ bulk_server_base_change(new_channel_id_in,
+ set_label_in || 'basechange',
+ set_uid_in);
+ delete from rhnSet
+ where label = set_label_in||'basechange'
+ and user_id = set_uid_in;
+ end bulk_server_basechange_from;
+
+ procedure bulk_guess_server_base(
+ set_label_in in varchar2,
+ set_uid_in in number
+ ) is
+ channel_id number;
+ begin
+ for server in rhn_set.set_iterator(set_label_in, set_uid_in)
+ loop
+ -- anything that doesn't work, we just ignore
+ begin
+ if rhn_server.can_change_base_channel(server.element) = 1
+ then
+ channel_id := guess_server_base(TO_NUMBER(server.element));
+ rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
+ rhn_channel.subscribe_server(TO_NUMBER(server.element), channel_id, 0, set_uid_in);
+ end if;
+ exception when others then
+ null;
+ end;
+ end loop server;
+ end;
+
+ function guess_server_base(
+ server_id_in in number
+ ) RETURN number is
+ cursor server_cursor is
+ select s.server_arch_id, s.release, s.org_id
+ from rhnServer s
+ where s.id = server_id_in;
+ 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 base_channel_cursor;
+ end loop server_cursor;
+ -- Server not found, or no base channel applies to it
+ return null;
+ end;
+
+ -- Private function
+ function normalize_server_arch(server_arch_in in varchar2)
+ return varchar2
+ deterministic
+ is
+ suffix VARCHAR2(128) := '-redhat-linux';
+ suffix_len NUMBER := length(suffix);
+ begin
+ if server_arch_in is NULL then
+ return NULL;
+ end if;
+ if instr(server_arch_in, '-') > 0
+ then
+ -- Suffix already present
+ return server_arch_in;
+ end if;
+ return server_arch_in || suffix;
+ end normalize_server_arch;
+
+ --
+ --
+ -- Raises:
+ -- server_arch_not_found
+ -- no_subscribe_permissions
+ function base_channel_for_release_arch(
+ release_in in varchar2,
+ server_arch_in in varchar2,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ server_arch varchar2(256) := normalize_server_arch(server_arch_in);
+ server_arch_id number;
+ begin
+ -- Look up the server arch
+ begin
+ select id
+ into server_arch_id
+ from rhnServerArch
+ where label = server_arch;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('server_arch_not_found');
+ end;
+ return base_channel_rel_archid(release_in, server_arch_id,
+ org_id_in, user_id_in);
+ end base_channel_for_release_arch;
+
+ function base_channel_rel_archid(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ denied_channel_id number := null;
+ valid_org_id number := org_id_in;
+ valid_user_id number := user_id_in;
+ channel_subscribable number;
+ begin
+ if org_id_in = -1 and user_id_in is not null then
+ -- Get the org id from the user id
+ begin
+ select org_id
+ into valid_org_id
+ from web_contact
+ where id = user_id_in;
+ exception
+ when no_data_found then
+ -- User doesn't exist
+ -- XXX Only list public stuff for now
+ valid_user_id := null;
+ valid_org_id := -1;
+ end;
+ 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 loose_user_role_check(c.id, user_id_in, 'subscribe')
+ into channel_subscribable
+ from dual;
+
+ 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 base_channel_fetch;
+
+ if denied_channel_id is not null then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+ -- No base channel applies
+ return NULL;
+ end base_channel_rel_archid;
+
+ procedure bulk_guess_server_base_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ channel_id_in in number
+ ) is
+ cursor channels(server_id_in in number) is
+ select rsc.channel_id
+ from rhnServerChannel rsc,
+ rhnChannel rc
+ where server_id_in = rsc.server_id
+ and rsc.channel_id = rc.id
+ and rc.parent_channel is null;
+ begin
+ for server in rhn_set.set_iterator(set_label_in, set_uid_in)
+ loop
+ for channel in channels(server.element)
+ loop
+ if channel.channel_id = channel_id_in
+ then
+ insert into rhnSet (user_id, label, element) values (set_uid_in, set_label_in || 'baseguess', server.element);
+ end if;
+ end loop channel;
+ end loop server;
+ bulk_guess_server_base(set_label_in||'baseguess',set_uid_in);
+ delete from rhnSet where label = set_label_in||'baseguess' and user_id = set_uid_in;
+ end;
+
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ cursor server_channels(server_id_in in number) is
+ 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;
+ BEGIN
+ for channel in server_channels(server_id_in)
+ loop
+ unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, update_family_countsYN);
+ end loop channel;
+ END clear_subscriptions;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ server_already_in_chan BOOLEAN;
+ cursor channel_family_is_proxy(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-proxy';
+ cursor channel_family_is_satellite(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-satellite';
+ -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
+ -- with the package-level one, we get a "cursor already open", so we need a
+ -- copy on our call stack instead. GROAN.
+ cursor local_chk_server_parent_memb (
+ server_id_in number,
+ channel_id_in number ) is
+ 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;
+ BEGIN
+ FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
+ LOOP
+ if unsubscribe_children_in = 1 then
+ unsubscribe_server(server_id_in => server_id_in,
+ channel_id_in => child.id,
+ immediate_in => immediate_in,
+ unsubscribe_children_in => unsubscribe_children_in,
+ deleting_server => deleting_server,
+ update_family_countsYN => update_family_countsYN);
+ else
+ rhn_exception.raise_exception('channel_unsubscribe_child_exists');
+ end if;
+ END LOOP child;
+
+ server_already_in_chan := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ if deleting_server = 0 then
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ 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 = sysdate 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
+ 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
+ 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;
+ delete from rhnSatelliteChannelFamily 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;
+
+ DELETE FROM rhnChannelFamilyLicenseConsent
+ WHERE channel_family_id = channel_family_id_val
+ AND server_id = server_id_in;
+
+ SELECT org_id INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ if update_family_countsYN = 1 then
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ end if;
+ END unsubscribe_server;
+
+ PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ rhn_channel.unsubscribe_server(server.element, channel_id_in, 0);
+ END LOOP server;
+ END bulk_unsubscribe_server;
+
+ FUNCTION family_for_channel(channel_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN channel_family_id_val;
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END family_for_channel;
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ current_members_val NUMBER;
+ max_members_val NUMBER;
+ found NUMBER;
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN
+ THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND
+ LOOP
+ found := 1;
+
+ current_members_val := cfp.current_members;
+ max_members_val := cfp.max_members;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN
+ THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ -- 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 available_family_subscriptions;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+ begin
+ select count(distinct 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;
+
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ update rhnPrivateChannelFamily
+ set current_members = (
+ 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;
+
+ END update_family_counts;
+
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
+ org_id_in IN NUMBER)
+ IS
+ 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
+ rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END update_group_family_counts;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO 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 available_chan_subscriptions;
+
+ -- *******************************************************************
+ -- PROCEDURE: entitle_customer
+ -- Creates a chan fam bucket, or sets max_members for an existing bucket
+ -- Called by: rhn_ep.poll_customer_internal
+ -- Calls: set_family_maxmembers + update_family_counts if the row
+ -- already exists, else it creates it in rhnPrivateChannelFamily.
+ -- *******************************************************************
+ procedure entitle_customer(customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number)
+ is
+ cursor permissions is
+ select 1
+ from rhnPrivateChannelFamily pcf
+ where pcf.org_id = customer_id_in
+ and pcf.channel_family_id = channel_family_id_in;
+ begin
+ for perm in permissions loop
+ set_family_maxmembers(
+ customer_id_in,
+ channel_family_id_in,
+ quantity_in
+ );
+ rhn_channel.update_family_counts(
+ channel_family_id_in,
+ customer_id_in
+ );
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily pcf (
+ channel_family_id, org_id, max_members, current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity_in, 0
+ );
+ end;
+
+ -- *******************************************************************
+ -- PROCEDURE: set_family_maxmembers
+ -- Prunes an existing channel family bucket by unsubscribing the
+ -- necessary servers and sets max_members.
+ -- Called by: rhn_channel.entitle_customer
+ -- Calls: unsubscribe_server_from_family
+ -- *******************************************************************
+ procedure set_family_maxmembers(customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number)
+ is
+ cursor servers is
+ select server_id from (
+ select rownum row_number, server_id, modified from (
+ select rcfsp.server_id,
+ rcfsp.modified
+ from rhnChannelFamilyServerPhysical rcfsp
+ where rcfsp.customer_id = customer_id_in
+ and rcfsp.channel_family_id = channel_family_id_in
+ order by modified
+ )
+ where rownum > quantity_in
+ );
+ begin
+ -- prune subscribed servers
+ for server in servers loop
+ rhn_channel.unsubscribe_server_from_family(server.server_id,
+ channel_family_id_in);
+ end loop;
+
+ update rhnPrivateChannelFamily pcf
+ set pcf.max_members = quantity_in
+ where pcf.org_id = customer_id_in
+ and pcf.channel_family_id = channel_family_id_in;
+ end;
+
+ procedure unsubscribe_server_from_family(server_id_in in number,
+ channel_family_id_in in number)
+ is
+ 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;
+
+ function get_org_id(channel_id_in in number)
+ return number
+ is
+ org_id_out number;
+ begin
+ select org_id into org_id_out
+ from rhnChannel
+ where id = channel_id_in;
+
+ return org_id_out;
+ end get_org_id;
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
+ return number
+ is
+ cursor families is
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = org_id_in;
+ begin
+ -- the idea: if we get past this query,
+ -- the user has the role, else catch the exception and return 0
+ for family in families loop
+ return 1;
+ end loop;
+ return 0;
+ end;
+
+ function get_org_access(channel_id_in in number, org_id_in in number)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query,
+ -- the org has access to the channel, else catch the exception and return 0
+ select distinct 1 into throwaway
+ 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);
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if a user has a given role, or if such a role is inferrable
+ function user_role_check_debug(channel_id_in in number,
+ user_id_in in number,
+ role_in in varchar2,
+ reason_out out varchar2)
+ return number
+ is
+ org_id number;
+ 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
+ return 1;
+ end if;
+
+ if role_in = 'manage' and
+ NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ reason_out := 'channel_not_owned';
+ return 0;
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ reason_out := 'channel_not_available';
+ return 0;
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ reason_out := 'channel_admin';
+ return 1;
+ 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';
+ return 1;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ reason_out := 'direct_permission';
+ return rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in);
+ end;
+
+ -- same as above, but with no OUT param; useful in views, etc
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway varchar2(256);
+ begin
+ return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
+ end;
+
+ --
+ -- For multiorg phase II, this function simply checks to see if the user's
+ -- has a trust relationship that includes this channel by id.
+ --
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ return number
+ is
+ n number;
+ oid number;
+ 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;
+ return 1;
+ exception
+ when no_data_found then
+ return 0;
+ end;
+
+ -- same as above, but returns 1 if user_id_in is null
+ -- This is useful in queries where user_id is not specified
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ begin
+ if user_id_in is null then
+ return 1;
+ end if;
+ return user_role_check(channel_id_in, user_id_in, role_in);
+ end loose_user_role_check;
+
+ -- directly checks the table, no inferred permissions
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
+ 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;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if an org has a certain setting
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
+ 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;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ FUNCTION channel_priority(channel_id_in IN number)
+ RETURN number
+ IS
+ channel_name varchar2(256);
+ priority number;
+ end_of_life_val date;
+ org_id_val number;
+ 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 channel_priority;
+
+ -- right now this only does the accounting changes; the cascade
+ -- actually does the rhnServerChannel delete.
+ procedure delete_server_channels(server_id_in in number)
+ is
+ 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;
+
+ -- this could certainly be optimized to do updates if needs be
+ procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
+ is
+ 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(sysdate, last_modified + 1/86400)
+ where id = channel_id_in;
+ end;
+
+ procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate )
+ is
+
+ channel_last_modified date;
+ last_modified_value date;
+
+ cursor snapshots is
+ 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 + 1/86400;
+ 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 update_channel;
+
+ procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ 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
+ rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
+ end loop;
+ end update_channels_by_package;
+
+
+ procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ 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
+ rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
+ end loop;
+ end update_channels_by_errata;
+
+END rhn_channel;
+/
+SHOW ERRORS
+
+--
+-- Revision 1.75 2005/03/04 00:04:19 jslagle
+-- bz #147617
+-- Made Red Hat Desktop sort a little better.
+--
+-- Revision 1.74 2005/02/22 03:24:47 jslagle
+-- bz #147617
+-- Improve channel_priority function to order channels better.
+--
+-- Revision 1.73 2004/08/16 20:39:30 pjones
+-- bugzilla: 129889 -- make bulk_server_basechange_from() actually work.
+--
+-- Revision 1.72 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.71 2004/04/13 16:28:36 bretm
+-- bugzilla: 119871
+--
+-- keep track of rhnServer.channels_changed through the pl/sql fns
+--
+-- Revision 1.70 2004/03/26 18:11:32 rbb
+-- Bugzilla: 114057
+--
+-- Add a script to determine channel priority.
+--
+-- Revision 1.69 2004/02/17 20:16:52 pjones
+-- bugzilla: none -- add cvs tags into the package as long as we're touching
+-- it anyway
+--
+-- Revision 1.68 2004/02/17 20:05:38 pjones
+-- bugzilla: 115782 -- make bulk_server_basechange_from() filter out servers
+-- with arches incompatible with the target channel
+--
+-- Revision 1.67 2004/02/06 02:36:10 misa
+-- Changed normalize_server_arch to allow for solaris arches
+--
+-- Revision 1.66 2003/11/13 16:58:34 cturner
+-- make use of new rhn_user.check_role_implied call; pragmas broke, removed them for now since I have no idea how to fix them
+--
+-- Revision 1.65 2003/10/23 20:26:24 bretm
+-- bugzilla: none
+--
+-- note the channel label when we unsubscribe, too
+--
+-- Revision 1.64 2003/10/15 14:47:17 bretm
+-- bugzilla: none
+--
+-- add the channel label to the server history summary line when we log a channel change
+--
+-- Revision 1.63 2003/09/24 19:25:56 pjones
+-- this wasn't the right fix, put it back
+--
+-- Revision 1.62 2003/09/24 17:42:19 pjones
+-- bugzilla: none
+--
+-- limit our server base channel guess to channels with available permissions
+--
+-- Revision 1.61 2003/09/22 21:00:40 cturner
+-- add method for easy acl check
+--
+-- Revision 1.60 2003/09/17 22:14:11 misa
+-- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
+--
+-- Revision 1.59 2003/08/21 13:41:17 cturner
+-- bugzilla: 99187. properly test for satellite and proxy in bulk_guess_server_base; reorg code for better reuse
+--
+-- Revision 1.58 2003/07/24 16:46:22 cturner
+-- bugzilla: 100723, the perm check was returning duplicates, so now it just calls the function it should have called anyway
+--
+-- Revision 1.57 2003/07/24 16:44:16 misa
+-- bugzilla: none A function more usable on the rhnapp side
+--
+-- Revision 1.56 2003/07/23 22:36:51 cturner
+-- argh, max returns null even when now rows; use distinct. how revolting
+--
+-- Revision 1.55 2003/07/23 22:01:31 cturner
+-- oops, this one can return multiple rows; eliminate that in a lazy way
+--
+-- Revision 1.54 2003/07/23 21:59:19 cturner
+-- rework how rhnUserChannel works; move to plsql for speed and maintenance
+--
+-- Revision 1.53 2003/07/21 17:49:12 pjones
+-- bugzilla: none
+--
+-- add optional user for subscribe_server
+--
+-- Revision 1.52 2003/07/14 22:19:29 misa
+-- bugzilla: none Updating guess_base_channel to work more like the rhnapp server code
+--
+-- Revision 1.51 2003/06/26 22:09:04 pjones
+-- bugzilla: none
+--
+-- log subscribe and unsubscribe
+--
+-- Revision 1.50 2003/06/05 19:31:15 pjones
+-- bugzilla: 88278 -- make the cursor name smaller
+--
+-- Revision 1.49 2003/06/05 19:18:21 pjones
+-- bugzilla: 88278
+--
+-- unsubscribe_server() opens the package-level cursor when it invokes itself,
+-- so we're using a local copy instead.
+--
+-- Revision 1.48 2003/06/04 16:41:39 pjones
+-- bugzilla: none
+--
+-- make bulk_guess_server_base() silently ignore unguessables
+--
+-- Revision 1.47 2003/06/04 16:27:03 pjones
+-- bugzilla: 88822
+--
+-- eliminate the last outliers that remove things from channels without using
+-- unsubscribe_server, I think.
+--
+-- Revision 1.46 2003/06/03 20:49:37 pjones
+-- bugzilla: 88822
+-- unsubscribing from rhn-satellite now clears rhnSatelliteChannelFamily
+-- for the server in question
+--
+-- Revision 1.45 2003/06/02 20:41:45 pjones
+-- bugzilla: none - fix rhnProxyInfo/rhnSatelliteInfo channel unsubscribe
+-- problem. Basicly, if you're out of the channel for any reason, you're
+-- also out of rhnProxyInfo/rhnProxyInfo
+--
+-- Revision 1.44 2003/03/24 15:26:28 pjones
+-- bugzilla: 85812
+--
+-- bulk_server_base_change silently ignores servers that are satellites
+-- or proxies, as requested.
+--
+-- Revision 1.43 2003/02/26 20:28:17 pjones
+-- rhn_channel.update_family_counts() in rhn_channel.entitle_customer()
+-- the old codepath is:
+--
+-- ep ->
+-- rhn_ep.entitlement_run_me() ->
+-- rhn_ep.poll_customer() ->
+-- rhn_channel.entitle_customer()
+--
+-- which doesn't change current_members, even though it may remove servers
+-- from the family.
+--
+-- There's another bug here: currently, we don't try to order forced
+-- unsubscribes in any way; we just use
+-- rhn_channel.unsubscribe_server_from_family . If there are any child
+-- channel subscriptions, this will leave them subscribed. We really need
+-- to iterate across the channels again, and subscribe any channel for which
+-- there are no parent channel subscriptions.
+--
+-- Ugh.
+--
+-- Revision 1.42 2003/01/28 00:19:45 pjones
+-- fix clear_subscriptions; AFAICT, this is only hit on the
+-- bulk_server_base_change / bulk_server_base_guess codepaths, which puts
+-- it infrequent enough that it could be our "bad count" culprit.
+--
+-- Revision 1.41 2003/01/14 19:51:45 pjones
+-- make setting current_members on rhnChannelFamilyPermissions work when
+-- a server is in more than one channel in a single family.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql
deleted file mode 100644
index 925dddd..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql
+++ /dev/null
@@ -1,1417 +0,0 @@
---
--- 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 OR REPLACE
-PACKAGE BODY rhn_channel
-IS
- body_version varchar2(100) := '';
-
- -- Cursor that fetches all the possible base channels for a
- -- (server_arch_id, release, org_id) combination
- cursor base_channel_cursor(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number
- ) return rhnChannel%ROWTYPE is
- 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;
-
- FUNCTION get_license_path(channel_id_in IN NUMBER)
- RETURN VARCHAR2
- IS
- license_val VARCHAR2(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;
-
- RETURN license_val;
-
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END get_license_path;
-
-
- PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER)
- IS
- channel_family_id_val NUMBER;
- BEGIN
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_subscribe_no_family');
- END IF;
-
- IF rhn_channel.get_license_path(channel_id_in) IS NULL
- THEN
- 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 license_consent;
-
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in NUMBER := 1)
- IS
- channel_parent_val rhnChannel.parent_channel%TYPE;
- parent_subscribed BOOLEAN;
- server_has_base_chan BOOLEAN;
- server_already_in_chan BOOLEAN;
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- consenting_user NUMBER;
- allowed number := 0;
- current_members_val number;
- 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
- 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 := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
- LOOP
- parent_subscribed := TRUE;
- END LOOP check_subscription;
-
- IF NOT parent_subscribed
- THEN
- RETURN;
- END IF;
- ELSE
- -- base channel
- server_has_base_chan := FALSE;
- FOR base IN server_base_subscriptions(server_id_in)
- LOOP
- server_has_base_chan := TRUE;
- END LOOP base;
-
- IF server_has_base_chan
- THEN
- rhn_exception.raise_exception('channel_server_one_base');
- END IF;
- END IF;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- 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
- 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 NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
- INTO server_org_id_val
- FROM rhnChannel
- WHERE id = channel_id_in;
-
- select current_members
- into current_members_val
- from rhnPrivateChannelFamily
- where org_id = server_org_id_val and channel_family_id = channel_family_id_val
- for update of current_members;
-
- available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
-
- IF available_subscriptions IS NULL OR
- available_subscriptions > 0 or
- can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1
- THEN
-
- IF rhn_channel.get_license_path(channel_id_in) IS NOT NULL
- THEN
- BEGIN
-
- SELECT user_id INTO consenting_user
- FROM rhnChannelFamilyLicenseConsent
- WHERE channel_family_id = channel_family_id_val
- AND server_id = server_id_in;
-
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- rhn_exception.raise_exception('channel_subscribe_no_consent');
- END;
- END IF;
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- 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 = sysdate WHERE id = server_id_in;
- INSERT INTO rhnServerChannel (server_id, channel_id) VALUES (server_id_in, channel_id_in);
- IF recalcfamily_in > 0
- THEN
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- END IF;
- queue_server(server_id_in, immediate_in);
- ELSE
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- END IF;
-
- END subscribe_server;
-
- function can_server_consume_virt_channl(
- server_id_in in number,
- family_id_in in number )
- return number
- is
-
- cursor server_virt_families is
- select vi.virtual_system_id, cfvsl.channel_family_id
- 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 );
- begin
-
- for server_virt_family in server_virt_families loop
- return 1;
- end loop;
-
- return 0;
-
- end;
-
-
- PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
- END LOOP server;
- END bulk_subscribe_server;
-
- PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- IF rhn_server.can_change_base_channel(server.element) = 1
- THEN
- rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
- rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
- END IF;
- END LOOP server;
- END bulk_server_base_change;
-
- procedure bulk_server_basechange_from(
- set_label_in in varchar2,
- set_uid_in in number,
- old_channel_id_in in number,
- new_channel_id_in in number
- ) is
- cursor servers is
- select sc.server_id id
- from rhnChannel nc,
- rhnServerChannelArchCompat scac,
- rhnServer s,
- rhnChannel oc,
- rhnServerChannel sc,
- rhnSet st
- where 1=1
- -- first, find the servers we're looking for.
- and st.label = set_label_in
- and st.user_id = set_uid_in
- and st.element = sc.server_id
- -- now, filter out anything that's not in the
- -- old base channel.
- and sc.channel_id = old_channel_id_in
- and sc.channel_id = oc.id
- and oc.parent_channel is null
- -- now, see if it's compatible with the new base channel
- and nc.id = new_channel_id_in
- and nc.parent_channel is null
- and sc.server_id = s.id
- and s.server_arch_id = scac.server_arch_id
- and scac.channel_arch_id = nc.channel_arch_id;
- begin
- for s in servers loop
- insert into rhnSet (
- user_id, label, element
- ) values (
- set_uid_in,
- set_label_in || 'basechange',
- s.id
- );
- end loop channel;
- bulk_server_base_change(new_channel_id_in,
- set_label_in || 'basechange',
- set_uid_in);
- delete from rhnSet
- where label = set_label_in||'basechange'
- and user_id = set_uid_in;
- end bulk_server_basechange_from;
-
- procedure bulk_guess_server_base(
- set_label_in in varchar2,
- set_uid_in in number
- ) is
- channel_id number;
- begin
- for server in rhn_set.set_iterator(set_label_in, set_uid_in)
- loop
- -- anything that doesn't work, we just ignore
- begin
- if rhn_server.can_change_base_channel(server.element) = 1
- then
- channel_id := guess_server_base(TO_NUMBER(server.element));
- rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
- rhn_channel.subscribe_server(TO_NUMBER(server.element), channel_id, 0, set_uid_in);
- end if;
- exception when others then
- null;
- end;
- end loop server;
- end;
-
- function guess_server_base(
- server_id_in in number
- ) RETURN number is
- cursor server_cursor is
- select s.server_arch_id, s.release, s.org_id
- from rhnServer s
- where s.id = server_id_in;
- 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 base_channel_cursor;
- end loop server_cursor;
- -- Server not found, or no base channel applies to it
- return null;
- end;
-
- -- Private function
- function normalize_server_arch(server_arch_in in varchar2)
- return varchar2
- deterministic
- is
- suffix VARCHAR2(128) := '-redhat-linux';
- suffix_len NUMBER := length(suffix);
- begin
- if server_arch_in is NULL then
- return NULL;
- end if;
- if instr(server_arch_in, '-') > 0
- then
- -- Suffix already present
- return server_arch_in;
- end if;
- return server_arch_in || suffix;
- end normalize_server_arch;
-
- --
- --
- -- Raises:
- -- server_arch_not_found
- -- no_subscribe_permissions
- function base_channel_for_release_arch(
- release_in in varchar2,
- server_arch_in in varchar2,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- server_arch varchar2(256) := normalize_server_arch(server_arch_in);
- server_arch_id number;
- begin
- -- Look up the server arch
- begin
- select id
- into server_arch_id
- from rhnServerArch
- where label = server_arch;
- exception
- when no_data_found then
- rhn_exception.raise_exception('server_arch_not_found');
- end;
- return base_channel_rel_archid(release_in, server_arch_id,
- org_id_in, user_id_in);
- end base_channel_for_release_arch;
-
- function base_channel_rel_archid(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- denied_channel_id number := null;
- valid_org_id number := org_id_in;
- valid_user_id number := user_id_in;
- channel_subscribable number;
- begin
- if org_id_in = -1 and user_id_in is not null then
- -- Get the org id from the user id
- begin
- select org_id
- into valid_org_id
- from web_contact
- where id = user_id_in;
- exception
- when no_data_found then
- -- User doesn't exist
- -- XXX Only list public stuff for now
- valid_user_id := null;
- valid_org_id := -1;
- end;
- 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 loose_user_role_check(c.id, user_id_in, 'subscribe')
- into channel_subscribable
- from dual;
-
- 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 base_channel_fetch;
-
- if denied_channel_id is not null then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
- -- No base channel applies
- return NULL;
- end base_channel_rel_archid;
-
- procedure bulk_guess_server_base_from(
- set_label_in in varchar2,
- set_uid_in in number,
- channel_id_in in number
- ) is
- cursor channels(server_id_in in number) is
- select rsc.channel_id
- from rhnServerChannel rsc,
- rhnChannel rc
- where server_id_in = rsc.server_id
- and rsc.channel_id = rc.id
- and rc.parent_channel is null;
- begin
- for server in rhn_set.set_iterator(set_label_in, set_uid_in)
- loop
- for channel in channels(server.element)
- loop
- if channel.channel_id = channel_id_in
- then
- insert into rhnSet (user_id, label, element) values (set_uid_in, set_label_in || 'baseguess', server.element);
- end if;
- end loop channel;
- end loop server;
- bulk_guess_server_base(set_label_in||'baseguess',set_uid_in);
- delete from rhnSet where label = set_label_in||'baseguess' and user_id = set_uid_in;
- end;
-
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- cursor server_channels(server_id_in in number) is
- 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;
- BEGIN
- for channel in server_channels(server_id_in)
- loop
- unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, update_family_countsYN);
- end loop channel;
- END clear_subscriptions;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- server_already_in_chan BOOLEAN;
- cursor channel_family_is_proxy(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-proxy';
- cursor channel_family_is_satellite(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-satellite';
- -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
- -- with the package-level one, we get a "cursor already open", so we need a
- -- copy on our call stack instead. GROAN.
- cursor local_chk_server_parent_memb (
- server_id_in number,
- channel_id_in number ) is
- 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;
- BEGIN
- FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
- LOOP
- if unsubscribe_children_in = 1 then
- unsubscribe_server(server_id_in => server_id_in,
- channel_id_in => child.id,
- immediate_in => immediate_in,
- unsubscribe_children_in => unsubscribe_children_in,
- deleting_server => deleting_server,
- update_family_countsYN => update_family_countsYN);
- else
- rhn_exception.raise_exception('channel_unsubscribe_child_exists');
- end if;
- END LOOP child;
-
- server_already_in_chan := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF NOT server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- if deleting_server = 0 then
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- 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 = sysdate 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
- 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
- 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;
- delete from rhnSatelliteChannelFamily 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;
-
- DELETE FROM rhnChannelFamilyLicenseConsent
- WHERE channel_family_id = channel_family_id_val
- AND server_id = server_id_in;
-
- SELECT org_id INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- if update_family_countsYN = 1 then
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- end if;
- END unsubscribe_server;
-
- PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- rhn_channel.unsubscribe_server(server.element, channel_id_in, 0);
- END LOOP server;
- END bulk_unsubscribe_server;
-
- FUNCTION family_for_channel(channel_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN channel_family_id_val;
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END family_for_channel;
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- current_members_val NUMBER;
- max_members_val NUMBER;
- found NUMBER;
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN
- THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND
- LOOP
- found := 1;
-
- current_members_val := cfp.current_members;
- max_members_val := cfp.max_members;
-
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN
- THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- -- 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 available_family_subscriptions;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
- begin
- select count(distinct 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;
-
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- IS
- BEGIN
- update rhnPrivateChannelFamily
- set current_members = (
- 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;
-
- END update_family_counts;
-
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
- org_id_in IN NUMBER)
- IS
- 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
- rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
- END LOOP;
- END update_group_family_counts;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO 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 available_chan_subscriptions;
-
- -- *******************************************************************
- -- PROCEDURE: entitle_customer
- -- Creates a chan fam bucket, or sets max_members for an existing bucket
- -- Called by: rhn_ep.poll_customer_internal
- -- Calls: set_family_maxmembers + update_family_counts if the row
- -- already exists, else it creates it in rhnPrivateChannelFamily.
- -- *******************************************************************
- procedure entitle_customer(customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number)
- is
- cursor permissions is
- select 1
- from rhnPrivateChannelFamily pcf
- where pcf.org_id = customer_id_in
- and pcf.channel_family_id = channel_family_id_in;
- begin
- for perm in permissions loop
- set_family_maxmembers(
- customer_id_in,
- channel_family_id_in,
- quantity_in
- );
- rhn_channel.update_family_counts(
- channel_family_id_in,
- customer_id_in
- );
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily pcf (
- channel_family_id, org_id, max_members, current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity_in, 0
- );
- end;
-
- -- *******************************************************************
- -- PROCEDURE: set_family_maxmembers
- -- Prunes an existing channel family bucket by unsubscribing the
- -- necessary servers and sets max_members.
- -- Called by: rhn_channel.entitle_customer
- -- Calls: unsubscribe_server_from_family
- -- *******************************************************************
- procedure set_family_maxmembers(customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number)
- is
- cursor servers is
- select server_id from (
- select rownum row_number, server_id, modified from (
- select rcfsp.server_id,
- rcfsp.modified
- from rhnChannelFamilyServerPhysical rcfsp
- where rcfsp.customer_id = customer_id_in
- and rcfsp.channel_family_id = channel_family_id_in
- order by modified
- )
- where rownum > quantity_in
- );
- begin
- -- prune subscribed servers
- for server in servers loop
- rhn_channel.unsubscribe_server_from_family(server.server_id,
- channel_family_id_in);
- end loop;
-
- update rhnPrivateChannelFamily pcf
- set pcf.max_members = quantity_in
- where pcf.org_id = customer_id_in
- and pcf.channel_family_id = channel_family_id_in;
- end;
-
- procedure unsubscribe_server_from_family(server_id_in in number,
- channel_family_id_in in number)
- is
- 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;
-
- function get_org_id(channel_id_in in number)
- return number
- is
- org_id_out number;
- begin
- select org_id into org_id_out
- from rhnChannel
- where id = channel_id_in;
-
- return org_id_out;
- end get_org_id;
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
- return number
- is
- cursor families is
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = org_id_in;
- begin
- -- the idea: if we get past this query,
- -- the user has the role, else catch the exception and return 0
- for family in families loop
- return 1;
- end loop;
- return 0;
- end;
-
- function get_org_access(channel_id_in in number, org_id_in in number)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query,
- -- the org has access to the channel, else catch the exception and return 0
- select distinct 1 into throwaway
- 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);
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if a user has a given role, or if such a role is inferrable
- function user_role_check_debug(channel_id_in in number,
- user_id_in in number,
- role_in in varchar2,
- reason_out out varchar2)
- return number
- is
- org_id number;
- 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
- return 1;
- end if;
-
- if role_in = 'manage' and
- NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- return 0;
- end if;
-
- if role_in = 'subscribe' and
- rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- return 0;
- end if;
-
- -- channel admins have all roles
- if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- return 1;
- 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';
- return 1;
- end if;
- end if;
-
- -- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- return rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
- end;
-
- -- same as above, but with no OUT param; useful in views, etc
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway varchar2(256);
- begin
- return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
- end;
-
- --
- -- For multiorg phase II, this function simply checks to see if the user's
- -- has a trust relationship that includes this channel by id.
- --
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- return number
- is
- n number;
- oid number;
- 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;
- return 1;
- exception
- when no_data_found then
- return 0;
- end;
-
- -- same as above, but returns 1 if user_id_in is null
- -- This is useful in queries where user_id is not specified
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- begin
- if user_id_in is null then
- return 1;
- end if;
- return user_role_check(channel_id_in, user_id_in, role_in);
- end loose_user_role_check;
-
- -- directly checks the table, no inferred permissions
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
- 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;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if an org has a certain setting
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
- 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;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- FUNCTION channel_priority(channel_id_in IN number)
- RETURN number
- IS
- channel_name varchar2(256);
- priority number;
- end_of_life_val date;
- org_id_val number;
- 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 channel_priority;
-
- -- right now this only does the accounting changes; the cascade
- -- actually does the rhnServerChannel delete.
- procedure delete_server_channels(server_id_in in number)
- is
- 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;
-
- -- this could certainly be optimized to do updates if needs be
- procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
- is
- 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(sysdate, last_modified + 1/86400)
- where id = channel_id_in;
- end;
-
- procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate )
- is
-
- channel_last_modified date;
- last_modified_value date;
-
- cursor snapshots is
- 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 + 1/86400;
- 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 update_channel;
-
- procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- 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
- rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
- end loop;
- end update_channels_by_package;
-
-
- procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- 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
- rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
- end loop;
- end update_channels_by_errata;
-
-END rhn_channel;
-/
-SHOW ERRORS
-
---
--- Revision 1.75 2005/03/04 00:04:19 jslagle
--- bz #147617
--- Made Red Hat Desktop sort a little better.
---
--- Revision 1.74 2005/02/22 03:24:47 jslagle
--- bz #147617
--- Improve channel_priority function to order channels better.
---
--- Revision 1.73 2004/08/16 20:39:30 pjones
--- bugzilla: 129889 -- make bulk_server_basechange_from() actually work.
---
--- Revision 1.72 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.71 2004/04/13 16:28:36 bretm
--- bugzilla: 119871
---
--- keep track of rhnServer.channels_changed through the pl/sql fns
---
--- Revision 1.70 2004/03/26 18:11:32 rbb
--- Bugzilla: 114057
---
--- Add a script to determine channel priority.
---
--- Revision 1.69 2004/02/17 20:16:52 pjones
--- bugzilla: none -- add cvs tags into the package as long as we're touching
--- it anyway
---
--- Revision 1.68 2004/02/17 20:05:38 pjones
--- bugzilla: 115782 -- make bulk_server_basechange_from() filter out servers
--- with arches incompatible with the target channel
---
--- Revision 1.67 2004/02/06 02:36:10 misa
--- Changed normalize_server_arch to allow for solaris arches
---
--- Revision 1.66 2003/11/13 16:58:34 cturner
--- make use of new rhn_user.check_role_implied call; pragmas broke, removed them for now since I have no idea how to fix them
---
--- Revision 1.65 2003/10/23 20:26:24 bretm
--- bugzilla: none
---
--- note the channel label when we unsubscribe, too
---
--- Revision 1.64 2003/10/15 14:47:17 bretm
--- bugzilla: none
---
--- add the channel label to the server history summary line when we log a channel change
---
--- Revision 1.63 2003/09/24 19:25:56 pjones
--- this wasn't the right fix, put it back
---
--- Revision 1.62 2003/09/24 17:42:19 pjones
--- bugzilla: none
---
--- limit our server base channel guess to channels with available permissions
---
--- Revision 1.61 2003/09/22 21:00:40 cturner
--- add method for easy acl check
---
--- Revision 1.60 2003/09/17 22:14:11 misa
--- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
---
--- Revision 1.59 2003/08/21 13:41:17 cturner
--- bugzilla: 99187. properly test for satellite and proxy in bulk_guess_server_base; reorg code for better reuse
---
--- Revision 1.58 2003/07/24 16:46:22 cturner
--- bugzilla: 100723, the perm check was returning duplicates, so now it just calls the function it should have called anyway
---
--- Revision 1.57 2003/07/24 16:44:16 misa
--- bugzilla: none A function more usable on the rhnapp side
---
--- Revision 1.56 2003/07/23 22:36:51 cturner
--- argh, max returns null even when now rows; use distinct. how revolting
---
--- Revision 1.55 2003/07/23 22:01:31 cturner
--- oops, this one can return multiple rows; eliminate that in a lazy way
---
--- Revision 1.54 2003/07/23 21:59:19 cturner
--- rework how rhnUserChannel works; move to plsql for speed and maintenance
---
--- Revision 1.53 2003/07/21 17:49:12 pjones
--- bugzilla: none
---
--- add optional user for subscribe_server
---
--- Revision 1.52 2003/07/14 22:19:29 misa
--- bugzilla: none Updating guess_base_channel to work more like the rhnapp server code
---
--- Revision 1.51 2003/06/26 22:09:04 pjones
--- bugzilla: none
---
--- log subscribe and unsubscribe
---
--- Revision 1.50 2003/06/05 19:31:15 pjones
--- bugzilla: 88278 -- make the cursor name smaller
---
--- Revision 1.49 2003/06/05 19:18:21 pjones
--- bugzilla: 88278
---
--- unsubscribe_server() opens the package-level cursor when it invokes itself,
--- so we're using a local copy instead.
---
--- Revision 1.48 2003/06/04 16:41:39 pjones
--- bugzilla: none
---
--- make bulk_guess_server_base() silently ignore unguessables
---
--- Revision 1.47 2003/06/04 16:27:03 pjones
--- bugzilla: 88822
---
--- eliminate the last outliers that remove things from channels without using
--- unsubscribe_server, I think.
---
--- Revision 1.46 2003/06/03 20:49:37 pjones
--- bugzilla: 88822
--- unsubscribing from rhn-satellite now clears rhnSatelliteChannelFamily
--- for the server in question
---
--- Revision 1.45 2003/06/02 20:41:45 pjones
--- bugzilla: none - fix rhnProxyInfo/rhnSatelliteInfo channel unsubscribe
--- problem. Basicly, if you're out of the channel for any reason, you're
--- also out of rhnProxyInfo/rhnProxyInfo
---
--- Revision 1.44 2003/03/24 15:26:28 pjones
--- bugzilla: 85812
---
--- bulk_server_base_change silently ignores servers that are satellites
--- or proxies, as requested.
---
--- Revision 1.43 2003/02/26 20:28:17 pjones
--- rhn_channel.update_family_counts() in rhn_channel.entitle_customer()
--- the old codepath is:
---
--- ep ->
--- rhn_ep.entitlement_run_me() ->
--- rhn_ep.poll_customer() ->
--- rhn_channel.entitle_customer()
---
--- which doesn't change current_members, even though it may remove servers
--- from the family.
---
--- There's another bug here: currently, we don't try to order forced
--- unsubscribes in any way; we just use
--- rhn_channel.unsubscribe_server_from_family . If there are any child
--- channel subscriptions, this will leave them subscribed. We really need
--- to iterate across the channels again, and subscribe any channel for which
--- there are no parent channel subscriptions.
---
--- Ugh.
---
--- Revision 1.42 2003/01/28 00:19:45 pjones
--- fix clear_subscriptions; AFAICT, this is only hit on the
--- bulk_server_base_change / bulk_server_base_guess codepaths, which puts
--- it infrequent enough that it could be our "bad count" culprit.
---
--- Revision 1.41 2003/01/14 19:51:45 pjones
--- make setting current_members on rhnChannelFamilyPermissions work when
--- a server is in more than one channel in a single family.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql
deleted file mode 100644
index a6de86d..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql
+++ /dev/null
@@ -1,253 +0,0 @@
---
--- 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 OR REPLACE
-PACKAGE rhn_channel
-IS
- version varchar2(100) := '';
-
- CURSOR server_base_subscriptions(server_id_in NUMBER) IS
- 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;
-
- CURSOR check_server_subscription(server_id_in NUMBER, channel_id_in NUMBER) IS
- SELECT channel_id
- FROM rhnServerChannel
- WHERE server_id = server_id_in
- AND channel_id = channel_id_in;
-
- CURSOR check_server_parent_membership(server_id_in NUMBER, channel_id_in NUMBER) IS
- SELECT C.id
- FROM rhnChannel C, rhnServerChannel SC
- WHERE C.parent_channel = channel_id_in
- AND C.id = SC.channel_id
- AND SC.server_id = server_id_in;
-
- CURSOR channel_family_perm_cursor(channel_family_id_in NUMBER, org_id_in NUMBER) IS
- SELECT *
- FROM rhnOrgChannelFamilyPermissions
- WHERE channel_family_id = channel_family_id_in
- AND org_id = org_id_in;
-
- PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER);
- FUNCTION get_license_path(channel_id_in IN NUMBER) RETURN VARCHAR2;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server in number := 0,
- update_family_countsYN IN NUMBER := 1);
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1);
-
- function can_server_consume_virt_channl(
- server_id_in IN NUMBER,
- family_id_in in number)
- return number;
-
- FUNCTION guess_server_base(server_id_in IN NUMBER) RETURN NUMBER;
-
- FUNCTION base_channel_for_release_arch(release_in in varchar2,
- server_arch_in in varchar2, org_id_in in number := -1,
- user_id_in in number := null) RETURN number;
-
- FUNCTION base_channel_rel_archid(release_in in varchar2,
- server_arch_id_in in number, org_id_in in number := -1,
- user_id_in in number := null) RETURN number;
-
- FUNCTION channel_priority(channel_id_in in number) RETURN number;
-
- PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
- PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
-
- PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
- procedure bulk_server_basechange_from(
- set_label_in in varchar2,
- set_uid_in in number,
- old_channel_id_in in number,
- new_channel_id_in in number);
-
- procedure bulk_guess_server_base(
- set_label_in in varchar2,
- set_uid_in in number);
-
- procedure bulk_guess_server_base_from(
- set_label_in in varchar2,
- set_uid_in in number,
- channel_id_in in number);
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server in number := 0,
- update_family_countsYN IN NUMBER := 1);
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
-
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number;
-
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER, org_id_in IN NUMBER);
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2, org_id_in IN NUMBER);
- FUNCTION family_for_channel(channel_id_in IN NUMBER) RETURN NUMBER;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
-
- procedure entitle_customer(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
- procedure set_family_maxmembers(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
- procedure unsubscribe_server_from_family(server_id_in in number, channel_family_id_in in number);
-
- procedure delete_server_channels(server_id_in in number);
- procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)');
-
- function get_org_id(channel_id_in in number) return number;
- PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
-
- function get_org_access(channel_id_in in number, org_id_in in number) return number;
- PRAGMA RESTRICT_REFERENCES(get_org_access, WNDS, RNPS, WNPS);
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
-
- function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2, reason_out out varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
-
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(user_role_check, WNDS, RNPS, WNPS);
-
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(loose_user_role_check, WNDS, RNPS, WNPS);
-
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(direct_user_role_check, WNDS, RNPS, WNPS);
-
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(shared_user_role_check, WNDS, RNPS, WNPS);
-
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- RETURN NUMBER;
-
- PROCEDURE update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate );
-
- PROCEDURE update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate );
-
- PROCEDURE update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate );
-
-
- PRAGMA RESTRICT_REFERENCES(org_channel_setting, WNDS, RNPS, WNPS);
-
-END rhn_channel;
-/
-SHOW ERRORS
-
---
--- Revision 1.37 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.36 2004/03/26 18:11:32 rbb
--- Bugzilla: 114057
---
--- Add a script to determine channel priority.
---
--- Revision 1.35 2004/02/17 20:16:52 pjones
--- bugzilla: none -- add cvs tags into the package as long as we're touching
--- it anyway
---
--- Revision 1.34 2003/11/13 18:13:09 cturner
--- pragmas can now return now that rhn_user pragmas are fixed
---
--- Revision 1.32 2003/09/22 21:00:40 cturner
--- add method for easy acl check
---
--- Revision 1.31 2003/09/17 22:14:11 misa
--- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
---
--- Revision 1.30 2003/07/24 16:44:16 misa
--- bugzilla: none A function more usable on the rhnapp side
---
--- Revision 1.29 2003/07/24 14:00:17 misa
--- bugzilla: none PRAGMA RESTRICT_REFERENCES good
---
--- Revision 1.28 2003/07/23 21:59:19 cturner
--- rework how rhnUserChannel works; move to plsql for speed and maintenance
---
--- Revision 1.27 2003/07/21 17:49:12 pjones
--- bugzilla: none
---
--- add optional user for subscribe_server
---
--- Revision 1.26 2002/12/19 18:13:42 misa
--- Added caller with a default value
---
--- Revision 1.25 2002/12/11 22:18:46 pjones
--- rhnChannelNewestPackage
---
--- Revision 1.24 2002/11/21 22:08:11 pjones
--- make unsubscribe_channels have a "unsubscribe_children_in number := 0"
--- argument so that you can tell it to unsubscribe children.
---
--- Also, make it raise an exception instead of silent failure in the
--- other case.
---
--- Revision 1.23 2002/11/18 17:20:50 pjones
--- this should have gone back too
---
--- Revision 1.22 2002/11/13 23:16:18 pjones
--- lookup_*_arch()
---
--- Revision 1.21 2002/10/07 20:01:59 rnorwood
--- guess base channel for ssm and single system
---
--- Revision 1.20 2002/10/02 19:21:03 bretm
--- o 3rd party channel schema changes, no more clobs...
---
--- Revision 1.19 2002/09/20 19:21:58 bretm
--- o more 3rd party channel stuff...
---
--- Revision 1.18 2002/06/12 22:33:03 pjones
--- procedure bulk_guess_server_base_from(
--- set_label_in in varchar2,
--- set_uid_in in number,
--- channel_id_in in number);
---
--- for bretm
---
--- Revision 1.17 2002/06/12 22:12:25 pjones
--- procedure bulk_guess_server_base(
--- set_label_in in varchar2,
--- set_uid_in in number);
---
--- for bretm
---
--- Revision 1.16 2002/06/12 19:37:55 pjones
--- bulk_server_basechange_from(
--- set_label_in in varchar2,
--- set_uid_in in number,
--- old_channel_id_in in number,
--- new_channel_id_in in number
--- );
---
--- for bretm
---
--- Revision 1.15 2002/05/10 22:08:22 pjones
--- id/log
---
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql
new file mode 100644
index 0000000..5e4489e
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql
@@ -0,0 +1,226 @@
+--
+-- 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 or replace
+package rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+ type ents_array is varray(10) of rhnServerGroupType.label%TYPE;
+
+ procedure remove_org_entitlements (
+ org_id_in number
+ );
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2
+ )
+ return number;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ )
+ return number;
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2,
+ sgid_out out number
+ )
+ return boolean;
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ );
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ );
+
+ procedure unentitle_server (
+ server_id_in in number
+ );
+
+ procedure repoll_virt_guest_entitlements(
+ server_id_in in number
+ );
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array;
+
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ );
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ );
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ );
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ );
+
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ );
+
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ );
+
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ );
+
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number
+ );
+
+ procedure set_group_count (
+ customer_id_in in number, -- customer_id
+ type_in in char, -- 'U' or 'S'
+ group_type_in in number, -- rhn[User|Server]GroupType.id
+ quantity_in in number, -- quantity
+ update_family_countsYN in number := 1 -- call update_family_counts inside
+ );
+
+ procedure set_family_count (
+ customer_id_in in number, -- customer_id
+ channel_family_id_in in number, -- 246
+ quantity_in in number -- 3
+ );
+
+ -- 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
+ procedure entitle_last_modified_servers (
+ customer_id_in in number, -- customer_id
+ type_label_in in varchar2, -- 'enterprise_entitled'
+ quantity_in in number -- 3
+ );
+
+ procedure prune_everything (
+ customer_id_in in number
+ );
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ );
+end rhn_entitlements;
+/
+show errors
+
+--
+-- Revision 1.19 2004/05/26 19:45:48 pjones
+-- bugzilla: 123639
+-- 1) reformat "entitlement_grants_service"
+-- 2) make the .pks and .pkb be in the same order.
+-- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
+-- 4) add monitoring specific data.
+--
+-- Revision 1.18 2004/02/19 20:17:49 pjones
+-- bugzilla: 115896 -- add sgt and oet data for nonlinux, add
+-- [un]set_customer_nonlinux
+--
+-- Revision 1.17 2004/01/13 23:37:08 pjones
+-- bugzilla: none -- mate provisioning and management slots.
+--
+-- Revision 1.16 2003/09/23 22:14:41 bretm
+-- bugzilla: 103655
+--
+-- need something in the db that knows provisioning boxes are management boxes too, etc.
+--
+-- Revision 1.15 2003/09/19 22:35:07 pjones
+-- bugzilla: none
+--
+-- provisioning and config management entitlement support
+--
+-- Revision 1.14 2003/09/02 22:22:54 pjones
+-- bugzilla: none
+--
+-- attempt to autoentitle upon entitlement changes
+--
+-- Revision 1.13 2003/06/05 21:43:40 pjones
+-- bugzilla: none
+--
+-- add rhn_entitlements.prune_everything(customer_id_in in number);
+--
+-- Revision 1.12 2003/05/22 16:01:14 pjones
+-- reformat
+-- remove update_[server|user]group_counts (unused)
+--
+-- Revision 1.11 2002/06/03 16:07:29 pjones
+-- make prune_group and prune_family update respective max_members
+-- correctly.
+--
+-- Revision 1.10 2002/05/29 19:10:31 pjones
+-- code to entitle the last N modified servers to a particular service
+-- level
+--
+-- Revision 1.9 2002/05/10 22:08:23 pjones
+-- id/log
+--
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql
new file mode 100644
index 0000000..837a49c
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql
@@ -0,0 +1,1730 @@
+--
+-- 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 or replace
+package body rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure remove_org_entitlements(
+ org_id_in in number
+ )
+ is
+
+ cursor system_ents is
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ cursor channel_subs is
+ 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 remove_org_entitlements;
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number is
+ 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 entitlement_grants_service;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ cursor server_groups is
+ 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 lookup_entitlement_group;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ sg_id_val number;
+ begin
+ select rhn_server_group_id_seq.nextval
+ into sg_id_val
+ from dual;
+
+ 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 create_entitlement_group;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 )
+ return number is
+ cursor addon_servergroups (base_label_in in varchar2,
+ addon_label_in in varchar2) is
+ 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 rhn_entitlements.ents_array;
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i number := 0;
+ sgid number := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.ents_array();
+ 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 previous_ent.count = 0 then
+ if (is_base_in = 'Y' and rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid)) then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ 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 <= previous_ent.count
+ 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
+ if rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid) 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 can_entitle_server;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ ) return number is
+
+ type_label_in_is_base char(1);
+ sgid number;
+
+ begin
+
+ begin
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end;
+
+ if type_label_in_is_base = 'N' then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ elsif rhn_entitlements.find_compatible_sg ( server_id_in,
+ type_label_in, sgid ) then
+ return 1;
+ else
+ return 0;
+ end if;
+
+ end can_switch_base;
+
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2,
+ sgid_out out number
+ ) return boolean is
+
+ cursor servergroups is
+ select sg.id 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
+ sgid_out := servergroup.id;
+ return true;
+ end loop;
+
+ --no servergroup found
+ sgid_out := 0;
+ return false;
+ end find_compatible_sg;
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) is
+ sgid number := 0;
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ 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
+ if rhn_entitlements.find_compatible_sg (server_id_in,
+ type_label_in, sgid) then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end entitle_server;
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ ) is
+ group_id number;
+ type_is_base char;
+ is_virt number := 0;
+ begin
+ begin
+
+
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ 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 ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ -- special case: clean up related monitornig data
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM state_change
+ WHERE o_id IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE /*+index(time_series time_series_probe_id_idx)*/
+ FROM time_series
+ WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
+ (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
+ IN (SELECT to_char(probe_id)
+ 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
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('invalid_server_group_member');
+ end;
+
+ end remove_server_entitlement;
+
+
+ procedure unentitle_server (server_id_in in number) is
+
+ cursor servergroups is
+ 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 number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end unentitle_server;
+
+
+ -- *******************************************************************
+ -- 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.
+ --
+ -- *******************************************************************
+ procedure repoll_virt_guest_entitlements(server_id_in in number)
+ is
+
+ -- All channel families associated with the guests of server_id_in
+ cursor families is
+ 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
+ cursor group_types is
+ 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 speicifc
+ -- host that are consuming physical channel slots over the limit.
+ cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, 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
+ )
+ where rownum <= quantity_in;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical system slots over the limit.
+ cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, 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
+ )
+ where rownum <= quantity_in;
+
+ org_id_val number;
+ max_members_val number;
+ current_members_calc number;
+ sg_id number;
+
+ begin
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ -- 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;
+
+ 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
+
+ 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?!
+ set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val);
+ 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?
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+ 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
+ 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 repoll_virt_guest_entitlements;
+
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array is
+
+ cursor server_groups is
+ 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 ents_array;
+
+ begin
+
+ ent_array := ents_array();
+
+ for sg in server_groups loop
+ ent_array.extend;
+ ent_array(ent_array.count) := sg.label;
+ end loop;
+
+ return ent_array;
+
+ end get_server_entitlement;
+
+
+ -- this desperately needs to be table driven.
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ ) is
+ type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
+ roles_to_process roles_v;
+ cursor roles(role_label_in in varchar2) is
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ cursor org_roles(role_label_in in varchar2) is
+ 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;
+
+ type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
+ ents_to_process ents_v;
+ cursor ents(ent_label_in in varchar2) is
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ cursor org_ents(ent_label_in in varchar2) is
+ 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 := ents_v();
+ roles_to_process := roles_v();
+ -- 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.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_applicant';
+ elsif service_label_in = 'provisioning' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_provisioning';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_monitor';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'monitoring_admin';
+ elsif service_label_in = 'virtualization' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..ents_to_process.count 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..roles_to_process.count 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 rhn_user_group_id_seq.nextval,
+ 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..ents_to_process.count 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 modify_org_service;
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end set_customer_enterprise;
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end set_customer_provisioning;
+
+ procedure set_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end set_customer_monitoring;
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end set_customer_nonlinux;
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'N');
+ end unset_customer_enterprise;
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'N');
+ end unset_customer_provisioning;
+
+ procedure unset_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'N');
+ end unset_customer_monitoring;
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end unset_customer_nonlinux;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_group_count, prune_everything, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ procedure prune_group (
+ group_id_in in number,
+ type_in in char,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ cursor usergroups is
+ 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 (
+ select rownum row_number,
+ user_id,
+ time
+ from (
+ select user_id,
+ modified time
+ from rhnUserGroupMembers
+ where user_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id;
+ cursor servergroups is
+ select server_id, server_group_id, sgt.id 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 server_id
+ from (
+ select rownum row_number,
+ server_id,
+ time
+ from (
+ select sep.server_id,
+ sep.modified time
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+ type_is_base char;
+ begin
+ if type_in = 'U' then
+ update rhnUserGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for ug in usergroups loop
+ rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
+ end loop;
+ elsif type_in = 'S' then
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sg in servergroups loop
+ remove_server_entitlement(sg.server_id, sg.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sg.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
+ rhn_channel.clear_subscriptions(sg.server_id,
+ update_family_countsYN => update_family_countsYN);
+ end if;
+
+ end loop;
+ end if;
+ end prune_group;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ to_org_prev_ent_count number;
+ new_ent_count number;
+ new_quantity number;
+ group_type number;
+ begin
+
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ rhn_entitlements.set_group_count(from_org_id_in,
+ 'S',
+ group_type,
+ new_ent_count);
+
+ 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
+ set_customer_enterprise(to_org_id_in);
+ else
+ unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ set_customer_provisioning(to_org_id_in);
+ else
+ unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ set_customer_monitoring(to_org_id_in);
+ else
+ unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end assign_system_entitlement;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ new_ent_count number;
+ to_org_prev_ent_count number;
+ new_quantity number;
+ cfam_id number;
+ begin
+
+ begin
+ select max_members
+ into 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;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ rhn_entitlements.set_family_count(from_org_id_in,
+ cfam_id,
+ new_ent_count);
+
+ rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity);
+
+ end assign_channel_entitlement;
+
+ -- *******************************************************************
+ -- 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.
+ -- *******************************************************************
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ group_type number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ -- 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ rhn_entitlements.set_group_count(org_id_in,
+ 'S',
+ group_type,
+ quantity_in,
+ update_family_countsYN => 0);
+ -- bulk update family counts
+ rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+
+ end activate_system_entitlement;
+
+ -- *******************************************************************
+ -- 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.
+ -- *******************************************************************
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ cfam_id number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ -- 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ rhn_entitlements.set_family_count(org_id_in,
+ cfam_id,
+ quantity_in);
+ end if;
+
+ end activate_channel_entitlement;
+
+
+ procedure set_group_count (
+ customer_id_in in number,
+ type_in in char,
+ group_type_in in number,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ group_id number;
+ quantity number;
+ 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;
+
+ rhn_entitlements.prune_group(
+ group_id,
+ type_in,
+ quantity,
+ update_family_countsYN
+ );
+ exception
+ when no_data_found then
+ if type_in = 'U' then
+ insert into rhnUserGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select rhn_user_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ 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 rhn_server_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end if;
+ end set_group_count;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count, prune_everything
+ -- *******************************************************************
+ procedure prune_family (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number
+ ) is
+ cursor serverchannels is
+ 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 server_id
+ from (
+ select server_id,
+ time,
+ rownum row_number
+ from (
+ select rs.id server_id,
+ rcfm.modified time
+ 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
+ -- 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 time asc
+ )
+ )
+ where row_number > quantity_in
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ update rhnPrivateChannelFamily
+ set max_members = quantity_in
+ where 1=1
+ and org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ for sc in serverchannels loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+ end loop;
+ rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end prune_family;
+
+ procedure set_family_count (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number
+ ) is
+ cursor privperms is
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ cursor pubperms is
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity number;
+ done number := 0;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ rhn_entitlements.prune_family(
+ customer_id_in,
+ channel_family_id_in,
+ quantity
+ );
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0
+ );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity
+ );
+ 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 set_family_count;
+
+ -- 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.
+ procedure entitle_last_modified_servers (
+ customer_id_in in number,
+ type_label_in in varchar2,
+ quantity_in in number
+ ) is
+ -- find the servers that aren't currently in slots
+ cursor servers(cid_in in number, quant_in in number) is
+ select server_id
+ from (
+ select rownum row_number,
+ server_id
+ from (
+ select rs.id 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
+ )
+ )
+ where row_number <= quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end entitle_last_modified_servers;
+
+ procedure prune_everything (
+ customer_id_in in number
+ ) is
+ cursor everything is
+ -- all our server groups
+ select sg.id id,
+ 'S' type,
+ sg.max_members quantity
+ from rhnServerGroup sg
+ where sg.org_id = customer_id_in
+ union
+ -- all our user groups
+ select ug.id id,
+ 'U' type,
+ ug.max_members quantity
+ from rhnUserGroup ug
+ where ug.org_id = customer_id_in
+ union (
+ -- all the channel families we have perms to
+ select cfp.channel_family_id id,
+ 'C' type,
+ cfp.max_members quantity
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = customer_id_in
+ union
+ -- plus all the ones we're using that we have no perms for
+ select cfm.channel_family_id id,
+ 'C' type,
+ 0 quantity
+ from rhnChannelFamily cf,
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnServer s
+ where s.org_id = customer_id_in
+ and s.id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = cf.id
+ and cf.org_id is not null
+ and cf.org_id != customer_id_in
+ and not exists (
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = customer_id_in
+ and cfp.channel_family_id = cfm.channel_family_id
+ )
+ );
+ begin
+ for one in everything loop
+ if one.type in ('U','S') then
+ prune_group(one.id, one.type, one.quantity);
+ else
+ prune_family(customer_id_in, one.id, one.quantity);
+ end if;
+ end loop;
+ end prune_everything;
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ ) is
+ -- find servers without base channels
+ cursor servers(cid_in in number) is
+ 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 number;
+ 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
+ rhn_channel.subscribe_server(server.id, channel_id);
+ commit;
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end subscribe_newest_servers;
+end rhn_entitlements;
+/
+show errors
+
+--
+--
+-- Revision 1.56 2004/07/21 21:27:36 nhansen
+-- bug 128196: use rhn_monitor instead of rhn_monitoring as the rhnOrgEntitlementType
+--
+-- Revision 1.55 2004/07/20 15:38:57 pjones
+-- bugzilla: 128196 -- make entitling "monitoring" work.
+--
+-- Revision 1.54 2004/07/14 19:13:13 pjones
+-- bugzilla: 126461 -- entitlement changes for new user roles
+--
+-- Revision 1.53 2004/07/02 19:18:20 pjones
+-- bugzilla: 125937 -- use rhn_user to remove user roles
+--
+-- Revision 1.52 2004/05/26 19:45:48 pjones
+-- bugzilla: 123639
+-- 1) reformat "entitlement_grants_service"
+-- 2) make the .pks and .pkb be in the same order.
+-- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
+-- 4) add monitoring specific data.
+--
+-- Revision 1.51 2004/04/19 18:18:51 pjones
+-- bugzilla: none -- misa's using set_family_count() to set null org entitlements
+--
+-- Revision 1.50 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.49 2004/03/26 16:53:42 pjones
+-- bugzilla: none -- make rhn_nonlinux give config_admin too on sat.
+--
+-- Revision 1.48 2004/03/25 22:29:56 pjones
+-- bugzilla: none -- only create config_admin in set_customer_prov if we're
+-- on a satellite
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql
deleted file mode 100644
index 7ecb95b..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql
+++ /dev/null
@@ -1,1730 +0,0 @@
---
--- 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 or replace
-package body rhn_entitlements
-is
- body_version varchar2(100) := '';
-
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure remove_org_entitlements(
- org_id_in in number
- )
- is
-
- cursor system_ents is
- select sg.id, sg.max_members, sg.group_type
- from rhnServerGroup sg
- where group_type is not null
- and org_id = org_id_in;
-
- cursor channel_subs is
- 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 remove_org_entitlements;
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number is
- 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 entitlement_grants_service;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- cursor server_groups is
- 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 lookup_entitlement_group;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- sg_id_val number;
- begin
- select rhn_server_group_id_seq.nextval
- into sg_id_val
- from dual;
-
- 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 create_entitlement_group;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2 )
- return number is
- cursor addon_servergroups (base_label_in in varchar2,
- addon_label_in in varchar2) is
- 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 rhn_entitlements.ents_array;
- is_base_in char := 'N';
- is_base_current char := 'N';
- i number := 0;
- sgid number := 0;
-
- begin
-
- previous_ent := rhn_entitlements.ents_array();
- 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 previous_ent.count = 0 then
- if (is_base_in = 'Y' and rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid)) then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- 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 <= previous_ent.count
- 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
- if rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid) 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 can_entitle_server;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- ) return number is
-
- type_label_in_is_base char(1);
- sgid number;
-
- begin
-
- begin
- select is_base into type_label_in_is_base
- from rhnServerGroupType
- where label = type_label_in;
- exception
- when no_data_found then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- end;
-
- if type_label_in_is_base = 'N' then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- elsif rhn_entitlements.find_compatible_sg ( server_id_in,
- type_label_in, sgid ) then
- return 1;
- else
- return 0;
- end if;
-
- end can_switch_base;
-
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2,
- sgid_out out number
- ) return boolean is
-
- cursor servergroups is
- select sg.id 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
- sgid_out := servergroup.id;
- return true;
- end loop;
-
- --no servergroup found
- sgid_out := 0;
- return false;
- end find_compatible_sg;
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) is
- sgid number := 0;
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- 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
- if rhn_entitlements.find_compatible_sg (server_id_in,
- type_label_in, sgid) then
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.insert_into_servergroup (server_id_in, sgid);
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- else
- rhn_exception.raise_exception ('no_available_server_group');
- end if;
- else
- rhn_exception.raise_exception ('invalid_entitlement');
- end if;
- end entitle_server;
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- ) is
- group_id number;
- type_is_base char;
- is_virt number := 0;
- begin
- begin
-
-
- -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- 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 ( type_is_base = 'Y' ) then
- -- unentitle_server should handle everything, don't really need to do anything else special here
- unentitle_server ( server_id_in );
- else
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.delete_from_servergroup(server_id_in, group_id);
-
- -- special case: clean up related monitornig data
- if type_label_in = 'monitoring_entitled' then
- DELETE
- FROM state_change
- WHERE o_id IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- DELETE /*+index(time_series time_series_probe_id_idx)*/
- FROM time_series
- WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
- (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
- IN (SELECT to_char(probe_id)
- 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
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
- end if;
-
- exception
- when no_data_found then
- rhn_exception.raise_exception('invalid_server_group_member');
- end;
-
- end remove_server_entitlement;
-
-
- procedure unentitle_server (server_id_in in number) is
-
- cursor servergroups is
- 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 number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- for servergroup in servergroups loop
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.delete_from_servergroup(server_id_in,
- servergroup.server_group_id );
- end loop;
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- end unentitle_server;
-
-
- -- *******************************************************************
- -- 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.
- --
- -- *******************************************************************
- procedure repoll_virt_guest_entitlements(server_id_in in number)
- is
-
- -- All channel families associated with the guests of server_id_in
- cursor families is
- 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
- cursor group_types is
- 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 speicifc
- -- host that are consuming physical channel slots over the limit.
- cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, 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
- )
- where rownum <= quantity_in;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical system slots over the limit.
- cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, 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
- )
- where rownum <= quantity_in;
-
- org_id_val number;
- max_members_val number;
- current_members_calc number;
- sg_id number;
-
- begin
-
- select org_id
- into org_id_val
- from rhnServer
- where id = server_id_in;
-
- -- deal w/ channel entitlements first ...
- for family in families loop
- -- 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;
-
- 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
-
- 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?!
- set_family_count(org_id_val,
- family.channel_family_id,
- max_members_val);
- 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?
- rhn_channel.update_family_counts(family.channel_family_id,
- org_id_val);
- 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
- 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 repoll_virt_guest_entitlements;
-
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array is
-
- cursor server_groups is
- 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 ents_array;
-
- begin
-
- ent_array := ents_array();
-
- for sg in server_groups loop
- ent_array.extend;
- ent_array(ent_array.count) := sg.label;
- end loop;
-
- return ent_array;
-
- end get_server_entitlement;
-
-
- -- this desperately needs to be table driven.
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- ) is
- type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
- roles_to_process roles_v;
- cursor roles(role_label_in in varchar2) is
- select label, id
- from rhnUserGroupType
- where label = role_label_in;
- cursor org_roles(role_label_in in varchar2) is
- 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;
-
- type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
- ents_to_process ents_v;
- cursor ents(ent_label_in in varchar2) is
- select label, id
- from rhnOrgEntitlementType
- where label = ent_label_in;
- cursor org_ents(ent_label_in in varchar2) is
- 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 := ents_v();
- roles_to_process := roles_v();
- -- 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.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_applicant';
- elsif service_label_in = 'provisioning' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_provisioning';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- -- another nasty special case...
- if enable_in = 'Y' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
- end if;
- elsif service_label_in = 'monitoring' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_monitor';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'monitoring_admin';
- elsif service_label_in = 'virtualization' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'virtualization_platform' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'nonlinux' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- end if;
-
- if enable_in = 'Y' then
- for i in 1..ents_to_process.count 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..roles_to_process.count 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 rhn_user_group_id_seq.nextval,
- 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..ents_to_process.count 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 modify_org_service;
-
- procedure set_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'Y');
- end set_customer_enterprise;
-
- procedure set_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'Y');
- end set_customer_provisioning;
-
- procedure set_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'Y');
- end set_customer_monitoring;
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'Y');
- end set_customer_nonlinux;
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'N');
- end unset_customer_enterprise;
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'N');
- end unset_customer_provisioning;
-
- procedure unset_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'N');
- end unset_customer_monitoring;
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'N');
- end unset_customer_nonlinux;
-
- -- *******************************************************************
- -- PROCEDURE: prune_group
- -- Unsubscribes servers consuming physical slots that over the org's
- -- limit.
- -- Called by: set_group_count, prune_everything, repoll_virt_guest_entitlements
- -- *******************************************************************
- procedure prune_group (
- group_id_in in number,
- type_in in char,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- cursor usergroups is
- 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 (
- select rownum row_number,
- user_id,
- time
- from (
- select user_id,
- modified time
- from rhnUserGroupMembers
- where user_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and ugm.user_group_id = ug.id
- and ug.group_type = ugt.id;
- cursor servergroups is
- select server_id, server_group_id, sgt.id 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 server_id
- from (
- select rownum row_number,
- server_id,
- time
- from (
- select sep.server_id,
- sep.modified time
- from
- rhnServerEntitlementPhysical sep
- where
- sep.server_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
- type_is_base char;
- begin
- if type_in = 'U' then
- update rhnUserGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for ug in usergroups loop
- rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
- end loop;
- elsif type_in = 'S' then
- update rhnServerGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for sg in servergroups loop
- remove_server_entitlement(sg.server_id, sg.label);
-
- select is_base
- into type_is_base
- from rhnServerGroupType sgt
- where sgt.id = sg.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
- rhn_channel.clear_subscriptions(sg.server_id,
- update_family_countsYN => update_family_countsYN);
- end if;
-
- end loop;
- end if;
- end prune_group;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- to_org_prev_ent_count number;
- new_ent_count number;
- new_quantity number;
- group_type number;
- begin
-
- 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;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
-
- rhn_entitlements.set_group_count(from_org_id_in,
- 'S',
- group_type,
- new_ent_count);
-
- 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
- set_customer_enterprise(to_org_id_in);
- else
- unset_customer_enterprise(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'provisioning_entitled' then
- if new_quantity > 0 then
- set_customer_provisioning(to_org_id_in);
- else
- unset_customer_provisioning(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'monitoring_entitled' then
- if new_quantity > 0 then
- set_customer_monitoring(to_org_id_in);
- else
- unset_customer_monitoring(to_org_id_in);
- end if;
- end if;
-
- end assign_system_entitlement;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- new_ent_count number;
- to_org_prev_ent_count number;
- new_quantity number;
- cfam_id number;
- begin
-
- begin
- select max_members
- into 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;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- rhn_entitlements.set_family_count(from_org_id_in,
- cfam_id,
- new_ent_count);
-
- rhn_entitlements.set_family_count(to_org_id_in,
- cfam_id,
- new_quantity);
-
- end assign_channel_entitlement;
-
- -- *******************************************************************
- -- 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.
- -- *******************************************************************
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- group_type number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- -- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- don't update family counts after every server
- -- will do bulk update afterwards
- rhn_entitlements.set_group_count(org_id_in,
- 'S',
- group_type,
- quantity_in,
- update_family_countsYN => 0);
- -- bulk update family counts
- rhn_channel.update_group_family_counts(group_label_in, org_id_in);
- end if;
-
-
- end activate_system_entitlement;
-
- -- *******************************************************************
- -- 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.
- -- *******************************************************************
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- cfam_id number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- -- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- rhn_entitlements.set_family_count(org_id_in,
- cfam_id,
- quantity_in);
- end if;
-
- end activate_channel_entitlement;
-
-
- procedure set_group_count (
- customer_id_in in number,
- type_in in char,
- group_type_in in number,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- group_id number;
- quantity number;
- 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;
-
- rhn_entitlements.prune_group(
- group_id,
- type_in,
- quantity,
- update_family_countsYN
- );
- exception
- when no_data_found then
- if type_in = 'U' then
- insert into rhnUserGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select rhn_user_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- 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 rhn_server_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- from rhnServerGroupType
- where id = group_type_in
- );
- end if;
- end set_group_count;
-
- -- *******************************************************************
- -- PROCEDURE: prune_family
- -- Unsubscribes servers consuming physical slots from the channel family
- -- that are over the org's limit.
- -- Called by: set_family_count, prune_everything
- -- *******************************************************************
- procedure prune_family (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number
- ) is
- cursor serverchannels is
- 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 server_id
- from (
- select server_id,
- time,
- rownum row_number
- from (
- select rs.id server_id,
- rcfm.modified time
- 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
- -- 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 time asc
- )
- )
- where row_number > quantity_in
- );
- begin
- -- if we get a null customer_id, this is completely bogus.
- if customer_id_in is null then
- return;
- end if;
-
- update rhnPrivateChannelFamily
- set max_members = quantity_in
- where 1=1
- and org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- for sc in serverchannels loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
- end loop;
- rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
- end prune_family;
-
- procedure set_family_count (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number
- ) is
- cursor privperms is
- select 1
- from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- cursor pubperms is
- select o.id org_id
- from web_customer o,
- rhnPublicChannelFamily pcf
- where pcf.channel_family_id = channel_family_id_in;
- quantity number;
- done number := 0;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
-
- if customer_id_in is not null then
- for perm in privperms loop
- rhn_entitlements.prune_family(
- customer_id_in,
- channel_family_id_in,
- quantity
- );
- update rhnPrivateChannelFamily
- set max_members = quantity
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily (
- channel_family_id, org_id, max_members, current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity, 0
- );
- return;
- end if;
-
- for perm in pubperms loop
- if quantity = 0 then
- rhn_entitlements.prune_family(
- perm.org_id,
- channel_family_id_in,
- quantity
- );
- 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 set_family_count;
-
- -- 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.
- procedure entitle_last_modified_servers (
- customer_id_in in number,
- type_label_in in varchar2,
- quantity_in in number
- ) is
- -- find the servers that aren't currently in slots
- cursor servers(cid_in in number, quant_in in number) is
- select server_id
- from (
- select rownum row_number,
- server_id
- from (
- select rs.id 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
- )
- )
- where row_number <= quant_in;
- begin
- for server in servers(customer_id_in, quantity_in) loop
- rhn_entitlements.entitle_server(server.server_id, type_label_in);
- end loop;
- end entitle_last_modified_servers;
-
- procedure prune_everything (
- customer_id_in in number
- ) is
- cursor everything is
- -- all our server groups
- select sg.id id,
- 'S' type,
- sg.max_members quantity
- from rhnServerGroup sg
- where sg.org_id = customer_id_in
- union
- -- all our user groups
- select ug.id id,
- 'U' type,
- ug.max_members quantity
- from rhnUserGroup ug
- where ug.org_id = customer_id_in
- union (
- -- all the channel families we have perms to
- select cfp.channel_family_id id,
- 'C' type,
- cfp.max_members quantity
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = customer_id_in
- union
- -- plus all the ones we're using that we have no perms for
- select cfm.channel_family_id id,
- 'C' type,
- 0 quantity
- from rhnChannelFamily cf,
- rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnServer s
- where s.org_id = customer_id_in
- and s.id = sc.server_id
- and sc.channel_id = cfm.channel_id
- and cfm.channel_family_id = cf.id
- and cf.org_id is not null
- and cf.org_id != customer_id_in
- and not exists (
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = customer_id_in
- and cfp.channel_family_id = cfm.channel_family_id
- )
- );
- begin
- for one in everything loop
- if one.type in ('U','S') then
- prune_group(one.id, one.type, one.quantity);
- else
- prune_family(customer_id_in, one.id, one.quantity);
- end if;
- end loop;
- end prune_everything;
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- ) is
- -- find servers without base channels
- cursor servers(cid_in in number) is
- 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 number;
- 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
- rhn_channel.subscribe_server(server.id, channel_id);
- commit;
- -- exception is really channel_family_no_subscriptions
- exception
- when others then
- null;
- end;
- end if;
- end loop;
- end subscribe_newest_servers;
-end rhn_entitlements;
-/
-show errors
-
---
---
--- Revision 1.56 2004/07/21 21:27:36 nhansen
--- bug 128196: use rhn_monitor instead of rhn_monitoring as the rhnOrgEntitlementType
---
--- Revision 1.55 2004/07/20 15:38:57 pjones
--- bugzilla: 128196 -- make entitling "monitoring" work.
---
--- Revision 1.54 2004/07/14 19:13:13 pjones
--- bugzilla: 126461 -- entitlement changes for new user roles
---
--- Revision 1.53 2004/07/02 19:18:20 pjones
--- bugzilla: 125937 -- use rhn_user to remove user roles
---
--- Revision 1.52 2004/05/26 19:45:48 pjones
--- bugzilla: 123639
--- 1) reformat "entitlement_grants_service"
--- 2) make the .pks and .pkb be in the same order.
--- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
--- 4) add monitoring specific data.
---
--- Revision 1.51 2004/04/19 18:18:51 pjones
--- bugzilla: none -- misa's using set_family_count() to set null org entitlements
---
--- Revision 1.50 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.49 2004/03/26 16:53:42 pjones
--- bugzilla: none -- make rhn_nonlinux give config_admin too on sat.
---
--- Revision 1.48 2004/03/25 22:29:56 pjones
--- bugzilla: none -- only create config_admin in set_customer_prov if we're
--- on a satellite
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql
deleted file mode 100644
index 40eafac..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql
+++ /dev/null
@@ -1,226 +0,0 @@
---
--- 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 or replace
-package rhn_entitlements
-is
- body_version varchar2(100) := '';
-
- type ents_array is varray(10) of rhnServerGroupType.label%TYPE;
-
- procedure remove_org_entitlements (
- org_id_in number
- );
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2
- )
- return number;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- )
- return number;
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2,
- sgid_out out number
- )
- return boolean;
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- );
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- );
-
- procedure unentitle_server (
- server_id_in in number
- );
-
- procedure repoll_virt_guest_entitlements(
- server_id_in in number
- );
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array;
-
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- );
-
- procedure set_customer_enterprise (
- customer_id_in in number
- );
-
- procedure set_customer_provisioning (
- customer_id_in in number
- );
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- );
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- );
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- );
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- );
-
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- );
-
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- );
-
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- );
-
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number
- );
-
- procedure set_group_count (
- customer_id_in in number, -- customer_id
- type_in in char, -- 'U' or 'S'
- group_type_in in number, -- rhn[User|Server]GroupType.id
- quantity_in in number, -- quantity
- update_family_countsYN in number := 1 -- call update_family_counts inside
- );
-
- procedure set_family_count (
- customer_id_in in number, -- customer_id
- channel_family_id_in in number, -- 246
- quantity_in in number -- 3
- );
-
- -- 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
- procedure entitle_last_modified_servers (
- customer_id_in in number, -- customer_id
- type_label_in in varchar2, -- 'enterprise_entitled'
- quantity_in in number -- 3
- );
-
- procedure prune_everything (
- customer_id_in in number
- );
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- );
-end rhn_entitlements;
-/
-show errors
-
---
--- Revision 1.19 2004/05/26 19:45:48 pjones
--- bugzilla: 123639
--- 1) reformat "entitlement_grants_service"
--- 2) make the .pks and .pkb be in the same order.
--- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
--- 4) add monitoring specific data.
---
--- Revision 1.18 2004/02/19 20:17:49 pjones
--- bugzilla: 115896 -- add sgt and oet data for nonlinux, add
--- [un]set_customer_nonlinux
---
--- Revision 1.17 2004/01/13 23:37:08 pjones
--- bugzilla: none -- mate provisioning and management slots.
---
--- Revision 1.16 2003/09/23 22:14:41 bretm
--- bugzilla: 103655
---
--- need something in the db that knows provisioning boxes are management boxes too, etc.
---
--- Revision 1.15 2003/09/19 22:35:07 pjones
--- bugzilla: none
---
--- provisioning and config management entitlement support
---
--- Revision 1.14 2003/09/02 22:22:54 pjones
--- bugzilla: none
---
--- attempt to autoentitle upon entitlement changes
---
--- Revision 1.13 2003/06/05 21:43:40 pjones
--- bugzilla: none
---
--- add rhn_entitlements.prune_everything(customer_id_in in number);
---
--- Revision 1.12 2003/05/22 16:01:14 pjones
--- reformat
--- remove update_[server|user]group_counts (unused)
---
--- Revision 1.11 2002/06/03 16:07:29 pjones
--- make prune_group and prune_family update respective max_members
--- correctly.
---
--- Revision 1.10 2002/05/29 19:10:31 pjones
--- code to entitle the last N modified servers to a particular service
--- level
---
--- Revision 1.9 2002/05/10 22:08:23 pjones
--- id/log
---
13 years, 9 months
backend/server
by Jan Pazdziora
backend/server/importlib/backendOracle.py | 1 +
1 file changed, 1 insertion(+)
New commits:
commit 460aad3e019c6fd064732aed14127d822d62217b
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Feb 19 12:09:49 2010 +0100
246480 - sync last_modified column for rhnKickstartableTree as well.
diff --git a/backend/server/importlib/backendOracle.py b/backend/server/importlib/backendOracle.py
index bf60073..38f27af 100644
--- a/backend/server/importlib/backendOracle.py
+++ b/backend/server/importlib/backendOracle.py
@@ -444,6 +444,7 @@ class OracleBackend(Backend):
'boot_image' : DBstring(128),
'kstree_type' : DBint(),
'install_type' : DBint(),
+ 'last_modified' : DBdateTime()
},
pk = ['label', 'org_id'],
nullable = ['org_id'],
13 years, 9 months
Changes to 'refs/tags/rhn-client-tools-0.9.3-1'
by Jan Pazdziora
Tag 'rhn-client-tools-0.9.3-1' created by Jan Pazdziora <jpazdziora(a)redhat.com> at 2010-02-19 13:54 +0000
Tagging package [rhn-client-tools] version [0.9.3-1] in directory [client/rhel/rhn-client-tools/].
Changes since spacewalk-java-0.9.8-1:
Jan Pazdziora (4):
Cannot call rpcServer.doCall on s which is rhnserver.RhnServer() -- it does the RPC directly.
Removing usused imports from rhn-virtualization/actions/virt.
Move the logging of XMLRPC calls down to up2date_client/rpcServer.
Automatic commit of package [rhn-client-tools] release [0.9.3-1].
---
client/rhel/rhn-client-tools/rhn-client-tools.spec | 6 +++++-
client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py | 9 +--------
client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py | 1 +
client/tools/rhn-virtualization/actions/virt.py | 4 ----
rel-eng/packages/rhn-client-tools | 2 +-
5 files changed, 8 insertions(+), 14 deletions(-)
---
13 years, 9 months
client/rhel rel-eng/packages
by Jan Pazdziora
client/rhel/rhn-client-tools/rhn-client-tools.spec | 6 +++++-
rel-eng/packages/rhn-client-tools | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 5f6a9a4e959045ec52b349e70295d96e7a8777cd
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Feb 19 14:54:01 2010 +0100
Automatic commit of package [rhn-client-tools] release [0.9.3-1].
diff --git a/client/rhel/rhn-client-tools/rhn-client-tools.spec b/client/rhel/rhn-client-tools/rhn-client-tools.spec
index c804020..3447c49 100644
--- a/client/rhel/rhn-client-tools/rhn-client-tools.spec
+++ b/client/rhel/rhn-client-tools/rhn-client-tools.spec
@@ -4,7 +4,7 @@ Group: System Environment/Base
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
URL: https://fedorahosted.org/spacewalk
Name: rhn-client-tools
-Version: 0.9.2
+Version: 0.9.3
Release: 1%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
@@ -235,6 +235,10 @@ make -f Makefile.rhn-client-tools test
%{_datadir}/applications/rhn_register.desktop
%changelog
+* Fri Feb 19 2010 Jan Pazdziora 0.9.3-1
+- Move the logging of XMLRPC calls down to up2date_client/rpcServer
+- Cleanup of unused code
+
* Wed Feb 17 2010 Miroslav Suchy <msuchy(a)redhat.com> 0.9.2-1
- 564491 - package should be noarch
diff --git a/rel-eng/packages/rhn-client-tools b/rel-eng/packages/rhn-client-tools
index 531af98..89078dd 100644
--- a/rel-eng/packages/rhn-client-tools
+++ b/rel-eng/packages/rhn-client-tools
@@ -1 +1 @@
-0.9.2-1 client/rhel/rhn-client-tools/
+0.9.3-1 client/rhel/rhn-client-tools/
13 years, 9 months
client/rhel
by Jan Pazdziora
client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py | 5 -----
client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py | 1 +
2 files changed, 1 insertion(+), 5 deletions(-)
New commits:
commit 430574d855766ca0664db3411fd37349cb4aa5e5
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Feb 19 14:39:25 2010 +0100
Move the logging of XMLRPC calls down to up2date_client/rpcServer.
diff --git a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py
index 4cdbb8c..5ac55d8 100644
--- a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py
+++ b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py
@@ -475,7 +475,6 @@ def registerSystem2(username = None, password = None,
activationKey,
other)
else:
- log.log_debug("Calling xmlrpc registration.new_system_user_pass.")
info = s.registration.new_system_user_pass(profileName,
up2dateUtils.getOSRelease(),
up2dateUtils.getVersion(),
@@ -531,8 +530,6 @@ def getRemainingSubscriptions(username, password):
#bz: 442694
release = up2dateUtils.getVersion()
version = up2dateUtils.getRelease()
- log.log_debug('Calling xmlrpc registration.remaining_subscriptions')
-
virt_uuid, virt_type = get_virt_info()
if virt_uuid is not None:
@@ -709,7 +706,6 @@ def activateRegistrationNumber(username, password, registrationNumber,
Communication errors, etc
"""
- log.log_debug('Calling xmlrpc activate_registration_number.')
server = rhnserver.RhnServer()
## if server.capabilities.hasCapability(
## 'registration.activate_subscription_number'):
@@ -754,7 +750,6 @@ def activateHardwareInfo(username, password, hardwareInfo, orgId=None):
"""
## import pprint
## pprint.pprint(hardwareInfo)
- log.log_debug('Calling xmlrpc activate_hardware_info.')
other = {}
if orgId:
diff --git a/client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py b/client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py
index 6e0794e..8ca327a 100644
--- a/client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py
+++ b/client/rhel/rhn-client-tools/src/up2date_client/rpcServer.py
@@ -187,6 +187,7 @@ def getServer(refreshCallback=None):
def doCall(method, *args, **kwargs):
log = up2dateLog.initLog()
+ log.log_debug("rpcServer: Calling XMLRPC %s" % method.__dict__['_Method__name'])
cfg = config.initUp2dateConfig()
ret = None
13 years, 9 months
Changes to 'refs/tags/spacewalk-schema-0.8.14-1'
by Michael Mraka
Tag 'spacewalk-schema-0.8.14-1' created by Michael Mraka <michael.mraka(a)redhat.com> at 2010-02-19 13:47 +0000
Tagging package [spacewalk-schema] version [0.8.14-1] in directory [schema/spacewalk/].
Changes since spacewalk-schema-0.8.13-1:
Michael Mraka (2):
fixed 0.7 -> 0.8 upgrade errors
Automatic commit of package [spacewalk-schema] release [0.8.14-1].
---
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/spacewalk-schema.spec | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql | 2
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql | 253 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql | 1417 ++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql | 1417 --------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql | 253 -
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql | 226 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql | 1730 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql | 1730 ----------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql | 226 -
14 files changed, 3665 insertions(+), 3634 deletions(-)
---
13 years, 9 months
Branch 'SPACEWALK-0.8' - 2 commits - rel-eng/packages schema/spacewalk
by Michael Mraka
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/spacewalk-schema.spec | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql | 2
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql | 5
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql | 253 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql | 1417 ++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql | 1417 --------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql | 253 -
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql | 226 +
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql | 1730 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql | 1730 ----------
schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql | 226 -
14 files changed, 3665 insertions(+), 3634 deletions(-)
New commits:
commit 9ed060f0a2f4fc30a7701c973a2bc2a63070a527
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 14:47:51 2010 +0100
Automatic commit of package [spacewalk-schema] release [0.8.14-1].
diff --git a/rel-eng/packages/spacewalk-schema b/rel-eng/packages/spacewalk-schema
index d5ec189..6fd8d6d 100644
--- a/rel-eng/packages/spacewalk-schema
+++ b/rel-eng/packages/spacewalk-schema
@@ -1 +1 @@
-0.8.13-1 schema/spacewalk/
+0.8.14-1 schema/spacewalk/
diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec
index 9337c74..038c312 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: 0.8.13
+Version: 0.8.14
Release: 1%{?dist}
Source0: %{name}-%{version}.tar.gz
@@ -58,6 +58,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/spacewalk-schema-upgrade*
%changelog
+* Fri Feb 19 2010 Michael Mraka <michael.mraka(a)redhat.com> 0.8.14-1
+- more fixes of 0.7 -> 0.8 upgrade errors
+
* Thu Feb 18 2010 Michael Mraka <michael.mraka(a)redhat.com> 0.8.13-1
- improved rhnPackageFile upgrades
commit bfbacb945ac058b9544576a6acaf1094d7785e87
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 14:40:49 2010 +0100
fixed 0.7 -> 0.8 upgrade errors
- rhnPackageFile-md5 - fix for runing out of UNDO
- rhnKickstartPackage - should fix unique keys before index creation
- rhn_channel & rhn_entitlements - fixed order of pks/pkb
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
index f8ad8db..cb46fc4 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/012-3-rhnPackageFile-md5.sql
@@ -1 +1 @@
-alter table rhnPackageFile drop column md5;
+alter table rhnPackageFile set unused column md5;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql
new file mode 100644
index 0000000..bae9b4f
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-1-rhnKickstartPackage.sql
@@ -0,0 +1,28 @@
+declare
+ i number;
+begin
+ for rec in (
+ select kickstart_id kid
+ from rhnKickstartPackage
+ where position = 0
+ group by kickstart_id
+ having count(*) > 1
+ ) loop
+ i := 0;
+ for erec in (
+ select rhnKickstartPackage.rowid rid
+ from rhnKickstartPackage, rhnPackageName
+ where rhnKickstartPackage.package_name_id = rhnPackageName.id
+ and rhnKickstartPackage.kickstart_id = rec.kid
+ order by rhnKickstartPackage.position, rhnPackageName.name
+ ) loop
+ update rhnKickstartPackage
+ set position = i
+ where rhnKickstartPackage.rowid = erec.rid;
+ i := i + 1;
+ end loop;
+ end loop;
+end;
+/
+
+commit;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql
new file mode 100644
index 0000000..c7d65f9
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-2-rhnKickstartPackage.sql
@@ -0,0 +1,5 @@
+DROP INDEX rhn_kspackage_id_idx;
+
+ALTER TABLE rhnKickstartPackage
+ ADD CONSTRAINT rhn_kspackage_pos_uq UNIQUE (kickstart_id, position)
+ USING INDEX TABLESPACE [[4m_tbs]];
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql
deleted file mode 100644
index c7d65f9..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/020-rhnKickstartPackage.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-DROP INDEX rhn_kspackage_id_idx;
-
-ALTER TABLE rhnKickstartPackage
- ADD CONSTRAINT rhn_kspackage_pos_uq UNIQUE (kickstart_id, position)
- USING INDEX TABLESPACE [[4m_tbs]];
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql
new file mode 100644
index 0000000..a6de86d
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-1-rhn_channel.pks.sql
@@ -0,0 +1,253 @@
+--
+-- 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 OR REPLACE
+PACKAGE rhn_channel
+IS
+ version varchar2(100) := '';
+
+ CURSOR server_base_subscriptions(server_id_in NUMBER) IS
+ 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;
+
+ CURSOR check_server_subscription(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT channel_id
+ FROM rhnServerChannel
+ WHERE server_id = server_id_in
+ AND channel_id = channel_id_in;
+
+ CURSOR check_server_parent_membership(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT C.id
+ FROM rhnChannel C, rhnServerChannel SC
+ WHERE C.parent_channel = channel_id_in
+ AND C.id = SC.channel_id
+ AND SC.server_id = server_id_in;
+
+ CURSOR channel_family_perm_cursor(channel_family_id_in NUMBER, org_id_in NUMBER) IS
+ SELECT *
+ FROM rhnOrgChannelFamilyPermissions
+ WHERE channel_family_id = channel_family_id_in
+ AND org_id = org_id_in;
+
+ PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER);
+ FUNCTION get_license_path(channel_id_in IN NUMBER) RETURN VARCHAR2;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1);
+
+ function can_server_consume_virt_channl(
+ server_id_in IN NUMBER,
+ family_id_in in number)
+ return number;
+
+ FUNCTION guess_server_base(server_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION base_channel_for_release_arch(release_in in varchar2,
+ server_arch_in in varchar2, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION base_channel_rel_archid(release_in in varchar2,
+ server_arch_id_in in number, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION channel_priority(channel_id_in in number) RETURN number;
+
+ PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+ PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+
+ PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
+ procedure bulk_server_basechange_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ old_channel_id_in in number,
+ new_channel_id_in in number);
+
+ procedure bulk_guess_server_base(
+ set_label_in in varchar2,
+ set_uid_in in number);
+
+ procedure bulk_guess_server_base_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ channel_id_in in number);
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number;
+
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER, org_id_in IN NUMBER);
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2, org_id_in IN NUMBER);
+ FUNCTION family_for_channel(channel_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ procedure entitle_customer(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
+ procedure set_family_maxmembers(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
+ procedure unsubscribe_server_from_family(server_id_in in number, channel_family_id_in in number);
+
+ procedure delete_server_channels(server_id_in in number);
+ procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)');
+
+ function get_org_id(channel_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
+
+ function get_org_access(channel_id_in in number, org_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_access, WNDS, RNPS, WNPS);
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
+
+ function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2, reason_out out varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
+
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(user_role_check, WNDS, RNPS, WNPS);
+
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(loose_user_role_check, WNDS, RNPS, WNPS);
+
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(direct_user_role_check, WNDS, RNPS, WNPS);
+
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(shared_user_role_check, WNDS, RNPS, WNPS);
+
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ RETURN NUMBER;
+
+ PROCEDURE update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate );
+
+
+ PRAGMA RESTRICT_REFERENCES(org_channel_setting, WNDS, RNPS, WNPS);
+
+END rhn_channel;
+/
+SHOW ERRORS
+
+--
+-- Revision 1.37 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.36 2004/03/26 18:11:32 rbb
+-- Bugzilla: 114057
+--
+-- Add a script to determine channel priority.
+--
+-- Revision 1.35 2004/02/17 20:16:52 pjones
+-- bugzilla: none -- add cvs tags into the package as long as we're touching
+-- it anyway
+--
+-- Revision 1.34 2003/11/13 18:13:09 cturner
+-- pragmas can now return now that rhn_user pragmas are fixed
+--
+-- Revision 1.32 2003/09/22 21:00:40 cturner
+-- add method for easy acl check
+--
+-- Revision 1.31 2003/09/17 22:14:11 misa
+-- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
+--
+-- Revision 1.30 2003/07/24 16:44:16 misa
+-- bugzilla: none A function more usable on the rhnapp side
+--
+-- Revision 1.29 2003/07/24 14:00:17 misa
+-- bugzilla: none PRAGMA RESTRICT_REFERENCES good
+--
+-- Revision 1.28 2003/07/23 21:59:19 cturner
+-- rework how rhnUserChannel works; move to plsql for speed and maintenance
+--
+-- Revision 1.27 2003/07/21 17:49:12 pjones
+-- bugzilla: none
+--
+-- add optional user for subscribe_server
+--
+-- Revision 1.26 2002/12/19 18:13:42 misa
+-- Added caller with a default value
+--
+-- Revision 1.25 2002/12/11 22:18:46 pjones
+-- rhnChannelNewestPackage
+--
+-- Revision 1.24 2002/11/21 22:08:11 pjones
+-- make unsubscribe_channels have a "unsubscribe_children_in number := 0"
+-- argument so that you can tell it to unsubscribe children.
+--
+-- Also, make it raise an exception instead of silent failure in the
+-- other case.
+--
+-- Revision 1.23 2002/11/18 17:20:50 pjones
+-- this should have gone back too
+--
+-- Revision 1.22 2002/11/13 23:16:18 pjones
+-- lookup_*_arch()
+--
+-- Revision 1.21 2002/10/07 20:01:59 rnorwood
+-- guess base channel for ssm and single system
+--
+-- Revision 1.20 2002/10/02 19:21:03 bretm
+-- o 3rd party channel schema changes, no more clobs...
+--
+-- Revision 1.19 2002/09/20 19:21:58 bretm
+-- o more 3rd party channel stuff...
+--
+-- Revision 1.18 2002/06/12 22:33:03 pjones
+-- procedure bulk_guess_server_base_from(
+-- set_label_in in varchar2,
+-- set_uid_in in number,
+-- channel_id_in in number);
+--
+-- for bretm
+--
+-- Revision 1.17 2002/06/12 22:12:25 pjones
+-- procedure bulk_guess_server_base(
+-- set_label_in in varchar2,
+-- set_uid_in in number);
+--
+-- for bretm
+--
+-- Revision 1.16 2002/06/12 19:37:55 pjones
+-- bulk_server_basechange_from(
+-- set_label_in in varchar2,
+-- set_uid_in in number,
+-- old_channel_id_in in number,
+-- new_channel_id_in in number
+-- );
+--
+-- for bretm
+--
+-- Revision 1.15 2002/05/10 22:08:22 pjones
+-- id/log
+--
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql
new file mode 100644
index 0000000..925dddd
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-2-rhn_channel.pkb.sql
@@ -0,0 +1,1417 @@
+--
+-- 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 OR REPLACE
+PACKAGE BODY rhn_channel
+IS
+ body_version varchar2(100) := '';
+
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ cursor base_channel_cursor(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number
+ ) return rhnChannel%ROWTYPE is
+ 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;
+
+ FUNCTION get_license_path(channel_id_in IN NUMBER)
+ RETURN VARCHAR2
+ IS
+ license_val VARCHAR2(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;
+
+ RETURN license_val;
+
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END get_license_path;
+
+
+ PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER)
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_subscribe_no_family');
+ END IF;
+
+ IF rhn_channel.get_license_path(channel_id_in) IS NULL
+ THEN
+ 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 license_consent;
+
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in NUMBER := 1)
+ IS
+ channel_parent_val rhnChannel.parent_channel%TYPE;
+ parent_subscribed BOOLEAN;
+ server_has_base_chan BOOLEAN;
+ server_already_in_chan BOOLEAN;
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ consenting_user NUMBER;
+ allowed number := 0;
+ current_members_val number;
+ 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
+ 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 := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
+ LOOP
+ parent_subscribed := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT parent_subscribed
+ THEN
+ RETURN;
+ END IF;
+ ELSE
+ -- base channel
+ server_has_base_chan := FALSE;
+ FOR base IN server_base_subscriptions(server_id_in)
+ LOOP
+ server_has_base_chan := TRUE;
+ END LOOP base;
+
+ IF server_has_base_chan
+ THEN
+ rhn_exception.raise_exception('channel_server_one_base');
+ END IF;
+ END IF;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ 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
+ 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 NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
+ INTO server_org_id_val
+ FROM rhnChannel
+ WHERE id = channel_id_in;
+
+ select current_members
+ into current_members_val
+ from rhnPrivateChannelFamily
+ where org_id = server_org_id_val and channel_family_id = channel_family_id_val
+ for update of current_members;
+
+ available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
+
+ IF available_subscriptions IS NULL OR
+ available_subscriptions > 0 or
+ can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1
+ THEN
+
+ IF rhn_channel.get_license_path(channel_id_in) IS NOT NULL
+ THEN
+ BEGIN
+
+ SELECT user_id INTO consenting_user
+ FROM rhnChannelFamilyLicenseConsent
+ WHERE channel_family_id = channel_family_id_val
+ AND server_id = server_id_in;
+
+ EXCEPTION
+ WHEN NO_DATA_FOUND THEN
+ rhn_exception.raise_exception('channel_subscribe_no_consent');
+ END;
+ END IF;
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ 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 = sysdate WHERE id = server_id_in;
+ INSERT INTO rhnServerChannel (server_id, channel_id) VALUES (server_id_in, channel_id_in);
+ IF recalcfamily_in > 0
+ THEN
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ END IF;
+ queue_server(server_id_in, immediate_in);
+ ELSE
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ END IF;
+
+ END subscribe_server;
+
+ function can_server_consume_virt_channl(
+ server_id_in in number,
+ family_id_in in number )
+ return number
+ is
+
+ cursor server_virt_families is
+ select vi.virtual_system_id, cfvsl.channel_family_id
+ 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 );
+ begin
+
+ for server_virt_family in server_virt_families loop
+ return 1;
+ end loop;
+
+ return 0;
+
+ end;
+
+
+ PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
+ END LOOP server;
+ END bulk_subscribe_server;
+
+ PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ IF rhn_server.can_change_base_channel(server.element) = 1
+ THEN
+ rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
+ rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
+ END IF;
+ END LOOP server;
+ END bulk_server_base_change;
+
+ procedure bulk_server_basechange_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ old_channel_id_in in number,
+ new_channel_id_in in number
+ ) is
+ cursor servers is
+ select sc.server_id id
+ from rhnChannel nc,
+ rhnServerChannelArchCompat scac,
+ rhnServer s,
+ rhnChannel oc,
+ rhnServerChannel sc,
+ rhnSet st
+ where 1=1
+ -- first, find the servers we're looking for.
+ and st.label = set_label_in
+ and st.user_id = set_uid_in
+ and st.element = sc.server_id
+ -- now, filter out anything that's not in the
+ -- old base channel.
+ and sc.channel_id = old_channel_id_in
+ and sc.channel_id = oc.id
+ and oc.parent_channel is null
+ -- now, see if it's compatible with the new base channel
+ and nc.id = new_channel_id_in
+ and nc.parent_channel is null
+ and sc.server_id = s.id
+ and s.server_arch_id = scac.server_arch_id
+ and scac.channel_arch_id = nc.channel_arch_id;
+ begin
+ for s in servers loop
+ insert into rhnSet (
+ user_id, label, element
+ ) values (
+ set_uid_in,
+ set_label_in || 'basechange',
+ s.id
+ );
+ end loop channel;
+ bulk_server_base_change(new_channel_id_in,
+ set_label_in || 'basechange',
+ set_uid_in);
+ delete from rhnSet
+ where label = set_label_in||'basechange'
+ and user_id = set_uid_in;
+ end bulk_server_basechange_from;
+
+ procedure bulk_guess_server_base(
+ set_label_in in varchar2,
+ set_uid_in in number
+ ) is
+ channel_id number;
+ begin
+ for server in rhn_set.set_iterator(set_label_in, set_uid_in)
+ loop
+ -- anything that doesn't work, we just ignore
+ begin
+ if rhn_server.can_change_base_channel(server.element) = 1
+ then
+ channel_id := guess_server_base(TO_NUMBER(server.element));
+ rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
+ rhn_channel.subscribe_server(TO_NUMBER(server.element), channel_id, 0, set_uid_in);
+ end if;
+ exception when others then
+ null;
+ end;
+ end loop server;
+ end;
+
+ function guess_server_base(
+ server_id_in in number
+ ) RETURN number is
+ cursor server_cursor is
+ select s.server_arch_id, s.release, s.org_id
+ from rhnServer s
+ where s.id = server_id_in;
+ 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 base_channel_cursor;
+ end loop server_cursor;
+ -- Server not found, or no base channel applies to it
+ return null;
+ end;
+
+ -- Private function
+ function normalize_server_arch(server_arch_in in varchar2)
+ return varchar2
+ deterministic
+ is
+ suffix VARCHAR2(128) := '-redhat-linux';
+ suffix_len NUMBER := length(suffix);
+ begin
+ if server_arch_in is NULL then
+ return NULL;
+ end if;
+ if instr(server_arch_in, '-') > 0
+ then
+ -- Suffix already present
+ return server_arch_in;
+ end if;
+ return server_arch_in || suffix;
+ end normalize_server_arch;
+
+ --
+ --
+ -- Raises:
+ -- server_arch_not_found
+ -- no_subscribe_permissions
+ function base_channel_for_release_arch(
+ release_in in varchar2,
+ server_arch_in in varchar2,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ server_arch varchar2(256) := normalize_server_arch(server_arch_in);
+ server_arch_id number;
+ begin
+ -- Look up the server arch
+ begin
+ select id
+ into server_arch_id
+ from rhnServerArch
+ where label = server_arch;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('server_arch_not_found');
+ end;
+ return base_channel_rel_archid(release_in, server_arch_id,
+ org_id_in, user_id_in);
+ end base_channel_for_release_arch;
+
+ function base_channel_rel_archid(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ denied_channel_id number := null;
+ valid_org_id number := org_id_in;
+ valid_user_id number := user_id_in;
+ channel_subscribable number;
+ begin
+ if org_id_in = -1 and user_id_in is not null then
+ -- Get the org id from the user id
+ begin
+ select org_id
+ into valid_org_id
+ from web_contact
+ where id = user_id_in;
+ exception
+ when no_data_found then
+ -- User doesn't exist
+ -- XXX Only list public stuff for now
+ valid_user_id := null;
+ valid_org_id := -1;
+ end;
+ 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 loose_user_role_check(c.id, user_id_in, 'subscribe')
+ into channel_subscribable
+ from dual;
+
+ 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 base_channel_fetch;
+
+ if denied_channel_id is not null then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+ -- No base channel applies
+ return NULL;
+ end base_channel_rel_archid;
+
+ procedure bulk_guess_server_base_from(
+ set_label_in in varchar2,
+ set_uid_in in number,
+ channel_id_in in number
+ ) is
+ cursor channels(server_id_in in number) is
+ select rsc.channel_id
+ from rhnServerChannel rsc,
+ rhnChannel rc
+ where server_id_in = rsc.server_id
+ and rsc.channel_id = rc.id
+ and rc.parent_channel is null;
+ begin
+ for server in rhn_set.set_iterator(set_label_in, set_uid_in)
+ loop
+ for channel in channels(server.element)
+ loop
+ if channel.channel_id = channel_id_in
+ then
+ insert into rhnSet (user_id, label, element) values (set_uid_in, set_label_in || 'baseguess', server.element);
+ end if;
+ end loop channel;
+ end loop server;
+ bulk_guess_server_base(set_label_in||'baseguess',set_uid_in);
+ delete from rhnSet where label = set_label_in||'baseguess' and user_id = set_uid_in;
+ end;
+
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ cursor server_channels(server_id_in in number) is
+ 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;
+ BEGIN
+ for channel in server_channels(server_id_in)
+ loop
+ unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, update_family_countsYN);
+ end loop channel;
+ END clear_subscriptions;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ server_already_in_chan BOOLEAN;
+ cursor channel_family_is_proxy(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-proxy';
+ cursor channel_family_is_satellite(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-satellite';
+ -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
+ -- with the package-level one, we get a "cursor already open", so we need a
+ -- copy on our call stack instead. GROAN.
+ cursor local_chk_server_parent_memb (
+ server_id_in number,
+ channel_id_in number ) is
+ 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;
+ BEGIN
+ FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
+ LOOP
+ if unsubscribe_children_in = 1 then
+ unsubscribe_server(server_id_in => server_id_in,
+ channel_id_in => child.id,
+ immediate_in => immediate_in,
+ unsubscribe_children_in => unsubscribe_children_in,
+ deleting_server => deleting_server,
+ update_family_countsYN => update_family_countsYN);
+ else
+ rhn_exception.raise_exception('channel_unsubscribe_child_exists');
+ end if;
+ END LOOP child;
+
+ server_already_in_chan := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ if deleting_server = 0 then
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ 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 = sysdate 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
+ 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
+ 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;
+ delete from rhnSatelliteChannelFamily 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;
+
+ DELETE FROM rhnChannelFamilyLicenseConsent
+ WHERE channel_family_id = channel_family_id_val
+ AND server_id = server_id_in;
+
+ SELECT org_id INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ if update_family_countsYN = 1 then
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ end if;
+ END unsubscribe_server;
+
+ PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
+ IS
+ BEGIN
+ FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
+ LOOP
+ rhn_channel.unsubscribe_server(server.element, channel_id_in, 0);
+ END LOOP server;
+ END bulk_unsubscribe_server;
+
+ FUNCTION family_for_channel(channel_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN channel_family_id_val;
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END family_for_channel;
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ current_members_val NUMBER;
+ max_members_val NUMBER;
+ found NUMBER;
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN
+ THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND
+ LOOP
+ found := 1;
+
+ current_members_val := cfp.current_members;
+ max_members_val := cfp.max_members;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN
+ THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ -- 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 available_family_subscriptions;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+ begin
+ select count(distinct 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;
+
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ update rhnPrivateChannelFamily
+ set current_members = (
+ 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;
+
+ END update_family_counts;
+
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
+ org_id_in IN NUMBER)
+ IS
+ 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
+ rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END update_group_family_counts;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO 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 available_chan_subscriptions;
+
+ -- *******************************************************************
+ -- PROCEDURE: entitle_customer
+ -- Creates a chan fam bucket, or sets max_members for an existing bucket
+ -- Called by: rhn_ep.poll_customer_internal
+ -- Calls: set_family_maxmembers + update_family_counts if the row
+ -- already exists, else it creates it in rhnPrivateChannelFamily.
+ -- *******************************************************************
+ procedure entitle_customer(customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number)
+ is
+ cursor permissions is
+ select 1
+ from rhnPrivateChannelFamily pcf
+ where pcf.org_id = customer_id_in
+ and pcf.channel_family_id = channel_family_id_in;
+ begin
+ for perm in permissions loop
+ set_family_maxmembers(
+ customer_id_in,
+ channel_family_id_in,
+ quantity_in
+ );
+ rhn_channel.update_family_counts(
+ channel_family_id_in,
+ customer_id_in
+ );
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily pcf (
+ channel_family_id, org_id, max_members, current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity_in, 0
+ );
+ end;
+
+ -- *******************************************************************
+ -- PROCEDURE: set_family_maxmembers
+ -- Prunes an existing channel family bucket by unsubscribing the
+ -- necessary servers and sets max_members.
+ -- Called by: rhn_channel.entitle_customer
+ -- Calls: unsubscribe_server_from_family
+ -- *******************************************************************
+ procedure set_family_maxmembers(customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number)
+ is
+ cursor servers is
+ select server_id from (
+ select rownum row_number, server_id, modified from (
+ select rcfsp.server_id,
+ rcfsp.modified
+ from rhnChannelFamilyServerPhysical rcfsp
+ where rcfsp.customer_id = customer_id_in
+ and rcfsp.channel_family_id = channel_family_id_in
+ order by modified
+ )
+ where rownum > quantity_in
+ );
+ begin
+ -- prune subscribed servers
+ for server in servers loop
+ rhn_channel.unsubscribe_server_from_family(server.server_id,
+ channel_family_id_in);
+ end loop;
+
+ update rhnPrivateChannelFamily pcf
+ set pcf.max_members = quantity_in
+ where pcf.org_id = customer_id_in
+ and pcf.channel_family_id = channel_family_id_in;
+ end;
+
+ procedure unsubscribe_server_from_family(server_id_in in number,
+ channel_family_id_in in number)
+ is
+ 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;
+
+ function get_org_id(channel_id_in in number)
+ return number
+ is
+ org_id_out number;
+ begin
+ select org_id into org_id_out
+ from rhnChannel
+ where id = channel_id_in;
+
+ return org_id_out;
+ end get_org_id;
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
+ return number
+ is
+ cursor families is
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = org_id_in;
+ begin
+ -- the idea: if we get past this query,
+ -- the user has the role, else catch the exception and return 0
+ for family in families loop
+ return 1;
+ end loop;
+ return 0;
+ end;
+
+ function get_org_access(channel_id_in in number, org_id_in in number)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query,
+ -- the org has access to the channel, else catch the exception and return 0
+ select distinct 1 into throwaway
+ 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);
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if a user has a given role, or if such a role is inferrable
+ function user_role_check_debug(channel_id_in in number,
+ user_id_in in number,
+ role_in in varchar2,
+ reason_out out varchar2)
+ return number
+ is
+ org_id number;
+ 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
+ return 1;
+ end if;
+
+ if role_in = 'manage' and
+ NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ reason_out := 'channel_not_owned';
+ return 0;
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ reason_out := 'channel_not_available';
+ return 0;
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ reason_out := 'channel_admin';
+ return 1;
+ 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';
+ return 1;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ reason_out := 'direct_permission';
+ return rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in);
+ end;
+
+ -- same as above, but with no OUT param; useful in views, etc
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway varchar2(256);
+ begin
+ return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
+ end;
+
+ --
+ -- For multiorg phase II, this function simply checks to see if the user's
+ -- has a trust relationship that includes this channel by id.
+ --
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ return number
+ is
+ n number;
+ oid number;
+ 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;
+ return 1;
+ exception
+ when no_data_found then
+ return 0;
+ end;
+
+ -- same as above, but returns 1 if user_id_in is null
+ -- This is useful in queries where user_id is not specified
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ begin
+ if user_id_in is null then
+ return 1;
+ end if;
+ return user_role_check(channel_id_in, user_id_in, role_in);
+ end loose_user_role_check;
+
+ -- directly checks the table, no inferred permissions
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
+ 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;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if an org has a certain setting
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
+ 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;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ FUNCTION channel_priority(channel_id_in IN number)
+ RETURN number
+ IS
+ channel_name varchar2(256);
+ priority number;
+ end_of_life_val date;
+ org_id_val number;
+ 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 channel_priority;
+
+ -- right now this only does the accounting changes; the cascade
+ -- actually does the rhnServerChannel delete.
+ procedure delete_server_channels(server_id_in in number)
+ is
+ 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;
+
+ -- this could certainly be optimized to do updates if needs be
+ procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
+ is
+ 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(sysdate, last_modified + 1/86400)
+ where id = channel_id_in;
+ end;
+
+ procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate )
+ is
+
+ channel_last_modified date;
+ last_modified_value date;
+
+ cursor snapshots is
+ 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 + 1/86400;
+ 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 update_channel;
+
+ procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ 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
+ rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
+ end loop;
+ end update_channels_by_package;
+
+
+ procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ 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
+ rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
+ end loop;
+ end update_channels_by_errata;
+
+END rhn_channel;
+/
+SHOW ERRORS
+
+--
+-- Revision 1.75 2005/03/04 00:04:19 jslagle
+-- bz #147617
+-- Made Red Hat Desktop sort a little better.
+--
+-- Revision 1.74 2005/02/22 03:24:47 jslagle
+-- bz #147617
+-- Improve channel_priority function to order channels better.
+--
+-- Revision 1.73 2004/08/16 20:39:30 pjones
+-- bugzilla: 129889 -- make bulk_server_basechange_from() actually work.
+--
+-- Revision 1.72 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.71 2004/04/13 16:28:36 bretm
+-- bugzilla: 119871
+--
+-- keep track of rhnServer.channels_changed through the pl/sql fns
+--
+-- Revision 1.70 2004/03/26 18:11:32 rbb
+-- Bugzilla: 114057
+--
+-- Add a script to determine channel priority.
+--
+-- Revision 1.69 2004/02/17 20:16:52 pjones
+-- bugzilla: none -- add cvs tags into the package as long as we're touching
+-- it anyway
+--
+-- Revision 1.68 2004/02/17 20:05:38 pjones
+-- bugzilla: 115782 -- make bulk_server_basechange_from() filter out servers
+-- with arches incompatible with the target channel
+--
+-- Revision 1.67 2004/02/06 02:36:10 misa
+-- Changed normalize_server_arch to allow for solaris arches
+--
+-- Revision 1.66 2003/11/13 16:58:34 cturner
+-- make use of new rhn_user.check_role_implied call; pragmas broke, removed them for now since I have no idea how to fix them
+--
+-- Revision 1.65 2003/10/23 20:26:24 bretm
+-- bugzilla: none
+--
+-- note the channel label when we unsubscribe, too
+--
+-- Revision 1.64 2003/10/15 14:47:17 bretm
+-- bugzilla: none
+--
+-- add the channel label to the server history summary line when we log a channel change
+--
+-- Revision 1.63 2003/09/24 19:25:56 pjones
+-- this wasn't the right fix, put it back
+--
+-- Revision 1.62 2003/09/24 17:42:19 pjones
+-- bugzilla: none
+--
+-- limit our server base channel guess to channels with available permissions
+--
+-- Revision 1.61 2003/09/22 21:00:40 cturner
+-- add method for easy acl check
+--
+-- Revision 1.60 2003/09/17 22:14:11 misa
+-- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
+--
+-- Revision 1.59 2003/08/21 13:41:17 cturner
+-- bugzilla: 99187. properly test for satellite and proxy in bulk_guess_server_base; reorg code for better reuse
+--
+-- Revision 1.58 2003/07/24 16:46:22 cturner
+-- bugzilla: 100723, the perm check was returning duplicates, so now it just calls the function it should have called anyway
+--
+-- Revision 1.57 2003/07/24 16:44:16 misa
+-- bugzilla: none A function more usable on the rhnapp side
+--
+-- Revision 1.56 2003/07/23 22:36:51 cturner
+-- argh, max returns null even when now rows; use distinct. how revolting
+--
+-- Revision 1.55 2003/07/23 22:01:31 cturner
+-- oops, this one can return multiple rows; eliminate that in a lazy way
+--
+-- Revision 1.54 2003/07/23 21:59:19 cturner
+-- rework how rhnUserChannel works; move to plsql for speed and maintenance
+--
+-- Revision 1.53 2003/07/21 17:49:12 pjones
+-- bugzilla: none
+--
+-- add optional user for subscribe_server
+--
+-- Revision 1.52 2003/07/14 22:19:29 misa
+-- bugzilla: none Updating guess_base_channel to work more like the rhnapp server code
+--
+-- Revision 1.51 2003/06/26 22:09:04 pjones
+-- bugzilla: none
+--
+-- log subscribe and unsubscribe
+--
+-- Revision 1.50 2003/06/05 19:31:15 pjones
+-- bugzilla: 88278 -- make the cursor name smaller
+--
+-- Revision 1.49 2003/06/05 19:18:21 pjones
+-- bugzilla: 88278
+--
+-- unsubscribe_server() opens the package-level cursor when it invokes itself,
+-- so we're using a local copy instead.
+--
+-- Revision 1.48 2003/06/04 16:41:39 pjones
+-- bugzilla: none
+--
+-- make bulk_guess_server_base() silently ignore unguessables
+--
+-- Revision 1.47 2003/06/04 16:27:03 pjones
+-- bugzilla: 88822
+--
+-- eliminate the last outliers that remove things from channels without using
+-- unsubscribe_server, I think.
+--
+-- Revision 1.46 2003/06/03 20:49:37 pjones
+-- bugzilla: 88822
+-- unsubscribing from rhn-satellite now clears rhnSatelliteChannelFamily
+-- for the server in question
+--
+-- Revision 1.45 2003/06/02 20:41:45 pjones
+-- bugzilla: none - fix rhnProxyInfo/rhnSatelliteInfo channel unsubscribe
+-- problem. Basicly, if you're out of the channel for any reason, you're
+-- also out of rhnProxyInfo/rhnProxyInfo
+--
+-- Revision 1.44 2003/03/24 15:26:28 pjones
+-- bugzilla: 85812
+--
+-- bulk_server_base_change silently ignores servers that are satellites
+-- or proxies, as requested.
+--
+-- Revision 1.43 2003/02/26 20:28:17 pjones
+-- rhn_channel.update_family_counts() in rhn_channel.entitle_customer()
+-- the old codepath is:
+--
+-- ep ->
+-- rhn_ep.entitlement_run_me() ->
+-- rhn_ep.poll_customer() ->
+-- rhn_channel.entitle_customer()
+--
+-- which doesn't change current_members, even though it may remove servers
+-- from the family.
+--
+-- There's another bug here: currently, we don't try to order forced
+-- unsubscribes in any way; we just use
+-- rhn_channel.unsubscribe_server_from_family . If there are any child
+-- channel subscriptions, this will leave them subscribed. We really need
+-- to iterate across the channels again, and subscribe any channel for which
+-- there are no parent channel subscriptions.
+--
+-- Ugh.
+--
+-- Revision 1.42 2003/01/28 00:19:45 pjones
+-- fix clear_subscriptions; AFAICT, this is only hit on the
+-- bulk_server_base_change / bulk_server_base_guess codepaths, which puts
+-- it infrequent enough that it could be our "bad count" culprit.
+--
+-- Revision 1.41 2003/01/14 19:51:45 pjones
+-- make setting current_members on rhnChannelFamilyPermissions work when
+-- a server is in more than one channel in a single family.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql
deleted file mode 100644
index 925dddd..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pkb.sql
+++ /dev/null
@@ -1,1417 +0,0 @@
---
--- 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 OR REPLACE
-PACKAGE BODY rhn_channel
-IS
- body_version varchar2(100) := '';
-
- -- Cursor that fetches all the possible base channels for a
- -- (server_arch_id, release, org_id) combination
- cursor base_channel_cursor(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number
- ) return rhnChannel%ROWTYPE is
- 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;
-
- FUNCTION get_license_path(channel_id_in IN NUMBER)
- RETURN VARCHAR2
- IS
- license_val VARCHAR2(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;
-
- RETURN license_val;
-
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END get_license_path;
-
-
- PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER)
- IS
- channel_family_id_val NUMBER;
- BEGIN
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_subscribe_no_family');
- END IF;
-
- IF rhn_channel.get_license_path(channel_id_in) IS NULL
- THEN
- 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 license_consent;
-
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in NUMBER := 1)
- IS
- channel_parent_val rhnChannel.parent_channel%TYPE;
- parent_subscribed BOOLEAN;
- server_has_base_chan BOOLEAN;
- server_already_in_chan BOOLEAN;
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- consenting_user NUMBER;
- allowed number := 0;
- current_members_val number;
- 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
- 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 := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
- LOOP
- parent_subscribed := TRUE;
- END LOOP check_subscription;
-
- IF NOT parent_subscribed
- THEN
- RETURN;
- END IF;
- ELSE
- -- base channel
- server_has_base_chan := FALSE;
- FOR base IN server_base_subscriptions(server_id_in)
- LOOP
- server_has_base_chan := TRUE;
- END LOOP base;
-
- IF server_has_base_chan
- THEN
- rhn_exception.raise_exception('channel_server_one_base');
- END IF;
- END IF;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- 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
- 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 NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
- INTO server_org_id_val
- FROM rhnChannel
- WHERE id = channel_id_in;
-
- select current_members
- into current_members_val
- from rhnPrivateChannelFamily
- where org_id = server_org_id_val and channel_family_id = channel_family_id_val
- for update of current_members;
-
- available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
-
- IF available_subscriptions IS NULL OR
- available_subscriptions > 0 or
- can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1
- THEN
-
- IF rhn_channel.get_license_path(channel_id_in) IS NOT NULL
- THEN
- BEGIN
-
- SELECT user_id INTO consenting_user
- FROM rhnChannelFamilyLicenseConsent
- WHERE channel_family_id = channel_family_id_val
- AND server_id = server_id_in;
-
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- rhn_exception.raise_exception('channel_subscribe_no_consent');
- END;
- END IF;
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- 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 = sysdate WHERE id = server_id_in;
- INSERT INTO rhnServerChannel (server_id, channel_id) VALUES (server_id_in, channel_id_in);
- IF recalcfamily_in > 0
- THEN
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- END IF;
- queue_server(server_id_in, immediate_in);
- ELSE
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- END IF;
-
- END subscribe_server;
-
- function can_server_consume_virt_channl(
- server_id_in in number,
- family_id_in in number )
- return number
- is
-
- cursor server_virt_families is
- select vi.virtual_system_id, cfvsl.channel_family_id
- 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 );
- begin
-
- for server_virt_family in server_virt_families loop
- return 1;
- end loop;
-
- return 0;
-
- end;
-
-
- PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
- END LOOP server;
- END bulk_subscribe_server;
-
- PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- IF rhn_server.can_change_base_channel(server.element) = 1
- THEN
- rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
- rhn_channel.subscribe_server(server.element, channel_id_in, 0, set_uid_in);
- END IF;
- END LOOP server;
- END bulk_server_base_change;
-
- procedure bulk_server_basechange_from(
- set_label_in in varchar2,
- set_uid_in in number,
- old_channel_id_in in number,
- new_channel_id_in in number
- ) is
- cursor servers is
- select sc.server_id id
- from rhnChannel nc,
- rhnServerChannelArchCompat scac,
- rhnServer s,
- rhnChannel oc,
- rhnServerChannel sc,
- rhnSet st
- where 1=1
- -- first, find the servers we're looking for.
- and st.label = set_label_in
- and st.user_id = set_uid_in
- and st.element = sc.server_id
- -- now, filter out anything that's not in the
- -- old base channel.
- and sc.channel_id = old_channel_id_in
- and sc.channel_id = oc.id
- and oc.parent_channel is null
- -- now, see if it's compatible with the new base channel
- and nc.id = new_channel_id_in
- and nc.parent_channel is null
- and sc.server_id = s.id
- and s.server_arch_id = scac.server_arch_id
- and scac.channel_arch_id = nc.channel_arch_id;
- begin
- for s in servers loop
- insert into rhnSet (
- user_id, label, element
- ) values (
- set_uid_in,
- set_label_in || 'basechange',
- s.id
- );
- end loop channel;
- bulk_server_base_change(new_channel_id_in,
- set_label_in || 'basechange',
- set_uid_in);
- delete from rhnSet
- where label = set_label_in||'basechange'
- and user_id = set_uid_in;
- end bulk_server_basechange_from;
-
- procedure bulk_guess_server_base(
- set_label_in in varchar2,
- set_uid_in in number
- ) is
- channel_id number;
- begin
- for server in rhn_set.set_iterator(set_label_in, set_uid_in)
- loop
- -- anything that doesn't work, we just ignore
- begin
- if rhn_server.can_change_base_channel(server.element) = 1
- then
- channel_id := guess_server_base(TO_NUMBER(server.element));
- rhn_channel.clear_subscriptions(TO_NUMBER(server.element));
- rhn_channel.subscribe_server(TO_NUMBER(server.element), channel_id, 0, set_uid_in);
- end if;
- exception when others then
- null;
- end;
- end loop server;
- end;
-
- function guess_server_base(
- server_id_in in number
- ) RETURN number is
- cursor server_cursor is
- select s.server_arch_id, s.release, s.org_id
- from rhnServer s
- where s.id = server_id_in;
- 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 base_channel_cursor;
- end loop server_cursor;
- -- Server not found, or no base channel applies to it
- return null;
- end;
-
- -- Private function
- function normalize_server_arch(server_arch_in in varchar2)
- return varchar2
- deterministic
- is
- suffix VARCHAR2(128) := '-redhat-linux';
- suffix_len NUMBER := length(suffix);
- begin
- if server_arch_in is NULL then
- return NULL;
- end if;
- if instr(server_arch_in, '-') > 0
- then
- -- Suffix already present
- return server_arch_in;
- end if;
- return server_arch_in || suffix;
- end normalize_server_arch;
-
- --
- --
- -- Raises:
- -- server_arch_not_found
- -- no_subscribe_permissions
- function base_channel_for_release_arch(
- release_in in varchar2,
- server_arch_in in varchar2,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- server_arch varchar2(256) := normalize_server_arch(server_arch_in);
- server_arch_id number;
- begin
- -- Look up the server arch
- begin
- select id
- into server_arch_id
- from rhnServerArch
- where label = server_arch;
- exception
- when no_data_found then
- rhn_exception.raise_exception('server_arch_not_found');
- end;
- return base_channel_rel_archid(release_in, server_arch_id,
- org_id_in, user_id_in);
- end base_channel_for_release_arch;
-
- function base_channel_rel_archid(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- denied_channel_id number := null;
- valid_org_id number := org_id_in;
- valid_user_id number := user_id_in;
- channel_subscribable number;
- begin
- if org_id_in = -1 and user_id_in is not null then
- -- Get the org id from the user id
- begin
- select org_id
- into valid_org_id
- from web_contact
- where id = user_id_in;
- exception
- when no_data_found then
- -- User doesn't exist
- -- XXX Only list public stuff for now
- valid_user_id := null;
- valid_org_id := -1;
- end;
- 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 loose_user_role_check(c.id, user_id_in, 'subscribe')
- into channel_subscribable
- from dual;
-
- 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 base_channel_fetch;
-
- if denied_channel_id is not null then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
- -- No base channel applies
- return NULL;
- end base_channel_rel_archid;
-
- procedure bulk_guess_server_base_from(
- set_label_in in varchar2,
- set_uid_in in number,
- channel_id_in in number
- ) is
- cursor channels(server_id_in in number) is
- select rsc.channel_id
- from rhnServerChannel rsc,
- rhnChannel rc
- where server_id_in = rsc.server_id
- and rsc.channel_id = rc.id
- and rc.parent_channel is null;
- begin
- for server in rhn_set.set_iterator(set_label_in, set_uid_in)
- loop
- for channel in channels(server.element)
- loop
- if channel.channel_id = channel_id_in
- then
- insert into rhnSet (user_id, label, element) values (set_uid_in, set_label_in || 'baseguess', server.element);
- end if;
- end loop channel;
- end loop server;
- bulk_guess_server_base(set_label_in||'baseguess',set_uid_in);
- delete from rhnSet where label = set_label_in||'baseguess' and user_id = set_uid_in;
- end;
-
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- cursor server_channels(server_id_in in number) is
- 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;
- BEGIN
- for channel in server_channels(server_id_in)
- loop
- unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, update_family_countsYN);
- end loop channel;
- END clear_subscriptions;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- server_already_in_chan BOOLEAN;
- cursor channel_family_is_proxy(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-proxy';
- cursor channel_family_is_satellite(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-satellite';
- -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
- -- with the package-level one, we get a "cursor already open", so we need a
- -- copy on our call stack instead. GROAN.
- cursor local_chk_server_parent_memb (
- server_id_in number,
- channel_id_in number ) is
- 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;
- BEGIN
- FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
- LOOP
- if unsubscribe_children_in = 1 then
- unsubscribe_server(server_id_in => server_id_in,
- channel_id_in => child.id,
- immediate_in => immediate_in,
- unsubscribe_children_in => unsubscribe_children_in,
- deleting_server => deleting_server,
- update_family_countsYN => update_family_countsYN);
- else
- rhn_exception.raise_exception('channel_unsubscribe_child_exists');
- end if;
- END LOOP child;
-
- server_already_in_chan := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF NOT server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- if deleting_server = 0 then
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- 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 = sysdate 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
- 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
- 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;
- delete from rhnSatelliteChannelFamily 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;
-
- DELETE FROM rhnChannelFamilyLicenseConsent
- WHERE channel_family_id = channel_family_id_val
- AND server_id = server_id_in;
-
- SELECT org_id INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- if update_family_countsYN = 1 then
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- end if;
- END unsubscribe_server;
-
- PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER)
- IS
- BEGIN
- FOR server IN rhn_set.set_iterator(set_label_in, set_uid_in)
- LOOP
- rhn_channel.unsubscribe_server(server.element, channel_id_in, 0);
- END LOOP server;
- END bulk_unsubscribe_server;
-
- FUNCTION family_for_channel(channel_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN channel_family_id_val;
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END family_for_channel;
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- current_members_val NUMBER;
- max_members_val NUMBER;
- found NUMBER;
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN
- THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND
- LOOP
- found := 1;
-
- current_members_val := cfp.current_members;
- max_members_val := cfp.max_members;
-
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN
- THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- -- 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 available_family_subscriptions;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
- begin
- select count(distinct 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;
-
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- IS
- BEGIN
- update rhnPrivateChannelFamily
- set current_members = (
- 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;
-
- END update_family_counts;
-
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
- org_id_in IN NUMBER)
- IS
- 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
- rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
- END LOOP;
- END update_group_family_counts;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO 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 available_chan_subscriptions;
-
- -- *******************************************************************
- -- PROCEDURE: entitle_customer
- -- Creates a chan fam bucket, or sets max_members for an existing bucket
- -- Called by: rhn_ep.poll_customer_internal
- -- Calls: set_family_maxmembers + update_family_counts if the row
- -- already exists, else it creates it in rhnPrivateChannelFamily.
- -- *******************************************************************
- procedure entitle_customer(customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number)
- is
- cursor permissions is
- select 1
- from rhnPrivateChannelFamily pcf
- where pcf.org_id = customer_id_in
- and pcf.channel_family_id = channel_family_id_in;
- begin
- for perm in permissions loop
- set_family_maxmembers(
- customer_id_in,
- channel_family_id_in,
- quantity_in
- );
- rhn_channel.update_family_counts(
- channel_family_id_in,
- customer_id_in
- );
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily pcf (
- channel_family_id, org_id, max_members, current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity_in, 0
- );
- end;
-
- -- *******************************************************************
- -- PROCEDURE: set_family_maxmembers
- -- Prunes an existing channel family bucket by unsubscribing the
- -- necessary servers and sets max_members.
- -- Called by: rhn_channel.entitle_customer
- -- Calls: unsubscribe_server_from_family
- -- *******************************************************************
- procedure set_family_maxmembers(customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number)
- is
- cursor servers is
- select server_id from (
- select rownum row_number, server_id, modified from (
- select rcfsp.server_id,
- rcfsp.modified
- from rhnChannelFamilyServerPhysical rcfsp
- where rcfsp.customer_id = customer_id_in
- and rcfsp.channel_family_id = channel_family_id_in
- order by modified
- )
- where rownum > quantity_in
- );
- begin
- -- prune subscribed servers
- for server in servers loop
- rhn_channel.unsubscribe_server_from_family(server.server_id,
- channel_family_id_in);
- end loop;
-
- update rhnPrivateChannelFamily pcf
- set pcf.max_members = quantity_in
- where pcf.org_id = customer_id_in
- and pcf.channel_family_id = channel_family_id_in;
- end;
-
- procedure unsubscribe_server_from_family(server_id_in in number,
- channel_family_id_in in number)
- is
- 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;
-
- function get_org_id(channel_id_in in number)
- return number
- is
- org_id_out number;
- begin
- select org_id into org_id_out
- from rhnChannel
- where id = channel_id_in;
-
- return org_id_out;
- end get_org_id;
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
- return number
- is
- cursor families is
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = org_id_in;
- begin
- -- the idea: if we get past this query,
- -- the user has the role, else catch the exception and return 0
- for family in families loop
- return 1;
- end loop;
- return 0;
- end;
-
- function get_org_access(channel_id_in in number, org_id_in in number)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query,
- -- the org has access to the channel, else catch the exception and return 0
- select distinct 1 into throwaway
- 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);
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if a user has a given role, or if such a role is inferrable
- function user_role_check_debug(channel_id_in in number,
- user_id_in in number,
- role_in in varchar2,
- reason_out out varchar2)
- return number
- is
- org_id number;
- 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
- return 1;
- end if;
-
- if role_in = 'manage' and
- NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- return 0;
- end if;
-
- if role_in = 'subscribe' and
- rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- return 0;
- end if;
-
- -- channel admins have all roles
- if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- return 1;
- 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';
- return 1;
- end if;
- end if;
-
- -- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- return rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
- end;
-
- -- same as above, but with no OUT param; useful in views, etc
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway varchar2(256);
- begin
- return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
- end;
-
- --
- -- For multiorg phase II, this function simply checks to see if the user's
- -- has a trust relationship that includes this channel by id.
- --
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- return number
- is
- n number;
- oid number;
- 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;
- return 1;
- exception
- when no_data_found then
- return 0;
- end;
-
- -- same as above, but returns 1 if user_id_in is null
- -- This is useful in queries where user_id is not specified
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- begin
- if user_id_in is null then
- return 1;
- end if;
- return user_role_check(channel_id_in, user_id_in, role_in);
- end loose_user_role_check;
-
- -- directly checks the table, no inferred permissions
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
- 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;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if an org has a certain setting
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
- 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;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- FUNCTION channel_priority(channel_id_in IN number)
- RETURN number
- IS
- channel_name varchar2(256);
- priority number;
- end_of_life_val date;
- org_id_val number;
- 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 channel_priority;
-
- -- right now this only does the accounting changes; the cascade
- -- actually does the rhnServerChannel delete.
- procedure delete_server_channels(server_id_in in number)
- is
- 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;
-
- -- this could certainly be optimized to do updates if needs be
- procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
- is
- 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(sysdate, last_modified + 1/86400)
- where id = channel_id_in;
- end;
-
- procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate )
- is
-
- channel_last_modified date;
- last_modified_value date;
-
- cursor snapshots is
- 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 + 1/86400;
- 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 update_channel;
-
- procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- 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
- rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
- end loop;
- end update_channels_by_package;
-
-
- procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- 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
- rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
- end loop;
- end update_channels_by_errata;
-
-END rhn_channel;
-/
-SHOW ERRORS
-
---
--- Revision 1.75 2005/03/04 00:04:19 jslagle
--- bz #147617
--- Made Red Hat Desktop sort a little better.
---
--- Revision 1.74 2005/02/22 03:24:47 jslagle
--- bz #147617
--- Improve channel_priority function to order channels better.
---
--- Revision 1.73 2004/08/16 20:39:30 pjones
--- bugzilla: 129889 -- make bulk_server_basechange_from() actually work.
---
--- Revision 1.72 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.71 2004/04/13 16:28:36 bretm
--- bugzilla: 119871
---
--- keep track of rhnServer.channels_changed through the pl/sql fns
---
--- Revision 1.70 2004/03/26 18:11:32 rbb
--- Bugzilla: 114057
---
--- Add a script to determine channel priority.
---
--- Revision 1.69 2004/02/17 20:16:52 pjones
--- bugzilla: none -- add cvs tags into the package as long as we're touching
--- it anyway
---
--- Revision 1.68 2004/02/17 20:05:38 pjones
--- bugzilla: 115782 -- make bulk_server_basechange_from() filter out servers
--- with arches incompatible with the target channel
---
--- Revision 1.67 2004/02/06 02:36:10 misa
--- Changed normalize_server_arch to allow for solaris arches
---
--- Revision 1.66 2003/11/13 16:58:34 cturner
--- make use of new rhn_user.check_role_implied call; pragmas broke, removed them for now since I have no idea how to fix them
---
--- Revision 1.65 2003/10/23 20:26:24 bretm
--- bugzilla: none
---
--- note the channel label when we unsubscribe, too
---
--- Revision 1.64 2003/10/15 14:47:17 bretm
--- bugzilla: none
---
--- add the channel label to the server history summary line when we log a channel change
---
--- Revision 1.63 2003/09/24 19:25:56 pjones
--- this wasn't the right fix, put it back
---
--- Revision 1.62 2003/09/24 17:42:19 pjones
--- bugzilla: none
---
--- limit our server base channel guess to channels with available permissions
---
--- Revision 1.61 2003/09/22 21:00:40 cturner
--- add method for easy acl check
---
--- Revision 1.60 2003/09/17 22:14:11 misa
--- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
---
--- Revision 1.59 2003/08/21 13:41:17 cturner
--- bugzilla: 99187. properly test for satellite and proxy in bulk_guess_server_base; reorg code for better reuse
---
--- Revision 1.58 2003/07/24 16:46:22 cturner
--- bugzilla: 100723, the perm check was returning duplicates, so now it just calls the function it should have called anyway
---
--- Revision 1.57 2003/07/24 16:44:16 misa
--- bugzilla: none A function more usable on the rhnapp side
---
--- Revision 1.56 2003/07/23 22:36:51 cturner
--- argh, max returns null even when now rows; use distinct. how revolting
---
--- Revision 1.55 2003/07/23 22:01:31 cturner
--- oops, this one can return multiple rows; eliminate that in a lazy way
---
--- Revision 1.54 2003/07/23 21:59:19 cturner
--- rework how rhnUserChannel works; move to plsql for speed and maintenance
---
--- Revision 1.53 2003/07/21 17:49:12 pjones
--- bugzilla: none
---
--- add optional user for subscribe_server
---
--- Revision 1.52 2003/07/14 22:19:29 misa
--- bugzilla: none Updating guess_base_channel to work more like the rhnapp server code
---
--- Revision 1.51 2003/06/26 22:09:04 pjones
--- bugzilla: none
---
--- log subscribe and unsubscribe
---
--- Revision 1.50 2003/06/05 19:31:15 pjones
--- bugzilla: 88278 -- make the cursor name smaller
---
--- Revision 1.49 2003/06/05 19:18:21 pjones
--- bugzilla: 88278
---
--- unsubscribe_server() opens the package-level cursor when it invokes itself,
--- so we're using a local copy instead.
---
--- Revision 1.48 2003/06/04 16:41:39 pjones
--- bugzilla: none
---
--- make bulk_guess_server_base() silently ignore unguessables
---
--- Revision 1.47 2003/06/04 16:27:03 pjones
--- bugzilla: 88822
---
--- eliminate the last outliers that remove things from channels without using
--- unsubscribe_server, I think.
---
--- Revision 1.46 2003/06/03 20:49:37 pjones
--- bugzilla: 88822
--- unsubscribing from rhn-satellite now clears rhnSatelliteChannelFamily
--- for the server in question
---
--- Revision 1.45 2003/06/02 20:41:45 pjones
--- bugzilla: none - fix rhnProxyInfo/rhnSatelliteInfo channel unsubscribe
--- problem. Basicly, if you're out of the channel for any reason, you're
--- also out of rhnProxyInfo/rhnProxyInfo
---
--- Revision 1.44 2003/03/24 15:26:28 pjones
--- bugzilla: 85812
---
--- bulk_server_base_change silently ignores servers that are satellites
--- or proxies, as requested.
---
--- Revision 1.43 2003/02/26 20:28:17 pjones
--- rhn_channel.update_family_counts() in rhn_channel.entitle_customer()
--- the old codepath is:
---
--- ep ->
--- rhn_ep.entitlement_run_me() ->
--- rhn_ep.poll_customer() ->
--- rhn_channel.entitle_customer()
---
--- which doesn't change current_members, even though it may remove servers
--- from the family.
---
--- There's another bug here: currently, we don't try to order forced
--- unsubscribes in any way; we just use
--- rhn_channel.unsubscribe_server_from_family . If there are any child
--- channel subscriptions, this will leave them subscribed. We really need
--- to iterate across the channels again, and subscribe any channel for which
--- there are no parent channel subscriptions.
---
--- Ugh.
---
--- Revision 1.42 2003/01/28 00:19:45 pjones
--- fix clear_subscriptions; AFAICT, this is only hit on the
--- bulk_server_base_change / bulk_server_base_guess codepaths, which puts
--- it infrequent enough that it could be our "bad count" culprit.
---
--- Revision 1.41 2003/01/14 19:51:45 pjones
--- make setting current_members on rhnChannelFamilyPermissions work when
--- a server is in more than one channel in a single family.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql
deleted file mode 100644
index a6de86d..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/050-rhn_channel.pks.sql
+++ /dev/null
@@ -1,253 +0,0 @@
---
--- 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 OR REPLACE
-PACKAGE rhn_channel
-IS
- version varchar2(100) := '';
-
- CURSOR server_base_subscriptions(server_id_in NUMBER) IS
- 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;
-
- CURSOR check_server_subscription(server_id_in NUMBER, channel_id_in NUMBER) IS
- SELECT channel_id
- FROM rhnServerChannel
- WHERE server_id = server_id_in
- AND channel_id = channel_id_in;
-
- CURSOR check_server_parent_membership(server_id_in NUMBER, channel_id_in NUMBER) IS
- SELECT C.id
- FROM rhnChannel C, rhnServerChannel SC
- WHERE C.parent_channel = channel_id_in
- AND C.id = SC.channel_id
- AND SC.server_id = server_id_in;
-
- CURSOR channel_family_perm_cursor(channel_family_id_in NUMBER, org_id_in NUMBER) IS
- SELECT *
- FROM rhnOrgChannelFamilyPermissions
- WHERE channel_family_id = channel_family_id_in
- AND org_id = org_id_in;
-
- PROCEDURE license_consent(channel_id_in IN NUMBER, user_id_in IN NUMBER, server_id_in IN NUMBER);
- FUNCTION get_license_path(channel_id_in IN NUMBER) RETURN VARCHAR2;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server in number := 0,
- update_family_countsYN IN NUMBER := 1);
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1);
-
- function can_server_consume_virt_channl(
- server_id_in IN NUMBER,
- family_id_in in number)
- return number;
-
- FUNCTION guess_server_base(server_id_in IN NUMBER) RETURN NUMBER;
-
- FUNCTION base_channel_for_release_arch(release_in in varchar2,
- server_arch_in in varchar2, org_id_in in number := -1,
- user_id_in in number := null) RETURN number;
-
- FUNCTION base_channel_rel_archid(release_in in varchar2,
- server_arch_id_in in number, org_id_in in number := -1,
- user_id_in in number := null) RETURN number;
-
- FUNCTION channel_priority(channel_id_in in number) RETURN number;
-
- PROCEDURE bulk_subscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
- PROCEDURE bulk_unsubscribe_server(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
-
- PROCEDURE bulk_server_base_change(channel_id_in IN NUMBER, set_label_in IN VARCHAR2, set_uid_in IN NUMBER);
- procedure bulk_server_basechange_from(
- set_label_in in varchar2,
- set_uid_in in number,
- old_channel_id_in in number,
- new_channel_id_in in number);
-
- procedure bulk_guess_server_base(
- set_label_in in varchar2,
- set_uid_in in number);
-
- procedure bulk_guess_server_base_from(
- set_label_in in varchar2,
- set_uid_in in number,
- channel_id_in in number);
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server in number := 0,
- update_family_countsYN IN NUMBER := 1);
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
-
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number;
-
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER, org_id_in IN NUMBER);
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2, org_id_in IN NUMBER);
- FUNCTION family_for_channel(channel_id_in IN NUMBER) RETURN NUMBER;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
-
- procedure entitle_customer(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
- procedure set_family_maxmembers(customer_id_in in number, channel_family_id_in in number, quantity_in in number);
- procedure unsubscribe_server_from_family(server_id_in in number, channel_family_id_in in number);
-
- procedure delete_server_channels(server_id_in in number);
- procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)');
-
- function get_org_id(channel_id_in in number) return number;
- PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
-
- function get_org_access(channel_id_in in number, org_id_in in number) return number;
- PRAGMA RESTRICT_REFERENCES(get_org_access, WNDS, RNPS, WNPS);
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
-
- function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2, reason_out out varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
-
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(user_role_check, WNDS, RNPS, WNPS);
-
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(loose_user_role_check, WNDS, RNPS, WNPS);
-
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(direct_user_role_check, WNDS, RNPS, WNPS);
-
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- RETURN NUMBER;
- PRAGMA RESTRICT_REFERENCES(shared_user_role_check, WNDS, RNPS, WNPS);
-
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- RETURN NUMBER;
-
- PROCEDURE update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate );
-
- PROCEDURE update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate );
-
- PROCEDURE update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate );
-
-
- PRAGMA RESTRICT_REFERENCES(org_channel_setting, WNDS, RNPS, WNPS);
-
-END rhn_channel;
-/
-SHOW ERRORS
-
---
--- Revision 1.37 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.36 2004/03/26 18:11:32 rbb
--- Bugzilla: 114057
---
--- Add a script to determine channel priority.
---
--- Revision 1.35 2004/02/17 20:16:52 pjones
--- bugzilla: none -- add cvs tags into the package as long as we're touching
--- it anyway
---
--- Revision 1.34 2003/11/13 18:13:09 cturner
--- pragmas can now return now that rhn_user pragmas are fixed
---
--- Revision 1.32 2003/09/22 21:00:40 cturner
--- add method for easy acl check
---
--- Revision 1.31 2003/09/17 22:14:11 misa
--- bugzilla: 103639 Changes to allow me to move the base channel guess into plsql
---
--- Revision 1.30 2003/07/24 16:44:16 misa
--- bugzilla: none A function more usable on the rhnapp side
---
--- Revision 1.29 2003/07/24 14:00:17 misa
--- bugzilla: none PRAGMA RESTRICT_REFERENCES good
---
--- Revision 1.28 2003/07/23 21:59:19 cturner
--- rework how rhnUserChannel works; move to plsql for speed and maintenance
---
--- Revision 1.27 2003/07/21 17:49:12 pjones
--- bugzilla: none
---
--- add optional user for subscribe_server
---
--- Revision 1.26 2002/12/19 18:13:42 misa
--- Added caller with a default value
---
--- Revision 1.25 2002/12/11 22:18:46 pjones
--- rhnChannelNewestPackage
---
--- Revision 1.24 2002/11/21 22:08:11 pjones
--- make unsubscribe_channels have a "unsubscribe_children_in number := 0"
--- argument so that you can tell it to unsubscribe children.
---
--- Also, make it raise an exception instead of silent failure in the
--- other case.
---
--- Revision 1.23 2002/11/18 17:20:50 pjones
--- this should have gone back too
---
--- Revision 1.22 2002/11/13 23:16:18 pjones
--- lookup_*_arch()
---
--- Revision 1.21 2002/10/07 20:01:59 rnorwood
--- guess base channel for ssm and single system
---
--- Revision 1.20 2002/10/02 19:21:03 bretm
--- o 3rd party channel schema changes, no more clobs...
---
--- Revision 1.19 2002/09/20 19:21:58 bretm
--- o more 3rd party channel stuff...
---
--- Revision 1.18 2002/06/12 22:33:03 pjones
--- procedure bulk_guess_server_base_from(
--- set_label_in in varchar2,
--- set_uid_in in number,
--- channel_id_in in number);
---
--- for bretm
---
--- Revision 1.17 2002/06/12 22:12:25 pjones
--- procedure bulk_guess_server_base(
--- set_label_in in varchar2,
--- set_uid_in in number);
---
--- for bretm
---
--- Revision 1.16 2002/06/12 19:37:55 pjones
--- bulk_server_basechange_from(
--- set_label_in in varchar2,
--- set_uid_in in number,
--- old_channel_id_in in number,
--- new_channel_id_in in number
--- );
---
--- for bretm
---
--- Revision 1.15 2002/05/10 22:08:22 pjones
--- id/log
---
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql
new file mode 100644
index 0000000..40eafac
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-1-rhn_entitlements.pks.sql
@@ -0,0 +1,226 @@
+--
+-- 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 or replace
+package rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+ type ents_array is varray(10) of rhnServerGroupType.label%TYPE;
+
+ procedure remove_org_entitlements (
+ org_id_in number
+ );
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2
+ )
+ return number;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ )
+ return number;
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2,
+ sgid_out out number
+ )
+ return boolean;
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ );
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ );
+
+ procedure unentitle_server (
+ server_id_in in number
+ );
+
+ procedure repoll_virt_guest_entitlements(
+ server_id_in in number
+ );
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array;
+
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ );
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ );
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ );
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ );
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ );
+
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ );
+
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ );
+
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ );
+
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number
+ );
+
+ procedure set_group_count (
+ customer_id_in in number, -- customer_id
+ type_in in char, -- 'U' or 'S'
+ group_type_in in number, -- rhn[User|Server]GroupType.id
+ quantity_in in number, -- quantity
+ update_family_countsYN in number := 1 -- call update_family_counts inside
+ );
+
+ procedure set_family_count (
+ customer_id_in in number, -- customer_id
+ channel_family_id_in in number, -- 246
+ quantity_in in number -- 3
+ );
+
+ -- 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
+ procedure entitle_last_modified_servers (
+ customer_id_in in number, -- customer_id
+ type_label_in in varchar2, -- 'enterprise_entitled'
+ quantity_in in number -- 3
+ );
+
+ procedure prune_everything (
+ customer_id_in in number
+ );
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ );
+end rhn_entitlements;
+/
+show errors
+
+--
+-- Revision 1.19 2004/05/26 19:45:48 pjones
+-- bugzilla: 123639
+-- 1) reformat "entitlement_grants_service"
+-- 2) make the .pks and .pkb be in the same order.
+-- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
+-- 4) add monitoring specific data.
+--
+-- Revision 1.18 2004/02/19 20:17:49 pjones
+-- bugzilla: 115896 -- add sgt and oet data for nonlinux, add
+-- [un]set_customer_nonlinux
+--
+-- Revision 1.17 2004/01/13 23:37:08 pjones
+-- bugzilla: none -- mate provisioning and management slots.
+--
+-- Revision 1.16 2003/09/23 22:14:41 bretm
+-- bugzilla: 103655
+--
+-- need something in the db that knows provisioning boxes are management boxes too, etc.
+--
+-- Revision 1.15 2003/09/19 22:35:07 pjones
+-- bugzilla: none
+--
+-- provisioning and config management entitlement support
+--
+-- Revision 1.14 2003/09/02 22:22:54 pjones
+-- bugzilla: none
+--
+-- attempt to autoentitle upon entitlement changes
+--
+-- Revision 1.13 2003/06/05 21:43:40 pjones
+-- bugzilla: none
+--
+-- add rhn_entitlements.prune_everything(customer_id_in in number);
+--
+-- Revision 1.12 2003/05/22 16:01:14 pjones
+-- reformat
+-- remove update_[server|user]group_counts (unused)
+--
+-- Revision 1.11 2002/06/03 16:07:29 pjones
+-- make prune_group and prune_family update respective max_members
+-- correctly.
+--
+-- Revision 1.10 2002/05/29 19:10:31 pjones
+-- code to entitle the last N modified servers to a particular service
+-- level
+--
+-- Revision 1.9 2002/05/10 22:08:23 pjones
+-- id/log
+--
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql
new file mode 100644
index 0000000..7ecb95b
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-2-rhn_entitlements.pkb.sql
@@ -0,0 +1,1730 @@
+--
+-- 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 or replace
+package body rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure remove_org_entitlements(
+ org_id_in in number
+ )
+ is
+
+ cursor system_ents is
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ cursor channel_subs is
+ 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 remove_org_entitlements;
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number is
+ 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 entitlement_grants_service;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ cursor server_groups is
+ 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 lookup_entitlement_group;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ sg_id_val number;
+ begin
+ select rhn_server_group_id_seq.nextval
+ into sg_id_val
+ from dual;
+
+ 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 create_entitlement_group;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 )
+ return number is
+ cursor addon_servergroups (base_label_in in varchar2,
+ addon_label_in in varchar2) is
+ 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 rhn_entitlements.ents_array;
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i number := 0;
+ sgid number := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.ents_array();
+ 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 previous_ent.count = 0 then
+ if (is_base_in = 'Y' and rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid)) then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ 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 <= previous_ent.count
+ 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
+ if rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid) 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 can_entitle_server;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ ) return number is
+
+ type_label_in_is_base char(1);
+ sgid number;
+
+ begin
+
+ begin
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end;
+
+ if type_label_in_is_base = 'N' then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ elsif rhn_entitlements.find_compatible_sg ( server_id_in,
+ type_label_in, sgid ) then
+ return 1;
+ else
+ return 0;
+ end if;
+
+ end can_switch_base;
+
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2,
+ sgid_out out number
+ ) return boolean is
+
+ cursor servergroups is
+ select sg.id 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
+ sgid_out := servergroup.id;
+ return true;
+ end loop;
+
+ --no servergroup found
+ sgid_out := 0;
+ return false;
+ end find_compatible_sg;
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) is
+ sgid number := 0;
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ 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
+ if rhn_entitlements.find_compatible_sg (server_id_in,
+ type_label_in, sgid) then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end entitle_server;
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ ) is
+ group_id number;
+ type_is_base char;
+ is_virt number := 0;
+ begin
+ begin
+
+
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ 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 ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ -- special case: clean up related monitornig data
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM state_change
+ WHERE o_id IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE /*+index(time_series time_series_probe_id_idx)*/
+ FROM time_series
+ WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
+ (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
+ IN (SELECT to_char(probe_id)
+ 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
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('invalid_server_group_member');
+ end;
+
+ end remove_server_entitlement;
+
+
+ procedure unentitle_server (server_id_in in number) is
+
+ cursor servergroups is
+ 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 number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, 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 );
+
+ rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end unentitle_server;
+
+
+ -- *******************************************************************
+ -- 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.
+ --
+ -- *******************************************************************
+ procedure repoll_virt_guest_entitlements(server_id_in in number)
+ is
+
+ -- All channel families associated with the guests of server_id_in
+ cursor families is
+ 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
+ cursor group_types is
+ 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 speicifc
+ -- host that are consuming physical channel slots over the limit.
+ cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, 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
+ )
+ where rownum <= quantity_in;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical system slots over the limit.
+ cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, 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
+ )
+ where rownum <= quantity_in;
+
+ org_id_val number;
+ max_members_val number;
+ current_members_calc number;
+ sg_id number;
+
+ begin
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ -- 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;
+
+ 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
+
+ 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?!
+ set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val);
+ 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?
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+ 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
+ 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 repoll_virt_guest_entitlements;
+
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array is
+
+ cursor server_groups is
+ 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 ents_array;
+
+ begin
+
+ ent_array := ents_array();
+
+ for sg in server_groups loop
+ ent_array.extend;
+ ent_array(ent_array.count) := sg.label;
+ end loop;
+
+ return ent_array;
+
+ end get_server_entitlement;
+
+
+ -- this desperately needs to be table driven.
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ ) is
+ type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
+ roles_to_process roles_v;
+ cursor roles(role_label_in in varchar2) is
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ cursor org_roles(role_label_in in varchar2) is
+ 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;
+
+ type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
+ ents_to_process ents_v;
+ cursor ents(ent_label_in in varchar2) is
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ cursor org_ents(ent_label_in in varchar2) is
+ 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 := ents_v();
+ roles_to_process := roles_v();
+ -- 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.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_applicant';
+ elsif service_label_in = 'provisioning' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_provisioning';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_monitor';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'monitoring_admin';
+ elsif service_label_in = 'virtualization' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..ents_to_process.count 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..roles_to_process.count 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 rhn_user_group_id_seq.nextval,
+ 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..ents_to_process.count 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 modify_org_service;
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end set_customer_enterprise;
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end set_customer_provisioning;
+
+ procedure set_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end set_customer_monitoring;
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end set_customer_nonlinux;
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'N');
+ end unset_customer_enterprise;
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'N');
+ end unset_customer_provisioning;
+
+ procedure unset_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'N');
+ end unset_customer_monitoring;
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end unset_customer_nonlinux;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_group_count, prune_everything, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ procedure prune_group (
+ group_id_in in number,
+ type_in in char,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ cursor usergroups is
+ 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 (
+ select rownum row_number,
+ user_id,
+ time
+ from (
+ select user_id,
+ modified time
+ from rhnUserGroupMembers
+ where user_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id;
+ cursor servergroups is
+ select server_id, server_group_id, sgt.id 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 server_id
+ from (
+ select rownum row_number,
+ server_id,
+ time
+ from (
+ select sep.server_id,
+ sep.modified time
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+ type_is_base char;
+ begin
+ if type_in = 'U' then
+ update rhnUserGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for ug in usergroups loop
+ rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
+ end loop;
+ elsif type_in = 'S' then
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sg in servergroups loop
+ remove_server_entitlement(sg.server_id, sg.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sg.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
+ rhn_channel.clear_subscriptions(sg.server_id,
+ update_family_countsYN => update_family_countsYN);
+ end if;
+
+ end loop;
+ end if;
+ end prune_group;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ to_org_prev_ent_count number;
+ new_ent_count number;
+ new_quantity number;
+ group_type number;
+ begin
+
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ rhn_entitlements.set_group_count(from_org_id_in,
+ 'S',
+ group_type,
+ new_ent_count);
+
+ 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
+ set_customer_enterprise(to_org_id_in);
+ else
+ unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ set_customer_provisioning(to_org_id_in);
+ else
+ unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ set_customer_monitoring(to_org_id_in);
+ else
+ unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end assign_system_entitlement;
+
+ -- *******************************************************************
+ -- 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
+ -- *******************************************************************
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ new_ent_count number;
+ to_org_prev_ent_count number;
+ new_quantity number;
+ cfam_id number;
+ begin
+
+ begin
+ select max_members
+ into 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;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ rhn_entitlements.set_family_count(from_org_id_in,
+ cfam_id,
+ new_ent_count);
+
+ rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity);
+
+ end assign_channel_entitlement;
+
+ -- *******************************************************************
+ -- 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.
+ -- *******************************************************************
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ group_type number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ -- 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ rhn_entitlements.set_group_count(org_id_in,
+ 'S',
+ group_type,
+ quantity_in,
+ update_family_countsYN => 0);
+ -- bulk update family counts
+ rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+
+ end activate_system_entitlement;
+
+ -- *******************************************************************
+ -- 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.
+ -- *******************************************************************
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ cfam_id number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ 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;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ -- 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
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ rhn_entitlements.set_family_count(org_id_in,
+ cfam_id,
+ quantity_in);
+ end if;
+
+ end activate_channel_entitlement;
+
+
+ procedure set_group_count (
+ customer_id_in in number,
+ type_in in char,
+ group_type_in in number,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ group_id number;
+ quantity number;
+ 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;
+
+ rhn_entitlements.prune_group(
+ group_id,
+ type_in,
+ quantity,
+ update_family_countsYN
+ );
+ exception
+ when no_data_found then
+ if type_in = 'U' then
+ insert into rhnUserGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select rhn_user_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ 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 rhn_server_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end if;
+ end set_group_count;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count, prune_everything
+ -- *******************************************************************
+ procedure prune_family (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number
+ ) is
+ cursor serverchannels is
+ 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 server_id
+ from (
+ select server_id,
+ time,
+ rownum row_number
+ from (
+ select rs.id server_id,
+ rcfm.modified time
+ 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
+ -- 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 time asc
+ )
+ )
+ where row_number > quantity_in
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ update rhnPrivateChannelFamily
+ set max_members = quantity_in
+ where 1=1
+ and org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ for sc in serverchannels loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+ end loop;
+ rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end prune_family;
+
+ procedure set_family_count (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number
+ ) is
+ cursor privperms is
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ cursor pubperms is
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity number;
+ done number := 0;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ rhn_entitlements.prune_family(
+ customer_id_in,
+ channel_family_id_in,
+ quantity
+ );
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0
+ );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity
+ );
+ 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 set_family_count;
+
+ -- 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.
+ procedure entitle_last_modified_servers (
+ customer_id_in in number,
+ type_label_in in varchar2,
+ quantity_in in number
+ ) is
+ -- find the servers that aren't currently in slots
+ cursor servers(cid_in in number, quant_in in number) is
+ select server_id
+ from (
+ select rownum row_number,
+ server_id
+ from (
+ select rs.id 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
+ )
+ )
+ where row_number <= quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end entitle_last_modified_servers;
+
+ procedure prune_everything (
+ customer_id_in in number
+ ) is
+ cursor everything is
+ -- all our server groups
+ select sg.id id,
+ 'S' type,
+ sg.max_members quantity
+ from rhnServerGroup sg
+ where sg.org_id = customer_id_in
+ union
+ -- all our user groups
+ select ug.id id,
+ 'U' type,
+ ug.max_members quantity
+ from rhnUserGroup ug
+ where ug.org_id = customer_id_in
+ union (
+ -- all the channel families we have perms to
+ select cfp.channel_family_id id,
+ 'C' type,
+ cfp.max_members quantity
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = customer_id_in
+ union
+ -- plus all the ones we're using that we have no perms for
+ select cfm.channel_family_id id,
+ 'C' type,
+ 0 quantity
+ from rhnChannelFamily cf,
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnServer s
+ where s.org_id = customer_id_in
+ and s.id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = cf.id
+ and cf.org_id is not null
+ and cf.org_id != customer_id_in
+ and not exists (
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = customer_id_in
+ and cfp.channel_family_id = cfm.channel_family_id
+ )
+ );
+ begin
+ for one in everything loop
+ if one.type in ('U','S') then
+ prune_group(one.id, one.type, one.quantity);
+ else
+ prune_family(customer_id_in, one.id, one.quantity);
+ end if;
+ end loop;
+ end prune_everything;
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ ) is
+ -- find servers without base channels
+ cursor servers(cid_in in number) is
+ 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 number;
+ 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
+ rhn_channel.subscribe_server(server.id, channel_id);
+ commit;
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end subscribe_newest_servers;
+end rhn_entitlements;
+/
+show errors
+
+--
+--
+-- Revision 1.56 2004/07/21 21:27:36 nhansen
+-- bug 128196: use rhn_monitor instead of rhn_monitoring as the rhnOrgEntitlementType
+--
+-- Revision 1.55 2004/07/20 15:38:57 pjones
+-- bugzilla: 128196 -- make entitling "monitoring" work.
+--
+-- Revision 1.54 2004/07/14 19:13:13 pjones
+-- bugzilla: 126461 -- entitlement changes for new user roles
+--
+-- Revision 1.53 2004/07/02 19:18:20 pjones
+-- bugzilla: 125937 -- use rhn_user to remove user roles
+--
+-- Revision 1.52 2004/05/26 19:45:48 pjones
+-- bugzilla: 123639
+-- 1) reformat "entitlement_grants_service"
+-- 2) make the .pks and .pkb be in the same order.
+-- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
+-- 4) add monitoring specific data.
+--
+-- Revision 1.51 2004/04/19 18:18:51 pjones
+-- bugzilla: none -- misa's using set_family_count() to set null org entitlements
+--
+-- Revision 1.50 2004/04/14 00:09:24 pjones
+-- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
+-- a frequent full table scan
+--
+-- Revision 1.49 2004/03/26 16:53:42 pjones
+-- bugzilla: none -- make rhn_nonlinux give config_admin too on sat.
+--
+-- Revision 1.48 2004/03/25 22:29:56 pjones
+-- bugzilla: none -- only create config_admin in set_customer_prov if we're
+-- on a satellite
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql
deleted file mode 100644
index 7ecb95b..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pkb.sql
+++ /dev/null
@@ -1,1730 +0,0 @@
---
--- 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 or replace
-package body rhn_entitlements
-is
- body_version varchar2(100) := '';
-
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure remove_org_entitlements(
- org_id_in in number
- )
- is
-
- cursor system_ents is
- select sg.id, sg.max_members, sg.group_type
- from rhnServerGroup sg
- where group_type is not null
- and org_id = org_id_in;
-
- cursor channel_subs is
- 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 remove_org_entitlements;
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number is
- 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 entitlement_grants_service;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- cursor server_groups is
- 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 lookup_entitlement_group;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- sg_id_val number;
- begin
- select rhn_server_group_id_seq.nextval
- into sg_id_val
- from dual;
-
- 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 create_entitlement_group;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2 )
- return number is
- cursor addon_servergroups (base_label_in in varchar2,
- addon_label_in in varchar2) is
- 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 rhn_entitlements.ents_array;
- is_base_in char := 'N';
- is_base_current char := 'N';
- i number := 0;
- sgid number := 0;
-
- begin
-
- previous_ent := rhn_entitlements.ents_array();
- 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 previous_ent.count = 0 then
- if (is_base_in = 'Y' and rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid)) then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- 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 <= previous_ent.count
- 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
- if rhn_entitlements.find_compatible_sg (server_id_in, type_label_in, sgid) 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 can_entitle_server;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- ) return number is
-
- type_label_in_is_base char(1);
- sgid number;
-
- begin
-
- begin
- select is_base into type_label_in_is_base
- from rhnServerGroupType
- where label = type_label_in;
- exception
- when no_data_found then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- end;
-
- if type_label_in_is_base = 'N' then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- elsif rhn_entitlements.find_compatible_sg ( server_id_in,
- type_label_in, sgid ) then
- return 1;
- else
- return 0;
- end if;
-
- end can_switch_base;
-
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2,
- sgid_out out number
- ) return boolean is
-
- cursor servergroups is
- select sg.id 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
- sgid_out := servergroup.id;
- return true;
- end loop;
-
- --no servergroup found
- sgid_out := 0;
- return false;
- end find_compatible_sg;
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) is
- sgid number := 0;
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- 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
- if rhn_entitlements.find_compatible_sg (server_id_in,
- type_label_in, sgid) then
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.insert_into_servergroup (server_id_in, sgid);
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- else
- rhn_exception.raise_exception ('no_available_server_group');
- end if;
- else
- rhn_exception.raise_exception ('invalid_entitlement');
- end if;
- end entitle_server;
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- ) is
- group_id number;
- type_is_base char;
- is_virt number := 0;
- begin
- begin
-
-
- -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- 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 ( type_is_base = 'Y' ) then
- -- unentitle_server should handle everything, don't really need to do anything else special here
- unentitle_server ( server_id_in );
- else
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.delete_from_servergroup(server_id_in, group_id);
-
- -- special case: clean up related monitornig data
- if type_label_in = 'monitoring_entitled' then
- DELETE
- FROM state_change
- WHERE o_id IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- DELETE /*+index(time_series time_series_probe_id_idx)*/
- FROM time_series
- WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
- (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
- IN (SELECT to_char(probe_id)
- 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
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
- end if;
-
- exception
- when no_data_found then
- rhn_exception.raise_exception('invalid_server_group_member');
- end;
-
- end remove_server_entitlement;
-
-
- procedure unentitle_server (server_id_in in number) is
-
- cursor servergroups is
- 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 number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- for servergroup in servergroups loop
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, 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 );
-
- rhn_server.delete_from_servergroup(server_id_in,
- servergroup.server_group_id );
- end loop;
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- end unentitle_server;
-
-
- -- *******************************************************************
- -- 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.
- --
- -- *******************************************************************
- procedure repoll_virt_guest_entitlements(server_id_in in number)
- is
-
- -- All channel families associated with the guests of server_id_in
- cursor families is
- 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
- cursor group_types is
- 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 speicifc
- -- host that are consuming physical channel slots over the limit.
- cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, 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
- )
- where rownum <= quantity_in;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical system slots over the limit.
- cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, 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
- )
- where rownum <= quantity_in;
-
- org_id_val number;
- max_members_val number;
- current_members_calc number;
- sg_id number;
-
- begin
-
- select org_id
- into org_id_val
- from rhnServer
- where id = server_id_in;
-
- -- deal w/ channel entitlements first ...
- for family in families loop
- -- 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;
-
- 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
-
- 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?!
- set_family_count(org_id_val,
- family.channel_family_id,
- max_members_val);
- 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?
- rhn_channel.update_family_counts(family.channel_family_id,
- org_id_val);
- 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
- 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 repoll_virt_guest_entitlements;
-
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array is
-
- cursor server_groups is
- 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 ents_array;
-
- begin
-
- ent_array := ents_array();
-
- for sg in server_groups loop
- ent_array.extend;
- ent_array(ent_array.count) := sg.label;
- end loop;
-
- return ent_array;
-
- end get_server_entitlement;
-
-
- -- this desperately needs to be table driven.
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- ) is
- type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
- roles_to_process roles_v;
- cursor roles(role_label_in in varchar2) is
- select label, id
- from rhnUserGroupType
- where label = role_label_in;
- cursor org_roles(role_label_in in varchar2) is
- 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;
-
- type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
- ents_to_process ents_v;
- cursor ents(ent_label_in in varchar2) is
- select label, id
- from rhnOrgEntitlementType
- where label = ent_label_in;
- cursor org_ents(ent_label_in in varchar2) is
- 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 := ents_v();
- roles_to_process := roles_v();
- -- 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.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_applicant';
- elsif service_label_in = 'provisioning' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_provisioning';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- -- another nasty special case...
- if enable_in = 'Y' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
- end if;
- elsif service_label_in = 'monitoring' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_monitor';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'monitoring_admin';
- elsif service_label_in = 'virtualization' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'virtualization_platform' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'nonlinux' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- end if;
-
- if enable_in = 'Y' then
- for i in 1..ents_to_process.count 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..roles_to_process.count 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 rhn_user_group_id_seq.nextval,
- 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..ents_to_process.count 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 modify_org_service;
-
- procedure set_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'Y');
- end set_customer_enterprise;
-
- procedure set_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'Y');
- end set_customer_provisioning;
-
- procedure set_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'Y');
- end set_customer_monitoring;
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'Y');
- end set_customer_nonlinux;
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'N');
- end unset_customer_enterprise;
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'N');
- end unset_customer_provisioning;
-
- procedure unset_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'N');
- end unset_customer_monitoring;
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'N');
- end unset_customer_nonlinux;
-
- -- *******************************************************************
- -- PROCEDURE: prune_group
- -- Unsubscribes servers consuming physical slots that over the org's
- -- limit.
- -- Called by: set_group_count, prune_everything, repoll_virt_guest_entitlements
- -- *******************************************************************
- procedure prune_group (
- group_id_in in number,
- type_in in char,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- cursor usergroups is
- 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 (
- select rownum row_number,
- user_id,
- time
- from (
- select user_id,
- modified time
- from rhnUserGroupMembers
- where user_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and ugm.user_group_id = ug.id
- and ug.group_type = ugt.id;
- cursor servergroups is
- select server_id, server_group_id, sgt.id 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 server_id
- from (
- select rownum row_number,
- server_id,
- time
- from (
- select sep.server_id,
- sep.modified time
- from
- rhnServerEntitlementPhysical sep
- where
- sep.server_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
- type_is_base char;
- begin
- if type_in = 'U' then
- update rhnUserGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for ug in usergroups loop
- rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
- end loop;
- elsif type_in = 'S' then
- update rhnServerGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for sg in servergroups loop
- remove_server_entitlement(sg.server_id, sg.label);
-
- select is_base
- into type_is_base
- from rhnServerGroupType sgt
- where sgt.id = sg.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
- rhn_channel.clear_subscriptions(sg.server_id,
- update_family_countsYN => update_family_countsYN);
- end if;
-
- end loop;
- end if;
- end prune_group;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- to_org_prev_ent_count number;
- new_ent_count number;
- new_quantity number;
- group_type number;
- begin
-
- 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;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
-
- rhn_entitlements.set_group_count(from_org_id_in,
- 'S',
- group_type,
- new_ent_count);
-
- 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
- set_customer_enterprise(to_org_id_in);
- else
- unset_customer_enterprise(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'provisioning_entitled' then
- if new_quantity > 0 then
- set_customer_provisioning(to_org_id_in);
- else
- unset_customer_provisioning(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'monitoring_entitled' then
- if new_quantity > 0 then
- set_customer_monitoring(to_org_id_in);
- else
- unset_customer_monitoring(to_org_id_in);
- end if;
- end if;
-
- end assign_system_entitlement;
-
- -- *******************************************************************
- -- 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
- -- *******************************************************************
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- new_ent_count number;
- to_org_prev_ent_count number;
- new_quantity number;
- cfam_id number;
- begin
-
- begin
- select max_members
- into 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;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- rhn_entitlements.set_family_count(from_org_id_in,
- cfam_id,
- new_ent_count);
-
- rhn_entitlements.set_family_count(to_org_id_in,
- cfam_id,
- new_quantity);
-
- end assign_channel_entitlement;
-
- -- *******************************************************************
- -- 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.
- -- *******************************************************************
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- group_type number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- -- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- don't update family counts after every server
- -- will do bulk update afterwards
- rhn_entitlements.set_group_count(org_id_in,
- 'S',
- group_type,
- quantity_in,
- update_family_countsYN => 0);
- -- bulk update family counts
- rhn_channel.update_group_family_counts(group_label_in, org_id_in);
- end if;
-
-
- end activate_system_entitlement;
-
- -- *******************************************************************
- -- 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.
- -- *******************************************************************
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- cfam_id number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- 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;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- -- 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
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- rhn_entitlements.set_family_count(org_id_in,
- cfam_id,
- quantity_in);
- end if;
-
- end activate_channel_entitlement;
-
-
- procedure set_group_count (
- customer_id_in in number,
- type_in in char,
- group_type_in in number,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- group_id number;
- quantity number;
- 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;
-
- rhn_entitlements.prune_group(
- group_id,
- type_in,
- quantity,
- update_family_countsYN
- );
- exception
- when no_data_found then
- if type_in = 'U' then
- insert into rhnUserGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select rhn_user_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- 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 rhn_server_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- from rhnServerGroupType
- where id = group_type_in
- );
- end if;
- end set_group_count;
-
- -- *******************************************************************
- -- PROCEDURE: prune_family
- -- Unsubscribes servers consuming physical slots from the channel family
- -- that are over the org's limit.
- -- Called by: set_family_count, prune_everything
- -- *******************************************************************
- procedure prune_family (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number
- ) is
- cursor serverchannels is
- 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 server_id
- from (
- select server_id,
- time,
- rownum row_number
- from (
- select rs.id server_id,
- rcfm.modified time
- 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
- -- 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 time asc
- )
- )
- where row_number > quantity_in
- );
- begin
- -- if we get a null customer_id, this is completely bogus.
- if customer_id_in is null then
- return;
- end if;
-
- update rhnPrivateChannelFamily
- set max_members = quantity_in
- where 1=1
- and org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- for sc in serverchannels loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
- end loop;
- rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
- end prune_family;
-
- procedure set_family_count (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number
- ) is
- cursor privperms is
- select 1
- from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- cursor pubperms is
- select o.id org_id
- from web_customer o,
- rhnPublicChannelFamily pcf
- where pcf.channel_family_id = channel_family_id_in;
- quantity number;
- done number := 0;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
-
- if customer_id_in is not null then
- for perm in privperms loop
- rhn_entitlements.prune_family(
- customer_id_in,
- channel_family_id_in,
- quantity
- );
- update rhnPrivateChannelFamily
- set max_members = quantity
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily (
- channel_family_id, org_id, max_members, current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity, 0
- );
- return;
- end if;
-
- for perm in pubperms loop
- if quantity = 0 then
- rhn_entitlements.prune_family(
- perm.org_id,
- channel_family_id_in,
- quantity
- );
- 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 set_family_count;
-
- -- 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.
- procedure entitle_last_modified_servers (
- customer_id_in in number,
- type_label_in in varchar2,
- quantity_in in number
- ) is
- -- find the servers that aren't currently in slots
- cursor servers(cid_in in number, quant_in in number) is
- select server_id
- from (
- select rownum row_number,
- server_id
- from (
- select rs.id 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
- )
- )
- where row_number <= quant_in;
- begin
- for server in servers(customer_id_in, quantity_in) loop
- rhn_entitlements.entitle_server(server.server_id, type_label_in);
- end loop;
- end entitle_last_modified_servers;
-
- procedure prune_everything (
- customer_id_in in number
- ) is
- cursor everything is
- -- all our server groups
- select sg.id id,
- 'S' type,
- sg.max_members quantity
- from rhnServerGroup sg
- where sg.org_id = customer_id_in
- union
- -- all our user groups
- select ug.id id,
- 'U' type,
- ug.max_members quantity
- from rhnUserGroup ug
- where ug.org_id = customer_id_in
- union (
- -- all the channel families we have perms to
- select cfp.channel_family_id id,
- 'C' type,
- cfp.max_members quantity
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = customer_id_in
- union
- -- plus all the ones we're using that we have no perms for
- select cfm.channel_family_id id,
- 'C' type,
- 0 quantity
- from rhnChannelFamily cf,
- rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnServer s
- where s.org_id = customer_id_in
- and s.id = sc.server_id
- and sc.channel_id = cfm.channel_id
- and cfm.channel_family_id = cf.id
- and cf.org_id is not null
- and cf.org_id != customer_id_in
- and not exists (
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = customer_id_in
- and cfp.channel_family_id = cfm.channel_family_id
- )
- );
- begin
- for one in everything loop
- if one.type in ('U','S') then
- prune_group(one.id, one.type, one.quantity);
- else
- prune_family(customer_id_in, one.id, one.quantity);
- end if;
- end loop;
- end prune_everything;
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- ) is
- -- find servers without base channels
- cursor servers(cid_in in number) is
- 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 number;
- 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
- rhn_channel.subscribe_server(server.id, channel_id);
- commit;
- -- exception is really channel_family_no_subscriptions
- exception
- when others then
- null;
- end;
- end if;
- end loop;
- end subscribe_newest_servers;
-end rhn_entitlements;
-/
-show errors
-
---
---
--- Revision 1.56 2004/07/21 21:27:36 nhansen
--- bug 128196: use rhn_monitor instead of rhn_monitoring as the rhnOrgEntitlementType
---
--- Revision 1.55 2004/07/20 15:38:57 pjones
--- bugzilla: 128196 -- make entitling "monitoring" work.
---
--- Revision 1.54 2004/07/14 19:13:13 pjones
--- bugzilla: 126461 -- entitlement changes for new user roles
---
--- Revision 1.53 2004/07/02 19:18:20 pjones
--- bugzilla: 125937 -- use rhn_user to remove user roles
---
--- Revision 1.52 2004/05/26 19:45:48 pjones
--- bugzilla: 123639
--- 1) reformat "entitlement_grants_service"
--- 2) make the .pks and .pkb be in the same order.
--- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
--- 4) add monitoring specific data.
---
--- Revision 1.51 2004/04/19 18:18:51 pjones
--- bugzilla: none -- misa's using set_family_count() to set null org entitlements
---
--- Revision 1.50 2004/04/14 00:09:24 pjones
--- bugzilla: 120761 -- split rhnChannelPermissions into two tables, eliminating
--- a frequent full table scan
---
--- Revision 1.49 2004/03/26 16:53:42 pjones
--- bugzilla: none -- make rhn_nonlinux give config_admin too on sat.
---
--- Revision 1.48 2004/03/25 22:29:56 pjones
--- bugzilla: none -- only create config_admin in set_customer_prov if we're
--- on a satellite
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql b/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql
deleted file mode 100644
index 40eafac..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-0.7-to-spacewalk-schema-0.8/051-rhn_entitlements.pks.sql
+++ /dev/null
@@ -1,226 +0,0 @@
---
--- 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 or replace
-package rhn_entitlements
-is
- body_version varchar2(100) := '';
-
- type ents_array is varray(10) of rhnServerGroupType.label%TYPE;
-
- procedure remove_org_entitlements (
- org_id_in number
- );
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2
- )
- return number;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- )
- return number;
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2,
- sgid_out out number
- )
- return boolean;
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- );
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- );
-
- procedure unentitle_server (
- server_id_in in number
- );
-
- procedure repoll_virt_guest_entitlements(
- server_id_in in number
- );
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array;
-
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- );
-
- procedure set_customer_enterprise (
- customer_id_in in number
- );
-
- procedure set_customer_provisioning (
- customer_id_in in number
- );
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- );
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- );
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- );
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- );
-
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- );
-
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- );
-
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- );
-
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number
- );
-
- procedure set_group_count (
- customer_id_in in number, -- customer_id
- type_in in char, -- 'U' or 'S'
- group_type_in in number, -- rhn[User|Server]GroupType.id
- quantity_in in number, -- quantity
- update_family_countsYN in number := 1 -- call update_family_counts inside
- );
-
- procedure set_family_count (
- customer_id_in in number, -- customer_id
- channel_family_id_in in number, -- 246
- quantity_in in number -- 3
- );
-
- -- 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
- procedure entitle_last_modified_servers (
- customer_id_in in number, -- customer_id
- type_label_in in varchar2, -- 'enterprise_entitled'
- quantity_in in number -- 3
- );
-
- procedure prune_everything (
- customer_id_in in number
- );
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- );
-end rhn_entitlements;
-/
-show errors
-
---
--- Revision 1.19 2004/05/26 19:45:48 pjones
--- bugzilla: 123639
--- 1) reformat "entitlement_grants_service"
--- 2) make the .pks and .pkb be in the same order.
--- 3) add "modify_org_service" (to be used instead of set_customer_SERVICELEVEL)
--- 4) add monitoring specific data.
---
--- Revision 1.18 2004/02/19 20:17:49 pjones
--- bugzilla: 115896 -- add sgt and oet data for nonlinux, add
--- [un]set_customer_nonlinux
---
--- Revision 1.17 2004/01/13 23:37:08 pjones
--- bugzilla: none -- mate provisioning and management slots.
---
--- Revision 1.16 2003/09/23 22:14:41 bretm
--- bugzilla: 103655
---
--- need something in the db that knows provisioning boxes are management boxes too, etc.
---
--- Revision 1.15 2003/09/19 22:35:07 pjones
--- bugzilla: none
---
--- provisioning and config management entitlement support
---
--- Revision 1.14 2003/09/02 22:22:54 pjones
--- bugzilla: none
---
--- attempt to autoentitle upon entitlement changes
---
--- Revision 1.13 2003/06/05 21:43:40 pjones
--- bugzilla: none
---
--- add rhn_entitlements.prune_everything(customer_id_in in number);
---
--- Revision 1.12 2003/05/22 16:01:14 pjones
--- reformat
--- remove update_[server|user]group_counts (unused)
---
--- Revision 1.11 2002/06/03 16:07:29 pjones
--- make prune_group and prune_family update respective max_members
--- correctly.
---
--- Revision 1.10 2002/05/29 19:10:31 pjones
--- code to entitle the last N modified servers to a particular service
--- level
---
--- Revision 1.9 2002/05/10 22:08:23 pjones
--- id/log
---
13 years, 9 months
client/tools
by Jan Pazdziora
client/tools/rhn-virtualization/actions/virt.py | 4 ----
1 file changed, 4 deletions(-)
New commits:
commit f7923924f3de47a1caad5f27bb1f3b4bfb68742e
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Feb 19 14:34:07 2010 +0100
Removing usused imports from rhn-virtualization/actions/virt.
diff --git a/client/tools/rhn-virtualization/actions/virt.py b/client/tools/rhn-virtualization/actions/virt.py
index d32b58c..543b9d8 100644
--- a/client/tools/rhn-virtualization/actions/virt.py
+++ b/client/tools/rhn-virtualization/actions/virt.py
@@ -15,11 +15,7 @@
import sys
sys.path.append("/usr/share/rhn/")
-from up2date_client import up2dateAuth
-from up2date_client import up2dateErrors
-from up2date_client import rpcServer
from virtualization import support, errors
-from rhn import rpclib
__rhnexport__ = [
'refresh',
13 years, 9 months