-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem-groups.py
executable file
·133 lines (124 loc) · 3.21 KB
/
system-groups.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python
import sys
import xmlrpclib
SATELLITE_URL = "http://spacewalk.usa.tribune.com/rpc/api"
SATELLITE_LOGIN = "abelopez"
SATELLITE_PASSWORD =
client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
hostIP = sys.argv[1]
tier = int(sys.argv[2])
# system ID's will be sorted out before hand
# I'm not _that_ smart of a programmer -yet
# lets make a list for each system group, populated with system id's
# will probably need to know channels too
# Function Definitions
def main():
sysID = searchForSystem( hostIP )
if sysID == 0:
client.auth.logout(key)
print '%s is not in spacewalk' % ( hostIP )
sys.exit(2)
#print sysID
chanID, chanLabel, OS = getSystemDetails(sysID)
gid = calcSystemGroup(tier, chanID)
groupName = getGroupName(gid)
print 'system %s will go in group %s' % (hostIP, groupName)
client.systemgroup.addOrRemoveSystems(key,groupName,sysID,True)
client.auth.logout(key)
def searchForSystem(IP):
print 'Looking for %s in spacewalk' % ( IP )
id = 0
sysSearch = client.system.search.ip(key, str(IP) )
#print len(sysSearch)
for system in sysSearch:
if system.get('ip') == IP:
#print 'test'
id = system.get('id')
#print system.get('name')
return id
def getSystemDetails(id):
#sysID = client.system.getId(key, host)
subscription = client.system.getSubscribedBaseChannel(key, id)
details = client.system.getDetails(key, id )
chanID = subscription.get('id')
chanLabel = subscription.get('label')
OS = details.get('release')
#print chanID, chanLabel, OS
return chanID, chanLabel, OS
#### Group ID cheat section
#group id is 29 name is Solaris 10 Tier 1 & 2
#group id is 30 name is CentOS 4 Dev/Test/QA/Tier 3
#group id is 14 name is Solaris 9 Tier 1 & 2
#group id is 28 name is CentOS 5 Dev/Test/QA/Tier 3
#group id is 31 name is CentOS 4 Tier 1 & 2
#group id is 16 name is Solaris 10 Dev/Test/QA/Tier 3
#group id is 13 name is Solaris 9 Dev/Test/QA/Tier 3
#group id is 27 name is CentOS 5 Tier 1 & 2
#
### Channel ID cheat section
#chan id is 103 name is CentOS 5 i386
#chan id is 106 name is Solaris 9 Sparc
#chan id is 104 name is Solaris 10 Intel
#chan id is 121 name is Solaris 10 Sparc
#chan id is 101 name is CentOS 4 x86_64
#chan id is 102 name is CentOS 5 x86_64
#chan id is 112 name is CentOS 4 i386
def calcSystemGroup(tier, chan):
#print "tier is %s " % (str(tier))
if chan == 101:
if tier == 1:
group = 31
elif tier == 2:
group = 31
else:
group = 30
elif chan == 102:
if tier == 1:
group = 27
elif tier == 2:
group = 27
else:
group = 28
elif chan == 103:
if tier == 1:
group = 27
elif tier == 2:
group = 27
else:
group = 28
elif chan == 104:
if tier == 1:
group = 29
elif tier == 2:
group = 29
else:
group = 16
elif chan == 106:
if tier == 1:
group = 14
elif tier == 2:
group = 14
else:
group = 13
elif chan == 112:
if tier == 1:
group = 31
elif tier == 2:
group = 31
else:
group = 30
elif chan == 121:
if tier == 1:
group = 29
elif tier == 2:
group = 29
else:
group = 16
return group
def getGroupName(id):
details = client.systemgroup.getDetails(key, id)
name = details.get('name')
return name
if __name__ == '__main__':
main()