From 30612bf62295720a21d39c4f589cfcefb7a86a2f Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 8 Oct 2021 18:06:11 +0100 Subject: [PATCH] Remove 'get_osc_show_columns_for_sdk_resource' duplicates There were a number of 'get_osc_show_columns_for_sdk_resource' defined in-tree. However, osc-lib has provided this method for some time (since 2.2.0, June 2020 [1] - our minimum version is currently 2.3.0) so there's no need to provide our own copies. Remove them. [1] https://github.com/openstack/osc-lib/commit/29a0c5a5 Change-Id: I25695f4f9a379dd691b7eaa1e3247164668ae77e Signed-off-by: Stephen Finucane --- openstackclient/common/sdk_utils.py | 58 ----------------- openstackclient/image/v1/image.py | 13 ++-- openstackclient/image/v2/image.py | 7 +-- openstackclient/network/sdk_utils.py | 63 ------------------- openstackclient/network/v2/address_group.py | 4 +- openstackclient/network/v2/address_scope.py | 4 +- openstackclient/network/v2/floating_ip.py | 3 +- .../network/v2/floating_ip_port_forwarding.py | 5 +- openstackclient/network/v2/ip_availability.py | 3 +- .../network/v2/l3_conntrack_helper.py | 4 +- openstackclient/network/v2/network.py | 5 +- openstackclient/network/v2/network_agent.py | 4 +- .../v2/network_auto_allocated_topology.py | 3 +- openstackclient/network/v2/network_flavor.py | 4 +- .../network/v2/network_flavor_profile.py | 4 +- openstackclient/network/v2/network_meter.py | 3 +- .../network/v2/network_meter_rule.py | 3 +- .../network/v2/network_qos_policy.py | 4 +- .../network/v2/network_qos_rule.py | 4 +- .../network/v2/network_qos_rule_type.py | 3 +- openstackclient/network/v2/network_rbac.py | 4 +- openstackclient/network/v2/network_segment.py | 4 +- .../network/v2/network_segment_range.py | 3 +- openstackclient/network/v2/port.py | 4 +- openstackclient/network/v2/router.py | 4 +- openstackclient/network/v2/security_group.py | 3 +- .../network/v2/security_group_rule.py | 4 +- openstackclient/network/v2/subnet.py | 4 +- openstackclient/network/v2/subnet_pool.py | 3 +- .../tests/unit/network/test_sdk_utils.py | 59 ----------------- 30 files changed, 37 insertions(+), 256 deletions(-) delete mode 100644 openstackclient/common/sdk_utils.py delete mode 100644 openstackclient/network/sdk_utils.py delete mode 100644 openstackclient/tests/unit/network/test_sdk_utils.py diff --git a/openstackclient/common/sdk_utils.py b/openstackclient/common/sdk_utils.py deleted file mode 100644 index af9c74f944..0000000000 --- a/openstackclient/common/sdk_utils.py +++ /dev/null @@ -1,58 +0,0 @@ -# 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. - - -def get_osc_show_columns_for_sdk_resource( - sdk_resource, - osc_column_map, - invisible_columns=None -): - """Get and filter the display and attribute columns for an SDK resource. - - Common utility function for preparing the output of an OSC show command. - Some of the columns may need to get renamed, others made invisible. - - :param sdk_resource: An SDK resource - :param osc_column_map: A hash of mappings for display column names - :param invisible_columns: A list of invisible column names - - :returns: Two tuples containing the names of the display and attribute - columns - """ - - if getattr(sdk_resource, 'allow_get', None) is not None: - resource_dict = sdk_resource.to_dict( - body=True, headers=False, ignore_none=False) - else: - resource_dict = sdk_resource - - # Build the OSC column names to display for the SDK resource. - attr_map = {} - display_columns = list(resource_dict.keys()) - invisible_columns = [] if invisible_columns is None else invisible_columns - for col_name in invisible_columns: - if col_name in display_columns: - display_columns.remove(col_name) - for sdk_attr, osc_attr in osc_column_map.items(): - if sdk_attr in display_columns: - attr_map[osc_attr] = sdk_attr - display_columns.remove(sdk_attr) - if osc_attr not in display_columns: - display_columns.append(osc_attr) - sorted_display_columns = sorted(display_columns) - - # Build the SDK attribute names for the OSC column names. - attr_columns = [] - for column in sorted_display_columns: - new_column = attr_map[column] if column in attr_map else column - attr_columns.append(new_column) - return tuple(sorted_display_columns), tuple(attr_columns) diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 64aa3fcdab..43ccf5d212 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -28,7 +28,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import utils -from openstackclient.common import sdk_utils from openstackclient.i18n import _ if os.name == "nt": @@ -48,15 +47,17 @@ LOG = logging.getLogger(__name__) def _get_columns(item): - # Trick sdk_utils to return URI attribute column_map = { 'is_protected': 'protected', 'owner_id': 'owner' } - hidden_columns = ['location', 'checksum', - 'copy_from', 'created_at', 'status', 'updated_at'] - return sdk_utils.get_osc_show_columns_for_sdk_resource( - item.to_dict(), column_map, hidden_columns) + hidden_columns = [ + 'location', 'checksum', 'copy_from', 'created_at', 'status', + 'updated_at', + ] + return utils.get_osc_show_columns_for_sdk_resource( + item.to_dict(), column_map, hidden_columns, + ) _formatters = { diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index c1f46d2d99..becb54f456 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -31,7 +31,6 @@ from osc_lib import exceptions from osc_lib import utils from openstackclient.common import progressbar -from openstackclient.common import sdk_utils from openstackclient.i18n import _ from openstackclient.identity import common @@ -99,13 +98,13 @@ _formatters = { def _get_member_columns(item): - # Trick sdk_utils to return URI attribute column_map = { 'image_id': 'image_id' } hidden_columns = ['id', 'location', 'name'] - return sdk_utils.get_osc_show_columns_for_sdk_resource( - item.to_dict(), column_map, hidden_columns) + return utils.get_osc_show_columns_for_sdk_resource( + item.to_dict(), column_map, hidden_columns, + ) def get_data_file(args): diff --git a/openstackclient/network/sdk_utils.py b/openstackclient/network/sdk_utils.py deleted file mode 100644 index cff3071354..0000000000 --- a/openstackclient/network/sdk_utils.py +++ /dev/null @@ -1,63 +0,0 @@ -# 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. - -import munch - - -def get_osc_show_columns_for_sdk_resource( - sdk_resource, - osc_column_map, - invisible_columns=None -): - """Get and filter the display and attribute columns for an SDK resource. - - Common utility function for preparing the output of an OSC show command. - Some of the columns may need to get renamed, others made invisible. - - :param sdk_resource: An SDK resource - :param osc_column_map: A hash of mappings for display column names - :param invisible_columns: A list of invisible column names - - :returns: Two tuples containing the names of the display and attribute - columns - """ - - if getattr(sdk_resource, 'allow_get', None) is not None: - resource_dict = sdk_resource.to_dict( - body=True, headers=False, ignore_none=False) - else: - resource_dict = sdk_resource - - # Build the OSC column names to display for the SDK resource. - attr_map = {} - display_columns = list(resource_dict.keys()) - for col_name in display_columns: - if isinstance(resource_dict[col_name], munch.Munch): - display_columns.remove(col_name) - invisible_columns = [] if invisible_columns is None else invisible_columns - for col_name in invisible_columns: - if col_name in display_columns: - display_columns.remove(col_name) - for sdk_attr, osc_attr in osc_column_map.items(): - if sdk_attr in display_columns: - attr_map[osc_attr] = sdk_attr - display_columns.remove(sdk_attr) - if osc_attr not in display_columns: - display_columns.append(osc_attr) - sorted_display_columns = sorted(display_columns) - - # Build the SDK attribute names for the OSC column names. - attr_columns = [] - for column in sorted_display_columns: - new_column = attr_map[column] if column in attr_map else column - attr_columns.append(new_column) - return tuple(sorted_display_columns), tuple(attr_columns) diff --git a/openstackclient/network/v2/address_group.py b/openstackclient/network/v2/address_group.py index fc83470053..9017047fac 100644 --- a/openstackclient/network/v2/address_group.py +++ b/openstackclient/network/v2/address_group.py @@ -23,8 +23,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -33,7 +31,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _format_addresses(addresses): diff --git a/openstackclient/network/v2/address_scope.py b/openstackclient/network/v2/address_scope.py index cd27678ee9..5748793a57 100644 --- a/openstackclient/network/v2/address_scope.py +++ b/openstackclient/network/v2/address_scope.py @@ -22,8 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -33,7 +31,7 @@ def _get_columns(item): 'is_shared': 'shared', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index 25b2a1baf6..0951565cb6 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -19,7 +19,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils _formatters = { @@ -31,7 +30,7 @@ def _get_network_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_columns(item): diff --git a/openstackclient/network/v2/floating_ip_port_forwarding.py b/openstackclient/network/v2/floating_ip_port_forwarding.py index 71b0b7da63..f137174cf1 100644 --- a/openstackclient/network/v2/floating_ip_port_forwarding.py +++ b/openstackclient/network/v2/floating_ip_port_forwarding.py @@ -12,6 +12,7 @@ # """Floating IP Port Forwarding action implementations""" + import logging from osc_lib.command import command @@ -20,8 +21,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -30,7 +29,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) class CreateFloatingIPPortForwarding(command.ShowOne, diff --git a/openstackclient/network/v2/ip_availability.py b/openstackclient/network/v2/ip_availability.py index ddc88e557e..6a3c67e21b 100644 --- a/openstackclient/network/v2/ip_availability.py +++ b/openstackclient/network/v2/ip_availability.py @@ -19,7 +19,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common -from openstackclient.network import sdk_utils _formatters = { 'subnet_ip_availability': format_columns.ListDictColumn, @@ -30,7 +29,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) # TODO(ankur-gupta-f): Use the SDK resource mapped attribute names once diff --git a/openstackclient/network/v2/l3_conntrack_helper.py b/openstackclient/network/v2/l3_conntrack_helper.py index 94788823ab..9fc33d8f15 100644 --- a/openstackclient/network/v2/l3_conntrack_helper.py +++ b/openstackclient/network/v2/l3_conntrack_helper.py @@ -20,15 +20,13 @@ from osc_lib import exceptions from osc_lib import utils from openstackclient.i18n import _ -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) def _get_columns(item): column_map = {} - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client, parsed_args): diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index b8eb9f014b..191e4aa8e2 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -21,7 +21,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils class AdminStateColumn(cliff_columns.FormattableColumn): @@ -62,14 +61,14 @@ def _get_columns_network(item): 'tenant_id': 'project_id', 'tags': 'tags', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_columns_compute(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs_network(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py index 1678485434..c995e36cb8 100644 --- a/openstackclient/network/v2/network_agent.py +++ b/openstackclient/network/v2/network_agent.py @@ -22,8 +22,6 @@ from osc_lib import exceptions from osc_lib import utils from openstackclient.i18n import _ -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -52,7 +50,7 @@ def _get_network_columns(item): 'is_admin_state_up': 'admin_state_up', 'is_alive': 'alive', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) class AddNetworkToAgent(command.Command): diff --git a/openstackclient/network/v2/network_auto_allocated_topology.py b/openstackclient/network/v2/network_auto_allocated_topology.py index 36f392006e..7b7df4d75c 100644 --- a/openstackclient/network/v2/network_auto_allocated_topology.py +++ b/openstackclient/network/v2/network_auto_allocated_topology.py @@ -20,7 +20,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common -from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) @@ -29,7 +28,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _format_check_resource_columns(): diff --git a/openstackclient/network/v2/network_flavor.py b/openstackclient/network/v2/network_flavor.py index 9e758ae29c..6e3a5a0432 100644 --- a/openstackclient/network/v2/network_flavor.py +++ b/openstackclient/network/v2/network_flavor.py @@ -22,8 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -34,7 +32,7 @@ def _get_columns(item): 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_flavor_profile.py b/openstackclient/network/v2/network_flavor_profile.py index 0212e0d9ba..df7cfb7430 100644 --- a/openstackclient/network/v2/network_flavor_profile.py +++ b/openstackclient/network/v2/network_flavor_profile.py @@ -20,8 +20,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -32,7 +30,7 @@ def _get_columns(item): 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_meter.py b/openstackclient/network/v2/network_meter.py index f8f188a806..8b63de2c7a 100644 --- a/openstackclient/network/v2/network_meter.py +++ b/openstackclient/network/v2/network_meter.py @@ -22,7 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) @@ -32,7 +31,7 @@ def _get_columns(item): 'is_shared': 'shared', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_meter_rule.py b/openstackclient/network/v2/network_meter_rule.py index 06362fa14c..4117d04342 100644 --- a/openstackclient/network/v2/network_meter_rule.py +++ b/openstackclient/network/v2/network_meter_rule.py @@ -22,7 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) @@ -31,7 +30,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_qos_policy.py b/openstackclient/network/v2/network_qos_policy.py index 7300a5c0ac..8d4312484b 100644 --- a/openstackclient/network/v2/network_qos_policy.py +++ b/openstackclient/network/v2/network_qos_policy.py @@ -22,8 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -33,7 +31,7 @@ def _get_columns(item): 'is_shared': 'shared', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_qos_rule.py b/openstackclient/network/v2/network_qos_rule.py index f30a5aeb1f..4bf72d269a 100644 --- a/openstackclient/network/v2/network_qos_rule.py +++ b/openstackclient/network/v2/network_qos_rule.py @@ -21,8 +21,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.network import common -from openstackclient.network import sdk_utils - RULE_TYPE_BANDWIDTH_LIMIT = 'bandwidth-limit' RULE_TYPE_DSCP_MARKING = 'dscp-marking' @@ -51,7 +49,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _check_type_parameters(attrs, type, is_create): diff --git a/openstackclient/network/v2/network_qos_rule_type.py b/openstackclient/network/v2/network_qos_rule_type.py index 7b92c8ad4b..036b682fae 100644 --- a/openstackclient/network/v2/network_qos_rule_type.py +++ b/openstackclient/network/v2/network_qos_rule_type.py @@ -17,7 +17,6 @@ from osc_lib.command import command from osc_lib import utils from openstackclient.i18n import _ -from openstackclient.network import sdk_utils def _get_columns(item): @@ -26,7 +25,7 @@ def _get_columns(item): "drivers": "drivers", } invisible_columns = ["id", "name"] - return sdk_utils.get_osc_show_columns_for_sdk_resource( + return utils.get_osc_show_columns_for_sdk_resource( item, column_map, invisible_columns) diff --git a/openstackclient/network/v2/network_rbac.py b/openstackclient/network/v2/network_rbac.py index 692a43857d..edca872cf2 100644 --- a/openstackclient/network/v2/network_rbac.py +++ b/openstackclient/network/v2/network_rbac.py @@ -22,8 +22,6 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -33,7 +31,7 @@ def _get_columns(item): 'target_tenant': 'target_project_id', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _get_attrs(client_manager, parsed_args): diff --git a/openstackclient/network/v2/network_segment.py b/openstackclient/network/v2/network_segment.py index 14a8edabe5..e18ac47529 100644 --- a/openstackclient/network/v2/network_segment.py +++ b/openstackclient/network/v2/network_segment.py @@ -21,14 +21,12 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) def _get_columns(item): - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, {}) + return utils.get_osc_show_columns_for_sdk_resource(item, {}) class CreateNetworkSegment(command.ShowOne, diff --git a/openstackclient/network/v2/network_segment_range.py b/openstackclient/network/v2/network_segment_range.py index ee414407ee..e105111dd0 100644 --- a/openstackclient/network/v2/network_segment_range.py +++ b/openstackclient/network/v2/network_segment_range.py @@ -26,14 +26,13 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) def _get_columns(item): - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, {}) + return utils.get_osc_show_columns_for_sdk_resource(item, {}) def _get_ranges(item): diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index ecb2382a85..132c384a0e 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -29,8 +29,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -67,7 +65,7 @@ def _get_columns(item): 'is_port_security_enabled': 'port_security_enabled', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) class JSONKeyValueAction(argparse.Action): diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index d15300a0b7..dde4eda99f 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -28,8 +28,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -83,7 +81,7 @@ def _get_columns(item): if item.is_distributed is None: invisible_columns.append('is_distributed') column_map.pop('is_distributed') - return sdk_utils.get_osc_show_columns_for_sdk_resource( + return utils.get_osc_show_columns_for_sdk_resource( item, column_map, invisible_columns) diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 49dc14e403..37d2dc5be0 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -23,7 +23,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils from openstackclient.network import utils as network_utils @@ -90,7 +89,7 @@ def _get_columns(item): 'security_group_rules': 'rules', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) # TODO(abhiraut): Use the SDK resource mapped attribute names once the diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py index e273ded3d6..252dcb05a8 100644 --- a/openstackclient/network/v2/security_group_rule.py +++ b/openstackclient/network/v2/security_group_rule.py @@ -23,10 +23,8 @@ from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils from openstackclient.network import utils as network_utils - LOG = logging.getLogger(__name__) @@ -76,7 +74,7 @@ def _get_columns(item): column_map = { 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) def _convert_to_lowercase(string): diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index 09fd7c7c39..c07fab4170 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -27,8 +27,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils - LOG = logging.getLogger(__name__) @@ -143,7 +141,7 @@ def _get_columns(item): } # Do not show this column when displaying a subnet invisible_columns = ['use_default_subnet_pool', 'prefix_length'] - return sdk_utils.get_osc_show_columns_for_sdk_resource( + return utils.get_osc_show_columns_for_sdk_resource( item, column_map, invisible_columns=invisible_columns diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index bdf7aba805..6b88888c0e 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -25,7 +25,6 @@ from osc_lib.utils import tags as _tag from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common -from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) @@ -39,7 +38,7 @@ def _get_columns(item): 'minimum_prefix_length': 'min_prefixlen', 'tenant_id': 'project_id', } - return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) + return utils.get_osc_show_columns_for_sdk_resource(item, column_map) _formatters = { diff --git a/openstackclient/tests/unit/network/test_sdk_utils.py b/openstackclient/tests/unit/network/test_sdk_utils.py deleted file mode 100644 index d1efa7e40a..0000000000 --- a/openstackclient/tests/unit/network/test_sdk_utils.py +++ /dev/null @@ -1,59 +0,0 @@ -# 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 openstackclient.network import sdk_utils -from openstackclient.tests.unit import utils as tests_utils - - -class TestSDKUtils(tests_utils.TestCase): - - def setUp(self): - super(TestSDKUtils, self).setUp() - - def _test_get_osc_show_columns_for_sdk_resource( - self, sdk_resource, column_map, - expected_display_columns, expected_attr_columns): - display_columns, attr_columns = \ - sdk_utils.get_osc_show_columns_for_sdk_resource( - sdk_resource, column_map) - self.assertEqual(expected_display_columns, display_columns) - self.assertEqual(expected_attr_columns, attr_columns) - - def test_get_osc_show_columns_for_sdk_resource_empty(self): - self._test_get_osc_show_columns_for_sdk_resource( - {}, {}, tuple(), tuple()) - - def test_get_osc_show_columns_for_sdk_resource_empty_map(self): - self._test_get_osc_show_columns_for_sdk_resource( - {'foo': 'foo1'}, {}, - ('foo',), ('foo',)) - - def test_get_osc_show_columns_for_sdk_resource_empty_data(self): - self._test_get_osc_show_columns_for_sdk_resource( - {}, {'foo': 'foo_map'}, - ('foo_map',), ('foo_map',)) - - def test_get_osc_show_columns_for_sdk_resource_map(self): - self._test_get_osc_show_columns_for_sdk_resource( - {'foo': 'foo1'}, {'foo': 'foo_map'}, - ('foo_map',), ('foo',)) - - def test_get_osc_show_columns_for_sdk_resource_map_dup(self): - self._test_get_osc_show_columns_for_sdk_resource( - {'foo': 'foo1', 'foo_map': 'foo1'}, {'foo': 'foo_map'}, - ('foo_map',), ('foo',)) - - def test_get_osc_show_columns_for_sdk_resource_map_full(self): - self._test_get_osc_show_columns_for_sdk_resource( - {'foo': 'foo1', 'bar': 'bar1'}, - {'foo': 'foo_map', 'new': 'bar'}, - ('bar', 'foo_map'), ('bar', 'foo'))