2015-05-20 13:06:37 +02:00
|
|
|
# Copyright 2015 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
|
2016-06-27 10:11:42 +01:00
|
|
|
import uuid
|
2015-05-20 13:06:37 +02:00
|
|
|
|
|
|
|
from cliff import command
|
|
|
|
from openstackclient.common import utils
|
2016-07-05 12:16:20 +01:00
|
|
|
from openstackclient.i18n import _
|
2015-05-20 13:06:37 +02:00
|
|
|
from tripleo_common import scale
|
|
|
|
|
2015-09-18 08:49:28 -04:00
|
|
|
from tripleoclient import constants
|
2016-06-27 10:11:42 +01:00
|
|
|
from tripleoclient.workflows import baremetal
|
2015-07-15 12:40:17 +02:00
|
|
|
|
2015-05-20 13:06:37 +02:00
|
|
|
|
|
|
|
class DeleteNode(command.Command):
|
|
|
|
"""Delete overcloud nodes."""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".DeleteNode")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeleteNode, self).get_parser(prog_name)
|
|
|
|
parser.add_argument('nodes', metavar='<node>', nargs="+",
|
2016-07-05 12:16:20 +01:00
|
|
|
help=_('Node ID(s) to delete'))
|
2015-05-20 13:06:37 +02:00
|
|
|
parser.add_argument('--stack', dest='stack',
|
2016-07-05 12:16:20 +01:00
|
|
|
help=_('Name or ID of heat stack to scale '
|
|
|
|
'(default=Env: OVERCLOUD_STACK_NAME)'),
|
2015-05-20 13:06:37 +02:00
|
|
|
default=utils.env('OVERCLOUD_STACK_NAME'))
|
2015-07-15 12:40:17 +02:00
|
|
|
parser.add_argument(
|
2015-09-18 08:49:28 -04:00
|
|
|
'--templates', nargs='?', const=constants.TRIPLEO_HEAT_TEMPLATES,
|
2016-07-05 12:16:20 +01:00
|
|
|
help=_("The directory containing the Heat templates to deploy")
|
2015-07-15 12:40:17 +02:00
|
|
|
)
|
2015-07-15 12:43:35 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'-e', '--environment-file', metavar='<HEAT ENVIRONMENT FILE>',
|
|
|
|
action='append', dest='environment_files',
|
2016-07-05 12:16:20 +01:00
|
|
|
help=_('Environment files to be passed to the heat stack-create '
|
2015-07-15 12:43:35 +02:00
|
|
|
'or heat stack-update command. (Can be specified more than '
|
2016-07-05 12:16:20 +01:00
|
|
|
'once.)')
|
2015-07-15 12:43:35 +02:00
|
|
|
)
|
2015-07-15 12:40:17 +02:00
|
|
|
|
2015-05-20 13:06:37 +02:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
2016-04-20 15:58:14 -04:00
|
|
|
clients = self.app.client_manager
|
2015-07-15 12:40:17 +02:00
|
|
|
|
2015-05-20 13:06:37 +02:00
|
|
|
scale_manager = scale.ScaleManager(
|
2016-04-20 15:58:14 -04:00
|
|
|
heatclient=clients.orchestration,
|
2015-07-15 12:40:17 +02:00
|
|
|
stack_id=parsed_args.stack,
|
2015-07-15 12:43:35 +02:00
|
|
|
tht_dir=parsed_args.templates,
|
|
|
|
environment_files=parsed_args.environment_files)
|
2015-05-20 13:06:37 +02:00
|
|
|
print("deleting nodes {0} from stack {1}".format(parsed_args.nodes,
|
2015-09-15 12:27:59 +01:00
|
|
|
parsed_args.stack))
|
2015-05-20 13:06:37 +02:00
|
|
|
scale_manager.scaledown(parsed_args.nodes)
|
2016-06-27 10:11:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ProvideNode(command.Command):
|
|
|
|
"""Mark nodes as available based on UUIDs or current 'manageable' state."""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".ProvideNode")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(ProvideNode, self).get_parser(prog_name)
|
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
group.add_argument('node_uuids',
|
|
|
|
nargs="*",
|
|
|
|
metavar="<node_uuid>",
|
|
|
|
default=[],
|
|
|
|
help=_('Ironic UUIDs for the node(s) to be '
|
|
|
|
'provided'))
|
|
|
|
group.add_argument("--all-manageable",
|
|
|
|
action='store_true',
|
|
|
|
help=_("Provide all nodes currently in 'manageable'"
|
|
|
|
" state"))
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
|
|
|
|
queue_name = str(uuid.uuid4())
|
|
|
|
|
|
|
|
if parsed_args.node_uuids:
|
|
|
|
baremetal.provide(self.app.client_manager,
|
|
|
|
node_uuids=parsed_args.node_uuids,
|
|
|
|
queue_name=queue_name)
|
|
|
|
else:
|
|
|
|
baremetal.provide_manageable_nodes(self.app.client_manager,
|
|
|
|
queue_name=queue_name)
|
2016-07-01 15:07:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IntrospectNode(command.Command):
|
|
|
|
"""Introspect specified nodes or all nodes in 'manageable' state."""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".IntrospectNode")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(IntrospectNode, self).get_parser(prog_name)
|
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
group.add_argument('node_uuids',
|
|
|
|
nargs="*",
|
|
|
|
metavar="<node_uuid>",
|
|
|
|
default=[],
|
|
|
|
help=_('Ironic UUIDs for the node(s) to be '
|
|
|
|
'introspected'))
|
|
|
|
group.add_argument("--all-manageable",
|
|
|
|
action='store_true',
|
|
|
|
help=_("Introspect all nodes currently in "
|
|
|
|
"'manageable' state"))
|
|
|
|
parser.add_argument('--provide',
|
|
|
|
action='store_true',
|
|
|
|
help=_('Provide (make available) the nodes once '
|
|
|
|
'introspected'))
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
|
|
|
|
queue_name = str(uuid.uuid4())
|
|
|
|
nodes = parsed_args.node_uuids
|
|
|
|
|
|
|
|
if nodes:
|
|
|
|
baremetal.introspect(self.app.client_manager,
|
|
|
|
node_uuids=nodes,
|
|
|
|
queue_name=queue_name)
|
|
|
|
else:
|
|
|
|
baremetal.introspect_manageable_nodes(self.app.client_manager,
|
|
|
|
queue_name=queue_name)
|
|
|
|
|
|
|
|
if parsed_args.provide:
|
|
|
|
if nodes:
|
|
|
|
baremetal.provide(self.app.client_manager,
|
|
|
|
node_uuids=nodes,
|
|
|
|
queue_name=queue_name)
|
|
|
|
else:
|
|
|
|
baremetal.provide_manageable_nodes(self.app.client_manager,
|
|
|
|
queue_name=queue_name)
|