Revision dd42df0a
Added by Ohad Levy about 12 years ago
- ID dd42df0a3b5d8645ad6db731ec813e64b85a4120
public/javascripts/host_edit.js | ||
---|---|---|
function computeResourceSelected(item){
|
||
var compute = $(item).val();
|
||
var attrs = attribute_hash(['architecture_id', 'compute_resource_id', 'operatingsystem_id']);
|
||
var label = $(item).children(":selected").text();
|
||
if(compute=='') { //Bare Metal
|
||
$('#mac_address').show();
|
||
$('#bmc').show();
|
||
$('#compute_resource').empty();
|
||
$('#vm_details').empty();
|
||
$("#libvirt_tab").hide();
|
||
$('#host_hypervisor_id').val("");
|
||
$("#compute_resource_tab").hide();
|
||
update_capabilities('build');
|
||
}else if(label == 'Libvirt'){
|
||
$('#mac_address').hide();
|
||
$("#libvirt_tab").show();
|
||
$("#compute_resource_tab").hide();
|
||
$('#compute_resource').empty();
|
||
$(item).children(":selected").val("");
|
||
update_capabilities('build');
|
||
}
|
||
else {
|
||
$('#mac_address').hide();
|
||
$('#bmc').hide();
|
||
$("#libvirt_tab").hide();
|
||
$('#host_hypervisor_id').val("");
|
||
$("#compute_resource_tab").show();
|
||
... | ... | |
$.ajax({
|
||
type:'post',
|
||
url: url,
|
||
data:'compute_resource_id=' + compute,
|
||
data: attrs,
|
||
success: function(result){
|
||
$('#compute_resource').html(result);
|
||
$('#compute_resource').html(result);
|
||
update_capabilities($('#capabilities').val());
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
function update_capabilities(capabilities){
|
||
var build = (/build/i.test(capabilities));
|
||
var image = (/image/i.test(capabilities));
|
||
if (build){
|
||
$('#manage_network').show();
|
||
$('#host_provision_method_build').click();
|
||
} else {
|
||
$('#manage_network').hide();
|
||
$('#host_provision_method_image').click();
|
||
}
|
||
if(build && image){
|
||
$('#provisioning_method').show();
|
||
}else{
|
||
$('#provisioning_method').hide();
|
||
}
|
||
$('#image_provisioning').empty();
|
||
$('#image_selection').appendTo($('#image_provisioning'));
|
||
update_provisioning_image();
|
||
}
|
||
|
||
var stop_pooling;
|
||
|
||
function submit_host(form){
|
||
var url = form.attr("action");
|
||
$('#host_submit').attr('disabled', true);
|
||
stop_pooling = false;
|
||
$("body").css("cursor", "progress");
|
||
clear_errors();
|
||
animate_progress();
|
||
|
||
$.ajax({
|
||
type:'POST',
|
||
url: url,
|
||
data: form.serialize(),
|
||
success: function(response){
|
||
if(response.redirect){
|
||
window.location.replace(response.redirect);
|
||
}
|
||
else{
|
||
$("#host-progress").hide();
|
||
$('#content').replaceWith($("#content", response));
|
||
onContentLoad();
|
||
onHostEditLoad();
|
||
}
|
||
},
|
||
error: function(response){
|
||
$('#content').html(response.responseText);
|
||
},
|
||
complete: function(){
|
||
stop_pooling = true;
|
||
$("body").css("cursor", "auto");
|
||
$('#host_submit').attr('disabled', false);
|
||
}
|
||
});
|
||
return false;
|
||
}
|
||
|
||
function clear_errors(){
|
||
$('.error').children().children('.help-inline').remove();
|
||
$('.error').removeClass('error');
|
||
$('.tab-error').removeClass('tab-error');
|
||
$('.alert-error').remove();
|
||
}
|
||
|
||
function animate_progress(){
|
||
if (stop_pooling == true) return;
|
||
setTimeout(function() {
|
||
var task_id = $('#host_queuename').val();
|
||
$.get('/tasks/' + task_id, function (response){
|
||
update_progress(response);
|
||
animate_progress();
|
||
})
|
||
}, 1600);
|
||
}
|
||
|
||
function update_progress(data){
|
||
var task_list_size = $('p',data).size();
|
||
if (task_list_size == 0 || stop_pooling == true) return;
|
||
|
||
var done_tasks = $('.icon-check',data).size();
|
||
var failed_tasks = $('.icon-remove',data).size();
|
||
var $progress = $('.progress');
|
||
|
||
$("#host-progress").show();
|
||
if(failed_tasks > 0) {
|
||
$progress.removeClass('progress-success').addClass('progress-danger');
|
||
}else{
|
||
$progress.removeClass('progress-danger').addClass('progress-success');
|
||
}
|
||
$('.bar').width(done_tasks/task_list_size *$progress.width());
|
||
$('#tasks_progress').replaceWith(data);
|
||
}
|
||
|
||
function add_puppet_class(item){
|
||
var id = $(item).attr('data-class-id');
|
||
var type = $(item).attr('data-type');
|
||
... | ... | |
|
||
function hostgroup_changed(element) {
|
||
var host_id = $(element).attr('data-host-id');
|
||
var type = $(element).attr('data-type');
|
||
var url = $(element).attr('data-url');
|
||
var attrs = attribute_hash(['hostgroup_id', 'compute_resource_id']);
|
||
if (attrs["hostgroup_id"] == undefined) attrs["hostgroup_id"] = $('#hostgroup_parent_id').attr('value');
|
||
$('#hostgroup_indicator').show();
|
||
if (!host_id){ // a new host
|
||
$.ajax({
|
||
type:'post',
|
||
url:'/' + type + '/process_hostgroup',
|
||
url: url,
|
||
data:attrs,
|
||
complete: function(request){
|
||
complete: function(){
|
||
$('#hostgroup_indicator').hide();
|
||
$('[rel="twipsy"]').tooltip();
|
||
update_provisioning_image();
|
||
}
|
||
})
|
||
} else { // edit host
|
||
... | ... | |
function update_puppetclasses(element) {
|
||
var host_id = $(element).attr('data-host-id');
|
||
var env_id = $('*[id*=environment_id]').attr('value');
|
||
var type = $(element).attr('data-type');
|
||
var url = $(element).attr('data-url');
|
||
var hostgroup_id = $('*[id*=hostgroup_id]').attr('value');
|
||
if (env_id == "") return false;
|
||
var url = '/' + type;
|
||
url = (type == "hosts") ? url + '/hostgroup_or_environment_selected' : url + '/environment_selected';
|
||
if (env_id == "") return;
|
||
$.ajax({
|
||
type: 'post',
|
||
url: url,
|
||
... | ... | |
success: function(request) {
|
||
$('#puppet_klasses').html(request);
|
||
},
|
||
complete: function(request) {
|
||
complete: function() {
|
||
$('#hostgroup_indicator').hide();
|
||
$('[rel="twipsy"]').tooltip();
|
||
}
|
||
... | ... | |
}
|
||
function hypervisor_selected(element){
|
||
var hypervisor_id = $(element).val();
|
||
var type = $(element).attr('data-type');
|
||
var url = $(element).attr('data-url');
|
||
$('#vm_indicator').show();
|
||
$.ajax({
|
||
data:'hypervisor_id=' + hypervisor_id,
|
||
type:'post',
|
||
url:'/' + type + '/hypervisor_selected',
|
||
complete: function(request){
|
||
url: url,
|
||
complete: function(){
|
||
$('#vm_indicator').hide();
|
||
if ($('#host_name').size() == 0 ) $('#host_powerup').parent().parent().remove();
|
||
}
|
||
... | ... | |
|
||
function subnet_selected(element){
|
||
var subnet_id = $(element).val();
|
||
if (subnet_id == '' || $('#host_ip').size() == 0) return false;
|
||
if (subnet_id == '' || $('#host_ip').size() == 0) return;
|
||
// We do not query the proxy if the host_ip field is filled in and contains an
|
||
// IP that is in the selected subnet
|
||
var drop_text = $(element).children(":selected").text();
|
||
if (drop_text.length !=0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) {
|
||
var details = drop_text.replace(/^[^(]+\(/, "").replace(")","").split("/");
|
||
if (subnet_contains(details[0], details[1], $('#host_ip').val()))
|
||
return false;
|
||
return;
|
||
}
|
||
var attrs = attribute_hash(["subnet_id", "host_mac"]);
|
||
$('#subnet_indicator').show();
|
||
... | ... | |
data: attrs,
|
||
type:'post',
|
||
url:'/subnets/freeip',
|
||
complete: function(request){$('#subnet_indicator').hide()}
|
||
complete: function(){$('#subnet_indicator').hide()}
|
||
})
|
||
}
|
||
|
||
... | ... | |
function _to_int(str){
|
||
var nibble = str.split(".");
|
||
var integer = 0;
|
||
for(i=0;i<=3;i++){
|
||
for(var i=0;i<=3;i++){
|
||
integer = (integer * 256) + parseInt(nibble[i]);
|
||
}
|
||
return integer;
|
||
... | ... | |
|
||
function domain_selected(element){
|
||
var domain_id = $(element).val();
|
||
var type = $(element).attr('data-type');
|
||
var url = $(element).attr('data-url');
|
||
$.ajax({
|
||
data:'domain_id=' + domain_id,
|
||
type:'post',
|
||
url:'/' + type +'/domain_selected',
|
||
url: url,
|
||
success: function(request) {
|
||
$('#subnet_select').html(request);
|
||
}
|
||
... | ... | |
|
||
function architecture_selected(element){
|
||
var architecture_id = $(element).val();
|
||
var type = $(element).attr('data-type');
|
||
var url = $(element).attr('data-url');
|
||
$.ajax({
|
||
data:'architecture_id=' + architecture_id,
|
||
type:'post',
|
||
url:'/' + type + '/architecture_selected',
|
||
url: url,
|
||
success: function(request) {
|
||
$('#os_select').html(request);
|
||
}
|
||
... | ... | |
}
|
||
|
||
function os_selected(element){
|
||
var operatingsystem_id = $(element).val();
|
||
var type = $(element).attr('data-type');
|
||
var os_id = $(element).val();
|
||
var url = $(element).attr('data-url');
|
||
$.ajax({
|
||
data:'operatingsystem_id=' + operatingsystem_id,
|
||
data:'operatingsystem_id=' + os_id,
|
||
type:'post',
|
||
url:'/' + type + '/os_selected',
|
||
url: url,
|
||
success: function(request) {
|
||
$('#media_select').html(request);
|
||
}
|
||
})
|
||
});
|
||
update_provisioning_image();
|
||
}
|
||
function update_provisioning_image(){
|
||
var compute_id = $('[id$="_compute_resource_id"]').val();
|
||
var arch_id = $('[id$="_architecture_id"]').val();
|
||
var os_id = $('[id$="_operatingsystem_id"]').val();
|
||
if((compute_id == undefined) || (compute_id == "") || (arch_id == "") || (os_id == "")) return;
|
||
var term = 'operatingsystem=' + os_id + ' architecture=' + arch_id;
|
||
var image_options = $("[id$=compute_attributes_image_id]").empty();
|
||
$.ajax({
|
||
data:'search=' + encodeURIComponent(term),
|
||
type:'get',
|
||
url:'/compute_resources/'+compute_id+'/images',
|
||
dataType: 'json',
|
||
success: function(result) {
|
||
$.each(result, function() {
|
||
image_options.append($("<option />").val(this.image.uuid).text(this.image.name));
|
||
});
|
||
if (image_options.find('option').length > 0)
|
||
image_options.attr('disabled', false);
|
||
}
|
||
})
|
||
}
|
||
|
||
function medium_selected(element){
|
||
var url = $(element).attr('data-url');
|
||
var type = $(element).attr('data-type');
|
||
var obj = (type == "hosts" ? "host" : "hostgroup");
|
||
var attrs = {};
|
||
... | ... | |
$.ajax({
|
||
data: attrs,
|
||
type:'post',
|
||
url:'/' + type + '/medium_selected',
|
||
url: url,
|
||
success: function(request) {
|
||
$('#image_details').html(request);
|
||
}
|
||
... | ... | |
}
|
||
|
||
function use_image_selected(element){
|
||
var url = $(element).attr('data-url');
|
||
var type = $(element).attr('data-type');
|
||
var obj = (type == "hosts" ? "host" : "hostgroup");
|
||
var attrs = {};
|
||
... | ... | |
$.ajax({
|
||
data: attrs,
|
||
type: 'post',
|
||
url: '/' + type + '/use_image_selected',
|
||
url: url,
|
||
success: function(response) {
|
||
var field = $('*[id*=image_file]');
|
||
if (attrs[obj]["use_image"]) {
|
||
... | ... | |
}
|
||
|
||
$(function () {
|
||
onHostEditLoad();
|
||
});
|
||
|
||
function onHostEditLoad(){
|
||
$("#host-conflicts-modal").modal({show: "true", backdrop: "static"});
|
||
$('#host-conflicts-modal').click(function(){
|
||
$('#host-conflicts-modal').modal('hide');
|
||
$('#host-conflicts-modal').click(function(){
|
||
$('#host-conflicts-modal').modal('hide');
|
||
});
|
||
var $form = $("[data-submit='progress_bar']");
|
||
$form.on('submit', function(){
|
||
submit_host($form);
|
||
return false;
|
||
});
|
||
});
|
||
|
||
$('#host_provision_method_build').on('click', function(){
|
||
$('#network_provisioning').show();
|
||
$('#image_provisioning').hide();
|
||
});
|
||
$('#host_provision_method_image').on('click', function(){
|
||
$('#network_provisioning').hide();
|
||
$('#image_provisioning').show();
|
||
});
|
||
|
||
$('#image_selection').appendTo($('#image_provisioning'));
|
||
}
|
Also available in: Unified diff
adds ec2 provisioning support fixes #1223
- added progress bar for instance creation
- minor fixes for certname based deployments
- added ssh provisioning support to orchestartion, which utilize finish
scripts by default
- added images support (part of the vm compute tab)
- cleanup a lot of unused view attributes in favour of a couple html5
data attributes
- adds capabilities to each compute resource (e.g. build vs. image
provisioning)
- allow to access @host.compute_resource and @host.info in provisioning
templates
- added automatic ssh key pair generation when creating a new compute
resource (note, if you already created one, you would need to delete
it and create it again
- reverse dns now depends on the selected subnet - fixes #1558
- added readonly console support for ec2