-
Notifications
You must be signed in to change notification settings - Fork 2
/
rhn-export-to-csv.py
executable file
·58 lines (50 loc) · 2.2 KB
/
rhn-export-to-csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
#NOTE: this requires pythoon 2.3 minumum
###
# To the extent possible under law, Red Hat, Inc. has dedicated all copyright to this software to the public domain worldwide, pursuant to the CC0 Public Domain Dedication.
# This software is distributed without any warranty. See <http://creativecommons.org/publicdomain/zero/1.0/>.
###
__author__ = "Felix Dewaleyne"
__credits__ = ["Felix Dewaleyne"]
__license__ = "GPL"
__version__ = "0.4"
__maintainer__ = "Felix Dewaleyne"
__email__ = "fdewaley@redhat.com"
__status__ = "prod"
import xmlrpclib, sys, getpass, os
#connection part
client = xmlrpclib.Server("https://xmlrpc.rhn.redhat.com/rpc/api")
sys.stderr.write("enter your RHN login: ")
login = raw_input().strip()
password = getpass.getpass(prompt="enter your RHN Password: ")
sys.stderr.write("\n")
key = client.auth.login(login,password)
#remove the password from memory
del password
#fetch the data
print "Fetching the list of systems and the details for each of your system. This may take some time"
rhn_data={}
for system in client.system.listUserSystems(key):
#gather the details for each system
rhn_data[system['id']] = {'id': system['id'], 'last_checkin': system['last_checkin']}
#add all the data from getDetails to this dictionary
rhn_data[system['id']].update(client.system.getDetails(key,int(system['id'])))
#add all the network details as well
rhn_data[system['id']].update(client.system.getNetwork(key,int(system['id'])))
client.auth.logout(key)
#now write the csv file
print "Writing data to the csv file"
headers=['id' , 'profile_name', 'hostname', 'ip', 'last_checkin', 'base_entitlement', 'description', 'adress1','adress2', 'city', 'state', 'country', 'building', 'room', 'rack']
import csv
csvfile = open('systems_'+login+'.csv', 'wb' )
csv_writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
csv_writer.writerow(headers)
for system in rhn_data.itervalues():
line = []
for value in headers:
line.append(system.get(value))
csv_writer.writerow(line)
del line
del rhn_data
csvfilepath = os.getcwd()+'/'+'systems_'+login+'.csv'
print "\n The list of systems and their details are available in the file:", csvfilepath