Replace dict(obj.iteritems()) with dict(obj)
This change makes the modified code compatible with Python 2 and Python 3. Add __iter__() and keys() methods to NovaObjectDictCompat. These methods are added temporarly, the change I4c52d44c7ba49f98b1bbd123209fce7b70ade98d added these methods to the base class VersionedObjectDictCompat of oslo.versionedobjects. sqlalchemy code is unchanged. sqlalchemy objects cannot be converted to a dictionary using dict(obj) directly yet. It will be possible with the change I702be362a58155a28482e733e60539d36c039509. Don't change get_instance_metadata() in nova/compute/api.py, it's fixed by the change Ifd455e70002eb9636b87f83788384127ba6edeeb. Blueprint nova-python3 Change-Id: I46e5fcaaef75178fb4db44368e34da8777b4c4b1
This commit is contained in:
@@ -82,7 +82,7 @@ class ServerExternalEventsController(wsgi.Controller):
|
||||
except exception.InstanceNotFound:
|
||||
LOG.debug('Dropping event %(name)s:%(tag)s for unknown '
|
||||
'instance %(instance_uuid)s',
|
||||
dict(event.iteritems()))
|
||||
dict(event))
|
||||
_event['status'] = 'failed'
|
||||
_event['code'] = 404
|
||||
result = 207
|
||||
@@ -96,7 +96,7 @@ class ServerExternalEventsController(wsgi.Controller):
|
||||
accepted_instances.add(instance)
|
||||
LOG.info(_LI('Creating event %(name)s:%(tag)s for '
|
||||
'instance %(instance_uuid)s'),
|
||||
dict(event.iteritems()))
|
||||
dict(event))
|
||||
# NOTE: as the event is processed asynchronously verify
|
||||
# whether 202 is a more suitable response code than 200
|
||||
_event['status'] = 'completed'
|
||||
|
||||
@@ -71,7 +71,7 @@ class ServerExternalEventsController(wsgi.Controller):
|
||||
except exception.InstanceNotFound:
|
||||
LOG.debug('Dropping event %(name)s:%(tag)s for unknown '
|
||||
'instance %(instance_uuid)s',
|
||||
dict(event.iteritems()))
|
||||
dict(event))
|
||||
_event['status'] = 'failed'
|
||||
_event['code'] = 404
|
||||
result = 207
|
||||
@@ -85,7 +85,7 @@ class ServerExternalEventsController(wsgi.Controller):
|
||||
accepted_instances.add(instance)
|
||||
LOG.info(_LI('Creating event %(name)s:%(tag)s for '
|
||||
'instance %(instance_uuid)s'),
|
||||
dict(event.iteritems()))
|
||||
dict(event))
|
||||
# NOTE: as the event is processed asynchronously verify
|
||||
# whether 202 is a more suitable response code than 200
|
||||
_event['status'] = 'completed'
|
||||
|
||||
@@ -77,7 +77,7 @@ def _build_metadata_by_host(aggregates, hosts=None):
|
||||
|
||||
def set_availability_zones(context, services):
|
||||
# Makes sure services isn't a sqlalchemy object
|
||||
services = [dict(service.iteritems()) for service in services]
|
||||
services = [dict(service) for service in services]
|
||||
hosts = set([service['host'] for service in services])
|
||||
aggregates = objects.AggregateList.get_by_metadata_key(context,
|
||||
'availability_zone', hosts=hosts)
|
||||
|
||||
@@ -5628,7 +5628,7 @@ def instance_fault_get_by_instance_uuids(context, instance_uuids):
|
||||
output[instance_uuid] = []
|
||||
|
||||
for row in rows:
|
||||
data = dict(row.iteritems())
|
||||
data = dict(row)
|
||||
output[row['instance_uuid']].append(data)
|
||||
|
||||
return output
|
||||
|
||||
@@ -494,7 +494,7 @@ class FloatingIP(object):
|
||||
"""Returns a floating IP as a dict."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
return dict(objects.FloatingIP.get_by_id(context, id).iteritems())
|
||||
return dict(objects.FloatingIP.get_by_id(context, id))
|
||||
|
||||
def get_floating_pools(self, context):
|
||||
"""Returns list of floating pools."""
|
||||
|
||||
@@ -1570,7 +1570,7 @@ class NetworkManager(manager.Manager):
|
||||
if vif.network_id is not None:
|
||||
network = self._get_network_by_id(context, vif.network_id)
|
||||
vif.net_uuid = network.uuid
|
||||
return [dict(vif.iteritems()) for vif in vifs]
|
||||
return [dict(vif) for vif in vifs]
|
||||
|
||||
def get_instance_id_by_floating_address(self, context, address):
|
||||
"""Returns the instance id a floating ip's fixed ip is allocated to."""
|
||||
|
||||
@@ -647,7 +647,14 @@ class NovaObject(object):
|
||||
|
||||
|
||||
class NovaObjectDictCompat(ovoo_base.VersionedObjectDictCompat):
|
||||
pass
|
||||
def __iter__(self):
|
||||
for name in self.obj_fields:
|
||||
if (self.obj_attr_is_set(name) or
|
||||
name in self.obj_extra_fields):
|
||||
yield name
|
||||
|
||||
def keys(self):
|
||||
return list(self)
|
||||
|
||||
|
||||
class NovaTimestampObject(object):
|
||||
|
||||
@@ -558,7 +558,7 @@ class HostManager(object):
|
||||
host_state.aggregates = [self.aggs_by_id[agg_id] for agg_id in
|
||||
self.host_aggregates_map[
|
||||
host_state.host]]
|
||||
host_state.update_service(dict(service.iteritems()))
|
||||
host_state.update_service(dict(service))
|
||||
self._add_instance_info(context, compute, host_state)
|
||||
seen_nodes.add(state_key)
|
||||
|
||||
|
||||
@@ -1581,7 +1581,7 @@ class _TestInstanceListObject(object):
|
||||
use_slave=False)
|
||||
self.assertEqual(2, len(instances))
|
||||
self.assertEqual(fake_faults['fake-uuid'][0],
|
||||
dict(instances[0].fault.iteritems()))
|
||||
dict(instances[0].fault))
|
||||
self.assertIsNone(instances[1].fault)
|
||||
|
||||
def test_fill_faults(self):
|
||||
|
||||
Reference in New Issue
Block a user