Merge branch 'master' of git.opennebula.org:apptools-hector

This commit is contained in:
Hector Sanjuan committed 2012-09-21 18:02:44 +02:00
commit 1728b8b2b1
17 files changed
+593 -73

No files matched your search

@@ -13,22 +13,67 @@
// limitations under the License. //
//--------------------------------------------------------------------------//
function updateAppEnvDashboard(what, json_info){
var db = $('#appenv_dashboard_tab',main_tabs_context);
switch (what){
case "environments":
var total_envs=json_info.length;
$('#appenv_total_environments',db).html(total_envs);
break;
};
}
var appenv_dashboard_tmpl = '\
<table class="dashboard_table" id="appenv_dashboard">\
<tr>\
<td style="width:100%">\
<td style="width:50%">\
<table id="system_information_table" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Summary of AppEnv resources") + '</h3>\
<div class="panel_info">\
\
<table class="info_table">\
<tr>\
<td class="key_td">Environments</td>\
<td class="value_td"><span id="appenv_total_environments"></span></td>\
</tr>\
</table>\
\
</div>\
</div>\
</td>\
</tr>\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Quickstart") + '</h3>\
<div class="panel_info dashboard_p">\
<ul>\
<li><a class="action_button" href="#appenvs_tab" value="AppEnv.create_dialog">Create a new Environment</a></li>\
</ul>\
</div>\
</div>\
</td>\
</tr>\
</table>\
</td>\
<td style="width:50%">\
<table id="table_right" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("AppEnv - A tool to manage environments") + '</h3>\
<h3>' + tr("AppEnv") + '</h3>\
<div class="panel_info">\
\
<p class="dashboard_p" style="margin-top: 10px"><img src="images/appenv_icon.png" height="80px" style="float:right;margin:15px 63px 15px 15px;" alt="appenv logo"/>AppEnv performs the automatic installation and configuration of the software stack that constitutes an application environment. With AppEnv you can easily define software configurations for your VMs and share them with other users.</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p>\
<img src="images/appenv_icon.png" height="80px" style="float:right;margin:0px 15px 15px 15px;" alt="appenv logo"/>\
AppEnv performs the automatic installation and configuration of the software stack that constitutes an application environment. With AppEnv you can easily define software configurations for your VMs and share them with other users.\
</p>\
<p>'+tr("You can find further information on the following links:")+'</p>\
<ul>\
<li><a href="http://doc.opennebula.pro/doku.php?id=appenv" target="_blank">AppEnv Documentation</a></li>\
</ul>\
</div>\
</div>\
</td>\
+2 -1
View File
@@ -417,7 +417,7 @@ var appenv_info_panel = {
}
var appenvs_tab = {
title: "AppEnv",
title: "Environments",
content: appenv_tab_content,
buttons: appenv_buttons,
tabClass: 'subTab',
@@ -479,6 +479,7 @@ function updateAppEnvsView(request, appenvs_list){
updateView(appenv_list_array,dataTable_appenvs);
//updateVResDashboard("images",images_list);
updateAppEnvDashboard('environments', appenv_list_array);
}
// Callback to update the information panel tabs and pop it up
+2 -18
View File
@@ -121,7 +121,7 @@ get '/service' do
end
status 200
#body Parser.render(service_pool)
body service_pool.to_json
end
@@ -135,7 +135,7 @@ get '/service/:id' do
end
status 200
#body Parser.render(service)
body service.to_json
end
@@ -246,7 +246,6 @@ get '/service_template' do
status 200
#body Parser.render(s_template_pool)
body s_template_pool.to_json
end
@@ -260,7 +259,6 @@ get '/service_template/:id' do
status 200
#body Parser.render(rc)
body service_template.to_json
end
@@ -273,22 +271,9 @@ delete '/service_template/:id' do
end
status 201
#body Parser.render(rc)
#body service_template.to_json
end
post '/service_template' do
#template = Parser.json_to_hash(request.body.read)
#begin
# Validator.validate(template)
#rescue
# error 403,
#end
#template_xml = Parser.hash_to_xml(template)
s_template = OpenNebula::ServiceTemplate.new(
OpenNebula::ServiceTemplate.build_xml,
@client)
@@ -332,7 +317,6 @@ post '/service_template/:id/action' do
service.info
#body Parser.render(rc)
body service.to_json
when 'chown'
if opts && opts['uid']
+1
View File
@@ -98,6 +98,7 @@ copy_files "sunstone/routes/*" "$SUNSTONE_LOCATION/routes"
# Do not link the ETC files
LINK="no"
copy_files "sunstone/etc/sunstone-appflow.conf" "$ETC_LOCATION"
copy_files "config/appflow-server.conf" "$ETC_LOCATION"
+13 -7
View File
@@ -22,6 +22,8 @@ class Log
# Log.info("LCM", "Service 3 started", 3), it will be written in a
# specific log for service number 3
LOG_COMP = "LOG"
DEBUG_LEVEL = [
Logger::ERROR, # 0
Logger::WARN, # 1
@@ -129,13 +131,17 @@ class Log
return true
end
# TBD capture exception
open("#{LOG_LOCATION}/appflow/#{service_id}.log", 'a') do |f|
f << MSG_FORMAT % [
Time.now.strftime(DATE_FORMAT),
Logger::SEV_LABEL[severity][0..0],
component,
message ]
begin
open("#{LOG_LOCATION}/appflow/#{service_id}.log", 'a') do |f|
f << MSG_FORMAT % [
Time.now.strftime(DATE_FORMAT),
Logger::SEV_LABEL[severity][0..0],
component,
message ]
end
rescue => e
message = "Could not log into #{LOG_LOCATION}/appflow/#{service_id}.log: #{e.message}"
error LOG_COMP, message
end
end
+7
View File
@@ -0,0 +1,7 @@
################################################################################
# Appflow
################################################################################
# Appflow endpoint
#
:appflow_server: http://localhost:2474/
@@ -13,22 +13,73 @@
// limitations under the License. //
//--------------------------------------------------------------------------//
function updateAppFlowDashboard(what, json_info){
var db = $('#appflow_dashboard_tab',main_tabs_context);
switch (what){
case "templates":
$('#appflow_total_templates',db).html(json_info.length);
break;
case "services":
$('#appflow_total_services',db).html(json_info.length);
break;
};
}
var appflow_dashboard_tmpl = '\
<table class="dashboard_table" id="appflow_dashboard">\
<tr>\
<td style="width:100%">\
<td style="width:50%">\
<table id="system_information_table" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Summary of AppFlow resources") + '</h3>\
<div class="panel_info">\
\
<table class="info_table">\
<tr>\
<td class="key_td">Templates</td>\
<td class="value_td"><span id="appflow_total_templates"></span></td>\
<tr>\
</tr>\
<td class="key_td">Services</td>\
<td class="value_td"><span id="appflow_total_services"></span></td>\
</tr>\
</table>\
\
</div>\
</div>\
</td>\
</tr>\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Quickstart") + '</h3>\
<div class="panel_info dashboard_p">\
<ul>\
<li><a class="action_button" href="#service_templates_tab" value="ServiceTemplate.create_dialog">Create a new Service Template</a></li>\
</ul>\
</div>\
</div>\
</td>\
</tr>\
</table>\
</td>\
<td style="width:50%">\
<table id="table_right" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Appflow - A tool to manage environments") + '</h3>\
<h3>' + tr("Appflow - A tool to manage environments") + '</h3>\
<div class="panel_info">\
\
<p class="dashboard_p" style="margin-top: 10px"><img src="images/appflow_icon.png" height="80px" style="float:right;margin:15px 63px 15px 15px;" alt="appflow logo"/>AppFlow enables the automatic execution of multi-tiered applications. With AppFlow you can define multi-tier applications composed of interconnected VMs and manage them as a single entity.</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p>\
<img src="images/appflow_icon.png" height="80px" style="float:right;margin:0px 15px 15px 15px;" alt="appflow logo"/>\
AppFlow enables the automatic execution of multi-tiered applications. With AppFlow you can define multi-tier applications composed of interconnected VMs and manage them as a single entity.\
</p>\
<p>'+tr("You can find further information on the following links:")+'</p>\
<ul>\
<li><a href="http://doc.opennebula.pro/doku.php?id=appflow" target="_blank">AppFlow Documentation</a></li>\
</ul>\
</div>\
</div>\
</td>\
@@ -429,6 +429,7 @@ function updateServicesView(request, services_list){
updateView(service_list_array,dataTable_services);
//updateVResDashboard("images",images_list);
updateAppFlowDashboard('services', service_list_array);
}
// Callback to refresh the list of Virtual Machines
@@ -435,6 +435,7 @@ function updateServiceTemplatesView(request, service_templates_list){
updateView(service_template_list_array,dataTable_service_templates);
//updateVResDashboard("images",images_list);
updateAppFlowDashboard('templates', service_template_list_array);
}
// Callback to update the information panel tabs and pop it up
+35 -23
View File
@@ -1,24 +1,36 @@
APPFLOW_CONF_FILE = ETC_LOCATION + "/sunstone-appflow.conf"
$: << RUBY_LIB_LOCATION+"/apptools/flow"
require 'appflow_client'
begin
appflow_conf = YAML.load_file(APPFLOW_CONF_FILE)
rescue Exception => e
STDERR.puts "Error parsing config file #{APPFLOW_CONF_FILE}: #{e.message}"
exit 1
end
set :appflow_config, appflow_conf
helpers do
def build_client
def af_build_client
flow_client = settings.cloud_auth.client(session[:user])
split_array = flow_client.one_auth.split(':')
Service::Client.new(
:url => settings.config[:appflow_server],
:url => settings.appflow_config[:appflow_server],
:user_agent => "Sunstone",
:username => split_array.shift,
:password => split_array.join(':'))
end
def format_response(resp)
def af_format_response(resp)
if CloudClient::is_error?(resp)
logger.error("[AppFlow] " + resp.to_s)
# TBD format error messages in JSON
error 500, resp.to_s
error = Error.new(resp.to_s)
error resp.code.to_i, error.to_json
else
body resp.body.to_s
end
@@ -30,35 +42,35 @@ end
##############################################################################
get '/service' do
client = build_client
client = af_build_client
resp = client.get('/service')
format_response(resp)
af_format_response(resp)
end
get '/service/:id' do
client = build_client
client = af_build_client
resp = client.get('/service/' + params[:id])
format_response(resp)
af_format_response(resp)
end
delete '/service/:id' do
client = build_client
client = af_build_client
resp = client.delete('/service/' + params[:id])
format_response(resp)
af_format_response(resp)
end
post '/service/:id/action' do
client = build_client
client = af_build_client
resp = client.post('/service/' + params[:id] + '/action', request.body.read)
format_response(resp)
af_format_response(resp)
end
##############################################################################
@@ -66,41 +78,41 @@ end
##############################################################################
get '/service_template' do
client = build_client
client = af_build_client
resp = client.get('/service_template')
format_response(resp)
af_format_response(resp)
end
get '/service_template/:id' do
client = build_client
client = af_build_client
resp = client.get('/service_template/' + params[:id])
format_response(resp)
af_format_response(resp)
end
delete '/service_template/:id' do
client = build_client
client = af_build_client
resp = client.delete('/service_template/' + params[:id])
format_response(resp)
af_format_response(resp)
end
post '/service_template/:id/action' do
client = build_client
client = af_build_client
resp = client.post('/service_template/' + params[:id] + '/action', request.body.read)
format_response(resp)
af_format_response(resp)
end
post '/service_template' do
client = build_client
client = af_build_client
resp = client.post('/service_template', request.body.read)
format_response(resp)
af_format_response(resp)
end
File renamed without changes.
+1
View File
@@ -96,5 +96,6 @@ copy_files "sunstone/routes/*" "$SUNSTONE_LOCATION/routes"
# Do not link the ETC files
LINK="no"
copy_files "sunstone/etc/sunstone-appmarket.conf" "$ETC_LOCATION"
copy_files "config/appmarket-server.conf" "$ETC_LOCATION"
@@ -0,0 +1,13 @@
################################################################################
# AppMarket
################################################################################
# AppMarket username and password
# If no credentials are provided, an anonymous client will be used
#
#:appmarket_username:
#:appmarket_password:
# AppMarket endpoint
#
:appmarket_url: https://localhost:6242
Whitespace-only changes.
@@ -13,22 +13,54 @@
// limitations under the License. //
//--------------------------------------------------------------------------//
function updateAppMarketDashboard(what, json_info){
var db = $('#appmarket_dashboard_tab',main_tabs_context);
switch (what){
case "appliances":
$('#appmarket_total_appliances',db).html(json_info.length);
break;
};
}
var appmarket_dashboard_tmpl = '\
<table class="dashboard_table" id="appmarket_dashboard">\
<tr>\
<td style="width:100%">\
<td style="width:50%">\
<table id="system_information_table" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("Summary of AppMarket resources") + '</h3>\
<div class="panel_info">\
\
<table class="info_table">\
<tr>\
<td class="key_td">Appliances</td>\
<td class="value_td"><span id="appmarket_total_appliances"></span></td>\
<tr>\
</table>\
\
</div>\
</div>\
</td>\
</tr>\
</table>\
</td>\
<td style="width:50%">\
<table id="table_right" style="width:100%">\
<tr>\
<td>\
<div class="panel">\
<h3>' + tr("AppEnv - Image repository") + '</h3>\
<h3>' + tr("AppMarket") + '</h3>\
<div class="panel_info">\
\
<p class="dashboard_p" style="margin-top: 10px"><img src="images/appmarket_icon.png" height="80px" style="float:right;margin:15px 15px;" alt="appflow logo"/>AppMarket builds a centralized catalog of cloud applications. With AppMarket you can build a private repository to share and distribute virtual appliances across OpenNebula instances.</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p class="dashboard_p">&nbsp;</p>\
<p>\
<img src="images/appmarket_icon.png" height="80px" style="float:right;margin:0px 15px 15px 15px;" alt="appmarket logo"/>\
AppMarket builds a centralized catalog of cloud applications. With AppMarket you can build a private repository to share and distribute virtual appliances across OpenNebula instances.\
</p>\
<p>'+tr("You can find further information on the following links:")+'</p>\
<ul>\
<li><a href="http://doc.opennebula.pro/doku.php?id=appmarket" target="_blank">AppMarket Documentation</a></li>\
</ul>\
</div>\
</div>\
</td>\
@@ -0,0 +1,316 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2010-2012, 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. */
/* -------------------------------------------------------------------------- */
/* Marketpplace tab plugin */
var dataTable_appmarket;
var AppMarket = {
"resource" : "APPMARKET",
"show" : function(params){
OpenNebula.Action.show(params,AppMarket.resource);
},
"list" : function(params){
//Custom list request function, since the contents do not come
//in the same format as the rest of opennebula resources.
var callback = params.success;
var callback_error = params.error;
var timeout = params.timeout || false;
var request = OpenNebula.Helper.request('APPMARKET','list');
$.ajax({
url: 'appmarket',
type: 'GET',
data: {timeout: timeout},
dataType: "json",
success: function(response){
return callback ?
callback(request, response) : null;
},
error: function(res){
return callback_error ? callback_error(request, OpenNebula.Error(res)) : null;
}
});
}
}
var appmarket_actions = {
"AppMarket.list" : {
type: "list",
call: AppMarket.list,
callback: function(req,res){
//data can be added to the table directly, without further
//processing
updateView(res.appliances,dataTable_appmarket);
updateAppMarketDashboard('appliances', res.appliances);
},
error: onError
},
"AppMarket.refresh" : {
type: "custom",
call: function () {
waitingNodes(dataTable_appmarket);
Sunstone.runAction('AppMarket.list');
}
},
"AppMarket.import" : {
//fetches images information and fills in the image creation
//dialog with it.
type: "multiple",
elements: appmarketplaceElements,
call: AppMarket.show,
callback: function(request,response){
$('#img_name', $create_image_dialog).val(response['name']);
$('#img_path', $create_image_dialog).val(response['links']['download']['href']);
$('#src_path_select input[value="path"]', $create_image_dialog).trigger('click');
$('select#img_type', $create_image_dialog).val('OS');
$('select#img_type', $create_image_dialog).trigger('change');
//remove any options from the custom vars dialog box
$("#custom_var_image_box",$create_image_dialog).empty();
var md5 = response['files'][0]['md5']
if ( md5 ) {
option = '<option value=\'' +
md5 + '\' name="MD5">MD5=' +
md5 + '</option>';
$("#custom_var_image_box",$create_image_dialog).append(option);
}
var sha1 = response['files'][0]['sha1']
if ( sha1 ) {
option = '<option value=\'' +
sha1 + '\' name="SHA1">SHA1=' +
sha1 + '</option>';
$("#custom_var_image_box",$create_image_dialog).append(option);
}
popUpCreateImageDialog();
},
error: onError
},
"AppMarket.showinfo" : {
type: "single",
call: AppMarket.show,
callback: updateMarketInfo,
error: onError
}
}
var appmarket_buttons = {
"AppMarket.refresh" : {
type: "action",
text: '<i class="icon-refresh icon-large">',
alwaysActive: true
},
"AppMarket.import" : {
type: "action",
text: tr('Import to local infrastructure')
}
};
var appmarketplace_tab_content = '\
<h2><i class="icon-shopping-cart"></i> '+tr("OpenNebula AppMarket")+'</h2>\
<form id="appmarketplace_form" action="" action="javascript:alert(\'js error!\');">\
<div class="action_blocks">\
</div>\
<table id="datatable_appmarketplace" class="display">\
<thead>\
<tr>\
<th class="check"></th>\
<th>'+tr("ID")+'</th>\
<th>'+tr("Name")+'</th>\
<th>'+tr("Publisher")+'</th>\
<th>'+tr("Hypervisor")+'</th>\
<th>'+tr("Arch")+'</th>\
<th>'+tr("Format")+'</th>\
<th>'+tr("Tags")+'</th>\
</tr>\
</thead>\
<tbody id="tbodyappmarketplace">\
</tbody>\
</table>\
</div>';
var appmarketplace_tab = {
title: "Appliances",
content: appmarketplace_tab_content,
buttons: appmarket_buttons,
tabClass: 'subTab',
parentTab: 'appmarket_dashboard_tab'
}
Sunstone.addMainTab('appmarketplace_tab', appmarketplace_tab);
Sunstone.addActions(appmarket_actions);
/*
* INFO PANEL
*/
var appmarketplace_info_panel = {
"appmarketplace_info_tab" : {
title: tr("Appliance information"),
content:""
}
};
Sunstone.addInfoPanel("appmarketplace_info_panel", appmarketplace_info_panel);
function appmarketplaceElements(){
return getSelectedNodes(dataTable_appmarket);
}
function updateMarketInfo(request,app){
var info_tab = {
title : tr("Appliance information"),
content :
'<table id="info_appmarketplace_table" class="info_table">\
<thead>\
<tr><th colspan="2">'+tr("Appliance information")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">' + tr("ID") + '</td>\
<td class="value_td">'+app['_id']["$oid"]+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("URL") + '</td>\
<td class="value_td"><a href="'+config_response.system_config.appmarketplace_url+'/'+app['_id']["$oid"]+'" target="_blank">'+config_response.system_config.appmarketplace_url+'/'+app['_id']["$oid"]+'</a></td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Publisher") + '</td>\
<td class="value_td">'+app['publisher']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Downloads") + '</td>\
<td class="value_td">'+app['downloads']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("OS") + '</td>\
<td class="value_td">'+app['files'][0]['os-id']+' '+app['files'][0]['os-release']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Arch") + '</td>\
<td class="value_td">'+app['files'][0]['os-arch']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Size") + '</td>\
<td class="value_td">'+humanize_size(app['files'][0]['size'],true)+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Hypervisor") + '</td>\
<td class="value_td">'+app['files'][0]['hypervisor']+'</td>\
</tr>\
</tbody>\
</table>\
<table id="info_appmarketplace_table2" class="info_table">\
<thead>\
<tr><th colspan="2">'+tr("Description")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="value_td">'+app['description'].replace(/\n/g, "<br />")+'</td>\
</tr>\
</tbody>\
</table>'
};
Sunstone.updateInfoPanelTab("appmarketplace_info_panel", "appmarketplace_info_tab", info_tab);
Sunstone.popUpInfoPanel("appmarketplace_info_panel");
};
function infoListenerMarket(dataTable){
$('tbody tr',dataTable).live("click",function(e){
if ($(e.target).is('input')) {return true;}
var aData = dataTable.fnGetData(this);
var id = aData["_id"]["$oid"];
if (!id) return true;
var count = $('tbody .check_item:checked', dataTable).length;
//If ctrl is pressed we check the column instead of
//doing showinfo()
if (e.ctrlKey || count >= 1){
$('.check_item',this).trigger('click');
return false;
}
popDialogLoading();
Sunstone.runAction('AppMarket.showinfo',id);
return false;
});
}
/*
* onlyOneCheckboxListener: Only one box can be checked
*/
function onlyOneCheckboxListener(dataTable) {
$('tbody input.check_item', dataTable).live("change", function(){
var checked = $(this).is(':checked');
$('input.check_item:checked', dataTable).removeAttr('checked');
$(this).attr('checked', checked);
});
}
/*
* Document
*/
$(document).ready(function(){
dataTable_appmarket = $("#datatable_appmarketplace", main_tabs_context).dataTable({
"bJQueryUI": true,
"bSortClasses": false,
"sPaginationType": "full_numbers",
"sDom" : '<"H"lfrC>t<"F"ip>',
"bAutoWidth":false,
"aoColumns": [
{ "bSortable": false,
"fnRender": function ( o, val ) {
//we render 1st column as a checkbox directly
return '<input class="check_item" type="checkbox" id="appmarketplace_'+
o.aData['_id']['$oid']+
'" name="selected_items" value="'+
o.aData['_id']['$oid']+'"/>'
},
"sWidth" : "60px"
},
{ "mDataProp": "_id.$oid", "bVisible": false, "sWidth" : "200px" },
{ "mDataProp": "name" },
{ "mDataProp": "publisher" },
{ "mDataProp": "files.0.hypervisor", "sWidth" : "100px"},
{ "mDataProp": "files.0.os-arch", "sWidth" : "100px"},
{ "mDataProp": "files.0.format", "sWidth" : "100px"},
{ "mDataProp": "tags", "bVisible": false}
],
"oLanguage": (datatable_lang != "") ?
{
sUrl: "locale/"+lang+"/"+datatable_lang
} : ""
});
tableCheckboxesListener(dataTable_appmarket);
onlyOneCheckboxListener(dataTable_appmarket);
infoListenerMarket(dataTable_appmarket);
Sunstone.runAction('AppMarket.list');
});
+49
View File
@@ -0,0 +1,49 @@
APPMARKET_CONF_FILE = ETC_LOCATION + "/sunstone-appmarket.conf"
$: << RUBY_LIB_LOCATION+"/apptools/market"
require 'appmarket_client'
begin
appmarket_conf = YAML.load_file(APPMARKET_CONF_FILE)
rescue Exception => e
STDERR.puts "Error parsing config file #{APPMARKET_CONF_FILE}: #{e.message}"
exit 1
end
set :appmarket_config, appmarket_conf
helpers do
def am_build_client
Market::ApplianceClient.new(
settings.appmarket_config[:appmarket_username],
settings.appmarket_config[:appmarket_password],
settings.appmarket_config[:appmarket_url],
"Sunstone")
end
def am_format_response(response)
if CloudClient::is_error?(response)
error = Error.new(response.to_s)
[response.code.to_i, error.to_json]
else
[200, response.body]
end
end
end
get '/appmarket' do
client = am_build_client
response = client.list
am_format_response(response)
end
get '/appmarket/:id' do
client = am_build_client
response = client.show(params[:id])
am_format_response(response)
end