Spacewalk 1.5

Trying to determine the best method of determining if a file was deployed to a client, from the command, while on the client. For instance, Currently I do a lookupFileInfo, calculate a local md5sum, compare that to the SW md5sum and report. This does not really say its been deployed though and only that it is the same. Thought I saw the later in the gui but cant seem to find it.

Is there some record such as a system+file pair showing it was indeed deployed available via the api?

Also I think I might have run into a bug but its more likely my misunderstanding. If I query a file that is "locally managed" lookupFileInfo returns one entry in the array. If I look up any file in any channel (not sandbox) I get 2 entries in the array that are duplicates. It doesnt matter in what order or what files, systems or channels etc. If its local, one entry. If its another channel, two entries. Also note that the double entries are for the same channel.

Code and a test output follows:

#!/usr/bin/python

import xmlrpclib
import getpass
import sys
import hashlib
from socket import gethostname

def md5sum(filename):
m = hashlib.md5()
try:
fin0 = open(filename,"rb")
except IOError:
print "Unable to open the file:", filename
return
file_content = fin0.readlines()
fin0.close()
for line in file_content:
m.update(line)
return m.hexdigest()

file_list = list(sys.argv[1:len(sys.argv)])
SATELLITE_URL = "https://spacewalk/rpc/api";
SATELLITE_LOGIN = "Administrator"
SATELLITE_PASSWORD = getpass.getpass(prompt='Password: ')
client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)

hostname = gethostname()
hosts = client.system.getId(key,hostname)
if len(hosts) > 1:
print "ERROR: Multiple profiles!"
print "There appear to be multiple profiles for this hostname."
print "Please correct this and reissue command."
exit

host_id = hosts[0].get('id')

file_info = client.system.config.lookupFileInfo(key,host_id,file_list,1)
for file in file_info:
print file.get('path')

print " Hostname : ", hostname
for file in file_info:
path = file.get('path')
localhost_md5sum = md5sum(path)
server_md5sum = file.get('md5')
print " File : ", path
print " Channel : ", file.get('channel')
print "Localhost MD5 : ", localhost_md5sum
print " Server MD5 : ", server_md5sum
if localhost_md5sum == server_md5sum:
print " Managed : Yes"
else:
print " Managed : No"

client.auth.logout(key)

==========================================

root@leonov:~/bin/spacewalk-scripts/dev# ./is_file_managed.py /etc/cron.d/spacewalk_rhncheck /etc/cron.d/spacewalk_archive_actions /etc/resolv.conf
Password:
/etc/cron.d/spacewalk_rhncheck
/etc/cron.d/spacewalk_rhncheck
/etc/cron.d/spacewalk_archive_actions
/etc/resolv.conf
/etc/resolv.conf
     Hostname :  leonov
         File :  /etc/cron.d/spacewalk_rhncheck
      Channel :  Global RHEL
Localhost MD5 :  195545c0101e94851adc5d95899a951b
   Server MD5 :  195545c0101e94851adc5d95899a951b
      Managed :  Yes
         File :  /etc/cron.d/spacewalk_rhncheck
      Channel :  Global RHEL
Localhost MD5 :  195545c0101e94851adc5d95899a951b
   Server MD5 :  195545c0101e94851adc5d95899a951b
      Managed :  Yes
         File :  /etc/cron.d/spacewalk_archive_actions
      Channel :  leonov
Localhost MD5 :  a49367ea0a2a330a6f76317055de4eca
   Server MD5 :  a49367ea0a2a330a6f76317055de4eca
      Managed :  Yes
         File :  /etc/resolv.conf
      Channel :  Global RHEL
Localhost MD5 :  08a44dc564fc565184f5705736ba0b77
   Server MD5 :  08a44dc564fc565184f5705736ba0b77
      Managed :  Yes
         File :  /etc/resolv.conf
      Channel :  Global RHEL
Localhost MD5 :  08a44dc564fc565184f5705736ba0b77
   Server MD5 :  08a44dc564fc565184f5705736ba0b77
      Managed :  Yes


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

Reply via email to