Make Server.networks use a predictable sort order
This changes the Server.networks property method to return an OrderedDict where the keys (network labels) are sorted which will allow for a predictable sort order on the resulting networks attached to a Server resource. This affects the output of "nova list" and "nova show" commands so a simple release note is added to mention the change. Change-Id: I2e9b3c6a256509c045966035da24d58628f1b33b
This commit is contained in:
parent
81ea9887f0
commit
874b03068f
@ -453,6 +453,12 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.assert_request_id(server, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assert_called('GET', '/servers/1234')
|
||||
self.assertEqual('sample-server', server.name)
|
||||
# The networks should be sorted.
|
||||
networks = server.networks
|
||||
self.assertEqual(2, len(networks))
|
||||
labels = list(networks) # returns the dict keys
|
||||
self.assertEqual('private', labels[0])
|
||||
self.assertEqual('public', labels[1])
|
||||
|
||||
self.assertRaises(exceptions.NoUniqueMatch, self.cs.servers.find,
|
||||
flavor={"id": 1, "name": "256 MiB Server"})
|
||||
|
@ -20,6 +20,7 @@ Server interface.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import collections
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
@ -399,10 +400,16 @@ class Server(base.Resource):
|
||||
def networks(self):
|
||||
"""
|
||||
Generate a simplified list of addresses
|
||||
|
||||
:returns: An OrderedDict, keyed by network name, and sorted by network
|
||||
name in ascending order.
|
||||
"""
|
||||
networks = {}
|
||||
networks = collections.OrderedDict()
|
||||
try:
|
||||
for network_label, address_list in self.addresses.items():
|
||||
# Sort the keys by network name in natural (ascending) order.
|
||||
network_labels = sorted(self.addresses.keys())
|
||||
for network_label in network_labels:
|
||||
address_list = self.addresses[network_label]
|
||||
networks[network_label] = [a['addr'] for a in address_list]
|
||||
return networks
|
||||
except AttributeError:
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
other:
|
||||
- |
|
||||
The ``novaclient.v2.servers.Server.networks`` property method now returns
|
||||
an OrderedDict where the keys are sorted in natural (ascending) order.
|
||||
This means the ``nova show`` and ``nova list`` output will have predictable
|
||||
sort order on the networks attached to a server.
|
Loading…
Reference in New Issue
Block a user