-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_custominfo.py
More file actions
executable file
·50 lines (42 loc) · 2.02 KB
/
update_custominfo.py
File metadata and controls
executable file
·50 lines (42 loc) · 2.02 KB
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
#!/usr/bin/env python3
"""
SUSE Manager / Uyuni API - Update Custom Info
"""
import argparse, xmlrpc.client, ssl, getpass, sys
def main():
p = argparse.ArgumentParser()
p.add_argument('-s', '--server'); p.add_argument('--url'); p.add_argument('-u', '--user', required=True)
p.add_argument('-p', '--password'); p.add_argument('--sid', type=int, required=True)
p.add_argument('--key', required=True); p.add_argument('--value', required=True)
p.add_argument('--verify', action='store_true')
args = p.parse_args()
if args.url: api_url = args.url
elif args.server: api_url = f"https://{args.server}/rpc/api"
else: print("[!] Error: Provide -s/--server or --url"); sys.exit(1)
pwd = args.password or getpass.getpass()
ctx = ssl.create_default_context()
if not args.verify: ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
try:
c = xmlrpc.client.ServerProxy(api_url, context=ctx); k = c.auth.login(args.user, pwd)
print(f"[*] Setting Custom Info for System {args.sid}...")
print(f" Key: {args.key}")
print(f" Value: {args.value}")
payload = {args.key: args.value}
try:
c.system.setCustomValues(k, args.sid, payload)
print("[+] Custom info updated successfully.")
except xmlrpc.client.Fault as f:
if "not defined" in f.faultString:
print(f"[*] Key '{args.key}' does not exist. Creating it now...")
try:
c.system.custominfo.createKey(k, args.key, "Created via API")
print(f"[+] Key '{args.key}' created.")
c.system.setCustomValues(k, args.sid, payload)
print("[+] Custom info updated successfully on retry.")
except Exception as creation_err:
print(f"[!] Failed to create key: {creation_err}")
else:
print(f"[!] API Fault: {f.faultString}")
c.auth.logout(k)
except Exception as e: print(e)
if __name__ == "__main__": main()