1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-24 02:03:52 +03:00

feature #2911: Add vCenter clusters and templates to the host create dialog

This commit is contained in:
Daniel Molina 2014-09-25 19:36:40 +02:00
parent 956b691878
commit ad8b7d2c9c
4 changed files with 255 additions and 18 deletions

View File

@ -1546,7 +1546,8 @@ SUNSTONE_PUBLIC_JS_PLUGINS_FILES="\
src/sunstone/public/js/plugins/support-tab.js \
src/sunstone/public/js/plugins/zones-tab.js"
SUNSTONE_ROUTES_FILES="src/sunstone/routes/oneflow.rb"
SUNSTONE_ROUTES_FILES="src/sunstone/routes/oneflow.rb \
src/sunstone/routes/vcenter.rb"
# begin bower

View File

@ -189,3 +189,4 @@
:routes:
- oneflow
- vcenter

View File

@ -127,21 +127,33 @@ var create_host_tmpl =
<div class="row vcenter_credentials hidden">\
<fieldset>\
<legend>'+tr("vCenter")+'</legend>\
<div class="large-6 columns">\
<label for="vcenter_user">' + tr("User") + '</label>\
<input type="text" name="vcenter_user" id="vcenter_user" />\
<div class="row">\
<div class="large-6 columns">\
<label for="vcenter_user">' + tr("User") + '</label>\
<input type="text" name="vcenter_user" id="vcenter_user" />\
</div>\
<div class="large-6 columns">\
<label for="vcenter_host">' + tr("Hostname") + '</label>\
<input type="text" name="vcenter_host" id="vcenter_host" />\
</div>\
</div>\
<div class="large-6 columns">\
<label for="vcenter_host">' + tr("Hostname") + '</label>\
<input type="text" name="vcenter_host" id="vcenter_host" />\
<div class="row">\
<div class="large-6 columns">\
<label for="vcenter_password">' + tr("Password") + '</label>\
<input type="password" name="vcenter_password" id="vcenter_password" />\
</div>\
<div class="large-6 columns">\
<br>\
<a class="button radius small right" id="get_vcenter_clusters">'+tr("Get vCenter Clusters")+'</a>\
</div>\
</div>\
<div class="large-6 columns">\
<label for="vcenter_password">' + tr("Password") + '</label>\
<input type="text" name="vcenter_password" id="vcenter_password" />\
<div class="vcenter_clusters">\
</div>\
<div class="large-6 columns">\
<br>\
<a class="button radius small right">'+tr("Get vCenter Clusters")+'</a>\
<div class="row import_vcenter_clusters_div hidden">\
<div class="large-12 columns">\
<br>\
<a class="button radius small right success" id="import_vcenter_clusters">'+tr("Import vCenter Clusters and Templates")+'</a>\
</div>\
</div>\
</fieldset>\
</div>\
@ -955,6 +967,12 @@ function setupCreateHostDialog(){
$create_host_dialog.addClass("reveal-modal medium").attr("data-reveal", "");
$create_host_dialog.foundation()
$("#wizard_host_reset_button", $create_host_dialog).on("click", function(){
$('#create_host_dialog').html("");
setupCreateHostDialog();
popUpCreateHostDialog();
})
$(".drivers", $create_host_dialog).hide();
$("#host_type_mad", $create_host_dialog).on("change", function(){
@ -964,21 +982,149 @@ function setupCreateHostDialog(){
if (this.value == "custom") {
$(".vcenter_credentials", $create_host_dialog).hide();
$("#vnm_mads", $create_host_dialog).show();
$("#create_host_submit", $create_host_dialog).removeAttr("disabled");
$("#create_host_submit", $create_host_dialog).show();
$(".drivers", $create_host_dialog).show();
} else if (this.value == "vcenter") {
$("#vnm_mads", $create_host_dialog).hide();
$(".vcenter_credentials", $create_host_dialog).show();
$("#create_host_submit", $create_host_dialog).attr("disabled", "disabled");
$("#create_host_submit", $create_host_dialog).hide();
$(".drivers", $create_host_dialog).hide();
} else {
$(".vcenter_credentials", $create_host_dialog).hide();
$("#vnm_mads", $create_host_dialog).show();
$("#create_host_submit", $create_host_dialog).removeAttr("disabled");
$("#create_host_submit", $create_host_dialog).show();
$(".drivers", $create_host_dialog).hide();
}
})
$("#get_vcenter_clusters", $create_host_dialog).on("click", function(){
// TODO notify if credentials empty
$(".vcenter_clusters", $create_host_dialog).html(
'<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
'</span>')
$.ajax({
url: '/vcenter',
type: "GET",
//data: {timeout: timeout},
dataType: "json",
headers: {
"X_VCENTER_USER": $("#vcenter_user", $create_host_dialog).val(),
"X_VCENTER_PASSWORD": $("#vcenter_password", $create_host_dialog).val(),
"X_VCENTER_HOST": $("#vcenter_host", $create_host_dialog).val()
},
success: function(response){
console.log(response);
$("#get_vcenter_clusters", $create_host_dialog).hide();
$(".import_vcenter_clusters_div", $create_host_dialog).show();
var vcenter_container = $(".vcenter_clusters", $create_host_dialog);
vcenter_container.html("");
$('<div class="row">' +
'<div class="large-12 columns">' +
'<h5>' +
datacenter_name + ' ' + tr("Clusters") +
'</h5>' +
'</div>' +
'</div>').appendTo(vcenter_container)
$.each(response, function(datacenter_name, clusters){
$('<div class="row">' +
'<div class="large-12 columns">' +
'<span style="color: #999">' + tr("Please select the vCenter Clusters and Templates to be imported to OpenNebula. Each vCenter Cluster will be included as a new OpenNebula Host") + '</span>' +
'</div>' +
'</div>').appendTo(vcenter_container)
if (clusters.length == 0) {
$('<div class="row">' +
'<div class="large-12 columns">' +
'<label>' +
tr("No clusters found in this DataCenter") +
'</label>' +
'</div>' +
'</div>').appendTo(vcenter_container)
} else {
$.each(clusters, function(id, cluster_name){
var row = $('<div class="vcenter_cluster">' +
'<div class="row">' +
'<div class="large-12 columns">' +
'<label>' +
'<input type="checkbox" class="cluster_name"/> ' +
cluster_name +
'</label>' +
'</div>' +
'</div>'+
'<div class="vcenter_templates">'+
'</div>'+
'</div>').appendTo(vcenter_container)
$(".cluster_name", row).data("cluster_name", cluster_name)
$(".cluster_name", row).data("datacenter_name", datacenter_name)
$(".cluster_name", row).on("change", function(){
var path = '/vcenter/' + $(this).data("datacenter_name") + '/cluster/' + $(this).data("cluster_name");
var templates_container = $(".vcenter_templates", $(this).closest(".vcenter_cluster"))
templates_container.html(generateAdvancedSection({
html_id: path,
title: tr("Templates"),
content: '<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
'</span>'
}))
$('a', templates_container).trigger("click")
$.ajax({
url: path,
type: "GET",
//data: {timeout: timeout},
dataType: "json",
headers: {
"X_VCENTER_USER": $("#vcenter_user", $create_host_dialog).val(),
"X_VCENTER_PASSWORD": $("#vcenter_password", $create_host_dialog).val(),
"X_VCENTER_HOST": $("#vcenter_host", $create_host_dialog).val()
},
success: function(response){
$(".content", templates_container).html("");
console.log(response);
$.each(response, function(id, template){
var trow = $('<div class="vcenter_template">' +
'<div class="row">' +
'<div class="large-12 columns">' +
'<label>' +
'<input type="checkbox" class="template_name"/> ' +
template.name + '&emsp;<span style="color: #999">' + template.uuid + '</span>' +
'</label>' +
'</div>' +
'</div>'+
'<div class="vcenter_templates">'+
'</div>'+
'</div>').appendTo($(".content", templates_container))
$(".template_name", trow).data("template_name", template.name)
$(".template_name", trow).data("one_template", template.one)
});
},
error: function(response){
onError({}, OpenNebula.Error(response));
}
});
})
});
}
});
},
error: function(response){
onError({}, OpenNebula.Error(response));
}
});
return false;
})
// Show custom driver input only when custom is selected in selects
$('input[name="custom_vmm_mad"],'+
'input[name="custom_im_mad"],'+
@ -1047,8 +1193,8 @@ function popUpCreateHostDialog(){
insertSelectOptions('#host_cluster_id',$('div#create_host_dialog'), "Cluster", cluster_id, false);
$('div#create_host_dialog').foundation('reveal', 'open');
$("input#name",$('div#create_host_dialog')).focus();
$("#create_host_dialog").foundation('reveal', 'open');
$("input#name",$("#create_host_dialog")).focus();
return false;
}

View File

@ -0,0 +1,89 @@
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L. #
# #
# 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. #
#--------------------------------------------------------------------------- #
if !ONE_LOCATION
REMOTES_LOCATION="/var/lib/one/remotes"
else
REMOTES_LOCATION=ONE_LOCATION+"/var/remotes"
end
# TODO vcenter_driver should be stored in RUBY_LIB_LOCATION
$: << REMOTES_LOCATION+"/vmm/vcenter/"
require 'vcenter_driver'
helpers do
def vcenter_client
vuser = request.env['HTTP_X_VCENTER_USER']
vpass = request.env['HTTP_X_VCENTER_PASSWORD']
vhost = request.env['HTTP_X_VCENTER_HOST']
if vuser.nil? || vpass.nil? || vhost.nil?
msg = "You have to provide the vCenter username, password and hostname"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 404, error.to_json
end
return VCenterDriver::VIClient.new_connection(
:user => vuser,
:password => vpass,
:host => vhost)
end
# def af_format_response(resp)
# if CloudClient::is_error?(resp)
# logger.error("[OneFlow] " + resp.to_s)
#
# error = Error.new(resp.to_s)
# error resp.code.to_i, error.to_json
# else
# body resp.body.to_s
# end
# end
end
get '/vcenter' do
begin
rs = vcenter_client.hierarchy
[200, rs.to_json]
rescue Exception => e
logger.error("[vCenter] " + e.message)
error = Error.new(e.message)
error 403, error.to_json
end
end
get '/vcenter/:datacenter/cluster/:name' do
begin
rs = vcenter_client.vm_templates
templates = rs[params[:datacenter]]
if templates.nil?
msg = "Datacenter " + params[:datacenter] + "not found"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 404, error.to_json
end
ctemplates = templates.select{|t| t[:host] == params[:name]}
[200, ctemplates.to_json]
rescue Exception => e
logger.error("[vCenter] " + e.message)
error = Error.new(e.message)
error 403, error.to_json
end
end