From 88d5b2e3baf6e5b873fd007e99bcc518d4470273 Mon Sep 17 00:00:00 2001 From: David Sullivan Date: Thu, 17 Jan 2019 10:58:43 -0500 Subject: [PATCH] Tie vswitch core changes to openstack-compute label Only allow vswitch cpu core changes if the host has the following label openstack-compute-node=enabled Change-Id: I23944ad1b7b61dbe7f287d55fb8ebc9a8901aa86 Story: 2004022 Task: 28948 Depends-On: https://review.openstack.org/#/c/631540 Signed-off-by: David Sullivan --- .../admin/inventory/cpu_functions/forms.py | 5 ++++- .../admin/inventory/cpu_functions/utils.py | 17 ++++++++++++++++- .../admin/inventory/cpu_functions/views.py | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/forms.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/forms.py index c9ba3002..d56d7bd1 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/forms.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/forms.py @@ -18,6 +18,8 @@ from horizon import forms from horizon import messages from starlingx_dashboard.api import sysinv +from starlingx_dashboard.dashboards.admin.inventory.cpu_functions \ + import utils as cpufunctions_utils from starlingx_dashboard.horizon.forms.fields import DynamicIntegerField LOG = logging.getLogger(__name__) @@ -146,7 +148,8 @@ class UpdateCpuFunctions(forms.SelfHandlingForm): 'platform_processor3'].help_text = \ "Processor 3 has %s physical cores." % avail_socket_cores - if 'worker' not in self.host.subfunctions: + if 'worker' not in self.host.subfunctions \ + or not cpufunctions_utils.has_openstack_compute(self.host): self.fields['vswitch'].widget = forms.widgets.HiddenInput() self.fields[ 'num_cores_on_processor0'].widget = forms.widgets.HiddenInput() diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py index cf9312bd..a13aadbc 100755 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2015 Wind River Systems, Inc. +# Copyright (c) 2013-2019 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -12,6 +12,7 @@ VSWITCH_CPU_TYPE = "Vswitch" SHARED_CPU_TYPE = "Shared" APPLICATIONS_CPU_TYPE = "Applications" NONE_CPU_TYPE = "None" +COMPUTE_NODE_LABEL_KEY = 'openstack-compute-node' CPU_TYPE_LIST = [PLATFORM_CPU_TYPE, VSWITCH_CPU_TYPE, SHARED_CPU_TYPE, APPLICATIONS_CPU_TYPE, @@ -235,3 +236,17 @@ def check_core_functions(personality, icpus): error_string = "There must be at least one" \ " core for %s." % APPLICATIONS_CPU_TYPE_FORMAT return error_string + + +def has_openstack_compute(host): + """Returns true if the host has the openstack compute label set """ + labels = host.labels + if not labels: + return False + + for label in labels: + if label.label_key == COMPUTE_NODE_LABEL_KEY: + return 'enabled' == label.label_value.lower() + + # We haven't found the openstack compute node key. Return False + return False diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/views.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/views.py index cc396639..267c27b4 100755 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/views.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/views.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2015 Wind River Systems, Inc. +# Copyright (c) 2013-2019 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -44,6 +44,7 @@ class UpdateCpuFunctionsView(forms.ModalFormView): host = sysinv.host_get(self.request, host_id) host.nodes = sysinv.host_node_list(self.request, host.uuid) host.cpus = sysinv.host_cpu_list(self.request, host.uuid) + host.labels = sysinv.host_label_list(self.request, host.uuid) icpu_utils.restructure_host_cpu_data(host) self._object = host self._object.host_id = host_id