Project

General

Profile

Download (7.19 KB) Statistics
| Branch: | Tag: | Revision:
334d0359 Amos Benari
function computeResourceSelected(item){
var compute = $(item).val();
var label = $(item).children(":selected").text();
if(compute=='') { //Bare Metal
$('#mac_address').show();
$('#compute_resource').empty();
$('#vm_details').empty();
$("#libvirt_tab").hide();
$('#host_hypervisor_id').val("");
$("#compute_resource_tab").hide();
}else if(label == 'Libvirt'){
$('#mac_address').hide();
$("#libvirt_tab").show();
$("#compute_resource_tab").hide();
$('#compute_resource').empty();
33e8b654 Ohad Levy
$(item).children(":selected").val("");
334d0359 Amos Benari
}
else {
$('#mac_address').hide();
$("#libvirt_tab").hide();
$('#host_hypervisor_id').val("");
$("#compute_resource_tab").show();
$('#vm_details').empty();
var url = $(item).attr('data-url');
$.ajax({
type:'post',
url: url,
data:'compute_resource_id=' + compute,
success: function(result){
$('#compute_resource').html(result);
}
})
}
}

017e1049 Ohad Levy
function add_puppet_class(item){
var id = $(item).attr('data-class-id');
30e1b33e Ohad Levy
var type = $(item).attr('data-type');
017e1049 Ohad Levy
var content = $(item).parent().clone();
content.attr('id', 'selected_puppetclass_'+ id);
30e1b33e Ohad Levy
content.append("<input id='" + type +"_puppetclass_ids_' name='" + type +"[puppetclass_ids][]' type='hidden' value=" +id+ ">");
82e47ae0 Amos Benari
content.children('span').tooltip();
017e1049 Ohad Levy
fdac5d15 Amos Benari
var link = content.children('a');
017e1049 Ohad Levy
link.attr('onclick', 'remove_puppet_class(this)');
fdac5d15 Amos Benari
link.attr('data-original-title', 'Click to undo adding this class');
82e47ae0 Amos Benari
link.removeClass('ui-icon-plus').addClass('ui-icon-minus').tooltip();
017e1049 Ohad Levy
3c673e9e Ohad Levy
$('#selected_classes').append(content);
017e1049 Ohad Levy
$("#selected_puppetclass_"+ id).show('highlight', 5000);
$("#puppetclass_"+ id).hide();
}

function remove_puppet_class(item){
var id = $(item).attr('data-class-id');
$('#puppetclass_' + id ).show();
82e47ae0 Amos Benari
$('#selected_puppetclass_' + id).children('a').tooltip('hide');
017e1049 Ohad Levy
$('#selected_puppetclass_' + id).remove();

return false;
}

function hostgroup_changed(element) {
var host_id = $(element).attr('data-host-id');
334d0359 Amos Benari
var type = $(element).attr('data-type');
var attrs = attribute_hash(['hostgroup_id', 'compute_resource_id']);
if (attrs["hostgroup_id"] == undefined) attrs["hostgroup_id"] = $('#hostgroup_parent_id').attr('value');
017e1049 Ohad Levy
$('#hostgroup_indicator').show();
if (!host_id){ // a new host
$.ajax({
type:'post',
24e55891 Ohad Levy
url:'/' + type + '/process_hostgroup',
334d0359 Amos Benari
data:attrs,
017e1049 Ohad Levy
complete: function(request){
b7cb4996 Ohad Levy
$('#hostgroup_indicator').hide();
82e47ae0 Amos Benari
$('[rel="twipsy"]').tooltip();
017e1049 Ohad Levy
}
})
} else { // edit host
update_puppetclasses(element);
}
}

function update_puppetclasses(element) {
var host_id = $(element).attr('data-host-id');
var env_id = $('*[id*=environment_id]').attr('value');
24e55891 Ohad Levy
var type = $(element).attr('data-type');
017e1049 Ohad Levy
var hostgroup_id = $('*[id*=hostgroup_id]').attr('value');
if (env_id == "") return false;
24e55891 Ohad Levy
var url = '/' + type;
331e9bce Ohad Levy
url = (type == "hosts") ? url + '/hostgroup_or_environment_selected' : url + '/environment_selected';
017e1049 Ohad Levy
$.ajax({
24e55891 Ohad Levy
type: 'post',
url: url,
017e1049 Ohad Levy
data:'host_id=' + host_id + '&hostgroup_id=' + hostgroup_id + '&environment_id=' + env_id,
success: function(request) {
$('#puppet_klasses').html(request);
},
complete: function(request) {
$('#hostgroup_indicator').hide();
82e47ae0 Amos Benari
$('[rel="twipsy"]').tooltip();
017e1049 Ohad Levy
}
})
}
function hypervisor_selected(element){
var hypervisor_id = $(element).val();
24e55891 Ohad Levy
var type = $(element).attr('data-type');
017e1049 Ohad Levy
$('#vm_indicator').show();
$.ajax({
data:'hypervisor_id=' + hypervisor_id,
type:'post',
24e55891 Ohad Levy
url:'/' + type + '/hypervisor_selected',
017e1049 Ohad Levy
complete: function(request){
$('#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;
fc782b06 Paul Kelly
// We do not query the proxy if the host_ip field is filled in and contains an
// IP that is in the selected subnet
ba303020 Sander Hoentjen
var drop_text = $(element).children(":selected").text();
fc782b06 Paul Kelly
if (drop_text.length !=0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) {
ba303020 Sander Hoentjen
var details = drop_text.replace(/^[^(]+\(/, "").replace(")","").split("/");
fc782b06 Paul Kelly
if (subnet_contains(details[0], details[1], $('#host_ip').val()))
return false;
}
e89efb28 Ohad Levy
var attrs = attribute_hash(["subnet_id", "host_mac"]);
017e1049 Ohad Levy
$('#subnet_indicator').show();
$.ajax({
e89efb28 Ohad Levy
data: attrs,
017e1049 Ohad Levy
type:'post',
url:'/subnets/freeip',
complete: function(request){$('#subnet_indicator').hide()}
})
}

fc782b06 Paul Kelly
function subnet_contains(number, cidr, ip){
var int_ip = _to_int(ip);
var int_number = _to_int(number);
var shift = 32 - parseInt(cidr);
return (int_ip >> shift == int_number >> shift);
}

function _to_int(str){
var nibble = str.split(".");
var integer = 0;
for(i=0;i<=3;i++){
integer = (integer * 256) + parseInt(nibble[i]);
}
return integer;
}

017e1049 Ohad Levy
function domain_selected(element){
var domain_id = $(element).val();
24e55891 Ohad Levy
var type = $(element).attr('data-type');
017e1049 Ohad Levy
$.ajax({
data:'domain_id=' + domain_id,
type:'post',
24e55891 Ohad Levy
url:'/' + type +'/domain_selected',
017e1049 Ohad Levy
success: function(request) {
$('#subnet_select').html(request);
}
})
}

function architecture_selected(element){
var architecture_id = $(element).val();
24e55891 Ohad Levy
var type = $(element).attr('data-type');
017e1049 Ohad Levy
$.ajax({
data:'architecture_id=' + architecture_id,
type:'post',
24e55891 Ohad Levy
url:'/' + type + '/architecture_selected',
017e1049 Ohad Levy
success: function(request) {
$('#os_select').html(request);
}
})
}

function os_selected(element){
var operatingsystem_id = $(element).val();
24e55891 Ohad Levy
var type = $(element).attr('data-type');
017e1049 Ohad Levy
$.ajax({
data:'operatingsystem_id=' + operatingsystem_id,
type:'post',
24e55891 Ohad Levy
url:'/' + type + '/os_selected',
017e1049 Ohad Levy
success: function(request) {
$('#media_select').html(request);
}
})
}
da6fa387 Ohad Levy
function medium_selected(element){
var type = $(element).attr('data-type');
var obj = (type == "hosts" ? "host" : "hostgroup");
var attrs = {};
attrs[obj] = attribute_hash(['medium_id', 'operatingsystem_id', 'architecture_id']);
dc0f0f5f Ohad Levy
attrs[obj]["use_image"] = $('*[id*=use_image]').attr('checked') == "checked";
da6fa387 Ohad Levy
$.ajax({
data: attrs,
type:'post',
url:'/' + type + '/medium_selected',
success: function(request) {
$('#image_details').html(request);
}
})
}

function use_image_selected(element){
var type = $(element).attr('data-type');
var obj = (type == "hosts" ? "host" : "hostgroup");
var attrs = {};
attrs[obj] = attribute_hash(['medium_id', 'operatingsystem_id', 'architecture_id', 'model_id']);
attrs[obj]['use_image'] = ($(element).attr('checked') == "checked");
$.ajax({
data: attrs,
type: 'post',
url: '/' + type + '/use_image_selected',
success: function(response) {
var field = $('*[id*=image_file]');
if (attrs[obj]["use_image"]) {
if (field.val() == "") field.val(response["image_file"]);
} else
field.val("");

field.attr("disabled", !attrs[obj]["use_image"]);
}
});
}

30ae12bf Ohad Levy
$(function () {
$("#host-conflicts-modal").modal({show: "true", backdrop: "static"});
$('#host-conflicts-modal').click(function(){
$('#host-conflicts-modal').modal('hide');
});
});