python3: Refactor dict for python2/python3 compat
Python3 changed the behavior of dict.keys and dict.values such that
it is now returns a dict_keys object, which is iterable but not
indexable. You can get the python2 result back with an explicit
call to list.
Story: 2006796
Task: 42671
Signed-off-by: Charles Short <charles.short@windriver.com>
Change-Id: I97c9b3c40b997da4ce514742af85bcb73bfe7ee0
(cherry picked from commit 033d32f983
)
This commit is contained in:
parent
81fee1c449
commit
a0645a4e09
|
@ -215,7 +215,7 @@ class NodeOperator(object):
|
|||
icpu_attrs = {}
|
||||
continue
|
||||
|
||||
self.num_nodes = len(self.topology.keys())
|
||||
self.num_nodes = len(list(self.topology.keys()))
|
||||
|
||||
# In the case topology not detected, hard-code structures
|
||||
if self.num_nodes == 0:
|
||||
|
@ -265,7 +265,7 @@ class NodeOperator(object):
|
|||
}
|
||||
icpus.append(attrs)
|
||||
cpu += 1
|
||||
self.num_nodes = len(self.topology.keys())
|
||||
self.num_nodes = len(list(self.topology.keys()))
|
||||
|
||||
LOG.debug("inumas= %s, icpus = %s" % (inumas, icpus))
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ class AddressPool(base.APIBase):
|
|||
"List of start-end pairs of IP address"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.address_pool.fields.keys()
|
||||
self.fields = list(objects.address_pool.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
# Skip fields that we choose to hide
|
||||
|
|
|
@ -114,7 +114,7 @@ class Cluster(base.APIBase):
|
|||
"Links to the collection of storage tiers on this cluster"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.cluster.fields.keys()
|
||||
self.fields = list(objects.cluster.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
# Skip fields that we choose to hide
|
||||
|
|
|
@ -97,7 +97,7 @@ class DataNetwork(base.APIBase):
|
|||
"Mode for this datanetwork. VxLan only"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.datanetwork.fields.keys()
|
||||
self.fields = list(objects.datanetwork.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -119,7 +119,7 @@ class Disk(base.APIBase):
|
|||
"applicable for SSDs."
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.disk.fields.keys()
|
||||
self.fields = list(objects.disk.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class InterfaceDataNetwork(base.APIBase):
|
|||
"Represents the type for the datanetwork"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.interface_datanetwork.fields.keys()
|
||||
self.fields = list(objects.interface_datanetwork.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -85,7 +85,7 @@ class InterfaceNetwork(base.APIBase):
|
|||
"Represents the type for the network"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.interface_network.fields.keys()
|
||||
self.fields = list(objects.interface_network.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -69,7 +69,7 @@ class KubeApp(base.APIBase):
|
|||
"Represents the application is active"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.kube_app.fields.keys()
|
||||
self.fields = list(objects.kube_app.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -62,7 +62,7 @@ class KubeUpgrade(base.APIBase):
|
|||
"A list containing a self link and associated kubernetes upgrade links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.kube_upgrade.fields.keys()
|
||||
self.fields = list(objects.kube_upgrade.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -41,7 +41,7 @@ class KubeVersion(base.APIBase):
|
|||
"State of this version"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.kube_version.fields.keys()
|
||||
self.fields = list(objects.kube_version.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -61,7 +61,7 @@ class Label(base.APIBase):
|
|||
"The uuid of the host this label belongs to"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.label.fields.keys()
|
||||
self.fields = list(objects.label.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -123,7 +123,7 @@ class LLDPAgent(base.APIBase):
|
|||
"Represent the 802.3 maximum frame size of the lldp agent"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.lldp_agent.fields.keys()
|
||||
self.fields = list(objects.lldp_agent.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ class LLDPNeighbour(base.APIBase):
|
|||
"Represent the neighbour time-to-live"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.lldp_neighbour.fields.keys()
|
||||
self.fields = list(objects.lldp_neighbour.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class LLDPTLV(base.APIBase):
|
|||
"Represent a list containing a self link and associated lldp tlv links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.lldp_tlv.fields.keys()
|
||||
self.fields = list(objects.lldp_tlv.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ class Load(base.APIBase):
|
|||
"A list of the patches required to upgrade to this load"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.load.fields.keys()
|
||||
self.fields = list(objects.load.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class Network(base.APIBase):
|
|||
"The UUID of the address pool associated with the network"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.network.fields.keys()
|
||||
self.fields = list(objects.network.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -89,7 +89,7 @@ class Node(base.APIBase):
|
|||
"Links to the collection of ports on this node"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.node.fields.keys()
|
||||
self.fields = list(objects.node.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ class Partition(base.APIBase):
|
|||
"This partition's meta data"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.partition.fields.keys()
|
||||
self.fields = list(objects.partition.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ class PCIDevice(base.APIBase):
|
|||
"Represent a list containing a self link and associated device links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.pci_device.fields.keys()
|
||||
self.fields = list(objects.pci_device.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ class Port(base.APIBase):
|
|||
"Links to the collection of LldpNeighbours on this port"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.port.fields.keys()
|
||||
self.fields = list(objects.port.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -1733,7 +1733,7 @@ def _create_storage_profile(profile_name, profile_node):
|
|||
sdict['journal_location'] = location_uuid
|
||||
else:
|
||||
# get the first journal
|
||||
journal = journals[journals.keys()[0]]
|
||||
journal = journals[list(journals.keys())[0]]
|
||||
sdict['journal_location'] = journal
|
||||
else:
|
||||
# journal is collocated
|
||||
|
|
|
@ -65,7 +65,7 @@ class PTP(base.APIBase):
|
|||
updated_at = wtypes.datetime.datetime
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.ptp.fields.keys()
|
||||
self.fields = list(objects.ptp.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ class PV(base.APIBase):
|
|||
"Links to the collection of partitions on this pv"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.pv.fields.keys()
|
||||
self.fields = list(objects.pv.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class Route(base.APIBase):
|
|||
"The ID of the host this interface belongs to"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.route.fields.keys()
|
||||
self.fields = list(objects.route.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
# Skip fields that we choose to hide
|
||||
|
|
|
@ -107,7 +107,7 @@ class SDNController(base.APIBase):
|
|||
"A list containing a self link and associated SDN controller links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.sdn_controller.fields.keys()
|
||||
self.fields = list(objects.sdn_controller.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ class Sensor(base.APIBase):
|
|||
"Represent a list containing a self link and associated isensor links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.sensor.fields.keys()
|
||||
self.fields = list(objects.sensor.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class Service(base.APIBase):
|
|||
"Service capabilities"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.service.fields.keys()
|
||||
self.fields = list(objects.service.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class ServiceParameter(base.APIBase):
|
|||
"A list containing a self link and associated links"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.service_parameter.fields.keys()
|
||||
self.fields = list(objects.service_parameter.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -914,7 +914,7 @@ def _capabilities_semantic_checks(caps_dict):
|
|||
|
||||
# Raise exception if unsupported capabilities are passed
|
||||
invalid_data = set(caps_dict.keys()) - set(valid_data.keys())
|
||||
if valid_data.keys() != caps_dict.keys():
|
||||
if list(valid_data.keys()) != list(caps_dict.keys()):
|
||||
# Build short customer message to help with supported capabilities
|
||||
# he can then search for them in the manual.
|
||||
params = " backend: %s\n" % ", ".join(CAPABILITIES['backend'])
|
||||
|
|
|
@ -100,7 +100,7 @@ class StorageTier(base.APIBase):
|
|||
"Links to the collection of OSDs on this storage tier"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.storage_tier.fields.keys()
|
||||
self.fields = list(objects.storage_tier.fields.keys())
|
||||
for k in self.fields:
|
||||
setattr(self, k, kwargs.get(k))
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ class System(base.APIBase):
|
|||
"Kernel arguments associated with exnabled spectre/meltdown fix features"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.system.fields.keys()
|
||||
self.fields = list(objects.system.fields.keys())
|
||||
|
||||
for k in self.fields:
|
||||
# Translate any special internal representation of data to its
|
||||
|
|
|
@ -73,7 +73,7 @@ class Upgrade(base.APIBase):
|
|||
"The load version that software upgrading to"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.fields = objects.software_upgrade.fields.keys()
|
||||
self.fields = list(objects.software_upgrade.fields.keys())
|
||||
for k in self.fields:
|
||||
if not hasattr(self, k):
|
||||
continue
|
||||
|
|
|
@ -540,7 +540,7 @@ def get_subclouds():
|
|||
"""
|
||||
|
||||
subcloud_secrets = get_subcloud_secrets()
|
||||
return subcloud_secrets.keys()
|
||||
return list(subcloud_secrets.keys())
|
||||
|
||||
|
||||
def get_intermediate_ca_secret_name(sc):
|
||||
|
|
|
@ -552,7 +552,7 @@ class RootCARenew(CertificateRenew):
|
|||
|
||||
@staticmethod
|
||||
def get_secrets_to_recreate():
|
||||
secret_names = utils.get_subcloud_secrets().values()
|
||||
secret_names = list(utils.get_subcloud_secrets().values())
|
||||
secret_names.insert(0, constants.DC_ADMIN_ENDPOINT_SECRET_NAME)
|
||||
return secret_names
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ def create_host_overrides(filename):
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
VALID_NOTIFICATION_VALUES = constants.HOOK_PARAMETERS_MAP.keys()
|
||||
VALID_NOTIFICATION_VALUES = list(constants.HOOK_PARAMETERS_MAP.keys())
|
||||
NOTIFICATION_ACTION_SUCCESS_VALUES = {'success': True,
|
||||
'failure': False}
|
||||
|
||||
|
@ -260,7 +260,7 @@ def add_action_parsers(subparsers):
|
|||
parser.set_defaults(func=send_notification)
|
||||
parser.add_argument('operation')
|
||||
parser.add_argument('success',
|
||||
choices=NOTIFICATION_ACTION_SUCCESS_VALUES.keys(),
|
||||
choices=list(NOTIFICATION_ACTION_SUCCESS_VALUES.keys()),
|
||||
default='success',
|
||||
nargs='?')
|
||||
|
||||
|
|
|
@ -613,7 +613,7 @@ FILESYSTEM_HOSTS_SUPPORTED_LIST_DICT = {
|
|||
STORAGE: FILESYSTEM_STORAGE_SUPPORTED_LIST,
|
||||
}
|
||||
|
||||
SUPPORTED_LOGICAL_VOLUME_LIST = FILESYSTEM_LV_DICT.values()
|
||||
SUPPORTED_LOGICAL_VOLUME_LIST = list(FILESYSTEM_LV_DICT.values())
|
||||
|
||||
SUPPORTED_REPLICATED_FILEYSTEM_LIST = [
|
||||
FILESYSTEM_NAME_PLATFORM,
|
||||
|
|
|
@ -12866,7 +12866,7 @@ class ConductorManager(service.PeriodicService):
|
|||
self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_ETCD_BACKUP)
|
||||
self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_BACKUP)
|
||||
|
||||
actions_list = self._backup_action_map.keys()
|
||||
actions_list = list(self._backup_action_map.keys())
|
||||
self._backup_actions_log = dict(zip(actions_list, [OrderedDict()] * len(actions_list)))
|
||||
|
||||
def _revert_backup_operation(self, operation):
|
||||
|
|
|
@ -306,8 +306,8 @@ class BaseHelm(object):
|
|||
elif name_filter:
|
||||
monitors = self._get_filtered_ceph_monitor_ips_using_function(name_filter)
|
||||
else:
|
||||
monitors = StorageBackendConfig.get_ceph_mon_ip_addresses(
|
||||
self.dbapi).values()
|
||||
monitors = list(StorageBackendConfig.get_ceph_mon_ip_addresses(
|
||||
self.dbapi).values())
|
||||
return monitors
|
||||
|
||||
def _get_formatted_ceph_monitor_ips(self, name_filter=None):
|
||||
|
|
|
@ -154,7 +154,7 @@ def _get_drivers():
|
|||
for notification_driver in CONF.notification_driver:
|
||||
add_driver(notification_driver)
|
||||
|
||||
return _drivers.values()
|
||||
return list(_drivers.values())
|
||||
|
||||
|
||||
def add_driver(notification_driver):
|
||||
|
|
|
@ -244,7 +244,7 @@ def get_cmdclass():
|
|||
for pkg in self.distribution.packages:
|
||||
if '.' not in pkg:
|
||||
os.path.walk(pkg, _find_modules, modules)
|
||||
module_list = modules.keys()
|
||||
module_list = list(modules.keys())
|
||||
module_list.sort()
|
||||
autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
|
||||
with open(autoindex_filename, 'w') as autoindex:
|
||||
|
|
Loading…
Reference in New Issue