Skip to content

Commit

Permalink
Merge pull request #324 from nvgoldin/generate_config
Browse files Browse the repository at this point in the history
Load configurations from the CLI plugins
  • Loading branch information
lago-bot authored Oct 13, 2016
2 parents f070ef8 + a771a9d commit 4187830
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 276 deletions.
2 changes: 2 additions & 0 deletions docs/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
sphinx>1.0
nose
dulwich
configparser
pyxdg
13 changes: 0 additions & 13 deletions etc/lago.d/lago.conf

This file was deleted.

47 changes: 38 additions & 9 deletions lago.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ Deploy and tear down environments of several virtual machines
%setup -q -n %{name}-%{version}

%build
LAGO_VERSION=%{version} %{__python} setup.py build
LAGO_VERSION=%{version} %{py2_build}

%install
LAGO_VERSION=%{version} %{__python} setup.py install --root $RPM_BUILD_ROOT
cd "$RPM_BUILD_DIR"

install -d "$RPM_BUILD_ROOT"/var/lib/lago/subnets
install -d "$RPM_BUILD_ROOT"/var/lib/lago/store
install -d "$RPM_BUILD_ROOT"/var/lib/lago/repos
LAGO_VERSION=%{version} %{py2_install}
install -d -m 755 %{buildroot}/%{_sysconfdir}/lago
PYTHONPATH="$PYTHONPATH:%{buildroot}/%{python_sitelib}"\
%{buildroot}/usr/bin/lago --ignore-warnings generate-config > "%{buildroot}/%{_sysconfdir}/lago/lago.conf"
sed -i 's/^\([^#]\)\(.*\)/#\0/' "%{buildroot}/%{_sysconfdir}/lago/lago.conf"

install -d %{buildroot}/var/lib/lago/subnets
install -d %{buildroot}/var/lib/lago/store
install -d %{buildroot}/var/lib/lago/repos
# this is for python-lago-ovirt
install -d "$RPM_BUILD_ROOT"/var/lib/lago/reposync
install -d %{buildroot}/var/lib/lago/reposync

%files

Expand All @@ -39,6 +42,23 @@ Summary: Library to perform lago operations
BuildArch: noarch
BuildRequires: python2-devel
BuildRequires: python-pbr
BuildRequires: python-stevedore
BuildRequires: python-setuptools
BuildRequires: python-magic
BuildRequires: python-lockfile
BuildRequires: python-yaml
BuildRequires: pyxdg
BuildRequires: python-xmltodict
BuildRequires: python-lxml
BuildRequires: libvirt-python
BuildRequires: python-enum
BuildRequires: python-scp
%if 0%{?fedora} >= 24
BuildRequires: python2-configparser
%else
BuildRequires: python-configparser
%endif

%if 0%{?fedora} >= 23
BuildRequires: python2-dulwich
%else
Expand All @@ -63,6 +83,12 @@ Requires: python-setuptools
Requires: python-stevedore
Requires: python-yaml
Requires: python-enum
Requires: pyxdg
%if 0%{?fedora} >= 24
Requires: python2-configparser
%else
Requires: python-configparser
%endif
Requires: qemu-img >= 2.1.2
Requires: qemu-kvm >= 2.1.2
Requires: git
Expand All @@ -82,12 +108,13 @@ Requires: sudo
%{_bindir}/lagocli
%{_bindir}/lago
%attr(0775, root, root) %{_sysconfdir}/sudoers.d/*
%config(noreplace) %{_sysconfdir}/lago.d/lago.conf
%config(noreplace) %{_sysconfdir}/lago/lago.conf
%dir %attr(2775, root, lago) /var/lib/lago/
%dir %attr(2775, root, lago) /var/lib/lago/subnets/
%dir %attr(2775, root, lago) /var/lib/lago/store/
%dir %attr(2775, root, lago) /var/lib/lago/repos/


%pre -n python-%{name}
if [[ "$1" -eq 1 ]]; then
groupadd lago
Expand All @@ -98,6 +125,7 @@ if [[ "$1" -eq 0 ]]; then
groupdel lago
fi


###################### lago-ovirt package
%package -n %{name}-ovirt
Summary: oVirt extension for lagocli
Expand Down Expand Up @@ -141,6 +169,7 @@ if which firewall-cmd &>/dev/null; then
firewall-cmd --reload
fi


%preun -n python-%{name}-ovirt
if which firewall-cmd &>/dev/null; then
firewall-cmd --permanent --zone=public --remove-service=ovirtlago
Expand Down
154 changes: 130 additions & 24 deletions lago/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import warnings

import lago
import lago.config
import lago.plugins
import lago.plugins.cli
import lago.templates
from lago.config import config
from lago import (log_utils, workdir as lago_workdir, )
from lago.utils import (in_prefix, with_logging)

Expand Down Expand Up @@ -83,6 +83,13 @@
@lago.plugins.cli.cli_plugin_add_argument(
'--template-store',
help='Location to store templates at',
default='/var/lib/lago/store',
type=os.path.abspath,
)
@lago.plugins.cli.cli_plugin_add_argument(
'--template-repos',
help='Location to store repos',
default='/var/lib/lago/repos',
type=os.path.abspath,
)
@lago.plugins.cli.cli_plugin_add_argument(
Expand All @@ -107,6 +114,7 @@ def do_init(
template_repo_path=None,
template_repo_name=None,
template_store=None,
template_repos=None,
set_current=False,
skip_bootstrap=False,
**kwargs
Expand Down Expand Up @@ -154,24 +162,17 @@ def do_init(
template_repo_path
)
else:
try:
repo_name = (
template_repo_name
or lago.config.get('template_default_repo')
if template_repo_name:
repo = lago.templates.find_repo_by_name(
name=template_repo_name
)
except KeyError:

else:
raise RuntimeError(
'No template repo was configured or specified'
)

repo = lago.templates.find_repo_by_name(repo_name)

template_store_path = (
template_store or lago.config.get(
'template_store', default=None
)
)
store = lago.templates.TemplateStore(template_store_path)
store = lago.templates.TemplateStore(template_store)

with open(virt_config, 'r') as virt_fd:
prefix.virt_conf_from_stream(
Expand Down Expand Up @@ -578,22 +579,40 @@ def do_deploy(prefix, **kwargs):
prefix.deploy()


@lago.plugins.cli.cli_plugin(help="Dump configuration file")
@lago.plugins.cli.cli_plugin_add_argument(
'--defaults_only',
help='Ignore CLI parameters and print loaded configs only.',
action='store_true',
default=False
)
@lago.plugins.cli.cli_plugin_add_argument(
'--verbose',
help='Include parameters with no default value.',
action='store_true',
default=False,
)
def do_generate(defaults_only, verbose, **kwargs):
print config.get_ini(defaults_only=defaults_only, incl_unset=verbose)


def create_parser(cli_plugins, out_plugins):
parser = argparse.ArgumentParser(
description='Command line interface to oVirt testing framework.'
description='Command line interface to Lago',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'-l',
'--loglevel',
default='info',
choices=['info', 'debug', 'error', 'warning'],
help='Log level to use, by default %(default)s'
help='Log level to use'
)
parser.add_argument(
'--logdepth',
default=3,
type=int,
help='How many task levels to show, by default %(default)s'
help='How many task levels to show'
)
pkg_info = pkg_resources.require("lago")[0]
parser.add_argument(
Expand Down Expand Up @@ -623,23 +642,110 @@ def create_parser(cli_plugins, out_plugins):
'-w',
action='store',
default=None,
help='Path to the workdir to use',
help='Path to the workdir to use.',
)
parser.add_argument(
'--prefix-name',
'-P',
action='store',
default='current',
dest='prefix_name',
help='Name of the prefix to use',
help='Name of the prefix to use.',
)
parser.add_argument(
'--ssh-user',
action='store',
default='root',
help='User for SSH provider.',
)
parser.add_argument(
'--ssh-password',
action='store',
default='123456',
help='Password for SSH provider.',
)
parser.add_argument(
'--ssh-tries',
action='store',
default=100,
type=int,
help='Number of ssh time outs to wait before failing.',
)
parser.add_argument(
'--ssh-timeout',
action='store',
default=10,
type=int,
help='Seconds to wait before marking SSH connection as failed.'
)
parser.add_argument(
'--libvirt_url',
action='store',
default='qemu:///system',
help='libvirt URI, currently only '
'system'
' is supported.'
)
parser.add_argument(
'--libvirt-user',
action='store',
help='libvirt user',
)
parser.add_argument(
'--libvirt-password',
action='store',
help='libvirt password',
)
parser.add_argument(
'--default_vm_type',
action='store',
default='default',
help='Default vm type',
)

parser.add_argument(
'--default_vm_provider',
action='store',
default='local-libvirt',
help='Default vm provider',
)
parser.add_argument(
'--default_root_password',
action='store',
default='123456',
help='Default root password',
)
parser.add_argument('--ignore-warnings', action='store_true', )
parser.add_argument(
'--lease_dir',
action='store',
default='/var/lib/lago/subnets',
help='Path to store created subnets configurations'
)
parser.add_argument(
'--reposync-dir',
action='store',
default='/var/lib/lago/reposync',
help='Reposync dir if used',
)
parser.add_argument(
'--reposync-config',
help='Reposync config',
default='config.repo',
action='store',
)

parser.add_argument('--ignore-warnings', action='store_true')
parser.set_defaults(**config.get_section('lago', {}))
verbs_parser = parser.add_subparsers(dest='verb', metavar='VERB')
for cli_plugin_name, cli_plugin in cli_plugins.items():
plugin_parser = verbs_parser.add_parser(
cli_plugin_name, **cli_plugin.init_args
name=cli_plugin_name,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
**cli_plugin.init_args
)
cli_plugin.populate_parser(plugin_parser)
plugin_parser.set_defaults(**config.get_section(cli_plugin_name, {}))
config.update_parser(parser=parser)

return parser

Expand All @@ -656,8 +762,9 @@ def main():
out_plugins = lago.plugins.load_plugins(
lago.plugins.PLUGIN_ENTRY_POINTS['out']
)
parser = create_parser(cli_plugins=cli_plugins, out_plugins=out_plugins)
parser = create_parser(cli_plugins=cli_plugins, out_plugins=out_plugins, )
args = parser.parse_args()
config.update_args(args)

logging.basicConfig(level=logging.DEBUG)
logging.root.handlers = [
Expand All @@ -683,13 +790,12 @@ def main():
if args.prefix_path:
warnings.warn(
'The option --prefix-path is going to be deprecated, use '
'--wordir and --prefix instead',
'--workdir and --prefix instead',
DeprecationWarning,
)

try:
cli_plugins[args.verb].do_run(args)

except Exception:
LOGGER.exception('Error occured, aborting')
sys.exit(1)
Expand Down
Loading

0 comments on commit 4187830

Please sign in to comment.