Simplify the code / make it more readable by returning early and getting
rid of one level of indentation on a common code path.
@@ -2586,12 +2586,15 @@ class GCENodeDriver(NodeDriver):
:return: List of Node objects
:rtype: ``list`` of :class:`Node`
"""
- list_nodes = []
zone = self._set_zone(ex_zone)
response = self.connection.request_aggregated_items('instances',
zone=zone)
- if 'items' in response:
+ if not response.get('items', []):
+ return []
+
+ list_nodes = []
+
# The aggregated response returns a dict for each zone
# Create volume cache now for fast lookups of disk info.
self._ex_populate_volume_dict()
@@ -2611,6 +2614,7 @@ class GCENodeDriver(NodeDriver):
# other nodes.
except ResourceNotFoundError:
pass
+
# Clear the volume cache as lookups are complete.
self._ex_volume_dict = {}
return list_nodes
