class MaasHandler(OperationsHandler): """Manage the MAAS server.""" api_doc_section_name = "MAAS server" create = read = update = delete = None @admin_method @operation(idempotent=False) def set_config(self, request): """Set a config value. :param name: The name of the config item to be set. :param value: The value of the config item to be set. %s """ name = get_mandatory_param(request.data, 'name', validators.String(min=1)) name = rewrite_config_name(name) value = get_mandatory_param(request.data, 'value') form = get_maas_form(name, value) if not form.is_valid(): raise MAASAPIValidationError(form.errors) form.save(ENDPOINT.API, request) return rc.ALL_OK # Populate the docstring with the dynamically-generated documentation # about the available configuration items. set_config.__doc__ %= get_config_doc(indentation=8) @operation(idempotent=True) def get_config(self, request): """Get a config value. :param name: The name of the config item to be retrieved. %s """ name = get_mandatory_param(request.GET, 'name') name = rewrite_config_name(name) if name in migrated_config_values: value = migrated_config_values[name].getter() else: validate_config_name(name) value = Config.objects.get_config(name) return HttpResponse(json.dumps(value), content_type='application/json') # Populate the docstring with the dynamically-generated documentation # about the available configuration items. get_config.__doc__ %= get_config_doc(indentation=8) @classmethod def resource_uri(cls, *args, **kwargs): return ('maas_handler', [])
class MaasHandler(OperationsHandler): """Manage the MAAS server.""" api_doc_section_name = "MAAS server" create = read = update = delete = None @admin_method @operation(idempotent=False) def set_config(self, request): """@description-title Set a configuration value @description Set a configuration value. @param (string) "value" [required=false] The value of the configuration item to be set. @param (string) "name" [required=true,formatting=true] The name of the configuration item to be set. %s @success (http-status-code) "server-success" 200 @success (content) "set-success" A plain-text string @success-example "set-success" OK """ name = get_mandatory_param(request.data, "name", validators.String(min=1)) name = rewrite_config_name(name) value = get_mandatory_param(request.data, "value") form = get_maas_form(name, value) if not form.is_valid(): raise MAASAPIValidationError(form.errors) form.save(ENDPOINT.API, request) return rc.ALL_OK # Populate the docstring with the dynamically-generated documentation # about the available configuration items. set_config.__doc__ %= get_config_doc(indentation=8) @operation(idempotent=True) def get_config(self, request): """@description-title Get a configuration value @description Get a configuration value. @param (string) "name" [required=true,formatting=true] The name of the configuration item to be retrieved. %s @success (http-status-code) "server-success" 200 @success (content) "default_distro_series" A plain-text string containing the requested value, e.g. ``default_distro_series``. @success-example "default_distro_series" "bionic" """ name = get_mandatory_param(request.GET, "name") name = rewrite_config_name(name) if name in migrated_config_values: value = migrated_config_values[name].getter() else: validate_config_name(name) value = Config.objects.get_config(name) return HttpResponse(json.dumps(value), content_type="application/json") # Populate the docstring with the dynamically-generated documentation # about the available configuration items. get_config.__doc__ %= get_config_doc(indentation=8) @classmethod def resource_uri(cls, *args, **kwargs): return ("maas_handler", [])
def test_get_config_doc(self): doc = get_config_doc() # Just make sure that the doc looks okay. self.assertIn('maas_name', doc)