2016-08-02 17:43:10 +01:00
|
|
|
# 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 json
|
|
|
|
import logging
|
2016-08-24 11:47:30 +01:00
|
|
|
import uuid
|
2016-08-02 17:43:10 +01:00
|
|
|
|
2016-06-29 12:55:58 +01:00
|
|
|
from osc_lib.command import command
|
|
|
|
from osc_lib.i18n import _
|
2016-08-02 17:43:10 +01:00
|
|
|
|
2016-08-25 08:47:16 +01:00
|
|
|
from tripleoclient import utils
|
|
|
|
from tripleoclient.workflows import deployment
|
2016-08-24 11:47:30 +01:00
|
|
|
from tripleoclient.workflows import plan_management
|
|
|
|
|
2016-08-02 17:43:10 +01:00
|
|
|
|
2016-06-29 12:55:58 +01:00
|
|
|
class ListPlans(command.Lister):
|
2016-08-03 15:02:18 +00:00
|
|
|
"""List overcloud deployment plans."""
|
2016-08-02 17:43:10 +01:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".ListPlans")
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
|
|
|
|
workflow_client = self.app.client_manager.workflow_engine
|
|
|
|
execution = workflow_client.action_executions.create(
|
2016-09-07 07:42:24 +01:00
|
|
|
'tripleo.plan.list')
|
2016-08-02 17:43:10 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
json_results = json.loads(execution.output)['result']
|
|
|
|
except Exception:
|
|
|
|
self.log.exception("Error parsing JSON %s", execution.output)
|
|
|
|
json_results = []
|
|
|
|
|
|
|
|
result = []
|
|
|
|
for r in json_results:
|
|
|
|
result.append((r,))
|
|
|
|
|
|
|
|
return (("Plan Name",), result)
|
2016-08-03 15:02:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DeletePlan(command.Command):
|
|
|
|
"""Delete an overcloud deployment plan.
|
|
|
|
|
|
|
|
The plan will not be deleted if a stack exists with the same name.
|
|
|
|
"""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".DeletePlan")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeletePlan, self).get_parser(prog_name)
|
|
|
|
parser.add_argument('plans', metavar='<name>', nargs="+",
|
|
|
|
help=_('Name of the plan(s) to delete'))
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
|
|
|
|
workflow_client = self.app.client_manager.workflow_engine
|
|
|
|
|
|
|
|
for plan in parsed_args.plans:
|
|
|
|
print("Deleting plan %s..." % plan)
|
2016-12-14 09:58:45 +00:00
|
|
|
plan_management.delete_deployment_plan(workflow_client,
|
|
|
|
container=plan)
|
2016-08-24 11:47:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CreatePlan(command.Command):
|
|
|
|
"""Create a deployment plan"""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".CreatePlan")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(CreatePlan, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'name',
|
|
|
|
help=_('The name of the plan, which is used for the object '
|
|
|
|
'storage container, workflow environment and orchestration '
|
|
|
|
'stack names.'))
|
|
|
|
parser.add_argument(
|
|
|
|
'--templates',
|
|
|
|
help=_('The directory containing the Heat templates to deploy. '
|
|
|
|
'If this isn\'t provided, the templates packaged on the '
|
|
|
|
'Undercloud will be used.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
clients = self.app.client_manager
|
|
|
|
|
|
|
|
name = parsed_args.name
|
|
|
|
|
|
|
|
if parsed_args.templates:
|
|
|
|
plan_management.create_plan_from_templates(
|
|
|
|
clients, name, parsed_args.templates)
|
|
|
|
else:
|
|
|
|
plan_management.create_default_plan(
|
|
|
|
clients, container=name, queue_name=str(uuid.uuid4()))
|
2016-08-25 08:47:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DeployPlan(command.Command):
|
|
|
|
"""Deploy a deployment plan"""
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__ + ".DeployPlan")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeployPlan, self).get_parser(prog_name)
|
|
|
|
parser.add_argument('name', help=_('The name of the plan to deploy.'))
|
2016-09-14 15:55:20 +01:00
|
|
|
parser.add_argument('--timeout', '-t', metavar='<TIMEOUT>',
|
|
|
|
type=int,
|
|
|
|
help=_('Deployment timeout in minutes.'))
|
2016-08-25 08:47:16 +01:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
self.log.debug("take_action(%s)" % parsed_args)
|
|
|
|
|
|
|
|
clients = self.app.client_manager
|
|
|
|
orchestration_client = clients.orchestration
|
|
|
|
stack = utils.get_stack(orchestration_client, parsed_args.name)
|
|
|
|
|
|
|
|
print("Starting to deploy plan: {}".format(parsed_args.name))
|
|
|
|
deployment.deploy_and_wait(self.log, clients, stack, parsed_args.name,
|
2016-09-14 15:55:20 +01:00
|
|
|
self.app_args.verbose_level,
|
|
|
|
timeout=parsed_args.timeout)
|