-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventary.py
64 lines (49 loc) · 1.42 KB
/
inventary.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Retorna o levantamento dos hosts cadastrados
no Spaccewalk, na forma de tupla:
'host': 'Oracle Linux Server release x.xx'
Paulo Ferraz - matricula
Uso:
python ./inventary.py Ambiente
['Desenvolvimento', 'Homologacao', 'Producao']
Histórico:
v1.0 - Tue Apr 25 16:57:09 -03 2023
Versão final que retorna uma tupla
podendo ser convertida para string e
importada no DB LSUS, a fim de manter
a sincronia entre os 2 ambientes.
COPYRIGHT: Este programa é GPL.
"""
from authenticate import authenticate
import xmlrpclib
def enum_srv(group):
"""
Inventário periódico de servidores cadastrados
no Spacewalk, relacionados por ambiente.
"""
# Autenticação
login = authenticate()
client = login["cliente"]
session = login["sessao"]
# Variáveis
lista = client.systemgroup.listSystems(session, group)
array = {}
if len(lista) != 0:
for system in lista:
array[
str(system["hostname"]).lower()
] = "Oracle Linux Server release " + str(
system["release"].replace("6Server", "6.10")
)
client.auth.logout(session)
return array
if __name__ == "__main__":
import sys
if len(sys.argv) < 2:
print("Faltou ambiente: 'Desenvolvimento', 'Homologacao', 'Producao'")
sys.exit(1)
else:
print(enum_srv(sys.argv[1]))