|
11 | 11 | # under the License. |
12 | 12 | # |
13 | 13 |
|
14 | | - |
15 | 14 | """Hypervisor Stats action implementations""" |
16 | 15 |
|
17 | 16 | from osc_lib.command import command |
| 17 | +from osc_lib import utils |
18 | 18 |
|
19 | 19 | from openstackclient.i18n import _ |
20 | 20 |
|
21 | 21 |
|
| 22 | +def _get_hypervisor_stat_columns(item): |
| 23 | + column_map = { |
| 24 | + # NOTE(gtema): If we decide to use SDK names - empty this |
| 25 | + 'disk_available': 'disk_available_least', |
| 26 | + 'local_disk_free': 'free_disk_gb', |
| 27 | + 'local_disk_size': 'local_gb', |
| 28 | + 'local_disk_used': 'local_gb_used', |
| 29 | + 'memory_free': 'free_ram_mb', |
| 30 | + 'memory_size': 'memory_mb', |
| 31 | + 'memory_used': 'memory_mb_used', |
| 32 | + |
| 33 | + } |
| 34 | + hidden_columns = ['id', 'links', 'location', 'name'] |
| 35 | + return utils.get_osc_show_columns_for_sdk_resource( |
| 36 | + item, column_map, hidden_columns) |
| 37 | + |
| 38 | + |
22 | 39 | class ShowHypervisorStats(command.ShowOne): |
23 | 40 | _description = _("Display hypervisor stats details") |
24 | 41 |
|
25 | 42 | def take_action(self, parsed_args): |
26 | | - compute_client = self.app.client_manager.compute |
27 | | - hypervisor_stats = compute_client.hypervisors.statistics().to_dict() |
28 | | - |
29 | | - return zip(*sorted(hypervisor_stats.items())) |
| 43 | + # The command is deprecated since it is being dropped in Nova. |
| 44 | + self.log.warning( |
| 45 | + _("This command is deprecated.") |
| 46 | + ) |
| 47 | + compute_client = self.app.client_manager.sdk_connection.compute |
| 48 | + # We do API request directly cause this deprecated method is not and |
| 49 | + # will not be supported by OpenStackSDK. |
| 50 | + response = compute_client.get( |
| 51 | + '/os-hypervisors/statistics', |
| 52 | + microversion='2.1') |
| 53 | + hypervisor_stats = response.json().get('hypervisor_statistics') |
| 54 | + |
| 55 | + display_columns, columns = _get_hypervisor_stat_columns( |
| 56 | + hypervisor_stats) |
| 57 | + data = utils.get_dict_properties( |
| 58 | + hypervisor_stats, columns) |
| 59 | + return (display_columns, data) |
0 commit comments