Check for beta in scripts/cdist.
This commit is contained in:
parent
1c07b63f1d
commit
fdf6a6570c
3 changed files with 36 additions and 18 deletions
|
@ -56,6 +56,20 @@ class UnresolvableRequirementsError(cdist.Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CdistBetaRequired(cdist.Error):
|
||||||
|
"""Beta functionality is used but beta is not enabled"""
|
||||||
|
|
||||||
|
def __init__(self, command, arg):
|
||||||
|
self.command = command
|
||||||
|
self.arg = arg
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
err_msg = ("\'{}\' argument of \'{}\' command is beta, but beta is "
|
||||||
|
"not enabled. If you want to use it please enable beta "
|
||||||
|
"functionalities.")
|
||||||
|
return err_msg.format(self.arg, self.command)
|
||||||
|
|
||||||
|
|
||||||
class CdistObjectError(Error):
|
class CdistObjectError(Error):
|
||||||
"""Something went wrong with an object"""
|
"""Something went wrong with an object"""
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,6 @@ def inspect_ssh_mux_opts():
|
||||||
class Config(object):
|
class Config(object):
|
||||||
"""Cdist main class to hold arbitrary data"""
|
"""Cdist main class to hold arbitrary data"""
|
||||||
|
|
||||||
BETA_ARGS = ['jobs']
|
|
||||||
|
|
||||||
def __init__(self, local, remote, dry_run=False, jobs=None):
|
def __init__(self, local, remote, dry_run=False, jobs=None):
|
||||||
|
|
||||||
self.local = local
|
self.local = local
|
||||||
|
@ -111,19 +109,6 @@ class Config(object):
|
||||||
for host in source:
|
for host in source:
|
||||||
yield host
|
yield host
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _check_beta(cls, args_dict):
|
|
||||||
if 'beta' not in args_dict:
|
|
||||||
args_dict['beta'] = False
|
|
||||||
# Check only if beta is not enabled: if beta option is specified then
|
|
||||||
# raise error.
|
|
||||||
if not args_dict['beta']:
|
|
||||||
err_msg = ("\'{}\' is beta, but beta is not enabled. If you want "
|
|
||||||
"to use it please enable beta functionalities.")
|
|
||||||
for arg in cls.BETA_ARGS:
|
|
||||||
if arg in args_dict:
|
|
||||||
raise cdist.Error(err_msg.format(arg))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def commandline(cls, args):
|
def commandline(cls, args):
|
||||||
"""Configure remote system"""
|
"""Configure remote system"""
|
||||||
|
@ -136,9 +121,6 @@ class Config(object):
|
||||||
raise cdist.Error(("Cannot read both, manifest and host file, "
|
raise cdist.Error(("Cannot read both, manifest and host file, "
|
||||||
"from stdin"))
|
"from stdin"))
|
||||||
|
|
||||||
args_dict = vars(args)
|
|
||||||
cls._check_beta(args_dict)
|
|
||||||
|
|
||||||
# if no host source is specified then read hosts from stdin
|
# if no host source is specified then read hosts from stdin
|
||||||
if not (args.hostfile or args.host):
|
if not (args.hostfile or args.host):
|
||||||
args.hostfile = '-'
|
args.hostfile = '-'
|
||||||
|
@ -167,6 +149,7 @@ class Config(object):
|
||||||
args.remote_exec_pattern = None
|
args.remote_exec_pattern = None
|
||||||
args.remote_copy_pattern = None
|
args.remote_copy_pattern = None
|
||||||
|
|
||||||
|
args_dict = vars(args)
|
||||||
# if remote-exec and/or remote-copy args are None then user
|
# if remote-exec and/or remote-copy args are None then user
|
||||||
# didn't specify command line options nor env vars:
|
# didn't specify command line options nor env vars:
|
||||||
# inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
|
# inspect multiplexing options for default cdist.REMOTE_COPY/EXEC
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# list of beta arguments for sub-commands
|
||||||
|
BETA_ARGS = {
|
||||||
|
'config': ['jobs', ],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def check_positive_int(value):
|
def check_positive_int(value):
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
@ -36,6 +42,20 @@ def check_positive_int(value):
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def check_beta(args_dict):
|
||||||
|
if 'beta' not in args_dict:
|
||||||
|
args_dict['beta'] = False
|
||||||
|
# Check only if beta is not enabled: if beta option is specified then
|
||||||
|
# raise error.
|
||||||
|
if not args_dict['beta']:
|
||||||
|
err_msg = ("\'{}\' is beta, but beta is not enabled. If you want "
|
||||||
|
"to use it please enable beta functionalities.")
|
||||||
|
cmd = args_dict['command']
|
||||||
|
for arg in BETA_ARGS[cmd]:
|
||||||
|
if arg in args_dict:
|
||||||
|
raise cdist.CdistBetaRequired(cmd, arg)
|
||||||
|
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -172,6 +192,7 @@ def commandline():
|
||||||
parser['main'].print_help()
|
parser['main'].print_help()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
check_beta(vars(args))
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue