/* -------------------------------------------------------------------------- */
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
var empty_graph_placeholder =
''+
''+
//''+
''+
' '+
''+
tr("There is no information available")+
'';
var empty_quota_placeholder = 0
var provision_quotas_dashboard =
'
'+
'
'+
'
'+
tr("Quotas")+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
''+tr("RUNNING VMS")+''+
' '+
''+
'
'+
'
'+
''+tr("CPU")+''+
' '+
''+
'
'+
'
'+
''+tr("MEMORY")+''+
' '+
''+
'
'+
'
'+
'
'+
'
'+
' '+
' ';
var provision_vdc_quotas_dashboard =
'
'+
'
'+
'
'+
tr("VDC Quotas")+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
''+
empty_quota_placeholder +
''+
''+"%"+''+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
''+tr("RUNNING VMS")+''+
' '+
''+
'
'+
'
'+
''+tr("CPU")+''+
' '+
''+
'
'+
'
'+
''+tr("MEMORY")+''+
' '+
''+
'
'+
'
'+
'
'+
'
'+
' '+
' ';
var provision_vms_dashboard =
'
'+
'
'+
'
'+
tr("Virtual Machines")+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("TOTAL")+''+
'
'+
'
'+
' '+
' '+
'
'+
'
'+
''+
''+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("RUNNING")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("DEPLOYING")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("OFF")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("ERROR")+''+
'
'+
'
'+
'
'+
'
'+
''+
'
'+
'
'+
'
'+tr("CPU hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+tr("Memory GB hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
' ';
var provision_vdc_vms_dashboard =
'
'+
'
'+
'
'+
tr("VDC Virtual Machines")+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("TOTAL")+''+
'
'+
'
'+
' '+
' '+
'
'+
'
'+
''+
''+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("RUNNING")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("DEPLOYING")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("OFF")+''+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("ERROR")+''+
'
'+
'
'+
'
'+
'
'+
''+
'
'+
'
'+
'
'+tr("CPU hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+tr("Memory GB hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
' ';
var provision_users_dashboard =
'
'+
'
'+
'
'+
tr("Users")+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
''+
''+
''+
' '+
''+tr("TOTAL")+''+
'
'+
'
'+
' '+
' '+
'
'+
'
'+
''+
''+
'
'+
'
'+
' '+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+
'
'+
'
'+
'
'+tr("CPU hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+tr("Memory GB hours")+'
'+
'
'+
'
'+
'
'+
empty_graph_placeholder +
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
' ';
var provision_dashboard = '
'+
'
';
var provision_create_vm = '';
var provision_create_flow = '';
var provision_create_user = '';
var provision_user_info = '
'+
''+
tr("This Virtual Machine will be saved in a new Template. Only the main disk will be preserved!")+
' '+
tr("You can then create a new Virtual Machine using this Template")+
''+
'
'+
''+
tr("This action will power off this Virtual Machine. The Virtual Machine will remain in the poweroff state, and can be powered on later")+
' '+
' '+
tr("You can send the power off signal to the Virtual Machine (this is equivalent to execute the command from the console). If that doesn't effect your Virtual Machine, try to Power off the machine (this is equivalent to pressing the power off button in a physical computer).")+
''+
'
'+
''+
tr("This action will reboot this Virtual Machine.")+
' '+
' '+
tr("You can send the reboot signal to the Virtual Machine (this is equivalent to execute the reboot command form the console). If that doesn't effect your Virtual Machine, try to Reboot the machine (this is equivalent to pressing the reset button a physical computer).")+
''+
'
');
});
context.on("click", ".provision_delete_template_button", function(){
var button = $(this);
button.attr("disabled", "disabled");
var template_id = $(this).attr("template_id");
var image_id = $(this).attr("image_id");
OpenNebula.Image.del({
timeout: true,
data : {
id : image_id
},
success: function (){
OpenNebula.Template.del({
timeout: true,
data : {
id : template_id
},
success: function (){
$(".provision_templates_list_refresh_button", context).trigger("click");
},
error: function (request,error_json, container) {
onError(request, error_json, container);
}
})
},
error: function (request,error_json, container) {
if (error_json.error.http_status=="404") {
OpenNebula.Template.del({
timeout: true,
data : {
id : template_id
},
success: function (){
$(".provision_templates_list_refresh_button", context).trigger("click");
},
error: function (request,error_json, container) {
onError(request, error_json, container);
$(".provision_templates_list_refresh_button", context).trigger("click");
}
})
} else {
onError(request, error_json, container);
}
}
})
});
}
if (Config.isTabActionEnabled("provision-tab", "Template.chmod")) {
context.on("click", ".provision_confirm_chmod_template_button", function(){
var ul_context = $(this).parents(".provision-pricing-table");
var template_id = ul_context.attr("opennebula_id");
var image_id = ul_context.attr("saved_to_image_id");
var template_name = $(".provision-title", ul_context).text();
$(".provision_confirm_delete_template_div", context).html(
'
'+
'
'+
'
'+
''+
tr("The template")+
' "' + template_name + '" ' +
tr("and the image associated will be shared and all the users will be able to instantiate new VMs using this template.") +
''+
'
');
});
context.on("click", ".provision_chmod_template_button", function(){
var button = $(this);
button.attr("disabled", "disabled");
var template_id = $(this).attr("template_id");
var image_id = $(this).attr("image_id");
OpenNebula.Template.chmod({
timeout: true,
data : {
id : template_id,
extra_param: {'group_u': 1}
},
success: function (){
$(".provision_templates_list_refresh_button", context).trigger("click");
OpenNebula.Image.chmod({
timeout: true,
data : {
id : image_id,
extra_param: {'group_u': 1}
},
success: function (){
},
error: onError
})
},
error: onError
})
});
context.on("click", ".provision_confirm_unshare_template_button", function(){
var ul_context = $(this).parents(".provision-pricing-table");
var template_id = ul_context.attr("opennebula_id");
var image_id = ul_context.attr("saved_to_image_id");
var template_name = $(".provision-title", ul_context).first().text();
$(".provision_confirm_delete_template_div", context).html(
'
'+
'
'+
'
'+
''+
tr("The template")+
' "' + template_name + '" ' +
tr("and the image associated will be unshared and the users will not be able to instantiate new VMs using this template.") +
''+
'
');
}
return true;
},
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var data = aData.USER;
//var state = get_provision_vm_state(data);
var vms = "";
var memory = "";
var cpu = "";
// Inject the VM user quota. This info is returned separately in the
// pool info call, but the userElementArray expects it inside the USER,
// as it is returned by the individual info call
var q = provision_quotas_list[data.ID];
var quotas_html;
if (q != undefined){
var quota = q.QUOTAS;
if (!$.isEmptyObject(quota.VM_QUOTA)){
quotas = quotaBarFloat(
quota.VM_QUOTA.VM.VMS_USED,
quota.VM_QUOTA.VM.VMS,
default_user_quotas.VM_QUOTA.VM.VMS,
true);
quotas_html = "";
quotas_html += '
');
}
return true;
},
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var data = aData.VMTEMPLATE;
var logo;
if (data.TEMPLATE.LOGO) {
logo = ''+
''+
'';
} else {
logo = ''+
''+
'';
}
var li = $('
'+
'
'+
'
'+
data.NAME+
'
'+
'
'+
logo +
'
'+
'
'+
(data.TEMPLATE.DESCRIPTION || '...')+
'
'+
'
'+
'
').appendTo($("#provision_system_templates_ul"));
$(".provision-pricing-table", li).data("opennebula", aData);
return nRow;
}
});
provision_vdc_templates_datatable = $('#provision_vdc_templates_table').dataTable({
"iDisplayLength": 6,
"sDom" : '<"H">t<"F"lp>',
"aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
"aoColumnDefs": [
{ "bVisible": false, "aTargets": ["all"]}
],
"aoColumns": [
{ "mDataProp": "VMTEMPLATE.ID" },
{ "mDataProp": "VMTEMPLATE.NAME" },
{ "mDataProp": "VMTEMPLATE.TEMPLATE.SAVED_TEMPLATE_ID", "sDefaultContent" : "-" },
{ "mDataProp": "VMTEMPLATE.PERMISSIONS.GROUP_U" }
],
"fnPreDrawCallback": function (oSettings) {
// create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
if (this.$('tr', {"filter": "applied"} ).length == 0) {
this.html('
'+
''+
''+
''+
''+
' '+
' '+
''+
tr("There are no templates available. Please contact your cloud administrator")+
''+
'
');
}
return true;
},
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var data = aData.VMTEMPLATE;
var logo;
if (data.TEMPLATE.LOGO) {
logo = ''+
''+
'';
} else {
logo = ''+
''+
'';
}
var li = ('
'+
'
'+
'
'+
data.NAME+
'
'+
'
'+
logo +
'
'+
'
'+
(data.TEMPLATE.DESCRIPTION || '...')+
'
'+
'
'+
'
').appendTo($("#provision_vdc_templates_ul"));
$(".provision-pricing-table", li).data("opennebula", aData);
return nRow;
}
});
provision_saved_templates_datatable = $('#provision_saved_templates_table').dataTable({
"iDisplayLength": 6,
"sDom" : '<"H">t<"F"lp>',
"aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
"aoColumnDefs": [
{ "bVisible": false, "aTargets": ["all"]}
],
"aoColumns": [
{ "mDataProp": "VMTEMPLATE.ID" },
{ "mDataProp": "VMTEMPLATE.NAME" },
{ "mDataProp": "VMTEMPLATE.TEMPLATE.SAVED_TEMPLATE_ID", "sDefaultContent" : "-" },
{ "mDataProp": "VMTEMPLATE.PERMISSIONS.GROUP_U" }
],
"fnPreDrawCallback": function (oSettings) {
// create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
if (this.$('tr', {"filter": "applied"} ).length == 0) {
this.html('
'+
''+
''+
''+
''+
' '+
' '+
''+
tr("There are no templates available. Please contact your cloud administrator")+
''+
'
');
}
return true;
},
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var data = aData.VMTEMPLATE;
var logo;
if (data.TEMPLATE.LOGO) {
logo = ''+
''+
'';
} else {
logo = ''+
''+
'';
}
var li = $('
'+
'
'+
'
'+
data.NAME+
'
'+
'
'+
logo +
'
'+
'
'+
(data.TEMPLATE.DESCRIPTION || '...')+
'
'+
'
'+
'
').appendTo($("#provision_saved_templates_ul"));
$(".provision-pricing-table", li).data("opennebula", aData);
return nRow;
}
});
$('#provision_create_template_search').on('keyup',function(){
provision_system_templates_datatable.fnFilter( $(this).val() );
provision_saved_templates_datatable.fnFilter( $(this).val() );
provision_vdc_templates_datatable.fnFilter( $(this).val() );
})
$('#provision_create_template_search').on('change',function(){
provision_system_templates_datatable.fnFilter( $(this).val() );
provision_saved_templates_datatable.fnFilter( $(this).val() );
provision_vdc_templates_datatable.fnFilter( $(this).val() );
})
$("#provision_create_template_refresh_button").click(function(){
OpenNebula.Helper.clear_cache("VMTEMPLATE");
update_provision_templates_datatable(provision_system_templates_datatable);
update_provision_templates_datatable(provision_saved_templates_datatable);
update_provision_templates_datatable(provision_vdc_templates_datatable);
});
tab.on("click", "#provision_create_vm .provision_select_template .provision-pricing-table.only-one" , function(){
var create_vm_context = $("#provision_create_vm");
if ($(this).hasClass("selected")){
$(".provision_network_selector", create_vm_context).html("");
$(".provision_capacity_selector", create_vm_context).html("");
$(".provision_accordion_template .selected_template").hide();
$(".provision_accordion_template .select_template").show();
} else {
var template_id = $(this).attr("opennebula_id");
var template_json = $(this).data("opennebula");
var template_nic = template_json.VMTEMPLATE.TEMPLATE.NIC
var nics = []
if ($.isArray(template_nic))
nics = template_nic
else if (!$.isEmptyObject(template_nic))
nics = [template_nic]
$(".provision_accordion_template .selected_template").show();
$(".provision_accordion_template .select_template").hide();
$(".provision_accordion_template .selected_template_name").html(template_json.VMTEMPLATE.NAME)
if (template_json.VMTEMPLATE.TEMPLATE.LOGO) {
$(".provision_accordion_template .selected_template_logo").html('');
} else {
$(".provision_accordion_template .selected_template_logo").html(' ');
}
$(".provision_accordion_template a").first().trigger("click");
generate_provision_instance_type_accordion(
$(".provision_capacity_selector", create_vm_context),
template_json.VMTEMPLATE.TEMPLATE);
generate_provision_network_accordion(
$(".provision_network_selector", create_vm_context));
$.each(nics, function(index, nic){
generate_provision_network_table(
$(".provision_nic_accordion", create_vm_context),
nic);
})
if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
generate_custom_attrs(
$(".provision_custom_attributes_selector", create_vm_context),
template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS);
}
}
})
tab.on("click", "#provision_create_vm .provision-pricing-table.only-one" , function(){
if ($(this).hasClass("selected")){
$(this).removeClass("selected");
} else {
$(".provision-pricing-table", $(this).parents(".large-block-grid-3,.large-block-grid-2")).removeClass("selected")
$(this).addClass("selected");
}
})
$("#provision_create_vm").submit(function(){
var context = $(this);
var vm_name = $("#vm_name", context).val();
var template_id = $(".tabs-content .content.active .selected", context).attr("opennebula_id");
var nics = [];
$(".selected_network", context).each(function(){
var nic;
if ($(this).attr("template_nic")) {
nic = JSON.parse($(this).attr("template_nic"))
} else {
nic = {
'network_id': $(this).attr("opennebula_id")
}
}
nics.push(nic);
});
var instance_type = $(".provision_instance_types_ul .selected", context);
if (!template_id) {
$(".alert-box-error", context).fadeIn().html(tr("You must select at least a template configuration"));
return false;
}
var extra_info = {
'vm_name' : vm_name,
'template': {
}
}
if (nics.length > 0) {
extra_info.template.nic = nics;
}
if (instance_type.length > 0) {
var instance_typa_data = instance_type.data("opennebula");
delete instance_typa_data.name;
$.extend(extra_info.template, instance_typa_data)
}
var missing_attr = false;
var user_inputs_values = {};
if ($(".provision_custom_attributes", $(this))) {
$(".provision_custom_attribute", $(".provision_custom_attributes", $(this))).each(function(){
if (!$(this).val()) {
$(this).parent("label").css("color", "red");
missing_attr = true;
} else {
$(this).parent("label").css("color", "#777");
user_inputs_values[$(this).attr("attr_name")] = $(this).val();
}
})
}
if (missing_attr) {
$(".alert-box-error", $(this)).fadeIn().html(tr("You have not specified all the Custom Atrributes for this VM"));
return false;
}
if (!$.isEmptyObject(user_inputs_values)) {
$.extend(extra_info.template, user_inputs_values)
}
Sunstone.runAction("Provision.instantiate", template_id, extra_info);
return false;
})
$(document).on("click", ".provision_create_vm_button", function(){
show_provision_create_vm();
});
//
// Create FLOW
//
provision_flow_templates_datatable = $('#provision_flow_templates_table').dataTable({
"iDisplayLength": 6,
"sDom" : '<"H">t<"F"lp>',
"aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
"aaSorting" : [[1, "asc"]],
"aoColumnDefs": [
{ "bVisible": false, "aTargets": ["all"]}
],
"aoColumns": [
{ "mDataProp": "DOCUMENT.ID" },
{ "mDataProp": "DOCUMENT.NAME" }
],
"fnPreDrawCallback": function (oSettings) {
// create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
if (this.$('tr', {"filter": "applied"} ).length == 0) {
this.html('
'+
''+
''+
''+
''+
' '+
' '+
''+
tr("There are no templates available")+
''+
'