Enabling specify --config file from CLI when building fuel-bootstrap
Closes-Bug: #1608925 Change-Id: I5bac895daf85bdc52b1672f53fec1b707db24473
This commit is contained in:
parent
cb77827303
commit
b3b10de4c5
|
@ -14,12 +14,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_bootstrap.commands import base
|
||||
from fuel_bootstrap.utils import bootstrap_image as bs_image
|
||||
|
||||
|
||||
class ActivateCommand(command.Command):
|
||||
class ActivateCommand(base.BaseCommand):
|
||||
"""Activate specified bootstrap image."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
@ -33,6 +32,7 @@ class ActivateCommand(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
super(ActivateCommand, self).take_action(parsed_args)
|
||||
# cliff handles errors by itself
|
||||
image_uuid = bs_image.activate(parsed_args.id)
|
||||
self.app.stdout.write("Bootstrap image {0} has been activated.\n"
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_bootstrap import consts
|
||||
from fuel_bootstrap import settings
|
||||
|
||||
CONF = settings.CONF
|
||||
|
||||
|
||||
class BaseCommand(command.Command):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(BaseCommand, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--config',
|
||||
dest='config_file',
|
||||
type=str,
|
||||
metavar='FILE',
|
||||
default=consts.CONFIG_FILE,
|
||||
help="The config file is to be used for taking configuration"
|
||||
" parameters from during building of the bootstrap."
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
CONF.read(parsed_args.config_file)
|
|
@ -14,12 +14,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_bootstrap.commands import base
|
||||
from fuel_bootstrap.utils import bootstrap_image as bs_image
|
||||
|
||||
|
||||
class BuildCommand(command.Command):
|
||||
class BuildCommand(base.BaseCommand):
|
||||
"""Build new bootstrap image with specified parameters."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
@ -173,6 +172,7 @@ class BuildCommand(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
super(BuildCommand, self).take_action(parsed_args)
|
||||
image_uuid, path = bs_image.make_bootstrap(vars(parsed_args))
|
||||
self.app.stdout.write("Bootstrap image {0} has been built: {1}\n"
|
||||
.format(image_uuid, path))
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_bootstrap.commands import base
|
||||
from fuel_bootstrap.utils import bootstrap_image as bs_image
|
||||
|
||||
|
||||
class DeleteCommand(command.Command):
|
||||
class DeleteCommand(base.BaseCommand):
|
||||
"""Delete specified bootstrap image from the system."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
@ -33,6 +32,7 @@ class DeleteCommand(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
super(DeleteCommand, self).take_action(parsed_args)
|
||||
# cliff handles errors by itself
|
||||
image_uuid = bs_image.delete(parsed_args.id)
|
||||
self.app.stdout.write("Bootstrap image {0} has been deleted.\n"
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_bootstrap.commands import base
|
||||
from fuel_bootstrap.utils import bootstrap_image as bs_image
|
||||
|
||||
|
||||
class ImportCommand(command.Command):
|
||||
class ImportCommand(base.BaseCommand):
|
||||
"""Import already created bootstrap image to the system."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
@ -39,6 +38,7 @@ class ImportCommand(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
super(ImportCommand, self).take_action(parsed_args)
|
||||
# Cliff handles errors by itself
|
||||
image_uuid = bs_image.import_image(parsed_args.filename)
|
||||
self.app.stdout.write("Bootstrap image {0} has been imported.\n"
|
||||
|
|
|
@ -14,24 +14,21 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cliff import command
|
||||
from cliff import lister
|
||||
|
||||
from fuelclient.common import data_utils
|
||||
|
||||
from fuel_bootstrap.commands import base
|
||||
from fuel_bootstrap.utils import bootstrap_image as bs_image
|
||||
|
||||
|
||||
class ListCommand(lister.Lister, command.Command):
|
||||
class ListCommand(base.BaseCommand, lister.Lister):
|
||||
"""List all available bootstrap images."""
|
||||
|
||||
columns = ('uuid', 'label', 'status')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListCommand, self).get_parser(prog_name)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
super(ListCommand, self).take_action(parsed_args)
|
||||
data = bs_image.get_all()
|
||||
data = data_utils.get_display_data_multi(self.columns, data)
|
||||
return (self.columns, data)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
# These consts shouldn't be configured
|
||||
|
||||
# TODO(asvechnikov): add possibility to specify custom config file
|
||||
# There is a possibility to specify custom config file with the key --config
|
||||
CONFIG_FILE = "/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml"
|
||||
METADATA_FILE = "metadata.yaml"
|
||||
COMPRESSED_CONTAINER_FORMAT = "tar.gz"
|
||||
|
|
|
@ -19,20 +19,19 @@ import sys
|
|||
|
||||
import yaml
|
||||
|
||||
from fuel_bootstrap import consts
|
||||
|
||||
|
||||
class Configuration(object):
|
||||
def __init__(self, config_file=None):
|
||||
def __init__(self):
|
||||
self._data = {}
|
||||
|
||||
def read(self, config_file):
|
||||
data = {}
|
||||
if not config_file:
|
||||
config_file = consts.CONFIG_FILE
|
||||
if os.path.exists(config_file):
|
||||
with open(config_file) as f:
|
||||
data = yaml.load(f)
|
||||
else:
|
||||
# TODO(atolochkova): need to add logger
|
||||
sys.stderr.write("Default config couldn't be found in {0}"
|
||||
sys.stderr.write("The config file couldn't be found: {0}"
|
||||
.format(config_file))
|
||||
self._data = data
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import copy
|
|||
|
||||
import mock
|
||||
|
||||
from fuel_bootstrap import consts
|
||||
from fuel_bootstrap.tests import base
|
||||
|
||||
PARSED_ARGS = {'extend_kopts': None,
|
||||
|
@ -39,7 +40,8 @@ PARSED_ARGS = {'extend_kopts': None,
|
|||
'extra_dirs': None,
|
||||
'no_default_packages': False,
|
||||
'no_default_extra_dirs': False,
|
||||
'packages': None}
|
||||
'packages': None,
|
||||
'config_file': consts.CONFIG_FILE}
|
||||
|
||||
UUID = 'fake_uuid'
|
||||
PATH = 'fake_path'
|
||||
|
|
Loading…
Reference in New Issue