Completion of wiring of design cli commands

added the create and show commands and wired to specific
api client calls
This commit is contained in:
Bryan Strassner 2017-07-14 16:13:53 -05:00 committed by Scott Hussey
parent a73d5d917d
commit 07f2afc112
3 changed files with 76 additions and 18 deletions

View File

@ -15,17 +15,15 @@
"""
import logging
from oslo_config import cfg
class CliAction(object):
class CliAction: # pylint: disable=too-few-public-methods
""" Action base for CliActions
"""
def __init__(self, api_client, debug):
self.logger = logging.getLogger(cfg.CONF.logging.control_logger_name)
def __init__(self, api_client):
self.logger = logging.getLogger('drydock_cli')
self.api_client = api_client
self.debug = debug
if self.debug:
self.logger.info("Action initialized with client %s" % (self.api_client), extra=extra)
self.logger.debug("Action initialized with client %s", self.api_client.session.host)
def invoke(self):
""" The action to be taken. By default, this is not implemented
"""
raise NotImplementedError("Invoke method has not been implemented")

View File

@ -0,0 +1,55 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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.
""" Actions related to design
"""
from drydock_provisioner.cli.action import CliAction
class DesignList(CliAction): # pylint: disable=too-few-public-methods
""" Action to list designs
"""
def __init__(self, api_client):
super().__init__(api_client)
self.logger.debug("DesignList action initialized")
def invoke(self):
return self.api_client.get_design_ids()
class DesignCreate(CliAction): # pylint: disable=too-few-public-methods
""" Action to create designs
:param string base_design: A UUID of the base design to model after
"""
def __init__(self, api_client, base_design=None):
super().__init__(api_client)
self.logger.debug("DesignCreate action initialized with base_design=%s", base_design)
self.base_design = base_design
def invoke(self):
return self.api_client.create_design(base_design=self.base_design)
class DesignShow(CliAction): # pylint: disable=too-few-public-methods
""" Action to show a design.
:param string design_id: A UUID design_id
:param string source: (Optional) The model source to return. 'designed' is as input,
'compiled' is after merging
"""
def __init__(self, api_client, design_id, source='designed'):
super().__init__(api_client)
self.design_id = design_id
self.source = source
self.logger.debug("DesignShow action initialized for design_id = %s", design_id)
def invoke(self):
return self.api_client.get_design(design_id=self.design_id, source=self.source)

View File

@ -14,34 +14,39 @@
""" cli.design.commands
Contains commands related to designs
"""
import logging
import click
from drydock_provisioner.cli.design.actions import DesignList
from drydock_provisioner.cli.design.actions import DesignShow
from drydock_provisioner.cli.design.actions import DesignCreate
@click.group()
@click.pass_context
def design(ctx):
def design():
""" Drydock design commands
"""
pass
@design.command(name='create')
@click.option('--base-design',
'-b',
help='The base design to model this new design after')
@click.pass_context
def design_create(ctx):
def design_create(ctx, base_design=None):
""" Create a design
"""
click.echo('create invoked')
click.echo(DesignCreate(ctx.obj['CLIENT'], base_design).invoke())
@design.command(name='list')
@click.pass_context
def design_list(ctx):
""" List designs
"""
click.echo(ctx.obj['CLIENT'].get_design_ids())
click.echo(DesignList(ctx.obj['CLIENT']).invoke())
@click.option('--design-id',
'-id',
help='The deisgn id to show')
@design.command(name='show')
@click.option('--design-id',
'-i',
help='The design id to show')
@click.pass_context
def design_show(ctx, design_id):
""" show designs
@ -49,4 +54,4 @@ def design_show(ctx, design_id):
if not design_id:
ctx.fail('The design id must be specified by --design-id')
click.echo('show invoked for {}'.format(design_id))
click.echo(DesignShow(ctx.obj['CLIENT'], design_id).invoke())