From: Michal Fojtik <[email protected]>
---
src/app/metal/connection_tester.rb | 20 ++++++++++++++++++++
src/app/views/provider/accounts.haml | 3 +++
src/public/javascripts/application.js | 15 +++++++++++++++
3 files changed, 38 insertions(+), 0 deletions(-)
create mode 100644 src/app/metal/connection_tester.rb
diff --git a/src/app/metal/connection_tester.rb
b/src/app/metal/connection_tester.rb
new file mode 100644
index 0000000..6d754db
--- /dev/null
+++ b/src/app/metal/connection_tester.rb
@@ -0,0 +1,20 @@
+# Allow the metal piece to run in isolation
+require(File.dirname(__FILE__) + "/../../config/environment") unless
defined?(Rails)
+
+class ConnectionTester
+ def self.call(env)
+ if env["PATH_INFO"] =~ /^\/account\/check/
+ account = CloudAccount.find(Rack::Request.new(env).params["id"])
+ begin
+ if account && DeltaCloud::valid_credentials?(account.username,
+ account.password, account.provider.url)
+ return [200, {"Content-Type" => "text/plain"}, ["OK"]]
+ end
+ rescue
+ end
+ [200, {"Content-Type" => "text/plain"}, ["ERROR"]]
+ else
+ [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+ end
+ end
+end
diff --git a/src/app/views/provider/accounts.haml
b/src/app/views/provider/accounts.haml
index 647f44a..785d7c9 100644
--- a/src/app/views/provider/accounts.haml
+++ b/src/app/views/provider/accounts.haml
@@ -4,6 +4,7 @@
%table
%thead
%tr
+ %th
%th{:scope => "col"} Label
%th{:scope => "col"} Username
%th{:scope => "col"}
@@ -11,6 +12,8 @@
%tbody
- @provider.cloud_accounts.each {|acct|
%tr
+ %td
+ %a{:href => "#", :onclick => "test_connection(this, #{acct.id});"}
Test connection
%td= acct.label
%td= acct.username
%td= link_to "Edit", {:controller => 'cloud_accounts', :action =>
'edit', :id => acct.id} if has_account_modify?(@provider)
diff --git a/src/public/javascripts/application.js
b/src/public/javascripts/application.js
index 1af4f77..c51e450 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -1,6 +1,21 @@
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
+function test_connection(el, id) {
+ $.ajax({
+ url : "/account/check",
+ data : { id : id },
+ success : function(data) {
+ if (data=="OK") {
+ $(el).css("color", "green")
+ } else {
+ $(el).css("color", "red")
+ }
+ },
+ })
+ return false;
+}
+
var Aggregator = {
extendTable: function(options) {
var table = $(options.id);
--
1.7.2.2
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel