Satellite activation key api

Latest response

I have a script to change the channels in an activation key using the satellite api. It looks something similar to this:
clone_channel_details = {
'base_channel_label' : "TEST-rhel-x86_64-server-6-update-4-11192013"
}

client.activationkey.setDetails(key,one_key,clone_channel_details)

This changes the base channel. I can see the children channels but they aren't selected. So I thought the addChildChannels method would "select" the children channels for the activation key, but I get an error when I run this:

client.activationkey.addChildChannels(key,one_key,"TEST-rhel-x86_64-server-optional-6-update-4-11192013")

Here is the error:

Traceback (most recent call last):
File "./update_activation_key.py", line 21, in
client.activationkey.addChildChannels(key,one_key,"TEST-rhel-x86_64-server-optional-6-update-4-11192013")
File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in call
return self.__send(self.__name, args)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
File "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_response
return u.close()
File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault:

Does anyone know why I am getting this error? Am I using the correct method to assign the children channels?

Responses

Hi Joseph - I don't have an answer (I use spacecmd for these types of activities). However - if you are good with python, you could tear apart their code to see how they do what you are trying to do.

I believe the equivalent command would be:

spacecmd activationkey_addchildchannels

This is the code I use whenever I build a new "set" of clones (which basically updates the entire set of activation keys that I have... (WARNING: I'm kind of a diehard bash guy.. python would make light-work of this entire thing, I am sure)

#!/bin/bash

#  1-default-rhel5 / 1-default-rhel6 - DO NOT MESS WITH THOSE

# rhel-x86_64-server-5
#   rhel-x86_64-server-productivity-5
#   rhel-x86_64-server-supplementary-5
#   rhn-tools-rhel-x86_64-server-5

# rhel-x86_64-server-6
#   rhel-x86_64-server-optional-6
#   rhel-x86_64-server-supplementary-6
#   rhn-tools-rhel-x86_64-server-6
SPACECMD="/usr/bin/spacecmd"

echo "# NOTE: This script simply creates the commands for you to cut-and-paste"
# Let's do this...
for ENV in aepa dba sms tms
do 
  for REDHATRELEASE in 5 6
  do 
    DEFAULTBASE=`${SPACECMD} -q activationkey_listbasechannel 1-default-rhel${REDHATRELEASE}`
    echo "${SPACECMD} -q activationkey_create -- -n ${ENV}-${DEFAULTBASE} -d 'Activation Key for ${ENV} on RHEL ${REDHATRELEASE}' -b ${ENV}-${DEFAULTBASE} -e provisioning_entitled"

    # ASSOCIATE A CONFIGURATION CHANNEL TO EACH NEW BASE (without ENV prefix)
    echo "${SPACECMD} -q activationkey_enableconfigdeployment 1-${ENV}-${DEFAULTBASE}"
    echo "${SPACECMD} -q activationkey_addconfigchannels -- -t 1-${ENV}-${DEFAULTBASE} default-rhel${REDHATRELEASE}"
    echo "${SPACECMD} -q activationkey_addconfigchannels -- -b 1-${ENV}-${DEFAULTBASE} default"

    for CHILDCHANNEL in `${SPACECMD} -q activationkey_listchildchannels 1-default-rhel${REDHATRELEASE}` 
    do 
      echo "${SPACECMD} -q activationkey_addchildchannels 1-${ENV}-rhel-x86_64-server-${REDHATRELEASE} ${ENV}-${CHILDCHANNEL}"
    done
    echo 
  done
done
echo "# NOTE: This script simply creates the commands for you to cut-and-paste"

exit 0

So - after I run that script above.. I get the followng output

/usr/bin/spacecmd -q activationkey_create -- -n tms-rhel-x86_64-server-6 -d 'Activation Key for tms on RHEL 6' -b tms-rhel-x86_64-server-6 -e provisioning_entitled
/usr/bin/spacecmd -q activationkey_enableconfigdeployment 1-tms-rhel-x86_64-server-6
/usr/bin/spacecmd -q activationkey_addconfigchannels -- -t 1-tms-rhel-x86_64-server-6 default-rhel6
/usr/bin/spacecmd -q activationkey_addconfigchannels -- -b 1-tms-rhel-x86_64-server-6 default
/usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhel-x86_64-server-optional-6
/usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhel-x86_64-server-supplementary-6
/usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhn-tools-rhel-x86_64-server-6

# NOTE: This script simply creates the commands for you to cut-and-paste

Which I then cut-and-paste in to my terminal...

[root@prhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_create -- -n tms-rhel-x86_64-server-6 -d 'Activation Key for tms on RHEL 6' -b tms-rhel-x86_64-server-6 -e provisioning_entitled
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_enableconfigdeployment 1-tms-rhel-x86_64-server-6
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_addconfigchannels -- -t 1-tms-rhel-x86_64-server-6 default-rhel6
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_addconfigchannels -- -b 1-tms-rhel-x86_64-server-6 default
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhel-x86_64-server-optional-6
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhel-x86_64-server-supplementary-6
[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_addchildchannels 1-tms-rhel-x86_64-server-6 tms-rhn-tools-rhel-x86_64-server-6

Which I can then validate using:

[root@rhnsat01 Cloning]# /usr/bin/spacecmd -q activationkey_listchildchannels 1-tms-rhel-x86_64-server-6
tms-rhel-x86_64-server-optional-6
tms-rhel-x86_64-server-supplementary-6
tms-rhn-tools-rhel-x86_64-server-6

NOTE: I also use this script to configure the config_channels the key is associated with.

What version of Satellite are you running. I am on 5.4, and I can't find the spacecmd executable.

Ugg... I have to apologize (and I am normally very good about remembering to identify this). Currently spacecmd is NOT part of Satellite (although if I recall correctly, I had heard it will become part of the standard package).

At this point you have to manually grab it from EPEL
https://fedorahosted.org/spacewalk/wiki/spacecmd

You can run it from an external machine and connect remotely to your satellite (or multiple satellites). It is actually a very powerful utility to augment the other spacewalk commands.

Again - I'm sorry I did not make that clear before. You will likely appreciate the recommendation though ;-)

Joseph,

It looks like the error message is incomplete. Are you not getting anything after the "raise Fault(**self._stack[0])
xmlrpclib.Fault: "

You should get the reason for the Fault, like below:

xmlrpclib.Fault: :method "__dir__" is not supported'>

Or .. as I just realized, the forum could have eaten it as the error I pasted is incomplete...

xmlrpclib.Fault: <Fault 1: '<type \'exceptions.Exception\'>:method "__dir__" is not supported'>

Can you repaste the error in a Code Block (put ~~~ on lines before and after, or check Formatting Help)?

I'll get back to you shortly. I apparently deleted my script, so I have to grab it from backup.

Close

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