Update Satellite Client Profile (Description, Location, Etc) Via Command Line

Latest response

I've created a script that is ran after a system is installed. This script prompts the admin if the machine needs to be added to the domain, Satellite server, and so on.

I want to be able to prompt the user for a location. For instance "What building and room is this machine located?" When a client is registered with Red Hat Satellite server, it seems to upload its profile (system architecture and all) but with the current location info blank. I'd like to modify this profile in this script to add the location. This configuration would occur after the system has been registered with the local Satellite server.

Unfortunately, I do not know the command or location where I can do this. I've tried editing the /etc/sysconfig/rhn/systemid file and running rhn_check, but this does not seem to work. I've also tried using /usr/sbin/rhn-profile-sync but this doesn't change anything either.

Any thoughts on how to update a Satellite client's profile via command line, mostly for the location field?

Responses

Hi Jonathan,

To set location details to system profile you can use API - system.setDetails

setDetails

string sessionKey
int serverId - ID of server to lookup details for.
struct - server details
    string "profile_name" - System's profile name
    string "base_entitlement" - System's base entitlement label. (enterprise_entitled or sw_mgr_entitled)
    boolean "auto_errata_update" - True if system has auto errata updates enabled
    string "description" - System description
    string "address1" - System's address line 1.
    string "address2" - System's address line 2.
    string "city"
    string "state"
    string "country"
    string "building"
    string "room"
    string "rack"

Either you can use python script or you can use "spacewalk-api" command to call system.setDetails API.

Regards,
Ashish

Ashish,

Could you provide me an example set of code for python using system.setDetails? Unfortunately, I am not familiar with python.

Hi Jonathan,

You can find sample API's on your Red Hat Satellite server by accessing the link below:

https://satellite.example.com/rhn/apidoc/scripts.jsp

Here is the sample python script to execute system.setDetails API :

#!/usr/bin/python

import xmlrpclib
server_url='https://satellite.example.com/rpc/api'
xmlrpclib.Server(server_url)
sc = xmlrpclib.Server(server_url)
sk = sc.auth.login('admin', 'secret')
options = {'profile_name': 'test-system.example.com', 'description': 'Custom Description set via API'}
list = sc.system.setDetails(sk, 1000038967, options)
print list

Here in options you can set available variables listed in my earlier update.

Note: Update server_url, username/password, systemid with appropriate values.

Hope this helps.

Regards,
Ashish

Hi Jonathan,
Do you use kickstart to register your host? (I.e. is it registered via the kickstart profile?). Or... do you use bootstrap.sh?

Either way - If you have not used either method for registration, I would recommend creating a "dummy" kickstart profile (which Satellite will add all the registration bits in the profile) and I would also create a bootstrap file. Even if you end up using neither method, the examples in those two files might shed some light on possible ways to interact with Satellite (in addition to what Ashish has provided).

I use bootstrap.sh myself as I feel it provides the most flexibility in my environment. I, like you, have specific needs to provide options during the bootstrap (config channels based on environment or location). So, I have a few "menu options" that will timeout and register using default values.

Also - I thought rhn-profile-sync was a valid response to your original question ;-) So, I am curious what the right answer(s) is.

James:

I use both the bootstrap file and kickstart. Satellite is new in our environment, so most of our machines are not joined to it. I've modified the bootstrap file to include additional packages, disabling update notifications, adding channels, turning on osad, and others. I intend to use this file to add current systems to Satellite. I've used kickstart to add new systems to the Satellite server.

I've tried modifying the /etc/sysconfig/rhn/systemid file to include building, room, etc. Running rhn-profile-sync doesn't seem to update these new xml values though. Maybe I'm doing it the wrong way. I can't seem to find anything else on how to use this command.

Ashish:

Here is my current python script...

#!/usr/bin/python

import xmlrpclib
import getpass
server_url = 'http://myurl/rpc/api'
xmlrpclib.Server(server_url)
sc = xmlrpclib.Server(server_url)
systemId = ########
options = {'building': input("Building number: "), 'room': input("Room number: "), 'rack': input("Rack number: ")}
uname = raw_input("Enter your Satellite username: ")
pw = getpass.getpass()
sk = sc.auth.login(uname, pw)
list = sc.system.setDetails(sk, systemId, options)
print list

I get the following error...

Error line 16: unhandled internal exception: java.lang.Integer incompatible with java.lang.String

Any ideas? It doesn't seem to like the list = sc.system.setDetails(sk, systemId, options) command. I've also tried using just a number instead of systemId. Same thing. Any suggestions? Thanks for the newbie help :)

Instead of input using raw_input to read room number , building no, rack number solves the issue. :)

#!/usr/bin/python

import xmlrpclib
import getpass
server_url = 'http://myurl/rpc/api'
xmlrpclib.Server(server_url)
sc = xmlrpclib.Server(server_url)
systemId = ########
options = {'building': raw_input("Building number: "), 'room': raw_input("Room number: "), 'rack': raw_input("Rack number: ")}
uname = raw_input("Enter your Satellite username: ")
pw = getpass.getpass()
sk = sc.auth.login(uname, pw)
list = sc.system.setDetails(sk, systemId, options)
print list

James/Jonathan,

We can not change systemid file on system, any changes in the systemid file will create problem for system to authenticate with RHN. The rhn-profile-sync command will update system hostname/IP/Package Profile/hardware details .. etc. Using this we can not set building/room/rack number.

Regards,
Ashish

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.