On 01.08.2012 11:24, Jan Pazdziora wrote:

during hackweek here at SUSE, I did a feature for bootstrapping new
machines with Spacewalk/SUSE Manager.
It works so far but I'd like to show it to you and ask if you are
interested in the feature and what you think in general about it.

I introduced the feature here:
http://suse.gansert.net/?p=542

maybe you can tell me what you think about it?

Uwe,

it looks very cool. Do you have a stream of patches for master?

I have attached patches that fit into master.
But actually they are more to show what I did and for discussion maybe.
The schema-upgrade for example is still missing because I don't know yet in which version that patch will end.

The patches are not too big but I'll explain what I did:

* inventing a new base entitlement called bootstrap_entitled that has the provisioning feature

* the changes in the Web UI are only for adding some ACLs that check this new entitlement and turn off some web-ui features like the "Software"-tab

* inventing a new architecture "bootstrap-linux" that automatically gets the new entitlement during registration.

* patching the registration process on the server to accept registration without user/pass or reg-key when "bootstrap-linux" is registering. Only org_id is needed then.

I did not change that database with new tables or columns. Just some data is inserted for the new architecture and entitlement.

the system_reg_final.py client is the registration client on the image.
It's called final but it's still a development version.
Important data during registration is the org_id (default is 1) and the address of the spacewalk server (default is IPAPPEND parameter) There are still some hardcoded values in there but those will be no problem an can be changed.

If you find the time to look at it, that would be great. I hope inventing a new entitlement was a good way for that but thanks to the ACLs, the changes in the webfrontend are quite minimal because of that.

Like I said, it's a prototype and maybe not the cleanest code but I hope you get an impression on how the feature should work from my point of view.


--
ciao, Uwe Gansert

SUSE LINUX Products GmbH, HRB 16746 (AG Nürnberg)
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
Home: http://www.suse.de/~ug - Blog: http://suse.gansert.net
listening to: "Control" by mind.in.a.box


>From 7a169ddb233b6db2915e3cb6db806077feb97e96 Mon Sep 17 00:00:00 2001
From: Uwe Gansert <u...@suse.de>
Date: Tue, 3 Apr 2012 13:05:09 +0200
Subject: [PATCH 1/5] bottstrap image patches

---
 backend/server/rhnServer/server_class.py           |    2 +-
 java/code/webapp/WEB-INF/nav/system_detail.xml     |    2 +-
 schema/spacewalk/common/data/rhnServerArch.sql     |    3 +++
 .../spacewalk/common/data/rhnServerGroupType.sql   |    8 ++++++++
 .../common/data/rhnServerGroupTypeFeature.sql      |    5 +++++
 .../common/data/rhnServerServerGroupArchCompat.sql |    7 +++++++
 .../spacewalk/oracle/packages/rhn_entitlements.pkb |    5 ++++-
 schema/spacewalk/oracle/packages/rhn_server.pkb    |    4 +++-
 8 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/backend/server/rhnServer/server_class.py b/backend/server/rhnServer/server_class.py
index 15238e0..ea0553a 100644
--- a/backend/server/rhnServer/server_class.py
+++ b/backend/server/rhnServer/server_class.py
@@ -395,7 +395,7 @@ class Server(ServerWrapper):
         # misa: as of 2005-05-27 nonlinux does not get a special treatment
         # anymore (this is in connection to feature 145440 - entitlement model
         # changes
-        entitlement_hierarchy = ['enterprise_entitled', 'sw_mgr_entitled']
+        entitlement_hierarchy = ['enterprise_entitled', 'sw_mgr_entitled', 'bootstrap_entitled']
 
         any_base_entitlements = 0
         
diff --git a/java/code/webapp/WEB-INF/nav/system_detail.xml b/java/code/webapp/WEB-INF/nav/system_detail.xml
index 4b314ec..fa395da 100644
--- a/java/code/webapp/WEB-INF/nav/system_detail.xml
+++ b/java/code/webapp/WEB-INF/nav/system_detail.xml
@@ -26,7 +26,7 @@
     </rhn-tab>
   </rhn-tab>
 
-  <rhn-tab name="Software" url="/rhn/systems/details/packages/Packages.do">
+  <rhn-tab name="Software" acl="not system_has_bootstrap_entitlement()"  url="/rhn/systems/details/packages/Packages.do">
 
     <rhn-tab name="Errata" acl="system_feature(ftr_errata_updates); not is_solaris()">
       <rhn-tab-url>/rhn/systems/details/ErrataList.do</rhn-tab-url>
diff --git a/schema/spacewalk/common/data/rhnServerArch.sql b/schema/spacewalk/common/data/rhnServerArch.sql
index 23a91be..f25dd14 100644
--- a/schema/spacewalk/common/data/rhnServerArch.sql
+++ b/schema/spacewalk/common/data/rhnServerArch.sql
@@ -121,6 +121,9 @@ insert into rhnServerArch (id, label, name, arch_type_id) values
 insert into rhnServerArch (id, label, name, arch_type_id) values
 (sequence_nextval('rhn_server_arch_id_seq'), 'mips-debian-linux', 'mips Debian', lookup_arch_type('deb'));
 
+insert into rhnServerArch (id, label, name, arch_type_id) values
+(sequence_nextval('rhn_server_arch_id_seq'), 'bootstrap-linux', 'Bootstrap Linux', lookup_arch_type('rpm'));
+
 commit;
 
 --
diff --git a/schema/spacewalk/common/data/rhnServerGroupType.sql b/schema/spacewalk/common/data/rhnServerGroupType.sql
index d6f18d1..6b10877 100644
--- a/schema/spacewalk/common/data/rhnServerGroupType.sql
+++ b/schema/spacewalk/common/data/rhnServerGroupType.sql
@@ -73,6 +73,14 @@ insert into rhnServerGroupType ( id, label, name, permanent, is_base)
    );      
 
 
+--  bootstrap_entitled type ----------------------------------------------------
+
+insert into rhnServerGroupType ( id, label, name, permanent, is_base)
+   values ( sequence_nextval('rhn_servergroup_type_seq'),
+      'bootstrap_entitled', 'Bootstrap Entitled Servers',
+      'N', 'Y'
+   );
+
 commit;
 
 --
diff --git a/schema/spacewalk/common/data/rhnServerGroupTypeFeature.sql b/schema/spacewalk/common/data/rhnServerGroupTypeFeature.sql
index 3b81404..e9b4ec2 100644
--- a/schema/spacewalk/common/data/rhnServerGroupTypeFeature.sql
+++ b/schema/spacewalk/common/data/rhnServerGroupTypeFeature.sql
@@ -146,3 +146,8 @@ insert into rhnServerGroupTypeFeature (server_group_type_id, feature_id,
 values (lookup_sg_type('monitoring_entitled'), lookup_feature_type('ftr_probes'),
         current_timestamp,current_timestamp);
 
+insert into rhnServerGroupTypeFeature (server_group_type_id, feature_id,
+                                       created, modified)
+values (lookup_sg_type('bootstrap_entitled'), lookup_feature_type('ftr_kickstart'),
+        current_timestamp,current_timestamp);
+
diff --git a/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql b/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql
index 0132cdb..b699f67 100644
--- a/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql
+++ b/schema/spacewalk/common/data/rhnServerServerGroupArchCompat.sql
@@ -726,6 +726,13 @@ insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type)
     values (lookup_server_arch('x86_64-redhat-linux'),
             lookup_sg_type('virtualization_host_platform'));
 
+insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type)
+    values (lookup_server_arch('bootstrap-linux'),
+            lookup_sg_type('bootstrap_entitled'));
+
+insert into rhnServerServerGroupArchCompat ( server_arch_id, server_group_type)
+    values (lookup_server_arch('bootstrap-linux'),
+            lookup_sg_type('provisioning_entitled'));
 commit;
 
 --
diff --git a/schema/spacewalk/oracle/packages/rhn_entitlements.pkb b/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
index 6594837..403cd2c 100644
--- a/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
@@ -337,6 +337,7 @@ is
                      'added system entitlement ',
                       case type_label_in
                        when 'enterprise_entitled' then 'Management'
+                       when 'bootstrap_entitled' then 'Bootstrap'
                        when 'sw_mgr_entitled' then 'Update'
                        when 'provisioning_entitled' then 'Provisioning'
                        when 'monitoring_entitled' then 'Monitoring'  
@@ -404,6 +405,7 @@ is
                   'removed system entitlement ',
                    case type_label_in
                     when 'enterprise_entitled' then 'Management'
+                    when 'bootstrap_entitled' then 'Bootstrap'
                     when 'sw_mgr_entitled' then 'Update'
                     when 'provisioning_entitled' then 'Provisioning'
                     when 'monitoring_entitled' then 'Monitoring'
@@ -469,6 +471,7 @@ is
                   'removed system entitlement ',
                    case servergroup.label
                     when 'enterprise_entitled' then 'Management'
+                    when 'bootstrap_entitled' then 'Bootstrap'
                     when 'sw_mgr_entitled' then 'Update'
                     when 'provisioning_entitled' then 'Provisioning'
                     when 'monitoring_entitled' then 'Monitoring'
@@ -753,7 +756,7 @@ is
                 and sg.id = sgm.server_group_id
                 and sgt.id = sg.group_type
                 and sgt.label in (
-                    'sw_mgr_entitled','enterprise_entitled',
+                    'sw_mgr_entitled','enterprise_entitled', 'bootstrap_entitled',
                     'provisioning_entitled', 'nonlinux_entitled',
                     'monitoring_entitled', 'virtualization_host',
                                         'virtualization_host_platform'
diff --git a/schema/spacewalk/oracle/packages/rhn_server.pkb b/schema/spacewalk/oracle/packages/rhn_server.pkb
index 66ad3ce..b9e3c5d 100644
--- a/schema/spacewalk/oracle/packages/rhn_server.pkb
+++ b/schema/spacewalk/oracle/packages/rhn_server.pkb
@@ -510,6 +510,7 @@ is
 		-- the naive easy path that gets hit most often and has to be quickest.
 		if group_label in ('sw_mgr_entitled',
                            'enterprise_entitled',
+                           'bootstrap_entitled',
                            'monitoring_entitled',
                            'provisioning_entitled',
                            'virtualization_host',
@@ -640,7 +641,8 @@ is
 		where	sgt.id = group_type;
 
 		if label in ('sw_mgr_entitled',
-                     'enterprise_entitled', 
+                     'enterprise_entitled',
+                     'bootstrap_entitled',
                      'provisioning_entitled', 
                      'monitoring_entitled',
                      'virtualization_host',
-- 
1.7.7

>From 4ddfd9e0553e4418d5faac8364364fbc1df4feeb Mon Sep 17 00:00:00 2001
From: Uwe Gansert <u...@suse.de>
Date: Tue, 24 Jul 2012 15:09:27 +0200
Subject: [PATCH 2/5] translation for bootstrap_entitled added

---
 .../strings/database/StringResource_en_US.xml      |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/frontend/strings/database/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/database/StringResource_en_US.xml
index 019fca4..903a57b 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/database/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/database/StringResource_en_US.xml
@@ -79,6 +79,9 @@ http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd";
 		    <context context-type="sourcefile">/rhn/systems/SystemEntitlements.do</context>
 		    <context context-type="sourcefile">/rhn/systems/details/Overview.do</context>
 		</context-group>
+		<trans-unit id="bootstrap_entitled">
+			<source>Image Bootstrap</source>
+		</trans-unit>
 		<trans-unit id="enterprise_entitled">
 			<source>Management</source>
 		</trans-unit>
-- 
1.7.7

>From 957ad33b99e234ec880adf162ce90a589f4b883f Mon Sep 17 00:00:00 2001
From: Uwe Gansert <u...@suse.de>
Date: Thu, 26 Jul 2012 16:38:41 +0200
Subject: [PATCH 3/5] more implementation of bootstrap image registration

---
 backend/server/handlers/xmlrpc/registration.py     |   56 ++++++++++++++++++--
 backend/server/rhnServer/server_certificate.py     |    4 ++
 backend/server/rhnServer/server_class.py           |    6 ++-
 client/rhel/rhn-client-tools/rhn-client-tools.spec |    1 +
 client/rhel/rhn-client-tools/src/bin/Makefile      |    1 +
 java/code/webapp/WEB-INF/nav/system_detail.xml     |    6 +-
 6 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/backend/server/handlers/xmlrpc/registration.py b/backend/server/handlers/xmlrpc/registration.py
index 84dda3e..f06445b 100644
--- a/backend/server/handlers/xmlrpc/registration.py
+++ b/backend/server/handlers/xmlrpc/registration.py
@@ -185,7 +185,8 @@ class Registration(rhnHandler):
             raise rhnFault(21, _("Required data missing"))
         # we require either a username and a password or a token
         if not hash_validate(data, "username", "password") and \
-           not hash_validate(data, "token"):
+           not hash_validate(data, "token") and \
+           not hash_validate(data, "org_id"):
             raise rhnFault(21, _("Required members missing"))
 
     def validate_system_user(self, username, password):
@@ -228,8 +229,11 @@ class Registration(rhnHandler):
         # log entry point
         if data.has_key("token"):
             log_item = "token = '%s'" % data["token"]
-        else:
+        elif data.has_key("user"):
             log_item = "username = '%s'" % user.username
+        else:
+            # bootstrap image case. We only have org_id
+            log_item = "orga = '%s'" % data["org_id"]
 
         log_debug(1, log_item, release_version, architecture)
         
@@ -256,12 +260,15 @@ class Registration(rhnHandler):
             # Look the token up; if the token does not exist or is invalid,
             # stop right here (search_token raises the appropriate rhnFault)
             tokens_obj = rhnServer.search_token(token_string)
-        else:
+        elif user != None:
             # user should not be null here
             tokens_obj = rhnServer.search_org_token(user.contact["org_id"])
             log_debug(3,"universal_registration_token set as %s" %
                         str(tokens_obj.get_tokens()))
             rhnFlags.set("universal_registration_token", tokens_obj)
+        else:
+            # bootstrap image
+            tokens_obj = rhnServer.search_org_token(data["org_id"])
 
         if data.has_key('channel') and len(data['channel']) > 0:
             channel = data['channel']
@@ -305,6 +312,8 @@ class Registration(rhnHandler):
         newserv.server["release"] = release
         if data.has_key('release_name'):
             newserv.server["os"] = data['release_name']
+        if data.has_key("org_id"):
+            newserv.server["org_id"] = data["org_id"]
 
         ## add the package list
         if data.has_key('packages'):
@@ -477,7 +486,7 @@ class Registration(rhnHandler):
         # Authorize username and password, if used. 
         # Store the user object in user.
         user = None
-        if not data.has_key('token'):
+        if not data.has_key('token') and data.has_key('user'):
             user = self.validate_system_user(data["username"],
                                              data["password"])
 
@@ -485,6 +494,8 @@ class Registration(rhnHandler):
         profile_name = data['profile_name']
         architecture = data['architecture']
 
+        self.delete_bootstrap_system(data)
+
         # Create the system and get back the rhnServer object.
         #
         # bretm 02/19/2007 -- the following things get thrown underneath,
@@ -506,6 +517,43 @@ class Registration(rhnHandler):
         # Return the server certificate file down to the client.
         return system_certificate
 
+    def delete_bootstrap_system(self, data):
+        sql = """
+        select SERVER_ID, HW_ADDR from RHNSERVERNETINTERFACE
+        where NAME != 'lo' AND SERVER_ID IN
+        (SELECT ID from RHNSERVER
+        where OS = 'bootstrap-image')
+        """
+        h = rhnSQL.prepare(sql)
+        h.execute()
+        result = h.fetchall_dict()
+        if not result:
+            return 0
+
+        bootstrapped_nic_list = []
+        for hwp in data["hardware_profile"]:
+            # check all NICs of the new server
+            if hwp["class"] == "NETINTERFACES":
+                # {'lo': {'hwaddr': '00:00:00:00:00:00', ..., 'module': 'loopback'}, 
+                #  'class': 'NETINTERFACES', 
+                #  'eth0': {'hwaddr': '52:54:00:30:0c:c9',..., 'module': 'e1000'}
+                for nic_name in hwp:
+                    if nic_name != "class" and nic_name != "lo":
+                        bootstrapped_nic_list.append( hwp[nic_name]["hwaddr"] )
+
+        for server in result:
+            # all registered bootstrap images
+            smac = server["hw_addr"]
+            sid  = server["server_id"]
+            if bootstrapped_nic_list.count( smac ) > 0:
+                # delete server with sid
+                delete_server = rhnSQL.Procedure("delete_server")
+                try:
+                    delete_server(sid)
+                except rhnSQL.SQLError:
+                    log_error("Error deleting server: %s" % sid)
+        return 0
+
     def new_system_user_pass(self, profile_name, os_release_name,
                              version, arch, username,
                              password, other):
diff --git a/backend/server/rhnServer/server_certificate.py b/backend/server/rhnServer/server_certificate.py
index 0573659..099e928 100644
--- a/backend/server/rhnServer/server_certificate.py
+++ b/backend/server/rhnServer/server_certificate.py
@@ -110,6 +110,10 @@ class Certificate:
         dump = self.attrs
         dump["checksum"] = self.__checksum
         dump["fields"] = self.__fields
+        if dump["username"] == None:
+            # in the case of bootstrap image, we'll have no username
+            # FIXME: I don't think we need a cert at all. Maybe skip this code
+            dump["username"] = ""
         try:
             x = xmlrpclib.dumps((dump,))
         except TypeError, e:
diff --git a/backend/server/rhnServer/server_class.py b/backend/server/rhnServer/server_class.py
index ea0553a..5c2673f 100644
--- a/backend/server/rhnServer/server_class.py
+++ b/backend/server/rhnServer/server_class.py
@@ -550,8 +550,10 @@ class Server(ServerWrapper):
                 # If a new server that was registered by an user (i.e. not
                 # with a registration token), look for this user's default 
                 # groups
-                self.join_groups()
-            
+                # we don't have a user, so no default groups for bootstrap image
+                if self.server["os"] != "bootstrap-image":
+                    self.join_groups()
+
             server_lib.join_rhn(org_id)
         # Update the uuid - but don't commit yet
         self.update_uuid(self.uuid, commit=0)
diff --git a/client/rhel/rhn-client-tools/rhn-client-tools.spec b/client/rhel/rhn-client-tools/rhn-client-tools.spec
index 2539589..0084f31 100644
--- a/client/rhel/rhn-client-tools/rhn-client-tools.spec
+++ b/client/rhel/rhn-client-tools/rhn-client-tools.spec
@@ -271,6 +271,7 @@ make -f Makefile.rhn-client-tools test
 %{_sbindir}/rhnreg_ks
 %{_sbindir}/spacewalk-channel
 %{_sbindir}/rhn-channel
+%{_sbindir}/bootstrap_register
 
 %{_datadir}/rhn/up2date_client/rhnreg.*
 %{_datadir}/rhn/up2date_client/yumPlugin.*
diff --git a/client/rhel/rhn-client-tools/src/bin/Makefile b/client/rhel/rhn-client-tools/src/bin/Makefile
index 7a1e73e..09c173c 100644
--- a/client/rhel/rhn-client-tools/src/bin/Makefile
+++ b/client/rhel/rhn-client-tools/src/bin/Makefile
@@ -29,6 +29,7 @@ install:: all $(DIRS)
 	$(INSTALL_BIN) rhn-profile-sync.py $(SBIN_DIR)/rhn-profile-sync
 	$(INSTALL_BIN) rhn_check.py $(SBIN_DIR)/rhn_check
 	$(INSTALL_BIN) spacewalk-channel.py $(SBIN_DIR)/spacewalk-channel
+	$(INSTALL_BIN) bootstrap_register.py $(SBIN_DIR)/bootstrap_register
 
 	ln -sf consolehelper $(BIN_DIR)/rhn_register
 	ln -s spacewalk-channel $(SBIN_DIR)/rhn-channel
diff --git a/java/code/webapp/WEB-INF/nav/system_detail.xml b/java/code/webapp/WEB-INF/nav/system_detail.xml
index fa395da..0753d42 100644
--- a/java/code/webapp/WEB-INF/nav/system_detail.xml
+++ b/java/code/webapp/WEB-INF/nav/system_detail.xml
@@ -3,7 +3,7 @@
     acl_mixins="com.redhat.rhn.common.security.acl.SystemAclHandler,com.redhat.rhn.common.security.acl.MonitoringAclHandler">
   <rhn-tab name="Details" url="/rhn/systems/details/Overview.do">
     <rhn-tab name="Overview" url="/rhn/systems/details/Overview.do" />
-    <rhn-tab name="Properties" url="/rhn/systems/details/Edit.do" />
+    <rhn-tab name="Properties" acl="not system_has_bootstrap_entitlement()" url="/rhn/systems/details/Edit.do" />
     <rhn-tab name="Remote Command" acl="system_feature(ftr_remote_command)">
       <rhn-tab-url>/network/systems/details/remote_commands.pxt</rhn-tab-url>
     </rhn-tab>
@@ -181,7 +181,7 @@
     <rhn-tab name="Images" url="/rhn/systems/details/virtualization/Images.do"/>
   </rhn-tab>
 
-  <rhn-tab name="Audit">
+  <rhn-tab name="Audit" acl="not system_has_bootstrap_entitlement()">
     <rhn-tab-url>/rhn/systems/details/audit/ListScap.do</rhn-tab-url>
     <rhn-tab name="nav.system.audit.list_scans">
       <rhn-tab-url>/rhn/systems/details/audit/ListScap.do</rhn-tab-url>
@@ -193,7 +193,7 @@
     </rhn-tab>
   </rhn-tab>
 
-  <rhn-tab name="Events">
+  <rhn-tab name="Events" acl="not system_has_bootstrap_entitlement()">
     <rhn-tab-url>/network/systems/details/history/pending.pxt</rhn-tab-url>
     <rhn-tab name="Pending">
       <rhn-tab-url>/network/systems/details/history/pending.pxt</rhn-tab-url>
-- 
1.7.7

>From aac606bd8fc710cfb98ce5fcd29a1334cae6aac4 Mon Sep 17 00:00:00 2001
From: Uwe Gansert <u...@suse.de>
Date: Fri, 27 Jul 2012 12:47:27 +0200
Subject: [PATCH 4/5] reduce number of options in system overview for
 bootstrap systems

---
 .../webapp/WEB-INF/pages/systems/sdc/overview.jsp  |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp b/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
index 123bddf..79026f7 100644
--- a/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
+++ b/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
@@ -10,6 +10,7 @@
     <h2><bean:message key="sdc.details.overview.systemstatus"/></h2>
 
       <div class="systeminfo">
+    <rhn:require acl="not system_has_bootstrap_entitlement();">
       <div class="systeminfo-full">
 
       <c:choose>
@@ -61,6 +62,7 @@
           </div>
         </div>
       </c:if>
+    </rhn:require>
 
       <div class="systeminfo-clear" />
       </div>
@@ -345,6 +347,7 @@
       </tr>
     </table>
   </div>
+  <rhn:require acl="not system_has_bootstrap_entitlement();">
   <div style="width: 45%; float: left;">
     <h2><bean:message key="sdc.details.overview.crashes.application"/></h2>
     <table class="details">
@@ -389,5 +392,6 @@
     </ul>
     </c:if>
   </div>
+  </rhn:require>
 </body>
 </html:html>
-- 
1.7.7

>From aeeb880e5c3e4a380625c26ed230b4b07a8f22df Mon Sep 17 00:00:00 2001
From: Uwe Gansert <u...@suse.de>
Date: Fri, 27 Jul 2012 15:30:19 +0200
Subject: [PATCH 5/5] reduce number of options when kickstarting a bootstrap
 systems

---
 .../fragments/kickstart/schedule/ks-wizard.jspf    |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/ks-wizard.jspf b/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/ks-wizard.jspf
index a38f61f..5e31a30 100644
--- a/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/ks-wizard.jspf
+++ b/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/ks-wizard.jspf
@@ -35,7 +35,9 @@
 		<%@ include file="/WEB-INF/pages/common/fragments/kickstart/schedule/proxy-options.jspf" %>
 
         <c:if test="${requestScope.hasProfiles == 'true'}">
+          <rhn:require acl="not system_has_bootstrap_entitlement();">
 		<%@ include file="/WEB-INF/pages/common/fragments/kickstart/schedule/schedule-options.jspf" %>
+          </rhn:require>
           <table width="100%">
             <tr>
               <td align="right">
@@ -45,7 +47,9 @@
 			onclick="setStep('fourth');this.form.submit();" />
 			  </c:if>
                 <input type="button" value="<bean:message key="kickstart.schedule.button1.jsp" />" onclick="setStep('second');this.form.submit();" />
+                <rhn:require acl="not system_has_bootstrap_entitlement();">
                 <input type="button" value="<bean:message key="kickstart.schedule.button2.jsp" />" onclick="setStep('third');this.form.submit();" />
+                </rhn:require>
               </td>
             </tr>
           </table>
-- 
1.7.7

#!/usr/bin/python
import xmlrpclib
import fcntl
import re
import sys
sys.path.append("/usr/share/rhn/")
from up2date_client import config, rpcServer
from optparse import OptionParser

from up2date_client import hardware
from up2date_client import rhnserver
from suseRegister.info import getProductProfile;

SERVER_HOST=None
ORG_ID=None

parser = OptionParser(version="%prog 0.1",
                      description="Register a bootstrap boot image to SUSE Manager")
parser.add_option("-s", "--server", action="store", dest="server",
                  help="IP or hostname of the server")
parser.add_option("-o", "--org_id", action="store", dest="org_id",
                  help="the org id you want to register the server under")
(options, args) = parser.parse_args()

if options.server:
    SERVER_HOST = options.server
elif options.org_id:
    ORG_ID = options.org_id

def getPXEIP():
    # set "IPAPPEND 2" in pxe config
    # ip=10.10.2.199:10.10.0.162:10.10.0.8:255.255.0.0
    #       my IP      TFTP IP    Gateway    Netmask
    #
    m = re.search( 'ip=([0-9.:]+)', cmdline )
    pxeIP = ""
    if m != None:
        pxeIP = m.group(1)
    pxeIPParts = pxeIP.split(':')
    return pxeIPParts

cmdline = open('/proc/cmdline').read()
pxeIPParts = getPXEIP()

def getOrgID():
    m = re.search( 'orgid=([0-9]+)', cmdline )
    orgid = "1"
    if m != None:
        orgid = m.group(1)
    return orgid

def getManagerAddress():
    m = re.search( 'susemanager=([a-zA-Z0-9.-]+)', cmdline )
    sm = None
    if m != None:
        sm = m.group(1)
    else:
        # tftp server ip address
        sm = pxeIPParts[1]
    return sm


if SERVER_HOST == None:
    SERVER_HOST = getManagerAddress()
SERVER_URL = "http://%s/XMLRPC"; % SERVER_HOST

if ORG_ID == None:
    ORG_ID = getOrgID()

cfg = config.initUp2dateConfig()
cfg['serverURL'] = SERVER_URL

hw_data = []

for hw in hardware.Hardware():
    if hw.has_key("class") and ( hw["class"] in [ "DMI", "CPU", "MEMORY", "NETINTERFACES", "NETINFO" ] ):
        hw_data.append( hw )

# 'token', 'username + password' or org_id (for bootstrap)
data = { "profile_name"     : "vbox-ug-test",
         "os_release"       : "11.1",
         "release_name"     : "bootstrap-image",
         "architecture"     : "i586-bootstrap-linux",
         "org_id"           : ORG_ID,
         "suse_products"    : getProductProfile(),
         "hardware_profile" : hw_data }


s = rhnserver.RhnServer()
sid = s.registration.new_system (data)

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to