Enable ExtraConfig Parameter in Tuskar UI
This patch enables the ExtraConfig parameter to be edited and its value applied to all roles. Change-Id: I90fa3a09b4bf984d2aaae0aed72648fd6695c10d
This commit is contained in:
parent
85f4ae4308
commit
fd9045c86a
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
import django.forms
|
||||
@ -20,6 +21,7 @@ import horizon.exceptions
|
||||
import horizon.forms
|
||||
import horizon.messages
|
||||
|
||||
|
||||
from tuskar_ui import api
|
||||
|
||||
|
||||
@ -80,15 +82,31 @@ class EditServiceConfig(horizon.forms.SelfHandlingForm):
|
||||
initial="",
|
||||
help_text=_('Address of the NTP server. If blank, public NTP servers '
|
||||
'will be used.'))
|
||||
extra_config = django.forms.CharField(
|
||||
label=_("Extra Config"),
|
||||
required=False,
|
||||
widget=django.forms.Textarea(attrs={'rows': 2}),
|
||||
help_text=("Additional configuration to inject into the cluster."
|
||||
"The data format of this field is JSON."
|
||||
"See http://git.io/PuwLXQ for more information."))
|
||||
|
||||
def clean_extra_config(self):
|
||||
data = self.cleaned_data['extra_config']
|
||||
try:
|
||||
json.loads(data)
|
||||
except Exception as json_error:
|
||||
raise django.forms.ValidationError(
|
||||
_("%(err_msg)s"), params={'err_msg': json_error.message})
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _load_snmp_parameters(plan, data):
|
||||
def _load_additional_parameters(plan, data, form_key, param_name):
|
||||
params = {}
|
||||
password = data.get('snmp_password')
|
||||
# Set the same SNMPd password in all roles.
|
||||
param_value = data.get(form_key)
|
||||
# Set the same parameter and value in all roles.
|
||||
for role in plan.role_list:
|
||||
key = role.parameter_prefix + 'SnmpdReadonlyUserPassword'
|
||||
params[key] = password
|
||||
key = role.parameter_prefix + param_name
|
||||
params[key] = param_value
|
||||
|
||||
return params
|
||||
|
||||
@ -122,7 +140,12 @@ class EditServiceConfig(horizon.forms.SelfHandlingForm):
|
||||
compute_prefix + 'NtpServer':
|
||||
ntp_server,
|
||||
}
|
||||
parameters.update(self._load_snmp_parameters(plan, data))
|
||||
parameters.update(self._load_additional_parameters(
|
||||
plan, data,
|
||||
'snmp_password', 'SnmpdReadonlyUserPassword'))
|
||||
parameters.update(self._load_additional_parameters(
|
||||
plan, data,
|
||||
'extra_config', 'ExtraConfig'))
|
||||
|
||||
try:
|
||||
plan.patch(request, plan.uuid, parameters)
|
||||
|
@ -74,7 +74,8 @@ class ParametersTest(test.BaseAdminViewTests):
|
||||
'snmp_password': 'password',
|
||||
'cinder_iscsi_helper': 'lioadm',
|
||||
'cloud_name': 'cloud_name',
|
||||
'neutron_public_interface': 'eth0'
|
||||
'neutron_public_interface': 'eth0',
|
||||
'extra_config': '{}'
|
||||
}
|
||||
with contextlib.nested(
|
||||
patch('tuskar_ui.api.tuskar.Plan.get_the_plan',
|
||||
@ -97,4 +98,8 @@ class ParametersTest(test.BaseAdminViewTests):
|
||||
'Compute-1::SnmpdReadonlyUserPassword': u'password',
|
||||
'Block Storage-1::SnmpdReadonlyUserPassword': u'password',
|
||||
'Object Storage-1::SnmpdReadonlyUserPassword': u'password',
|
||||
'Controller-1::NtpServer': u''})
|
||||
'Controller-1::NtpServer': u'',
|
||||
'Controller-1::ExtraConfig': u'{}',
|
||||
'Compute-1::ExtraConfig': u'{}',
|
||||
'Block Storage-1::ExtraConfig': u'{}',
|
||||
'Object Storage-1::ExtraConfig': u'{}'})
|
||||
|
@ -23,10 +23,10 @@ from tuskar_ui.infrastructure.parameters import tabs
|
||||
|
||||
|
||||
class ServiceConfigView(horizon.forms.ModalFormView):
|
||||
template_name = "infrastructure/parameters/service_config.html"
|
||||
form_class = forms.EditServiceConfig
|
||||
success_url = reverse_lazy('horizon:infrastructure:parameters:index')
|
||||
submit_label = _("Save Configuration")
|
||||
template_name = "infrastructure/parameters/service_config.html"
|
||||
|
||||
def get_initial(self):
|
||||
plan = api.tuskar.Plan.get_the_plan(self.request)
|
||||
@ -34,26 +34,29 @@ class ServiceConfigView(horizon.forms.ModalFormView):
|
||||
controller_prefix = plan.get_role_by_name(
|
||||
'controller').parameter_prefix
|
||||
|
||||
virt_type = plan.parameter_value(
|
||||
compute_prefix + 'NovaComputeLibvirtType')
|
||||
snmp_password = plan.parameter_value(
|
||||
controller_prefix + 'SnmpdReadonlyUserPassword')
|
||||
cinder_iscsi_helper = plan.parameter_value(
|
||||
controller_prefix + 'CinderISCSIHelper')
|
||||
cloud_name = plan.parameter_value(
|
||||
controller_prefix + 'CloudName')
|
||||
extra_config = plan.parameter_value(
|
||||
controller_prefix + 'ExtraConfig')
|
||||
neutron_public_interface = plan.parameter_value(
|
||||
controller_prefix + 'NeutronPublicInterface')
|
||||
ntp_server = plan.parameter_value(
|
||||
controller_prefix + 'NtpServer')
|
||||
|
||||
snmp_password = plan.parameter_value(
|
||||
controller_prefix + 'SnmpdReadonlyUserPassword')
|
||||
virt_type = plan.parameter_value(
|
||||
compute_prefix + 'NovaComputeLibvirtType')
|
||||
return {
|
||||
'virt_type': virt_type,
|
||||
'snmp_password': snmp_password,
|
||||
'cinder_iscsi_helper': cinder_iscsi_helper,
|
||||
'cloud_name': cloud_name,
|
||||
'neutron_public_interface': neutron_public_interface,
|
||||
'ntp_server': ntp_server}
|
||||
'ntp_server': ntp_server,
|
||||
'extra_config': extra_config,
|
||||
'neutron_public_interface': neutron_public_interface,
|
||||
'snmp_password': snmp_password,
|
||||
'virt_type': virt_type}
|
||||
|
||||
|
||||
class IndexView(horizon_tabs.TabbedTableView):
|
||||
|
@ -133,6 +133,30 @@ def data(TEST):
|
||||
'description': 'Snmpd password',
|
||||
'hidden': True,
|
||||
'value': 'unset',
|
||||
}, {
|
||||
'name': 'Controller-1::ExtraConfig',
|
||||
'label': 'Extra Config',
|
||||
'description': 'Extra Config',
|
||||
'hidden': False,
|
||||
'value': '{}',
|
||||
}, {
|
||||
'name': 'Compute-1::ExtraConfig',
|
||||
'label': 'Extra Config',
|
||||
'description': 'Extra Config',
|
||||
'hidden': False,
|
||||
'value': '{}',
|
||||
}, {
|
||||
'name': 'Block Storage-1::ExtraConfig',
|
||||
'label': 'Extra Config',
|
||||
'description': 'Extra Config',
|
||||
'hidden': False,
|
||||
'value': '{}',
|
||||
}, {
|
||||
'name': 'Object Storage-1::ExtraConfig',
|
||||
'label': 'Extra Config',
|
||||
'description': 'Extra Config',
|
||||
'hidden': False,
|
||||
'value': '{}',
|
||||
}],
|
||||
})
|
||||
TEST.tuskarclient_plans.add(plan_1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user