-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify configuration #713
base: master
Are you sure you want to change the base?
Verify configuration #713
Changes from all commits
29c4c0e
aecb7eb
5140a16
c23a065
2026708
058d79d
8fa2ee2
8185fb6
0663330
fc43bd5
8842a05
6a4fe61
73e46c8
67b89ab
4c45a46
38fad21
7ed2805
e202d70
9b05fbb
e9732c2
d73752a
2e86849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
from lago.config import config | ||
from lago import (log_utils, workdir as lago_workdir, utils, lago_ansible) | ||
from lago.utils import (in_prefix, with_logging, LagoUserException) | ||
from lago.verify_configuration import (fix_configuration, check_configuration, check_user, check_directory,validate_status, VerifyLagoStatus) | ||
|
||
LOGGER = logging.getLogger('cli') | ||
in_lago_prefix = in_prefix( | ||
|
@@ -67,7 +68,6 @@ | |
'$PWD/.lago' | ||
), | ||
metavar='WORKDIR', | ||
type=os.path.abspath, | ||
nargs='?', | ||
) | ||
@lago.plugins.cli.cli_plugin_add_argument( | ||
|
@@ -751,7 +751,6 @@ def do_copy_to_vm(prefix, host, remote_path, local_path, **kwargs): | |
def do_collect(prefix, output, no_skip, **kwargs): | ||
prefix.collect_artifacts(output, ignore_nopath=not no_skip) | ||
|
||
|
||
@lago.plugins.cli.cli_plugin( | ||
help='Run scripts that install necessary RPMs and configuration' | ||
) | ||
|
@@ -760,6 +759,79 @@ def do_collect(prefix, output, no_skip, **kwargs): | |
def do_deploy(prefix, **kwargs): | ||
prefix.deploy() | ||
|
||
@lago.plugins.cli.cli_plugin( | ||
help='Verify that the machine runninh Lago is well configured and configure if needed' | ||
) | ||
@lago.plugins.cli.cli_plugin_add_argument( | ||
'--username', | ||
'-u', | ||
help='Which user needs to be configured', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add a default here: |
||
action='store', | ||
) | ||
|
||
@lago.plugins.cli.cli_plugin_add_argument( | ||
'--envs-dir', | ||
'-e', | ||
dest='envs_dir', | ||
help='Which directory the qemu has access permissions', | ||
default="/var/lib/lago", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This switch is about where the user is going to create the lago envs. |
||
type=os.path.abspath, | ||
action='store', | ||
) | ||
|
||
@lago.plugins.cli.cli_plugin_add_argument( | ||
'--verify', | ||
'-v', | ||
help='Return report that describes which configurations are OK, and which are not.', | ||
action='store_true', | ||
) | ||
@in_lago_prefix | ||
@with_logging | ||
def do_setup( | ||
prefix, username, envs_dir, verify, **kwargs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
): | ||
msg_error = [] | ||
if (username): | ||
if (check_user(username)): | ||
msg_error.append("Username doesn't exists " + username) | ||
else: | ||
username = os.getenv("SUDO_USER") or os.getenv("USER") | ||
|
||
if (envs_dir): | ||
if (check_directory(envs_dir)): | ||
msg_error.append("Directory doesn't exists "+ envs_dir) | ||
|
||
if ( msg_error ): | ||
msg_error_str = '\n'.join(msg_error) | ||
LOGGER.error("%s", msg_error_str) | ||
sys.exit(1) | ||
|
||
config_dict = check_configuration(username,envs_dir) | ||
(verify_status,list_not_configure) = validate_status(config_dict) | ||
verify_lago = VerifyLagoStatus(username,envs_dir,config_dict,verify_status) | ||
|
||
if (verify): | ||
verify_lago.displayLagoStatus(True) | ||
if verify_status: | ||
sys.exit(0) | ||
else: | ||
sys.exit(2) | ||
else: | ||
if (os.getuid() != 0): | ||
print("Please use 'sudo', you need adminstrator permissions for configuration") | ||
sys.exit(1) | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for an |
||
fix_configuration(username,envs_dir,config_dict) | ||
config_dict = check_configuration(username,envs_dir) | ||
(verify_status,list_not_configure) = validate_status(config_dict) | ||
verify_lago.fixLagoConfiguration(config_dict,verify_status) | ||
|
||
if verify_status: | ||
sys.exit(0) | ||
else: | ||
LOGGER.error("Problem to configure: %s", str(list_not_configure)) | ||
verify_lago.displayLagoStatus(False) | ||
sys.exit(2) | ||
|
||
@lago.plugins.cli.cli_plugin(help="Dump configuration file") | ||
@lago.plugins.cli.cli_plugin_add_argument( | ||
|
@@ -768,6 +840,7 @@ def do_deploy(prefix, **kwargs): | |
action='store_true', | ||
default=False, | ||
) | ||
|
||
def do_generate(verbose, **kwargs): | ||
print(config.get_ini(incl_unset=verbose)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be removed