Skip to content

Commit c686224

Browse files
committed
Add support for showing scheduler_hints in server details
Adds support for a new compute microversion that returns the associated scheduler_hints in ``GET /servers/{server_id}``, ``GET /servers/detail``, ``PUT /servers/{server_id}`` and ``POST /server/{server_id}/action`` (rebuild) responses. Change-Id: Ia5a4e0047b5123f2fb063cfc9ab1f58b2844308f
1 parent d22b773 commit c686224

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

openstackclient/compute/v2/server.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def _prep_server_detail(compute_client, image_client, server, *, refresh=True):
184184
'user_data': 'OS-EXT-SRV-ATTR:user_data',
185185
'vm_state': 'OS-EXT-STS:vm_state',
186186
'pinned_availability_zone': 'pinned_availability_zone',
187+
'scheduler_hints': 'scheduler_hints',
187188
}
188189
# Some columns returned by openstacksdk should not be shown because they're
189190
# either irrelevant or duplicates
@@ -204,7 +205,6 @@ def _prep_server_detail(compute_client, image_client, server, *, refresh=True):
204205
'min_count',
205206
'networks',
206207
'personality',
207-
'scheduler_hints',
208208
# aliases
209209
'volumes',
210210
# unnecessary
@@ -235,6 +235,11 @@ def _prep_server_detail(compute_client, image_client, server, *, refresh=True):
235235

236236
info = data
237237

238+
# NOTE(dviroel): microversion 2.100 is now retrieving scheduler_hints
239+
# content from request_spec on detailed responses
240+
if not sdk_utils.supports_microversion(compute_client, '2.100'):
241+
info.pop('scheduler_hints', None)
242+
238243
# Convert the image blob to a name
239244
image_info = info.get('image', {})
240245
if image_info and any(image_info.values()):
@@ -321,6 +326,11 @@ def _prep_server_detail(compute_client, image_client, server, *, refresh=True):
321326
info['OS-EXT-STS:power_state']
322327
)
323328

329+
if 'scheduler_hints' in info:
330+
info['scheduler_hints'] = format_columns.DictListColumn(
331+
info.pop('scheduler_hints', {}),
332+
)
333+
324334
return info
325335

326336

@@ -2873,12 +2883,14 @@ def take_action(self, parsed_args):
28732883
'pinned_availability_zone',
28742884
'hypervisor_hostname',
28752885
'metadata',
2886+
'scheduler_hints',
28762887
)
28772888
column_headers += (
28782889
'Availability Zone',
28792890
'Pinned Availability Zone',
28802891
'Host',
28812892
'Properties',
2893+
'Scheduler Hints',
28822894
)
28832895

28842896
# support for additional columns
@@ -2923,6 +2935,12 @@ def take_action(self, parsed_args):
29232935
if c in ('Properties', "properties"):
29242936
columns += ('Metadata',)
29252937
column_headers += ('Properties',)
2938+
if c in (
2939+
'scheduler_hints',
2940+
"Scheduler Hints",
2941+
):
2942+
columns += ('scheduler_hints',)
2943+
column_headers += ('Scheduler Hints',)
29262944

29272945
# remove duplicates
29282946
column_headers = tuple(dict.fromkeys(column_headers))
@@ -3089,6 +3107,7 @@ def take_action(self, parsed_args):
30893107
'metadata': format_columns.DictColumn,
30903108
'security_groups_name': format_columns.ListColumn,
30913109
'hypervisor_hostname': HostColumn,
3110+
'scheduler_hints': format_columns.DictListColumn,
30923111
},
30933112
)
30943113
for s in data

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,6 +4603,7 @@ class _TestServerList(TestServer):
46034603
'Pinned Availability Zone',
46044604
'Host',
46054605
'Properties',
4606+
'Scheduler Hints',
46064607
)
46074608

46084609
def setUp(self):
@@ -4742,6 +4743,7 @@ def test_server_list_long_option(self):
47424743
getattr(s, 'pinned_availability_zone', ''),
47434744
server.HostColumn(getattr(s, 'hypervisor_hostname')),
47444745
format_columns.DictColumn(s.metadata),
4746+
format_columns.DictListColumn(None),
47454747
)
47464748
for s in self.servers
47474749
)
@@ -4790,6 +4792,8 @@ def test_server_list_column_option(self):
47904792
'Host',
47914793
'-c',
47924794
'Properties',
4795+
'-c',
4796+
'Scheduler Hints',
47934797
'--long',
47944798
]
47954799
verifylist = [
@@ -4812,6 +4816,7 @@ def test_server_list_column_option(self):
48124816
self.assertIn('Pinned Availability Zone', columns)
48134817
self.assertIn('Host', columns)
48144818
self.assertIn('Properties', columns)
4819+
self.assertIn('Scheduler Hints', columns)
48154820
self.assertCountEqual(columns, set(columns))
48164821

48174822
def test_server_list_no_name_lookup_option(self):
@@ -5225,6 +5230,7 @@ def test_server_list_long_with_host_status_v216(self):
52255230
getattr(s, 'pinned_availability_zone', ''),
52265231
server.HostColumn(getattr(s, 'hypervisor_hostname')),
52275232
format_columns.DictColumn(s.metadata),
5233+
format_columns.DictListColumn(s.scheduler_hints),
52285234
)
52295235
for s in self.servers
52305236
)
@@ -5280,6 +5286,7 @@ def test_server_list_long_with_host_status_v216(self):
52805286
getattr(s, 'pinned_availability_zone', ''),
52815287
server.HostColumn(getattr(s, 'hypervisor_hostname')),
52825288
format_columns.DictColumn(s.metadata),
5289+
format_columns.DictListColumn(s.scheduler_hints),
52835290
s.host_status,
52845291
)
52855292
for s in servers
@@ -5317,6 +5324,7 @@ class TestServerListV273(_TestServerList):
53175324
'Pinned Availability Zone',
53185325
'Host',
53195326
'Properties',
5327+
'Scheduler Hints',
53205328
)
53215329

53225330
def setUp(self):

0 commit comments

Comments
 (0)