Merge pull request #1536 from leigh-johnson/ScheduleExtraVars

Support extra_vars on job template schedules
This commit is contained in:
Leigh
2016-04-14 14:14:51 -04:00
6 changed files with 686 additions and 632 deletions

View File

@@ -173,8 +173,8 @@ export default
} }
$state.go("^"); $state.go("^");
}); });
scope.saveSchedule = function() { scope.saveSchedule = function() {
schedule.extra_data = scope.serializedExtraVars;
SchedulePost({ SchedulePost({
scope: scope, scope: scope,
url: url, url: url,
@@ -192,6 +192,7 @@ export default
Rest.get() Rest.get()
.success(function(data) { .success(function(data) {
schedule = data; schedule = data;
scope.serializedExtraVars = schedule.extra_data;
if(schedule.extra_data.hasOwnProperty('granularity')){ if(schedule.extra_data.hasOwnProperty('granularity')){
scope.isFactCleanup = true; scope.isFactCleanup = true;
} }
@@ -312,7 +313,6 @@ export default
schedule = (params.schedule) ? params.schedule : {}, schedule = (params.schedule) ? params.schedule : {},
callback = params.callback, callback = params.callback,
newSchedule, rrule, extra_vars; newSchedule, rrule, extra_vars;
if (scheduler.isValid()) { if (scheduler.isValid()) {
Wait('start'); Wait('start');
newSchedule = scheduler.getValue(); newSchedule = scheduler.getValue();
@@ -326,14 +326,16 @@ export default
"older_than": scope.scheduler_form.keep_amount.$viewValue + scope.scheduler_form.keep_unit.$viewValue.value, "older_than": scope.scheduler_form.keep_amount.$viewValue + scope.scheduler_form.keep_unit.$viewValue.value,
"granularity": scope.scheduler_form.granularity_keep_amount.$viewValue + scope.scheduler_form.granularity_keep_unit.$viewValue.value "granularity": scope.scheduler_form.granularity_keep_amount.$viewValue + scope.scheduler_form.granularity_keep_unit.$viewValue.value
}; };
schedule.extra_data = JSON.stringify(extra_vars);
} else if (scope.cleanupJob) { } else if (scope.cleanupJob) {
extra_vars = { extra_vars = {
"days" : scope.scheduler_form.schedulerPurgeDays.$viewValue "days" : scope.scheduler_form.schedulerPurgeDays.$viewValue
}; };
}
schedule.extra_data = JSON.stringify(extra_vars); schedule.extra_data = JSON.stringify(extra_vars);
}
else if (scope.serializedExtraVars){
schedule.extra_data = scope.serializedExtraVars;
}
Rest.setUrl(url); Rest.setUrl(url);
if (mode === 'add') { if (mode === 'add') {
Rest.post(schedule) Rest.post(schedule)

View File

@@ -52,7 +52,7 @@ export default
filter: "longDate", filter: "longDate",
searchable: false, searchable: false,
columnClass: "List-staticColumn--schedulerTime hidden-xs" columnClass: "List-staticColumn--schedulerTime hidden-xs"
} },
}, },
actions: { actions: {

View File

@@ -34,6 +34,14 @@ export default
resolve: { resolve: {
features: ['FeaturesService', function(FeaturesService) { features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get(); return FeaturesService.get();
}],
JobTemplateExtraVars: ['Rest', 'GetBasePath', 'ToJSON', '$stateParams', function(Rest, GetBasePath, ToJSON, $stateParams) {
var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/';
Rest.setUrl(defaultUrl);
return Rest.get().then(function(res){
// handle unescaped newlines
return JSON.parse(JSON.stringify(res.data.extra_vars))
});
}] }]
} }
}); });

View File

@@ -1,4 +1,4 @@
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2) { export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'JobTemplateExtraVars', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, JobTemplateExtraVars) {
$scope.$on("ScheduleFormCreated", function(e, scope) { $scope.$on("ScheduleFormCreated", function(e, scope) {
$scope.hideForm = false; $scope.hideForm = false;
$scope = angular.extend($scope, scope); $scope = angular.extend($scope, scope);
@@ -41,10 +41,35 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
$scope.hideForm = true; $scope.hideForm = true;
$scope.formCancel = function() { $scope.formCancel = function() {
$state.go("^"); $state.go("^");
}; };
$scope.parseType = 'yaml';
$scope.extraVars = JobTemplateExtraVars === '' ? '---' : JobTemplateExtraVars;
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
});
$scope.$watch('extraVars', function(){
if ($scope.parseType === 'yaml'){
try{
$scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars);
}
catch(err){ return; }
}
else if ($scope.parseType === 'json'){
try{
$scope.serializedExtraVars = JSON.parse($scope.extraVars);
}
catch(err){ return; }
}
});
AddSchedule({ AddSchedule({
scope: $scope, scope: $scope,
callback: 'SchedulesRefresh', callback: 'SchedulesRefresh',

View File

@@ -1,4 +1,4 @@
export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', function($compile, $state, $stateParams, EditSchedule, Wait, $scope, $rootScope, CreateSelect2) { export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', function($compile, $state, $stateParams, EditSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange) {
$scope.$on("ScheduleFormCreated", function(e, scope) { $scope.$on("ScheduleFormCreated", function(e, scope) {
$scope.hideForm = false; $scope.hideForm = false;
$scope = angular.extend($scope, scope); $scope = angular.extend($scope, scope);
@@ -41,13 +41,49 @@ export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$
}); });
$scope.isEdit = true; $scope.isEdit = true;
$scope.hideForm = true; $scope.hideForm = true;
$scope.parseType = 'yaml';
$scope.formCancel = function() { $scope.formCancel = function() {
$state.go("^"); $state.go("^");
} }
$scope.$on('ScheduleFound', function(){
if ($scope.parseType === 'yaml'){
try{
$scope.extraVars = '---\n' + jsyaml.safeDump($scope.serializedExtraVars);
}
catch(err){ return; }
}
else if ($scope.parseType === 'json'){
try{
$scope.extraVars = JSON.stringify($scope.serializedExtraVars, null, ' ');
}
catch(err){ return; }
}
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
});
});
$scope.$watch('extraVars', function(){
if ($scope.parseType === 'yaml'){
try{
$scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars);
}
catch(err){ return; }
}
else if ($scope.parseType === 'json'){
try{
$scope.serializedExtraVars = JSON.parse($scope.extraVars);
}
catch(err){ return; }
}
});
EditSchedule({ EditSchedule({
scope: $scope, scope: $scope,
id: parseInt($stateParams.schedule_id), id: parseInt($stateParams.schedule_id),

View File

@@ -9,7 +9,6 @@
</div> </div>
</div> </div>
<div id="SchedulerFormTarget"> <div id="SchedulerFormTarget">
<form class="form Form" <form class="form Form"
role="form" role="form"
name="scheduler_form_new" name="scheduler_form_new"
@@ -526,47 +525,6 @@
<div class="RepeatFrequencyOptions-subFormBorderFixer" <div class="RepeatFrequencyOptions-subFormBorderFixer"
ng-show="schedulerFrequency.value && schedulerFrequency.value !== 'none'"> ng-show="schedulerFrequency.value && schedulerFrequency.value !== 'none'">
</div> </div>
<!-- <div class="factDetailsNote" ng-if="isFactCleanup"><span class="factDetailsHeader">Note:</span> For facts collected older than the time period specified, save one fact scan (snapshot) per time window (frequency). For example, facts older than 30 days are purged, while one weekly fact scan is kept.
Caution: Setting both numerical variables to "0" will delete all facts.</div> -->
<!-- <div class="form-group" ng-if="cleanupJob && !isFactCleanup">
<label class="Form-inputLabel"><span class="red-text">*</span> Days of data to keep</label>
<input type="number" class="form-control input-sm" name="schedulerPurgeDays" id="schedulerPurgeDays" min="1" ng-model="schedulerPurgeDays" required placeholder="Days of data to keep">
<div class="error" ng-show="scheduler_form.schedulerPurgeDays.$dirty && scheduler_form.schedulerPurgeDays.$error.required">A value is required.</div>
<div class="error" ng-show="scheduler_form.schedulerPurgeDays.$error.number">This is not a valid number.</div>
</div>
<div class="form-group cleanupStretcher factDaysToKeepCompacter" ng-if="isFactCleanup">
<div class="col-md-12">
<label class="Form-inputLabel"><span class="red-text">*</span> Select a time period after which to remove old facts</label>
</div>
<div class="col-md-6 inputSpacer inputCompactMobile">
<input type="number" id="keep_amount" name="keep_amount" ng-model="keep_amount" ng-required="true" class="form-control input-sm" aw-min=0 aw-max=9999 integer></input>
<div class="error" ng-show="scheduler_form.keep_amount.$dirty && scheduler_form.keep_amount.$error.required">Please enter the number of days you would like to keep this data.</div>
<div class="error survey_error" ng-show="scheduler_form.keep_amount.$error.number || scheduler_form.keep_amount.$error.integer" >Please enter a valid number.</div>
<div class="error survey_error" ng-show="scheduler_form.keep_amount.$error.awMin">Please enter a non-negative number.</div>
<div class="error survey_error" ng-show="scheduler_form.keep_amount.$error.awMax">Please enter a number smaller than 9999.</div>
</div>
<div class="col-md-6 inputSpacer">
<select id="keep_unit" name="keep_unit" ng-model="keep_unit" ng-options="type.label for type in keep_unit_choices track by type.value" ng-required="true" class="form-control input-sm"></select>
</div>
</div> -->
<!-- <div class="form-group cleanupStretcher" ng-if="isFactCleanup">
<div class="col-md-12">
<label class="Form-inputLabel"><span class="red-text">*</span> Select a frequency for snapshot retention</label>
</div>
<div class="col-md-6 inputSpacer inputCompactMobile">
<input type="number" class="form-control input-sm" id="granularity_keep_amount" name="granularity_keep_amount" ng-model="granularity_keep_amount" ng-required="true" aw-min=0 aw-max=9999 >
<div class="error" ng-show="scheduler_form.granularity_keep_amount.$dirty && scheduler_form.granularity_keep_amount.$error.required">Please enter the number of days you would like to keep this data.</div>
<div class="error survey_error" ng-show="scheduler_form.granularity_keep_amount.$error.number || scheduler_form.granularity_keep_amount.$error.integer" >Please enter a valid number.</div>
<div class="error survey_error" ng-show="scheduler_form.granularity_keep_amount.$error.awMin">Please enter a non-negative number.</div>
<div class="error survey_error" ng-show="scheduler_form.granularity_keep_amount.$error.awMax">Please enter a number smaller than 9999.</div>
</div>
<div class="col-md-6 inputSpacer">
<select id="granularity_keep_unit" name="granularity_keep_unit" ng-model="granularity_keep_unit" ng-options="type.label for type in granularity_keep_unit_choices track by type.value" ng-required="true" class="form-control input-sm"></select>
</div>
</div> -->
</form> </form>
<div class="SchedulerFormDetail-container <div class="SchedulerFormDetail-container
SchedulerFormDetail-container--error" SchedulerFormDetail-container--error"
@@ -632,8 +590,33 @@
{{ occurrence.local }} {{ occurrence.local }}
</li> </li>
</ul> </ul>
</div>
<div class="form-group Form-formGroup Form-textAreaLabel">
<label for="Scheduler-extraVars">
<span class="Form-inputLabel">
Extra Variables
</span>
<!-- tooltip -->
<a aw-pop-over="<p>Pass extra command line variables to the playbook. This is the -e or --extra-vars command line parameter for ansible-playbook. Provide key/value pairs using either YAML or JSON.</p>JSON:<br />
<blockquote>{<br />&quot;somevar&quot;: &quot;somevalue&quot;,<br />&quot;password&quot;: &quot;magic&quot;<br /> }</blockquote>
YAML:<br />
<blockquote>---<br />somevar: somevalue<br />password: magic<br /></blockquote>"
data-placement="right" data-container="body" over-title="Extra Variables" class="help-link" data-original-title="" title="" tabindex="-1">
<i class="fa fa-question-circle"></i>
</a>
<div class="parse-selection">
<input type="radio" ng-model="parseType" ng-change="parseTypeChange()" value="yaml"><span class="parse-label">YAML</span>
<input type="radio" ng-model="parseType" ng-change="parseTypeChange()" value="json"> <span class="parse-label">JSON</span>
</div> </div>
</label>
<div>
<textarea rows="6" ng-model="extraVars" name="Scheduler-extraVars" class="form-control" id="SchedulerForm-extraVars"></textarea>
</div>
</div>
</div>
<div class="buttons Form-buttons"> <div class="buttons Form-buttons">
<button type="button" <button type="button"
class="btn btn-sm Form-saveButton" class="btn btn-sm Form-saveButton"