refactor: Remove usage of useless command.command.OpenStackCommand

It seems OpenStackCommand was introduced to make neutronclient
comamnds usable in OpenStack client, but at now OpenStack client
directly implements cliff Command and does not require this kind
of wrapper. To simplify the code, this commit drops the useless class.

Partial-Bug: #1532258
Change-Id: Iaa5ce9f4b98d5c85ee6ba0303067e65a829fc78e
This commit is contained in:
Akihiro Motoki
2016-01-08 22:56:22 +09:00
parent a0134f89af
commit f903ad9eea
3 changed files with 22 additions and 44 deletions

View File

@@ -1,35 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All 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.
#
from cliff import command
class OpenStackCommand(command.Command):
"""Base class for OpenStack commands."""
api = None
def run(self, parsed_args):
if not self.api:
return
else:
return super(OpenStackCommand, self).run(parsed_args)
def get_data(self, parsed_args):
pass
def take_action(self, parsed_args):
return self.get_data(parsed_args)

View File

@@ -21,13 +21,13 @@ import argparse
import logging
import re
from cliff import command
from cliff import lister
from cliff import show
from oslo_serialization import jsonutils
import six
from neutronclient._i18n import _
from neutronclient.common import command
from neutronclient.common import exceptions
from neutronclient.common import utils
@@ -369,7 +369,7 @@ def update_dict(obj, dict, attributes):
dict[attribute] = getattr(obj, attribute)
# command.OpenStackCommand is abstract class so that metaclass of
# cliff.command.Command is abstract class so that metaclass of
# subclass must be subclass of metaclass of all its base.
# otherwise metaclass conflict exception is raised.
class NeutronCommandMeta(abc.ABCMeta):
@@ -382,8 +382,10 @@ class NeutronCommandMeta(abc.ABCMeta):
@six.add_metaclass(NeutronCommandMeta)
class NeutronCommand(command.OpenStackCommand):
class NeutronCommand(command.Command):
# TODO(amotoki): Get rid of 'api' attribute. There is no such convention
# in OpenStack client. It may be an ancient convention though.
api = 'network'
values_specs = []
json_indent = None
@@ -391,6 +393,14 @@ class NeutronCommand(command.OpenStackCommand):
shadow_resource = None
parent_id = None
# TODO(amotoki): Remove the usage of get_data and use take_action directly.
# Overriding take_action() is recommended when implementing cliff command.
def get_data(self, parsed_args):
pass
def take_action(self, parsed_args):
return self.get_data(parsed_args)
@property
def cmd_resource(self):
if self.shadow_resource:

View File

@@ -32,11 +32,11 @@ import os_client_config
from oslo_utils import encodeutils
from cliff import app
from cliff import command
from cliff import commandmanager
from neutronclient._i18n import _
from neutronclient.common import clientmanager
from neutronclient.common import command as openstack_command
from neutronclient.common import exceptions as exc
from neutronclient.common import extension as client_extension
from neutronclient.common import utils
@@ -140,9 +140,12 @@ def check_non_negative_int(value):
return value
class BashCompletionCommand(openstack_command.OpenStackCommand):
class BashCompletionCommand(command.Command):
"""Prints all of the commands and options for bash-completion."""
resource = "bash_completion"
def take_action(self, parsed_args):
pass
COMMAND_V2 = {
'bash-completion': BashCompletionCommand,
@@ -727,9 +730,9 @@ class NeutronShell(app.App):
options = set()
for option, _action in self.parser._option_string_actions.items():
options.add(option)
for command_name, command in self.command_manager:
commands.add(command_name)
cmd_factory = command.load()
for _name, _command in self.command_manager:
commands.add(_name)
cmd_factory = _command.load()
cmd = cmd_factory(self, None)
cmd_parser = cmd.get_parser('')
for option, _action in cmd_parser._option_string_actions.items():