Merge "SDK Refactor: Prepare network qos policy commands"

This commit is contained in:
Jenkins 2016-12-02 18:50:29 +00:00 committed by Gerrit Code Review
commit 6977105383
2 changed files with 19 additions and 11 deletions

View File

@ -21,17 +21,18 @@ from osc_lib import utils
from openstackclient.i18n import _ from openstackclient.i18n import _
from openstackclient.identity import common as identity_common from openstackclient.identity import common as identity_common
from openstackclient.network import sdk_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
def _get_columns(item): def _get_columns(item):
columns = list(item.keys()) column_map = {
if 'tenant_id' in columns: 'is_shared': 'shared',
columns.remove('tenant_id') 'tenant_id': 'project_id',
columns.append('project_id') }
return tuple(sorted(columns)) return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
def _get_attrs(client_manager, parsed_args): def _get_attrs(client_manager, parsed_args):
@ -56,6 +57,8 @@ def _get_attrs(client_manager, parsed_args):
return attrs return attrs
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class CreateNetworkQosPolicy(command.ShowOne): class CreateNetworkQosPolicy(command.ShowOne):
_description = _("Create a QoS policy") _description = _("Create a QoS policy")
@ -96,9 +99,9 @@ class CreateNetworkQosPolicy(command.ShowOne):
client = self.app.client_manager.network client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args) attrs = _get_attrs(self.app.client_manager, parsed_args)
obj = client.create_qos_policy(**attrs) obj = client.create_qos_policy(**attrs)
columns = _get_columns(obj) display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={}) data = utils.get_item_properties(obj, columns, formatters={})
return columns, data return (display_columns, data)
class DeleteNetworkQosPolicy(command.Command): class DeleteNetworkQosPolicy(command.Command):
@ -135,6 +138,8 @@ class DeleteNetworkQosPolicy(command.Command):
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
# TODO(abhiraut): Use only the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class ListNetworkQosPolicy(command.Lister): class ListNetworkQosPolicy(command.Lister):
_description = _("List QoS policies") _description = _("List QoS policies")
@ -143,8 +148,8 @@ class ListNetworkQosPolicy(command.Lister):
columns = ( columns = (
'id', 'id',
'name', 'name',
'shared', 'is_shared',
'tenant_id', 'project_id',
) )
column_headers = ( column_headers = (
'ID', 'ID',
@ -160,6 +165,8 @@ class ListNetworkQosPolicy(command.Lister):
) for s in data)) ) for s in data))
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class SetNetworkQosPolicy(command.Command): class SetNetworkQosPolicy(command.Command):
_description = _("Set QoS policy properties") _description = _("Set QoS policy properties")
@ -226,6 +233,6 @@ class ShowNetworkQosPolicy(command.ShowOne):
client = self.app.client_manager.network client = self.app.client_manager.network
obj = client.find_qos_policy(parsed_args.policy, obj = client.find_qos_policy(parsed_args.policy,
ignore_missing=False) ignore_missing=False)
columns = _get_columns(obj) display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns) data = utils.get_item_properties(obj, columns)
return columns, data return (display_columns, data)

View File

@ -746,6 +746,7 @@ class FakeNetworkQosPolicy(object):
loaded=True) loaded=True)
# Set attributes with special mapping in OpenStack SDK. # Set attributes with special mapping in OpenStack SDK.
qos_policy.is_shared = qos_policy_attrs['shared']
qos_policy.project_id = qos_policy_attrs['tenant_id'] qos_policy.project_id = qos_policy_attrs['tenant_id']
return qos_policy return qos_policy