python-tripleoclient/tripleoclient/v1/overcloud_raid.py
Kevin Carter 624a61f206 Update verbosity so it is consistently set
This change will set the verbosity consistently whenever a playbook is
executed via the client.

All tests have been updated to ensure that the verbosity setting is always
defined when a playbook is executed.

Change-Id: I35b10d48344c8b7f71186bc529a300f75d7b8d63
Signed-off-by: Kevin Carter <kecarter@redhat.com>
2020-04-04 03:46:36 +00:00

80 lines
2.9 KiB
Python

# Copyright 2016 Red Hat, 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.
#
import logging
import os
from osc_lib.i18n import _
import yaml
from tripleoclient import command
from tripleoclient import utils
from tripleoclient.workflows import baremetal
class CreateRAID(command.Command):
"""Create RAID on given nodes"""
log = logging.getLogger(__name__ + ".CreateRAID")
def get_parser(self, prog_name):
parser = super(CreateRAID, self).get_parser(prog_name)
parser.add_argument('--node', action='append', required=True,
help=_('Nodes to create RAID on (expected to be '
'in manageable state). Can be specified '
'multiple times.'))
parser.add_argument('configuration',
help=_('RAID configuration (YAML/JSON string or '
'file name).'))
return parser
def take_action(self, parsed_args):
self.log.debug("take_action({args})".format(args=parsed_args))
if os.path.exists(parsed_args.configuration):
with open(parsed_args.configuration, 'r') as fp:
configuration = yaml.safe_load(fp.read())
else:
try:
configuration = yaml.safe_load(parsed_args.configuration)
except yaml.YAMLError as exc:
raise RuntimeError(
_('Configuration is not an existing file and cannot be '
'parsed as YAML: %s') % exc)
# Basic sanity check, we defer the full check to Ironic
try:
disks = configuration['logical_disks']
except KeyError:
raise ValueError(
_('Configuration must contain key "logical_disks"'))
except TypeError:
raise TypeError(
_('Configuration must be an object, got %r instead')
% configuration)
if (not isinstance(disks, list) or
not all(isinstance(item, dict) for item in disks)):
raise TypeError(
_('Logical disks list is expected to be a list of objects, '
'got %r instead') % disks)
baremetal.create_raid_configuration(
clients=self.app.client_manager,
node_uuids=parsed_args.node,
configuration=configuration,
verbosity=utils.playbook_verbosity(self=self)
)