show login names and config instructions on VMs page
authorTom Clegg <tom@clinicalfuture.com>
Mon, 1 Jul 2013 18:48:52 +0000 (14:48 -0400)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 1 Jul 2013 18:50:01 +0000 (14:50 -0400)
apps/workbench/app/controllers/virtual_machines_controller.rb
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/models/virtual_machine.rb
apps/workbench/app/views/application/_index.html.erb [new file with mode: 0644]
apps/workbench/app/views/application/index.html.erb
apps/workbench/app/views/virtual_machines/index.html.erb [new file with mode: 0644]
apps/workbench/app/views/virtual_machines/show.html.erb [deleted file]

index 9ccbfa68219eaa8fd3a5348365db3e795b9eb85a..a62ba81b0941cf46870ddc7f27bf3b97692fd172 100644 (file)
@@ -1,2 +1,22 @@
 class VirtualMachinesController < ApplicationController
+  def index
+    @objects ||= model_class.all
+    @vm_logins = {}
+    if @objects.andand.first
+      Link.where(tail_uuid: current_user.uuid,
+                 head_uuid: @objects.collect(&:uuid),
+                 link_class: 'permission',
+                 name: 'can_login').
+        each do |perm_link|
+        if perm_link.properties.andand[:username]
+          @vm_logins[perm_link.head_uuid] ||= []
+          @vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
+        end
+      end
+      @objects.each do |vm|
+        vm.current_user_logins = @vm_logins[vm.uuid].andand.compact || []
+      end
+    end
+    super
+  end
 end
index 049326b26ff2be45d2c12ff9ec2a0e8340f68571..d16656602cd9893760eda32e4e1164310922a631 100644 (file)
@@ -40,7 +40,7 @@ module ApplicationHelper
     return attrvalue if !object.attribute_editable? attr
 
     input_type = 'text'
-    case object.class.attribute_info[attr.to_sym][:type]
+    case object.class.attribute_info[attr.to_sym].andand[:type]
     when 'text'
       input_type = 'textarea'
     when 'datetime'
@@ -49,7 +49,7 @@ module ApplicationHelper
       input_type = 'text'
     end
 
-    attrvalue = attrvalue.to_json if attrvalue.is_a? Hash
+    attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
 
     link_to attrvalue.to_s, '#', {
       "data-emptytext" => "none",
index 61b3b6b36173703a8a554b9e4083773dc0015788..31ee9122f71ce48163ac6f3512d6b0bddcd5b6e3 100644 (file)
@@ -1,5 +1,19 @@
 class VirtualMachine < ArvadosBase
+  attr_accessor :current_user_logins
   def self.creatable?
     current_user.andand.is_admin
   end
+  def attributes_for_display
+    logger.debug super.append ['current_user_logins', @current_user_logins]
+    super.append ['current_user_logins', @current_user_logins]
+  end
+  def attribute_editable?(attr)
+    attr != 'current_user_logins' and super
+  end
+  def self.attribute_info
+    merger = ->(k,a,b) { a.merge(b, &merger) }
+    merger [nil,
+            {current_user_logins: {column_heading: "logins", type: 'array'}},
+            super]
+  end
 end
diff --git a/apps/workbench/app/views/application/_index.html.erb b/apps/workbench/app/views/application/_index.html.erb
new file mode 100644 (file)
index 0000000..632d61b
--- /dev/null
@@ -0,0 +1,50 @@
+<% if @objects.empty? %>
+
+<p>
+  No <%= controller.model_class.to_s.underscore.pluralize.gsub '_', ' ' %> to display.
+</p>
+
+<% else %>
+
+<% attr_blacklist = 'created_at modified_at modified_by_user modified_by_client updated_at' %>
+
+<table class="table arv-index">
+  <thead>
+    <tr>
+      <% @objects.first.attributes_for_display.each do |attr, attrvalue| %>
+      <% next if attr_blacklist.index attr %>
+      <th class="arv-attr-<%= attr %>">
+        <%= controller.model_class.attribute_info[attr.to_sym].andand[:column_heading] or attr.sub /_uuid/, '' %>
+      </th>
+      <% end %>
+    </tr>
+  </thead>
+      
+  <tbody>
+    <% @objects.each do |object| %>
+    <tr>
+      <% object.attributes_for_display.each do |attr, attrvalue| %>
+      <% next if attr_blacklist.index attr %>
+      <td class="arv-object-<%= object.class.to_s %> arv-attr-<%= attr %>">
+        <% if attr == 'uuid' %>
+        <%= link_to_if_arvados_object object %>
+        <% elsif object.attribute_editable? attr %>
+        <%= render_editable_attribute object, attr %>
+        <% else %>
+        <%= link_to_if_arvados_object attrvalue, {referring_attr: attr, referring_object: @object, with_class_name: true} %>
+        <% end %>
+      </td>
+      <% end %>
+    </tr>
+    <% end %>
+  </tbody>
+
+  <tfoot>
+  </tfoot>
+</table>
+
+<% end %>
+
+<% if controller.model_class.creatable? %>
+<%= button_to "Add a new #{controller.model_class.to_s.underscore.gsub '_', ' '}", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>
+<% end %>
index bb9dde3087183c738801af4df93793f091bce942..6256b2848e268c7c1aacf1bff2d60969da5512a8 100644 (file)
@@ -1,50 +1 @@
-<% if @objects.empty? %>
-
-<p>
-  No <%= controller.model_class.to_s.underscore.pluralize.gsub '_', ' ' %> to display.
-</p>
-
-<% else %>
-
-<% attr_blacklist = 'created_at modified_at modified_by_user modified_by_client updated_at' %>
-
-<table class="table arv-index">
-  <thead>
-    <tr>
-      <% @objects.first.attributes_for_display.each do |attr, attrvalue| %>
-      <% next if attr_blacklist.index attr %>
-      <th class="arv-attr-<%= attr %>">
-        <%= attr.sub /_uuid/, '' %>
-      </th>
-      <% end %>
-    </tr>
-  </thead>
-      
-  <tbody>
-    <% @objects.each do |object| %>
-    <tr>
-      <% object.attributes_for_display.each do |attr, attrvalue| %>
-      <% next if attr_blacklist.index attr %>
-      <td class="arv-object-<%= object.class.to_s %> arv-attr-<%= attr %>">
-        <% if attr == 'uuid' %>
-        <%= link_to_if_arvados_object object %>
-        <% elsif object.attribute_editable? attr %>
-        <%= render_editable_attribute object, attr %>
-        <% else %>
-        <%= link_to_if_arvados_object attrvalue, {referring_attr: attr, referring_object: @object, with_class_name: true} %>
-        <% end %>
-      </td>
-      <% end %>
-    </tr>
-    <% end %>
-  </tbody>
-
-  <tfoot>
-  </tfoot>
-</table>
-
-<% end %>
-
-<% if controller.model_class.creatable? %>
-<%= button_to "Add a new #{controller.model_class.to_s.underscore.gsub '_', ' '}", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>
-<% end %>
+<%= render partial: 'index' %>
diff --git a/apps/workbench/app/views/virtual_machines/index.html.erb b/apps/workbench/app/views/virtual_machines/index.html.erb
new file mode 100644 (file)
index 0000000..2ba5712
--- /dev/null
@@ -0,0 +1,26 @@
+<%= render partial: 'application/index' %>
+
+<p>
+Sample <code>~/.ssh/config</code> section:
+</p>
+
+<pre>
+Host *.arvados
+  ProxyCommand ssh -p2222 turnout@switchyard.<%= Rails.configuration.arvados_v1_base.match(/\/\/(.*?)\//).andand[1] || 'xyzzy.arvadosapi.com' %> -x -a $SSH_PROXY_FLAGS %h
+<% if @objects.first.current_user_logins.andand.first %>
+  User <%= @objects.first.current_user_logins.andand.first %>
+<% end %>
+</pre>
+
+<p>
+Sample login command:
+</p>
+
+<pre>
+ssh <%= @objects.first.andand.hostname.sub(/\..*/,'') or 'vm-hostname' %>.arvados
+</pre>
+
+<p>
+  See also:
+  <%= link_to raw('Arvados Docs &rarr; User Guide &rarr; SSH access'), 'http://doc.arvados.org/user/ssh-access.html' %>.
+</p>
diff --git a/apps/workbench/app/views/virtual_machines/show.html.erb b/apps/workbench/app/views/virtual_machines/show.html.erb
deleted file mode 100644 (file)
index 9079085..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => 'application/arvados_object' %>