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:
parent
a73d5d917d
commit
07f2afc112
|
@ -15,17 +15,15 @@
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_config import cfg
|
class CliAction: # pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
class CliAction(object):
|
|
||||||
""" Action base for CliActions
|
""" Action base for CliActions
|
||||||
"""
|
"""
|
||||||
def __init__(self, api_client, debug):
|
def __init__(self, api_client):
|
||||||
self.logger = logging.getLogger(cfg.CONF.logging.control_logger_name)
|
self.logger = logging.getLogger('drydock_cli')
|
||||||
self.api_client = api_client
|
self.api_client = api_client
|
||||||
self.debug = debug
|
self.logger.debug("Action initialized with client %s", self.api_client.session.host)
|
||||||
if self.debug:
|
|
||||||
self.logger.info("Action initialized with client %s" % (self.api_client), extra=extra)
|
|
||||||
|
|
||||||
def invoke(self):
|
def invoke(self):
|
||||||
|
""" The action to be taken. By default, this is not implemented
|
||||||
|
"""
|
||||||
raise NotImplementedError("Invoke method has not been implemented")
|
raise NotImplementedError("Invoke method has not been implemented")
|
||||||
|
|
|
@ -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)
|
|
@ -14,34 +14,39 @@
|
||||||
""" cli.design.commands
|
""" cli.design.commands
|
||||||
Contains commands related to designs
|
Contains commands related to designs
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
import click
|
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.group()
|
||||||
@click.pass_context
|
def design():
|
||||||
def design(ctx):
|
|
||||||
""" Drydock design commands
|
""" Drydock design commands
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@design.command(name='create')
|
@design.command(name='create')
|
||||||
|
@click.option('--base-design',
|
||||||
|
'-b',
|
||||||
|
help='The base design to model this new design after')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def design_create(ctx):
|
def design_create(ctx, base_design=None):
|
||||||
""" Create a design
|
""" Create a design
|
||||||
"""
|
"""
|
||||||
click.echo('create invoked')
|
click.echo(DesignCreate(ctx.obj['CLIENT'], base_design).invoke())
|
||||||
|
|
||||||
@design.command(name='list')
|
@design.command(name='list')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def design_list(ctx):
|
def design_list(ctx):
|
||||||
""" List designs
|
""" 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')
|
@design.command(name='show')
|
||||||
|
@click.option('--design-id',
|
||||||
|
'-i',
|
||||||
|
help='The design id to show')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def design_show(ctx, design_id):
|
def design_show(ctx, design_id):
|
||||||
""" show designs
|
""" show designs
|
||||||
|
@ -49,4 +54,4 @@ def design_show(ctx, design_id):
|
||||||
if not design_id:
|
if not design_id:
|
||||||
ctx.fail('The design id must be specified by --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())
|
||||||
|
|
Loading…
Reference in New Issue