Skip to content

Commit 77ea8ba

Browse files
committed
SDK Refactor: Prepare network qos policy commands
Prepare the OSC "network qos policy" commands for the SDK refactor. See [1] for details. [1] https://etherpad.openstack.org/p/osc-network-command-sdk-support Change-Id: I12dd8bda40801c26176a73646ed87aea66f09fcc Partially-Implements: blueprint network-command-sdk-support
1 parent d6e058f commit 77ea8ba

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

openstackclient/network/v2/network_qos_policy.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121

2222
from openstackclient.i18n import _
2323
from openstackclient.identity import common as identity_common
24+
from openstackclient.network import sdk_utils
2425

2526

2627
LOG = logging.getLogger(__name__)
2728

2829

2930
def _get_columns(item):
30-
columns = list(item.keys())
31-
if 'tenant_id' in columns:
32-
columns.remove('tenant_id')
33-
columns.append('project_id')
34-
return tuple(sorted(columns))
31+
column_map = {
32+
'is_shared': 'shared',
33+
'tenant_id': 'project_id',
34+
}
35+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
3536

3637

3738
def _get_attrs(client_manager, parsed_args):
@@ -56,6 +57,8 @@ def _get_attrs(client_manager, parsed_args):
5657
return attrs
5758

5859

60+
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
61+
# OSC minimum requirements include SDK 1.0.
5962
class CreateNetworkQosPolicy(command.ShowOne):
6063
_description = _("Create a QoS policy")
6164

@@ -96,9 +99,9 @@ def take_action(self, parsed_args):
9699
client = self.app.client_manager.network
97100
attrs = _get_attrs(self.app.client_manager, parsed_args)
98101
obj = client.create_qos_policy(**attrs)
99-
columns = _get_columns(obj)
102+
display_columns, columns = _get_columns(obj)
100103
data = utils.get_item_properties(obj, columns, formatters={})
101-
return columns, data
104+
return (display_columns, data)
102105

103106

104107
class DeleteNetworkQosPolicy(command.Command):
@@ -135,6 +138,8 @@ def take_action(self, parsed_args):
135138
raise exceptions.CommandError(msg)
136139

137140

141+
# TODO(abhiraut): Use only the SDK resource mapped attribute names once the
142+
# OSC minimum requirements include SDK 1.0.
138143
class ListNetworkQosPolicy(command.Lister):
139144
_description = _("List QoS policies")
140145

@@ -143,8 +148,8 @@ def take_action(self, parsed_args):
143148
columns = (
144149
'id',
145150
'name',
146-
'shared',
147-
'tenant_id',
151+
'is_shared',
152+
'project_id',
148153
)
149154
column_headers = (
150155
'ID',
@@ -160,6 +165,8 @@ def take_action(self, parsed_args):
160165
) for s in data))
161166

162167

168+
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
169+
# OSC minimum requirements include SDK 1.0.
163170
class SetNetworkQosPolicy(command.Command):
164171
_description = _("Set QoS policy properties")
165172

@@ -226,6 +233,6 @@ def take_action(self, parsed_args):
226233
client = self.app.client_manager.network
227234
obj = client.find_qos_policy(parsed_args.policy,
228235
ignore_missing=False)
229-
columns = _get_columns(obj)
236+
display_columns, columns = _get_columns(obj)
230237
data = utils.get_item_properties(obj, columns)
231-
return columns, data
238+
return (display_columns, data)

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ def create_one_qos_policy(attrs=None):
746746
loaded=True)
747747

748748
# Set attributes with special mapping in OpenStack SDK.
749+
qos_policy.is_shared = qos_policy_attrs['shared']
749750
qos_policy.project_id = qos_policy_attrs['tenant_id']
750751

751752
return qos_policy

0 commit comments

Comments
 (0)