def execute(self, argv): try: opts, args = getopt.gnu_getopt(argv, 'i:v', [ 'verbose', 'debug', 'help']) except getopt.GetoptError as e: logger.error(e) self.print_help() sys.exit(1) for o, _ in opts: if o == '--debug': logging.getLogger().setLevel(logging.DEBUG) elif o in ('-v', '--verbose'): logging.getLogger().setLevel(logging.INFO) elif o == '--help': self.print_help() sys.exit() else: logger.error('Unknown option: %s', o) self.print_help() sys.exit(1) if len(args) != 1: logger.error('Missing instance ID') self.print_help() sys.exit(1) instance_name = args[0] instance = pki.server.instance.PKIInstance(instance_name) if not instance.is_valid(): logger.error('Invalid instance %s.', instance_name) sys.exit(1) if not instance.is_active(): self.print_message('%s instance already stopped' % instance_name) return instance.load() instance.stop() self.print_message('%s instance stopped' % instance_name)
def print_instance(instance): print(' Instance ID: %s' % instance.name) print(' Active: %s' % instance.is_active())