https://bugzilla.redhat.com/show_bug.cgi?id=642432
This adds a link to download the private key, so the user can ssh into their instance. As a side effect, also fixes the model relationship between instance and instance_key. --- src/app/controllers/instance_controller.rb | 21 +++++++++++++++++++-- src/app/models/instance.rb | 1 + src/app/views/instance/show.haml | 4 ++++ src/app/views/layouts/_notification.rhtml | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb index 3bef6f0..2073937 100644 --- a/src/app/controllers/instance_controller.rb +++ b/src/app/controllers/instance_controller.rb @@ -23,6 +23,7 @@ require 'util/condormatic' class InstanceController < ApplicationController before_filter :require_user, :get_nav_items + before_filter :instance, :only => [:show, :key] layout :layout def section_id @@ -53,8 +54,17 @@ class InstanceController < ApplicationController end def show - @instance = Instance.find(params[:id]) - require_privilege(Privilege::INSTANCE_VIEW, @instance.pool) + end + + def key + unless @instance.instance_key.nil? + send_data @instance.instance_key.pem, + :filename => "#[email protected]_key.name}.pem", + :type => "text/plain" + end + rescue + flash[:warning] = "SSH Key not found for this Instance." + redirect_to :action => "show", :id => @instance end def new @@ -171,4 +181,11 @@ class InstanceController < ApplicationController action end + private + + def instance + @instance = Instance.find(params[:id]) + require_privilege(Privilege::INSTANCE_VIEW, @instance.pool) + end + end diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 5ede90e..22069e2 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -33,6 +33,7 @@ class Instance < ActiveRecord::Base belongs_to :template belongs_to :realm belongs_to :owner, :class_name => "User", :foreign_key => "owner_id" + belongs_to :instance_key validates_presence_of :pool_id validates_presence_of :hardware_profile_id diff --git a/src/app/views/instance/show.haml b/src/app/views/instance/show.haml index 42236c8..071ec7c 100644 --- a/src/app/views/instance/show.haml +++ b/src/app/views/instance/show.haml @@ -40,6 +40,10 @@ %li = label_tag :console_connection, 'Console Connection' %span= 'via SSH' + - unless @instance.instance_key_id.nil? + %li + = label_tag :owner, 'SSH key' + %span= link_to("Download", { :controller => "instance", :action => "key", :id => @instance }) %li = label_tag :owner, 'Owner' %span= "#[email protected]_name} #[email protected]_name}" diff --git a/src/app/views/layouts/_notification.rhtml b/src/app/views/layouts/_notification.rhtml index 44793a5..02a65de 100644 --- a/src/app/views/layouts/_notification.rhtml +++ b/src/app/views/layouts/_notification.rhtml @@ -23,7 +23,7 @@ <% end %> <% end %> <% if flash[:warning] %> - <div class="warning"><h4><%= flash[:warning] %></h4></div> + <div class="error"><ul><li><%= flash[:warning] %></li></ul></div> <% end %> <% if flash[:notice] %> <div class="success"><ul><li><%= flash[:notice] %></li></ul></div> -- 1.7.2.3 _______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
