#!/usr/bin/python3 # Style Guide: https://www.python.org/dev/peps/pep-0008/ import argparse import libvirt import sys parser = argparse.ArgumentParser() parser.add_argument("selection", type=str, choices=["is-active"]) parser.add_argument("domain", type=str) args = parser.parse_args() def is_active(dom): conn = libvirt.openReadOnly(None) if conn == None: print('Failed to open connection to the hypervisor') sys.exit(1) dom = conn.lookupByName(args.domain) return dom.isActive() if args.selection == 'is-active': if is_active(args.domain): sys.exit(0) else: sys.exit(1)