[2/3]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 The patch list: 1. cells. 2. compute api. 3. image. 4. network. 5. objects. 6. scheduler. 7. virt. 8. other resources. Partial-Implements: blueprint replace-iteritems-with-items Change-Id: Ic6e469eb80ee1774de1374bb36f38b5134b6b311
This commit is contained in:
parent
f55815b2f9
commit
70730c09ab
@ -17,7 +17,7 @@ import re
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
@ -89,11 +89,11 @@ class BlockDeviceDict(dict):
|
||||
bdm_dict.get('delete_on_termination'))
|
||||
# NOTE (ndipanov): Never default db fields
|
||||
self.update({field: None for field in self._fields - do_not_default})
|
||||
self.update(list(six.iteritems(bdm_dict)))
|
||||
self.update(bdm_dict.items())
|
||||
|
||||
def _validate(self, bdm_dict):
|
||||
"""Basic data format validations."""
|
||||
dict_fields = set(key for key, _ in six.iteritems(bdm_dict))
|
||||
dict_fields = set(key for key, _ in bdm_dict.items())
|
||||
|
||||
# Check that there are no bogus fields
|
||||
if not (dict_fields <=
|
||||
@ -139,7 +139,7 @@ class BlockDeviceDict(dict):
|
||||
non_computable_fields = set(['boot_index', 'disk_bus',
|
||||
'guest_format', 'device_type'])
|
||||
|
||||
new_bdm = {fld: val for fld, val in six.iteritems(legacy_bdm)
|
||||
new_bdm = {fld: val for fld, val in legacy_bdm.items()
|
||||
if fld in copy_over_fields}
|
||||
|
||||
virt_name = legacy_bdm.get('virtual_name')
|
||||
|
@ -23,7 +23,7 @@ from oslo_log import log as logging
|
||||
import oslo_messaging
|
||||
from oslo_service import periodic_task
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from nova.cells import messaging
|
||||
@ -386,7 +386,7 @@ class CellsManager(manager.Manager):
|
||||
totals = {}
|
||||
for response in responses:
|
||||
data = response.value_or_raise()
|
||||
for key, val in six.iteritems(data):
|
||||
for key, val in data.items():
|
||||
totals.setdefault(key, 0)
|
||||
totals[key] += val
|
||||
return totals
|
||||
|
@ -1116,7 +1116,7 @@ class _BroadcastMessageMethods(_BaseMessageMethods):
|
||||
services = objects.ServiceList.get_all(message.ctxt, disabled=disabled)
|
||||
ret_services = []
|
||||
for service in services:
|
||||
for key, val in six.iteritems(filters):
|
||||
for key, val in filters.items():
|
||||
if getattr(service, key) != val:
|
||||
break
|
||||
else:
|
||||
@ -1259,7 +1259,7 @@ class MessageRunner(object):
|
||||
self.response_queues = {}
|
||||
self.methods_by_type = {}
|
||||
self.our_name = CONF.cells.name
|
||||
for msg_type, cls in six.iteritems(_CELL_MESSAGE_TYPE_TO_METHODS_CLS):
|
||||
for msg_type, cls in _CELL_MESSAGE_TYPE_TO_METHODS_CLS.items():
|
||||
self.methods_by_type[msg_type] = cls(self)
|
||||
self.serializer = objects_base.NovaObjectSerializer()
|
||||
|
||||
|
@ -63,7 +63,7 @@ class CellState(object):
|
||||
|
||||
def update_db_info(self, cell_db_info):
|
||||
"""Update cell credentials from db."""
|
||||
self.db_info = {k: v for k, v in six.iteritems(cell_db_info)
|
||||
self.db_info = {k: v for k, v in cell_db_info.items()
|
||||
if k != 'name'}
|
||||
|
||||
def update_capabilities(self, cell_metadata):
|
||||
|
@ -68,7 +68,7 @@ import oslo_messaging as messaging
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import uuidutils
|
||||
import prettytable
|
||||
import six
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from nova.api.ec2 import ec2utils
|
||||
@ -263,7 +263,7 @@ class ProjectCommands(object):
|
||||
quota = QUOTAS.get_user_quotas(ctxt, project_id, user_id)
|
||||
else:
|
||||
quota = QUOTAS.get_project_quotas(ctxt, project_id)
|
||||
for key, value in six.iteritems(quota):
|
||||
for key, value in quota.items():
|
||||
if value['limit'] is None or value['limit'] < 0:
|
||||
value['limit'] = 'unlimited'
|
||||
print(print_format % (key, value['limit'], value['in_use'],
|
||||
@ -455,7 +455,7 @@ class NetworkCommands(object):
|
||||
if not (cidr or cidr_v6):
|
||||
raise exception.NetworkNotCreated(req="cidr or cidr_v6")
|
||||
|
||||
kwargs = {k: v for k, v in six.iteritems(locals())
|
||||
kwargs = {k: v for k, v in locals().items()
|
||||
if v and k != "self"}
|
||||
if multi_host is not None:
|
||||
kwargs['multi_host'] = multi_host == 'T'
|
||||
@ -710,7 +710,7 @@ class DbCommands(object):
|
||||
"""
|
||||
hits = migration.db_null_instance_uuid_scan(delete)
|
||||
records_found = False
|
||||
for table_name, records in six.iteritems(hits):
|
||||
for table_name, records in hits.items():
|
||||
# Don't print anything for 0 hits
|
||||
if records:
|
||||
records_found = True
|
||||
@ -862,7 +862,7 @@ class AgentBuildCommands(object):
|
||||
|
||||
buildlist.append(agent_build)
|
||||
|
||||
for key, buildlist in six.iteritems(by_hypervisor):
|
||||
for key, buildlist in by_hypervisor.items():
|
||||
if hypervisor and key != hypervisor:
|
||||
continue
|
||||
|
||||
|
@ -392,7 +392,7 @@ class API(base.Base):
|
||||
# as if this is quota-controlled for forwards compatibility.
|
||||
# Those are only used in V2 API, from V2.1 API, those checks are
|
||||
# validated at API layer schema validation.
|
||||
for k, v in six.iteritems(metadata):
|
||||
for k, v in metadata.items():
|
||||
try:
|
||||
utils.check_string_length(v)
|
||||
utils.check_string_length(k, min_length=1)
|
||||
@ -2350,7 +2350,7 @@ class API(base.Base):
|
||||
'system_metadata': _remap_system_metadata_filter}
|
||||
|
||||
# copy from search_opts, doing various remappings as necessary
|
||||
for opt, value in six.iteritems(search_opts):
|
||||
for opt, value in search_opts.items():
|
||||
# Do remappings.
|
||||
# Values not in the filter_mapping table are copied as-is.
|
||||
# If remapping is None, option is not copied
|
||||
@ -4115,7 +4115,7 @@ class HostAPI(base.Base):
|
||||
set_zones=set_zones)
|
||||
ret_services = []
|
||||
for service in services:
|
||||
for key, val in six.iteritems(filters):
|
||||
for key, val in filters.items():
|
||||
if service[key] != val:
|
||||
break
|
||||
else:
|
||||
|
@ -2742,7 +2742,7 @@ def _instance_update(context, instance_uuid, values, expected, original=None):
|
||||
else:
|
||||
# Coerce all single values to singleton lists
|
||||
expected = {k: [None] if v is None else sqlalchemyutils.to_list(v)
|
||||
for (k, v) in six.iteritems(expected)}
|
||||
for (k, v) in expected.items()}
|
||||
|
||||
# Extract 'expected_' values from values dict, as these aren't actually
|
||||
# updates
|
||||
@ -2798,7 +2798,7 @@ def _instance_update(context, instance_uuid, values, expected, original=None):
|
||||
|
||||
conflicts_expected = {}
|
||||
conflicts_actual = {}
|
||||
for (field, expected_values) in six.iteritems(expected):
|
||||
for (field, expected_values) in expected.items():
|
||||
actual = original[field]
|
||||
if actual not in expected_values:
|
||||
conflicts_expected[field] = expected_values
|
||||
|
@ -23,7 +23,7 @@ SHOULD include dedicated exception logging.
|
||||
"""
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
import webob.exc
|
||||
from webob import util as woutil
|
||||
|
||||
@ -89,7 +89,7 @@ class NovaException(Exception):
|
||||
# kwargs doesn't match a variable in the message
|
||||
# log the issue and the kwargs
|
||||
LOG.exception(_LE('Exception in string format operation'))
|
||||
for name, value in six.iteritems(kwargs):
|
||||
for name, value in kwargs.items():
|
||||
LOG.error("%s: %s" % (name, value)) # noqa
|
||||
|
||||
message = self.msg_fmt
|
||||
|
@ -14,7 +14,7 @@ import functools
|
||||
import inspect
|
||||
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
from nova.notifications.objects import base
|
||||
@ -91,4 +91,4 @@ def _get_call_dict(function, self, context, *args, **kw):
|
||||
|
||||
def _cleanse_dict(original):
|
||||
"""Strip all admin_password, new_pass, rescue_pass keys from a dict."""
|
||||
return {k: v for k, v in six.iteritems(original) if "_pass" not in k}
|
||||
return {k: v for k, v in original.items() if "_pass" not in k}
|
||||
|
@ -731,7 +731,7 @@ def check_doubled_words(physical_line, filename):
|
||||
|
||||
|
||||
def check_python3_no_iteritems(logical_line):
|
||||
msg = ("N344: Use six.iteritems() instead of dict.iteritems().")
|
||||
msg = ("N344: Use items() instead of dict.iteritems().")
|
||||
|
||||
if re.search(r".*\.iteritems\(\)", logical_line):
|
||||
yield(0, msg)
|
||||
|
@ -201,7 +201,7 @@ class GlanceImageService(object):
|
||||
self._download_handlers = {}
|
||||
download_modules = image_xfers.load_transfer_modules()
|
||||
|
||||
for scheme, mod in six.iteritems(download_modules):
|
||||
for scheme, mod in download_modules.items():
|
||||
if scheme not in CONF.glance.allowed_direct_url_schemes:
|
||||
continue
|
||||
|
||||
@ -436,7 +436,7 @@ class GlanceImageServiceV2(object):
|
||||
self._download_handlers = {}
|
||||
download_modules = image_xfers.load_transfer_modules()
|
||||
|
||||
for scheme, mod in six.iteritems(download_modules):
|
||||
for scheme, mod in download_modules.items():
|
||||
if scheme not in CONF.glance.allowed_direct_url_schemes:
|
||||
continue
|
||||
|
||||
@ -875,9 +875,9 @@ def _translate_to_glance(image_meta):
|
||||
|
||||
def _convert_to_v2(image_meta):
|
||||
output = {}
|
||||
for name, value in six.iteritems(image_meta):
|
||||
for name, value in image_meta.items():
|
||||
if name == 'properties':
|
||||
for prop_name, prop_value in six.iteritems(value):
|
||||
for prop_name, prop_value in value.items():
|
||||
# if allow_additional_image_properties is disabled we can't
|
||||
# define kernel_id and ramdisk_id as None, so we have to omit
|
||||
# these properties if they are not set.
|
||||
@ -1018,7 +1018,7 @@ def _extract_attributes_v2(image, include_locations=False):
|
||||
output = {'properties': {}, 'deleted': False, 'deleted_at': None,
|
||||
'disk_format': None, 'container_format': None, 'name': None,
|
||||
'checksum': None}
|
||||
for name, value in six.iteritems(image):
|
||||
for name, value in image.items():
|
||||
if (name in omit_attrs
|
||||
or name in include_locations_attrs and not include_locations):
|
||||
continue
|
||||
|
@ -298,7 +298,7 @@ class IptablesManager(object):
|
||||
elif ip_version == 6:
|
||||
tables = self.ipv6
|
||||
|
||||
for table, chains in six.iteritems(builtin_chains[ip_version]):
|
||||
for table, chains in builtin_chains[ip_version].items():
|
||||
for chain in chains:
|
||||
tables[table].add_chain(chain)
|
||||
tables[table].add_rule(chain, '-j $%s' % (chain,),
|
||||
@ -365,7 +365,7 @@ class IptablesManager(object):
|
||||
run_as_root=True,
|
||||
attempts=5)
|
||||
all_lines = all_tables.split('\n')
|
||||
for table_name, table in six.iteritems(tables):
|
||||
for table_name, table in tables.items():
|
||||
start, end = self._find_table(all_lines, table_name)
|
||||
all_lines[start:end] = self._modify_rules(
|
||||
all_lines[start:end], table, table_name)
|
||||
|
@ -26,7 +26,7 @@ from nova import utils
|
||||
|
||||
def ensure_string_keys(d):
|
||||
# http://bugs.python.org/issue4978
|
||||
return {str(k): v for k, v in six.iteritems(d)}
|
||||
return {str(k): v for k, v in d.items()}
|
||||
|
||||
# Constants for the 'vif_type' field in VIF class
|
||||
VIF_TYPE_OVS = 'ovs'
|
||||
|
@ -1945,7 +1945,7 @@ class API(base_api.NetworkAPI):
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_LE('Unable to access floating IP for %s'),
|
||||
', '.join(['%s %s' % (k, v)
|
||||
for k, v in six.iteritems(kwargs)]))
|
||||
for k, v in kwargs.items()]))
|
||||
|
||||
def _get_floating_ip_by_address(self, client, address):
|
||||
"""Get floating IP from floating IP address."""
|
||||
|
@ -384,7 +384,7 @@ def image_meta(system_metadata):
|
||||
system metadata.
|
||||
"""
|
||||
image_meta = {}
|
||||
for md_key, md_value in six.iteritems(system_metadata):
|
||||
for md_key, md_value in system_metadata.items():
|
||||
if md_key.startswith('image_'):
|
||||
image_meta[md_key[6:]] = md_value
|
||||
|
||||
|
@ -228,7 +228,7 @@ class NovaObjectSerializer(messaging.NoOpSerializer):
|
||||
iterable = values.__class__
|
||||
if issubclass(iterable, dict):
|
||||
return iterable(**{k: action_fn(context, v)
|
||||
for k, v in six.iteritems(values)})
|
||||
for k, v in values.items()})
|
||||
else:
|
||||
# NOTE(danms, gibi) A set can't have an unhashable value inside,
|
||||
# such as a dict. Convert the set to list, which is fine, since we
|
||||
@ -306,7 +306,7 @@ def serialize_args(fn):
|
||||
def wrapper(obj, *args, **kwargs):
|
||||
args = [utils.strtime(arg) if isinstance(arg, datetime.datetime)
|
||||
else arg for arg in args]
|
||||
for k, v in six.iteritems(kwargs):
|
||||
for k, v in kwargs.items():
|
||||
if k == 'exc_val' and v:
|
||||
kwargs[k] = six.text_type(v)
|
||||
elif k == 'exc_tb' and v and not isinstance(v, six.string_types):
|
||||
|
@ -168,7 +168,7 @@ class BuildRequest(base.NovaObject):
|
||||
|
||||
def _get_update_primitives(self):
|
||||
updates = self.obj_get_changes()
|
||||
for key, value in six.iteritems(updates):
|
||||
for key, value in updates.items():
|
||||
if isinstance(self.fields[key], fields.ObjectField):
|
||||
updates[key] = jsonutils.dumps(value.obj_to_primitive())
|
||||
return updates
|
||||
|
@ -63,7 +63,7 @@ class PciDevicePool(base.NovaObject):
|
||||
def to_dict(self):
|
||||
pci_pool = base.obj_to_primitive(self)
|
||||
tags = pci_pool.pop('tags', {})
|
||||
for k, v in six.iteritems(tags):
|
||||
for k, v in tags.items():
|
||||
pci_pool[k] = v
|
||||
return pci_pool
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import versionutils
|
||||
import six
|
||||
|
||||
|
||||
from nova.db.sqlalchemy import api as db
|
||||
from nova.db.sqlalchemy import api_models
|
||||
@ -215,7 +215,7 @@ class RequestSpec(base.NovaObject):
|
||||
return
|
||||
self.scheduler_hints = {
|
||||
hint: value if isinstance(value, list) else [value]
|
||||
for hint, value in six.iteritems(hints_dict)}
|
||||
for hint, value in hints_dict.items()}
|
||||
|
||||
@classmethod
|
||||
def from_primitives(cls, context, request_spec, filter_properties):
|
||||
|
@ -571,7 +571,7 @@ class ResourceProviderList(base.ObjectListBase, base.NovaObject):
|
||||
# NOTE(sbauza): We want to key the dict by the resource class IDs
|
||||
# and we want to make sure those class names aren't incorrect.
|
||||
resources = {_RC_CACHE.id_from_string(r_name): amount
|
||||
for r_name, amount in six.iteritems(resources)}
|
||||
for r_name, amount in resources.items()}
|
||||
query = context.session.query(models.ResourceProvider)
|
||||
if name:
|
||||
query = query.filter(models.ResourceProvider.name == name)
|
||||
@ -665,7 +665,7 @@ class ResourceProviderList(base.ObjectListBase, base.NovaObject):
|
||||
_INV_TBL.c.max_unit >= amount,
|
||||
amount % _INV_TBL.c.step_size == 0
|
||||
)
|
||||
for (r_idx, amount) in six.iteritems(resources)]
|
||||
for (r_idx, amount) in resources.items()]
|
||||
query = query.filter(sa.or_(*where_clauses))
|
||||
query = query.group_by(_RP_TBL.c.uuid)
|
||||
# NOTE(sbauza): Only RPs having all the asked resources can be provided
|
||||
|
@ -287,7 +287,7 @@ class PciDeviceStats(object):
|
||||
# 'devices' shouldn't be part of stats
|
||||
pools = []
|
||||
for pool in self.pools:
|
||||
tmp = {k: v for k, v in six.iteritems(pool) if k != 'devices'}
|
||||
tmp = {k: v for k, v in pool.items() if k != 'devices'}
|
||||
pools.append(tmp)
|
||||
return iter(pools)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
import re
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _LW
|
||||
@ -49,7 +49,7 @@ def pci_device_prop_match(pci_dev, specs):
|
||||
|
||||
"""
|
||||
def _matching_devices(spec):
|
||||
return all(pci_dev.get(k) == v for k, v in six.iteritems(spec))
|
||||
return all(pci_dev.get(k) == v for k, v in spec.items())
|
||||
|
||||
return any(_matching_devices(spec) for spec in specs)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_policy import policy
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _LE, _LW
|
||||
@ -89,7 +89,7 @@ def _serialize_rules(rules):
|
||||
rules list.
|
||||
"""
|
||||
result = [(rule_name, str(rule))
|
||||
for rule_name, rule in six.iteritems(rules)]
|
||||
for rule_name, rule in rules.items()]
|
||||
return sorted(result, key=lambda rule: rule[0])
|
||||
|
||||
|
||||
|
@ -180,7 +180,7 @@ class DbQuotaDriver(object):
|
||||
# Use the project quota for default user quota.
|
||||
proj_quotas = project_quotas or db.quota_get_all_by_project(
|
||||
context, project_id)
|
||||
for key, value in six.iteritems(proj_quotas):
|
||||
for key, value in proj_quotas.items():
|
||||
if key not in user_quotas.keys():
|
||||
user_quotas[key] = value
|
||||
user_usages = None
|
||||
|
@ -14,7 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
from nova.i18n import _LW
|
||||
@ -44,7 +44,7 @@ class AggregateImagePropertiesIsolation(filters.BaseHostFilter):
|
||||
image_props = spec_obj.image.properties if spec_obj.image else {}
|
||||
metadata = utils.aggregate_metadata_get_by_host(host_state)
|
||||
|
||||
for key, options in six.iteritems(metadata):
|
||||
for key, options in metadata.items():
|
||||
if (cfg_namespace and
|
||||
not key.startswith(cfg_namespace + cfg_separator)):
|
||||
continue
|
||||
|
@ -15,7 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
|
||||
from nova.scheduler import filters
|
||||
from nova.scheduler.filters import extra_specs_ops
|
||||
@ -48,7 +48,7 @@ class AggregateInstanceExtraSpecsFilter(filters.BaseHostFilter):
|
||||
|
||||
metadata = utils.aggregate_metadata_get_by_host(host_state)
|
||||
|
||||
for key, req in six.iteritems(instance_type.extra_specs):
|
||||
for key, req in instance_type.extra_specs.items():
|
||||
# Either not scope format, or aggregate_instance_extra_specs scope
|
||||
scope = key.split(':', 1)
|
||||
if len(scope) > 1:
|
||||
|
@ -71,7 +71,7 @@ class ComputeCapabilitiesFilter(filters.BaseHostFilter):
|
||||
if 'extra_specs' not in instance_type:
|
||||
return True
|
||||
|
||||
for key, req in six.iteritems(instance_type.extra_specs):
|
||||
for key, req in instance_type.extra_specs.items():
|
||||
# Either not scope format, or in capabilities scope
|
||||
scope = key.split(':')
|
||||
# If key does not have a namespace, the scope's size is 1, check
|
||||
|
@ -336,7 +336,7 @@ class TestCase(testtools.TestCase):
|
||||
def flags(self, **kw):
|
||||
"""Override flag variables for a test."""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in six.iteritems(kw):
|
||||
for k, v in kw.items():
|
||||
CONF.set_override(k, v, group, enforce_type=True)
|
||||
|
||||
def start_service(self, name, host=None, **kwargs):
|
||||
|
@ -928,7 +928,7 @@ def metadata_to_dict(metadata, include_deleted=False):
|
||||
|
||||
def dict_to_metadata(metadata):
|
||||
result = []
|
||||
for key, value in six.iteritems(metadata):
|
||||
for key, value in metadata.items():
|
||||
result.append(dict(key=key, value=value))
|
||||
return result
|
||||
|
||||
@ -1133,7 +1133,7 @@ def get_system_metadata_from_image(image_meta, flavor=None):
|
||||
system_meta = {}
|
||||
prefix_format = SM_IMAGE_PROP_PREFIX + '%s'
|
||||
|
||||
for key, value in six.iteritems(image_meta.get('properties', {})):
|
||||
for key, value in image_meta.get('properties', {}).items():
|
||||
if key in SM_SKIP_KEYS:
|
||||
continue
|
||||
|
||||
@ -1164,7 +1164,7 @@ def get_image_from_system_metadata(system_meta):
|
||||
if not isinstance(system_meta, dict):
|
||||
system_meta = metadata_to_dict(system_meta, include_deleted=True)
|
||||
|
||||
for key, value in six.iteritems(system_meta):
|
||||
for key, value in system_meta.items():
|
||||
if value is None:
|
||||
continue
|
||||
|
||||
@ -1295,7 +1295,7 @@ def filter_and_format_resource_metadata(resource_type, resource_list,
|
||||
if ids and _get_id(resource) not in ids:
|
||||
return {}
|
||||
|
||||
for k, v in six.iteritems(input_metadata):
|
||||
for k, v in input_metadata.items():
|
||||
# Both keys and value defined -- AND
|
||||
if (keys_filter and values_filter and
|
||||
not _match_any(keys_filter, k) and
|
||||
|
@ -18,7 +18,7 @@ import itertools
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
|
||||
from nova import block_device
|
||||
import nova.conf
|
||||
@ -154,7 +154,7 @@ class DriverBlockDevice(dict):
|
||||
raise NotImplementedError()
|
||||
|
||||
def save(self):
|
||||
for attr_name, key_name in six.iteritems(self._update_on_save):
|
||||
for attr_name, key_name in self._update_on_save.items():
|
||||
lookup_name = key_name or attr_name
|
||||
if self[lookup_name] != getattr(self._bdm_obj, attr_name):
|
||||
setattr(self._bdm_obj, attr_name, self[lookup_name])
|
||||
@ -224,7 +224,7 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
|
||||
raise _InvalidType
|
||||
|
||||
self.update(
|
||||
{k: v for k, v in six.iteritems(self._bdm_obj)
|
||||
{k: v for k, v in self._bdm_obj.items()
|
||||
if k in self._new_fields | set(['delete_on_termination'])}
|
||||
)
|
||||
self['mount_device'] = self._bdm_obj.device_name
|
||||
|
@ -13,7 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
@ -174,7 +173,7 @@ class Diagnostics(object):
|
||||
|
||||
def serialize(self):
|
||||
s = {}
|
||||
for k, v in six.iteritems(self.__dict__):
|
||||
for k, v in self.__dict__.items():
|
||||
# Treat case of CpuDiagnostics, NicDiagnostics and
|
||||
# DiskDiagnostics - these are lists
|
||||
if isinstance(v, list):
|
||||
|
@ -21,7 +21,7 @@ Helper classes for Ironic HTTP PATCH creation.
|
||||
"""
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
|
||||
@ -91,7 +91,7 @@ class GenericDriverFields(object):
|
||||
# scan through the extra_specs values and ignore the keys
|
||||
# not starting with keyword 'capabilities'.
|
||||
|
||||
for key, val in six.iteritems(extra_specs):
|
||||
for key, val in extra_specs.items():
|
||||
if not key.startswith('capabilities:'):
|
||||
continue
|
||||
|
||||
|
@ -73,7 +73,7 @@ import itertools
|
||||
import operator
|
||||
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
|
||||
|
||||
from nova import block_device
|
||||
from nova import exception
|
||||
@ -646,7 +646,7 @@ def get_disk_info(virt_type, instance, image_meta,
|
||||
|
||||
|
||||
def get_boot_order(disk_info):
|
||||
boot_mapping = (info for name, info in six.iteritems(disk_info['mapping'])
|
||||
boot_mapping = (info for name, info in disk_info['mapping'].items()
|
||||
if name != 'root' and info.get('boot_index') is not None)
|
||||
boot_devs_dup = (BOOT_DEV_FOR_TYPE[dev['type']] for dev in
|
||||
sorted(boot_mapping,
|
||||
|
@ -19,7 +19,6 @@ This module provides helper APIs for populating the config.py
|
||||
classes based on common operational needs / policies
|
||||
"""
|
||||
|
||||
import six
|
||||
|
||||
from nova.pci import utils as pci_utils
|
||||
|
||||
@ -157,7 +156,7 @@ def set_vif_bandwidth_config(conf, inst_type):
|
||||
bandwidth_items = ['vif_inbound_average', 'vif_inbound_peak',
|
||||
'vif_inbound_burst', 'vif_outbound_average', 'vif_outbound_peak',
|
||||
'vif_outbound_burst']
|
||||
for key, value in six.iteritems(inst_type.get('extra_specs', {})):
|
||||
for key, value in inst_type.get('extra_specs', {}).items():
|
||||
scope = key.split(':')
|
||||
if len(scope) > 1 and scope[0] == 'quota':
|
||||
if scope[1] in bandwidth_items:
|
||||
|
@ -152,7 +152,7 @@ class Image(object):
|
||||
tune_items = ['disk_read_bytes_sec', 'disk_read_iops_sec',
|
||||
'disk_write_bytes_sec', 'disk_write_iops_sec',
|
||||
'disk_total_bytes_sec', 'disk_total_iops_sec']
|
||||
for key, value in six.iteritems(extra_specs):
|
||||
for key, value in extra_specs.items():
|
||||
scope = key.split(':')
|
||||
if len(scope) > 1 and scope[0] == 'quota':
|
||||
if scope[1] in tune_items:
|
||||
@ -337,7 +337,7 @@ class Image(object):
|
||||
with open(self.disk_info_path) as disk_info_file:
|
||||
line = disk_info_file.read().rstrip()
|
||||
dct = _dict_from_line(line)
|
||||
for path, driver_format in six.iteritems(dct):
|
||||
for path, driver_format in dct.items():
|
||||
if path == self.path:
|
||||
return driver_format
|
||||
driver_format = self._get_driver_format()
|
||||
|
@ -17,7 +17,7 @@
|
||||
"""Volume drivers for libvirt."""
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
@ -72,7 +72,7 @@ class LibvirtBaseVolumeDriver(object):
|
||||
'read_iops_sec', 'write_iops_sec']
|
||||
specs = data['qos_specs']
|
||||
if isinstance(specs, dict):
|
||||
for k, v in six.iteritems(specs):
|
||||
for k, v in specs.items():
|
||||
if k in tune_opts:
|
||||
new_key = 'disk_' + k
|
||||
setattr(conf, new_key, v)
|
||||
|
@ -28,7 +28,7 @@ from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import units
|
||||
from oslo_vmware import rw_handles
|
||||
import six
|
||||
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LI
|
||||
@ -173,7 +173,7 @@ class VMwareImage(object):
|
||||
'hw_vif_model': 'vif_model'
|
||||
}
|
||||
|
||||
for k, v in six.iteritems(props_map):
|
||||
for k, v in props_map.items():
|
||||
if properties.obj_attr_is_set(k):
|
||||
props[v] = properties.get(k)
|
||||
|
||||
|
@ -18,7 +18,7 @@ The VMware API utility module.
|
||||
"""
|
||||
|
||||
from oslo_vmware import vim_util as vutil
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
|
||||
@ -32,7 +32,7 @@ def object_to_dict(obj, list_depth=1):
|
||||
are converted.
|
||||
"""
|
||||
d = {}
|
||||
for k, v in six.iteritems(dict(obj)):
|
||||
for k, v in dict(obj).items():
|
||||
if hasattr(v, '__keylist__'):
|
||||
d[k] = object_to_dict(v, list_depth=list_depth)
|
||||
elif isinstance(v, list):
|
||||
|
@ -29,7 +29,7 @@ from oslo_vmware import exceptions as vexc
|
||||
from oslo_vmware.objects import datastore as ds_obj
|
||||
from oslo_vmware import pbm
|
||||
from oslo_vmware import vim_util as vutil
|
||||
import six
|
||||
|
||||
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
@ -592,7 +592,7 @@ def get_vm_extra_config_spec(client_factory, extra_opts):
|
||||
config_spec = client_factory.create('ns0:VirtualMachineConfigSpec')
|
||||
# add the key value pairs
|
||||
extra_config = []
|
||||
for key, value in six.iteritems(extra_opts):
|
||||
for key, value in extra_opts.items():
|
||||
opt = client_factory.create('ns0:OptionValue')
|
||||
opt.key = key
|
||||
opt.value = value
|
||||
|
@ -29,7 +29,7 @@ from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import units
|
||||
from oslo_utils import versionutils
|
||||
import six
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
import nova.conf
|
||||
@ -330,7 +330,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
# of mac addresses with values that are the bw counters:
|
||||
# e.g. {'instance-001' : { 12:34:56:78:90:12 : {'bw_in': 0, ....}}
|
||||
all_counters = self._vmops.get_all_bw_counters()
|
||||
for instance_name, counters in six.iteritems(all_counters):
|
||||
for instance_name, counters in all_counters.items():
|
||||
if instance_name in imap:
|
||||
# yes these are stats for a nova-managed vm
|
||||
# correlate the stats with the nova instance uuid:
|
||||
|
@ -59,7 +59,7 @@ from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import units
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
@ -560,7 +560,7 @@ class SessionBase(object):
|
||||
|
||||
def SR_introduce(self, _1, sr_uuid, label, desc, type, content_type,
|
||||
shared, sm_config):
|
||||
for ref, rec in six.iteritems(_db_content['SR']):
|
||||
for ref, rec in _db_content['SR'].items():
|
||||
if rec.get('uuid') == sr_uuid:
|
||||
# make forgotten = 0 and return ref
|
||||
_db_content['SR'][ref]['forgotten'] = 0
|
||||
@ -1079,7 +1079,7 @@ class SessionBase(object):
|
||||
|
||||
def _get_by_field(self, recs, k, v, return_singleton):
|
||||
result = []
|
||||
for ref, rec in six.iteritems(recs):
|
||||
for ref, rec in recs.items():
|
||||
if rec.get(k) == v:
|
||||
result.append(ref)
|
||||
|
||||
|
@ -22,7 +22,7 @@ import re
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
|
||||
from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
@ -388,7 +388,7 @@ def _host_find(context, session, src_aggregate, host_ref):
|
||||
# CONF.host in the XenServer host's other-config map.
|
||||
# TODO(armando-migliaccio): improve according the note above
|
||||
uuid = session.host.get_uuid(host_ref)
|
||||
for compute_host, host_uuid in six.iteritems(src_aggregate.metadetails):
|
||||
for compute_host, host_uuid in src_aggregate.metadetails.items():
|
||||
if host_uuid == uuid:
|
||||
return compute_host
|
||||
raise exception.NoValidHost(reason='Host %(host_uuid)s could not be found '
|
||||
|
@ -537,7 +537,7 @@ def _set_vdi_info(session, vdi_ref, vdi_type, name_label, description,
|
||||
session.call_xenapi('VDI.set_name_description', vdi_ref, description)
|
||||
|
||||
other_config = _get_vdi_other_config(vdi_type, instance=instance)
|
||||
for key, value in six.iteritems(other_config):
|
||||
for key, value in other_config.items():
|
||||
if key not in existing_other_config:
|
||||
session.call_xenapi(
|
||||
"VDI.add_to_other_config", vdi_ref, key, value)
|
||||
@ -1306,7 +1306,7 @@ def create_image(context, session, instance, name_label, image_id,
|
||||
{'image_id': image_id, 'cache': cache, 'downloaded': downloaded,
|
||||
'duration': duration})
|
||||
|
||||
for vdi_type, vdi in six.iteritems(vdis):
|
||||
for vdi_type, vdi in vdis.items():
|
||||
vdi_ref = session.call_xenapi('VDI.get_by_uuid', vdi['uuid'])
|
||||
_set_vdi_info(session, vdi_ref, vdi_type, name_label, vdi_type,
|
||||
instance)
|
||||
@ -1330,7 +1330,7 @@ def _fetch_image(context, session, instance, name_label, image_id, image_type):
|
||||
vdis = _fetch_disk_image(context, session, instance, name_label,
|
||||
image_id, image_type)
|
||||
|
||||
for vdi_type, vdi in six.iteritems(vdis):
|
||||
for vdi_type, vdi in vdis.items():
|
||||
vdi_uuid = vdi['uuid']
|
||||
LOG.debug("Fetched VDIs of type '%(vdi_type)s' with UUID"
|
||||
" '%(vdi_uuid)s'",
|
||||
|
@ -664,7 +664,7 @@ class VMOps(object):
|
||||
vbd_refs.append(vbd_ref)
|
||||
|
||||
# Attach original ephemeral disks
|
||||
for userdevice, vdi_ref in six.iteritems(orig_vdi_refs):
|
||||
for userdevice, vdi_ref in orig_vdi_refs.items():
|
||||
if userdevice >= DEVICE_EPHEMERAL:
|
||||
vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
|
||||
userdevice, bootable=False)
|
||||
@ -789,7 +789,7 @@ class VMOps(object):
|
||||
ephemeral_vdis = vdis.get('ephemerals')
|
||||
if ephemeral_vdis:
|
||||
# attach existing (migrated) ephemeral disks
|
||||
for userdevice, ephemeral_vdi in six.iteritems(ephemeral_vdis):
|
||||
for userdevice, ephemeral_vdi in ephemeral_vdis.items():
|
||||
vm_utils.create_vbd(self._session, vm_ref,
|
||||
ephemeral_vdi['ref'],
|
||||
userdevice, bootable=False)
|
||||
@ -1796,7 +1796,7 @@ class VMOps(object):
|
||||
if dom is None or dom not in counters:
|
||||
continue
|
||||
vifs_bw = bw.setdefault(name, {})
|
||||
for vif_num, vif_data in six.iteritems(counters[dom]):
|
||||
for vif_num, vif_data in counters[dom].items():
|
||||
mac = vif_map[vif_num]
|
||||
vif_data['mac_address'] = mac
|
||||
vifs_bw[mac] = vif_data
|
||||
|
@ -386,7 +386,7 @@ class Debug(Middleware):
|
||||
resp = req.get_response(self.application)
|
||||
|
||||
print(('*' * 40) + ' RESPONSE HEADERS')
|
||||
for (key, value) in six.iteritems(resp.headers):
|
||||
for (key, value) in resp.headers.items():
|
||||
print(key, '=', value)
|
||||
print()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user