-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdelete_system.py
More file actions
executable file
·31 lines (26 loc) · 1.19 KB
/
delete_system.py
File metadata and controls
executable file
·31 lines (26 loc) · 1.19 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
#!/usr/bin/env python3
"""
SUSE Manager / Uyuni API - Delete System
"""
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('--force', action='store_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)
if not args.force:
if input(f"Delete system {args.sid}? (yes/no): ") != 'yes': sys.exit(0)
c.system.deleteSystem(k, args.sid)
print("[+] System deleted.")
c.auth.logout(k)
except Exception as e: print(e)
if __name__ == "__main__": main()