diff options
| author | lihaijing <lihaijing@fiberhome.com> | 2017-07-07 11:48:48 +0800 |
|---|---|---|
| committer | Akihiro Motoki <amotoki@gmail.com> | 2020-01-09 18:41:29 +0900 |
| commit | d15bbada73f81136c966007d9c564dd6cfb2fd9c (patch) | |
| tree | 63f42d709601bd2adbc0863adedd5dc732e1579d /openstackclient/compute | |
| parent | 4b575083b7979473b9c83eb01a520d5bacb88dc3 (diff) | |
| download | python-openstackclient-d15bbada73f81136c966007d9c564dd6cfb2fd9c.tar.gz | |
Replace six.iteritems() with .items()
1. As mentioned in [1], we should avoid using six.iteritems to achieve
iterators. We can use dict.items instead, as it will return iterators
in PY3 as well. And dict.items/keys will more readable.
2. In py2, the performance about list should be negligible,
see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: I4b9edb326444264c0f6c4ad281acaac356a07e85
Implements: blueprint replace-iteritems-with-items
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/agent.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/aggregate.py | 9 | ||||
| -rw-r--r-- | openstackclient/compute/v2/console.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/flavor.py | 5 | ||||
| -rw-r--r-- | openstackclient/compute/v2/hypervisor.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/hypervisor_stats.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/keypair.py | 5 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server.py | 6 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_backup.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_event.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_image.py | 3 | ||||
| -rw-r--r-- | openstackclient/compute/v2/usage.py | 3 |
12 files changed, 19 insertions, 30 deletions
diff --git a/openstackclient/compute/v2/agent.py b/openstackclient/compute/v2/agent.py index 151dcc1e..3feb99ec 100644 --- a/openstackclient/compute/v2/agent.py +++ b/openstackclient/compute/v2/agent.py @@ -20,7 +20,6 @@ import logging from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from openstackclient.i18n import _ @@ -77,7 +76,7 @@ class CreateAgent(command.ShowOne): parsed_args.hypervisor ) agent = compute_client.agents.create(*args)._info.copy() - return zip(*sorted(six.iteritems(agent))) + return zip(*sorted(agent.items())) class DeleteAgent(command.Command): diff --git a/openstackclient/compute/v2/aggregate.py b/openstackclient/compute/v2/aggregate.py index 3834de1f..599659a3 100644 --- a/openstackclient/compute/v2/aggregate.py +++ b/openstackclient/compute/v2/aggregate.py @@ -23,7 +23,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from openstackclient.i18n import _ @@ -68,7 +67,7 @@ class AddAggregateHost(command.ShowOne): 'properties': format_columns.DictColumn(info.pop('metadata')), }, ) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class CreateAggregate(command.ShowOne): @@ -125,7 +124,7 @@ class CreateAggregate(command.ShowOne): 'properties': properties, }, ) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class DeleteAggregate(command.Command): @@ -255,7 +254,7 @@ class RemoveAggregateHost(command.ShowOne): 'properties': format_columns.DictColumn(info.pop('metadata')), }, ) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class SetAggregate(command.Command): @@ -372,7 +371,7 @@ class ShowAggregate(command.ShowOne): info = {} info.update(data._info) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class UnsetAggregate(command.Command): diff --git a/openstackclient/compute/v2/console.py b/openstackclient/compute/v2/console.py index b2f7288f..110b21b8 100644 --- a/openstackclient/compute/v2/console.py +++ b/openstackclient/compute/v2/console.py @@ -18,7 +18,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import utils -import six from openstackclient.i18n import _ @@ -138,4 +137,4 @@ class ShowConsoleURL(command.ShowOne): # handle for different microversion API. console_data = data.get('remote_console', data.get('console')) info.update(console_data) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 4f1e48af..42649db5 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -22,7 +22,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from openstackclient.i18n import _ from openstackclient.identity import common as identity_common @@ -195,7 +194,7 @@ class CreateFlavor(command.ShowOne): flavor_info.pop("links") flavor_info['properties'] = utils.format_dict(flavor.get_keys()) - return zip(*sorted(six.iteritems(flavor_info))) + return zip(*sorted(flavor_info.items())) class DeleteFlavor(command.Command): @@ -447,7 +446,7 @@ class ShowFlavor(command.ShowOne): flavor['properties'] = utils.format_dict(resource_flavor.get_keys()) - return zip(*sorted(six.iteritems(flavor))) + return zip(*sorted(flavor.items())) class UnsetFlavor(command.Command): diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py index 0d367fee..7f110028 100644 --- a/openstackclient/compute/v2/hypervisor.py +++ b/openstackclient/compute/v2/hypervisor.py @@ -20,7 +20,6 @@ import re from novaclient import exceptions as nova_exceptions from osc_lib.command import command from osc_lib import utils -import six from openstackclient.i18n import _ @@ -126,4 +125,4 @@ class ShowHypervisor(command.ShowOne): hypervisor["service_host"] = hypervisor["service"]["host"] del hypervisor["service"] - return zip(*sorted(six.iteritems(hypervisor))) + return zip(*sorted(hypervisor.items())) diff --git a/openstackclient/compute/v2/hypervisor_stats.py b/openstackclient/compute/v2/hypervisor_stats.py index b0413005..4493e080 100644 --- a/openstackclient/compute/v2/hypervisor_stats.py +++ b/openstackclient/compute/v2/hypervisor_stats.py @@ -15,7 +15,6 @@ """Hypervisor Stats action implementations""" from osc_lib.command import command -import six from openstackclient.i18n import _ @@ -27,4 +26,4 @@ class ShowHypervisorStats(command.ShowOne): compute_client = self.app.client_manager.compute hypervisor_stats = compute_client.hypervisors.statistics().to_dict() - return zip(*sorted(six.iteritems(hypervisor_stats))) + return zip(*sorted(hypervisor_stats.items())) diff --git a/openstackclient/compute/v2/keypair.py b/openstackclient/compute/v2/keypair.py index 851cced0..2b365ceb 100644 --- a/openstackclient/compute/v2/keypair.py +++ b/openstackclient/compute/v2/keypair.py @@ -23,7 +23,6 @@ import sys from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from openstackclient.i18n import _ @@ -101,7 +100,7 @@ class CreateKeypair(command.ShowOne): del info['public_key'] if 'private_key' in info: del info['private_key'] - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) else: sys.stdout.write(keypair.private_key) return ({}, {}) @@ -184,7 +183,7 @@ class ShowKeypair(command.ShowOne): info.update(keypair._info) if not parsed_args.public_key: del info['public_key'] - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) else: # NOTE(dtroyer): a way to get the public key in a similar form # as the private key in the create command diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 84061a53..b5c420fe 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1069,7 +1069,7 @@ class CreateServer(command.ShowOne): raise SystemExit details = _prep_server_detail(compute_client, image_client, server) - return zip(*sorted(six.iteritems(details))) + return zip(*sorted(details.items())) class CreateServerDump(command.Command): @@ -1967,7 +1967,7 @@ class RebuildServer(command.ShowOne): details = _prep_server_detail(compute_client, image_client, server, refresh=False) - return zip(*sorted(six.iteritems(details))) + return zip(*sorted(details.items())) class RemoveFixedIP(command.Command): @@ -2537,7 +2537,7 @@ class ShowServer(command.ShowOne): self.app.client_manager.image, server, refresh=False) - return zip(*sorted(six.iteritems(data))) + return zip(*sorted(data.items())) class SshServer(command.Command): diff --git a/openstackclient/compute/v2/server_backup.py b/openstackclient/compute/v2/server_backup.py index a79f5f70..1d560dc0 100644 --- a/openstackclient/compute/v2/server_backup.py +++ b/openstackclient/compute/v2/server_backup.py @@ -19,7 +19,6 @@ from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils from oslo_utils import importutils -import six from openstackclient.i18n import _ @@ -129,4 +128,4 @@ class CreateServerBackup(command.ShowOne): ] ) info = image_module._format_image(image) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) diff --git a/openstackclient/compute/v2/server_event.py b/openstackclient/compute/v2/server_event.py index 6d33d02d..4fcc9136 100644 --- a/openstackclient/compute/v2/server_event.py +++ b/openstackclient/compute/v2/server_event.py @@ -19,7 +19,6 @@ import logging from osc_lib.command import command from osc_lib import utils -import six from openstackclient.i18n import _ @@ -122,4 +121,4 @@ class ShowServerEvent(command.ShowOne): action_detail = compute_client.instance_action.get( server_id, parsed_args.request_id) - return zip(*sorted(six.iteritems(action_detail.to_dict()))) + return zip(*sorted(action_detail.to_dict().items())) diff --git a/openstackclient/compute/v2/server_image.py b/openstackclient/compute/v2/server_image.py index 3bc5d94a..b93cd4d8 100644 --- a/openstackclient/compute/v2/server_image.py +++ b/openstackclient/compute/v2/server_image.py @@ -21,7 +21,6 @@ from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils from oslo_utils import importutils -import six from openstackclient.i18n import _ @@ -109,4 +108,4 @@ class CreateServerImage(command.ShowOne): ] ) info = image_module._format_image(image) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py index f84cd61d..307c238a 100644 --- a/openstackclient/compute/v2/usage.py +++ b/openstackclient/compute/v2/usage.py @@ -21,7 +21,6 @@ import datetime from novaclient import api_versions from osc_lib.command import command from osc_lib import utils -import six from openstackclient.i18n import _ @@ -236,4 +235,4 @@ class ShowUsage(command.ShowOne): info['Disk GB-Hours'] = ( float("%.2f" % usage.total_local_gb_usage) if hasattr(usage, "total_local_gb_usage") else None) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) |
