Skip to content

Commit

Permalink
Handling scheduling conf
Browse files Browse the repository at this point in the history
  • Loading branch information
maricaantonacci committed Apr 11, 2019
1 parent 6a038df commit d19b636
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
26 changes: 21 additions & 5 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,35 @@ def createdep():

access_token = iam_blueprint.session.token['access_token']

app.logger.debug("Form data: " + json.dumps(request.form.to_dict()))

try:
with io.open( toscaDir + request.args.get('template')) as stream:
template = yaml.load(stream)
if 'selectSla' in request.form.to_dict():
template = add_sla_to_template(template, request.form.get('selectedSLA'))

payload = { "template" : yaml.dump(template,default_flow_style=False), "parameters": request.form.to_dict() }
form_data = request.form.to_dict()

params={}
if 'extra_opts.keepLastAttempt' in form_data:
params['keepLastAttempt'] = 'true'
else:
params['keepLastAttempt'] = 'false'

if form_data['extra_opts.schedtype'] == "man":
template = add_sla_to_template(template, form_data['extra_opts.selectedSLA'])

inputs = { k:v for (k,v) in form_data.items() if not k.startswith("extra_opts.") }

app.logger.debug("Parameters: " + json.dumps(inputs))

payload = { "template" : yaml.dump(template,default_flow_style=False), "parameters": inputs }

body= json.dumps(payload)
#body= json.dumps(payload)

url = orchestratorUrl + "/deployments/"
headers = {'Content-Type': 'application/json', 'Authorization': 'bearer %s' % (access_token)}
response = requests.post(url, data=body, headers=headers)
#response = requests.post(url, data=body, headers=headers)
response = requests.post(url, json=payload, params=params, headers=headers)

if not response.ok:
flash("Error submitting deployment: \n" + response.text)
Expand Down
44 changes: 39 additions & 5 deletions app/templates/createdep.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,25 @@ <h2>Set input values:</h2>
{% endfor %}
{% endif %}
<div class="form-group">
<input type="checkbox" id="checkboxSLA" name="selectSla" value=""></label>
<label for="sel1">Select a provider:</label>
<select class="form-control" id="selectSLA" name="selectedSLA" disabled>
<p><h2>Configure scheduling:</h2></p>
<label class="radio-inline">
<input id="autosched" type="radio" name="extra_opts.schedtype" value="auto" checked>Auto
</label>
<label class="radio-inline">
<input id="mansched" type="radio" name="extra_opts.schedtype" value="man">Manual
</label>
</div>
<div id="autoschedConf" class="form-group">
<label for="keepLastAttempt">Do not delete the deployment in case of failure
<input type="checkbox" id="keepLastAttempt" name="extra_opts.keepLastAttempt" value="">
</label>
</div>
<div id="manschedConf" class="form-group">
<label for="keepLastAttempt">Do not delete the deployment in case of failure
<input type="checkbox" id="keepLastAttempt" name="extra_opts.keepLastAttempt" value="">
</label><p><p>
<label>Select a provider:</label>
<select class="form-control" id="selectSLA" name="extra_opts.selectedSLA">
{% for sla in slas %}
<option name="selectedSLA" value={{sla.id}}>{{sla.sitename}}: {{sla.service_type}}</option>
{% endfor %}
Expand All @@ -66,6 +82,11 @@ <h2>Set input values:</h2>
{% endif %}
</div>

<style>
#manschedConf {
display: none;
}
</style>
<script>
$(document).ready(function() {
$('.js-example-basic-single').select2();
Expand All @@ -80,8 +101,21 @@ <h2>Set input values:</h2>
});
});

$('#checkboxSLA').change(function() {
$('#selectSLA').attr('disabled',!this.checked)
$(document).ready(function () {
$("input[name='extra_opts.schedtype']").click(function() {
if ($("#mansched").is(":checked")){
$('#manschedConf').show();
$('#autoschedConf').hide();
}
else {
$('#manschedConf').hide();
$('#autoschedConf').show();
}
});
});

//$('#checkboxSLA').change(function() {
// $('#selectSLA').attr('disabled',!this.checked)
//});
</script>
{% endblock %}

0 comments on commit d19b636

Please sign in to comment.