mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 05:59:28 -02:30
Change default pod spec in OPTIONS request to json
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import yaml
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
@@ -203,7 +202,7 @@ class Metadata(metadata.SimpleMetadata):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if field == "pod_spec_override":
|
if field == "pod_spec_override":
|
||||||
meta['default'] = yaml.dump(PodManager().pod_definition)
|
meta['default'] = PodManager().pod_definition
|
||||||
|
|
||||||
# Add type choices if available from the serializer.
|
# Add type choices if available from the serializer.
|
||||||
if field == 'type' and hasattr(serializer, 'get_type_choices'):
|
if field == 'type' and hasattr(serializer, 'get_type_choices'):
|
||||||
|
|||||||
@@ -57,9 +57,42 @@ function EditContainerGroupController($rootScope, $scope, $state, models, string
|
|||||||
toggleLabel: strings.get('container.POD_SPEC_TOGGLE')
|
toggleLabel: strings.get('container.POD_SPEC_TOGGLE')
|
||||||
};
|
};
|
||||||
|
|
||||||
const podSpecValue = EditContainerGroupDataset.data.pod_spec_override.trim();
|
function sanitizeVars (str) {
|
||||||
const defaultPodSpecValue = instanceGroup.model.OPTIONS.actions.PUT.pod_spec_override.default.trim();
|
// Quick function to test if the host vars are a json-object-string,
|
||||||
if (podSpecValue && podSpecValue !== defaultPodSpecValue) {
|
// by testing if they can be converted to a JSON object w/o error.
|
||||||
|
function IsJsonString (varStr) {
|
||||||
|
try {
|
||||||
|
JSON.parse(varStr);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof str === 'undefined') {
|
||||||
|
return '---';
|
||||||
|
}
|
||||||
|
if (typeof str !== 'string') {
|
||||||
|
const yamlStr = jsyaml.safeDump(str);
|
||||||
|
// jsyaml.safeDump doesn't process an empty object correctly
|
||||||
|
if (yamlStr === '{}\n') {
|
||||||
|
return '---';
|
||||||
|
}
|
||||||
|
return yamlStr;
|
||||||
|
}
|
||||||
|
if (str === '' || str === '{}') {
|
||||||
|
return '---';
|
||||||
|
} else if (IsJsonString(str)) {
|
||||||
|
str = JSON.parse(str);
|
||||||
|
return jsyaml.safeDump(str);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
const podSpecValue = sanitizeVars(EditContainerGroupDataset.data.pod_spec_override);
|
||||||
|
const defaultPodSpecValue = sanitizeVars(instanceGroup.model.OPTIONS.actions.PUT.pod_spec_override.default);
|
||||||
|
|
||||||
|
if (podSpecValue && podSpecValue.trim() !== defaultPodSpecValue.trim()) {
|
||||||
vm.form.extraVars.isOpen = true;
|
vm.form.extraVars.isOpen = true;
|
||||||
} else {
|
} else {
|
||||||
vm.form.extraVars.isOpen = false;
|
vm.form.extraVars.isOpen = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user