Revision 843ea5cb
Added by Amos Benari almost 11 years ago
- ID 843ea5cbc7341e31a36341906b0d63b153370fe4
app/assets/javascripts/compute_resource.js | ||
---|---|---|
function testConnection(item) {
|
||
var cr_id = $("form").data('id');
|
||
var password = $("input[id$='password']").val();
|
||
$('.tab-error').removeClass('tab-error');
|
||
$('#test_connection_indicator').show();
|
||
$.ajax({
|
||
type:'put',
|
app/controllers/compute_resources_controller.rb | ||
---|---|---|
else
|
||
@compute_resource = ComputeResource.new_provider(params[:compute_resource])
|
||
end
|
||
@compute_resource.test_connection
|
||
@compute_resource.test_connection :force => true
|
||
render :partial => "compute_resources/form", :locals => { :compute_resource => @compute_resource }
|
||
end
|
||
|
app/helpers/compute_resources_helper.rb | ||
---|---|---|
def password_placeholder(obj)
|
||
obj.id ? "********" : ""
|
||
end
|
||
|
||
def list_datacenters compute
|
||
return [] unless compute.uuid || controller.action_name == 'test_connection'
|
||
compute.datacenters
|
||
rescue Foreman::FingerprintException => e
|
||
compute.errors[:pubkey_hash] = e
|
||
[]
|
||
rescue
|
||
[]
|
||
end
|
||
end
|
app/models/compute_resource.rb | ||
---|---|---|
{:uuid => :identity}
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
valid?
|
||
end
|
||
|
app/views/compute_resources/form/_vmware.html.erb | ||
---|---|---|
<%= text_f f, :server, :label => _("VCenter/Server"), :class => "input-xlarge" %>
|
||
<%= text_f f, :user %>
|
||
<%= password_f f, :password, :placeholder => password_placeholder(f.object) %>
|
||
<% datacenters = (f.object.uuid.nil? && controller.action_name != 'test_connection') ? [] : f.object.datacenters rescue []%>
|
||
<% datacenters = list_datacenters f.object%>
|
||
<%= selectable_f(f, :uuid, datacenters, {}, {:label => _('Datacenter'),
|
||
:help_inline => link_to_function(datacenters.empty? ? "Load Datacenters" : "Test Connection", "testConnection(this)",
|
||
:class => "btn + #{datacenters.empty? ? "" : "btn-success"}",
|
||
:'data-url' => test_connection_compute_resources_path) + image_tag('/assets/spinner.gif', :id => 'test_connection_indicator', :class => 'hide').html_safe }) %>
|
||
<%= text_f f, :pubkey_hash, :disabled => true, :label => _("Fingerprint"), :class=>"input-xxlarge" %>
|
||
<%= f.hidden_field(:pubkey_hash) if f.object.uuid.present? %>
|
lib/foreman/exception.rb | ||
---|---|---|
alias :to_s :message
|
||
end
|
||
|
||
class FingerprintException < Exception
|
||
def fingerprint
|
||
@params[0]
|
||
end
|
||
end
|
||
|
||
end
|
lib/foreman/model/ec2.rb | ||
---|---|---|
client.flavors
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
super
|
||
errors[:user].empty? and errors[:password].empty? and regions
|
||
rescue Fog::Compute::AWS::Error => e
|
lib/foreman/model/libvirt.rb | ||
---|---|---|
16*1024*1024*1024
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
super
|
||
errors[:url].empty? and hypervisor
|
||
rescue => e
|
lib/foreman/model/openstack.rb | ||
---|---|---|
[:image]
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
super
|
||
errors[:user].empty? and errors[:password] and tenants
|
||
rescue => e
|
lib/foreman/model/rackspace.rb | ||
---|---|---|
client.images
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
super and flavors
|
||
rescue Excon::Errors::Unauthorized => e
|
||
errors[:base] << e.response.body
|
lib/foreman/model/vmware.rb | ||
---|---|---|
require 'fog_extensions/vsphere/mini_servers'
|
||
require 'foreman/exception'
|
||
|
||
module Foreman::Model
|
||
class Vmware < ComputeResource
|
||
... | ... | |
dc.datastores.all(:accessible => true)
|
||
end
|
||
|
||
def test_connection
|
||
def test_connection options = {}
|
||
super
|
||
if errors[:server].empty? and errors[:user].empty? and errors[:password].empty?
|
||
update_public_key
|
||
update_public_key options
|
||
datacenters
|
||
end
|
||
rescue => e
|
||
... | ... | |
client.volumes.new attr.merge(:size_gb => 10)
|
||
end
|
||
|
||
def pubkey_hash
|
||
attrs[:pubkey_hash]
|
||
end
|
||
|
||
def pubkey_hash= key
|
||
attrs[:pubkey_hash] = key
|
||
end
|
||
|
||
private
|
||
|
||
def dc
|
||
client.datacenters.get(datacenter)
|
||
end
|
||
|
||
def update_public_key
|
||
return unless pubkey_hash.blank?
|
||
def update_public_key options ={}
|
||
return unless pubkey_hash.blank? || options[:force]
|
||
client
|
||
rescue => e
|
||
if e.message =~ /The remote system presented a public key with hash (\w+) but we're expecting a hash of/
|
||
self.pubkey_hash = $1
|
||
else
|
||
raise e
|
||
end
|
||
end
|
||
|
||
def pubkey_hash
|
||
attrs[:pubkey_hash]
|
||
end
|
||
|
||
def pubkey_hash= key
|
||
attrs[:pubkey_hash] = key
|
||
rescue Foreman::FingerprintException => e
|
||
self.pubkey_hash = e.fingerprint
|
||
end
|
||
|
||
def client
|
||
... | ... | |
:vsphere_server => server,
|
||
:vsphere_expected_pubkey_hash => pubkey_hash
|
||
)
|
||
rescue => e
|
||
if e.message =~ /The remote system presented a public key with hash (\w+) but we're expecting a hash of/
|
||
raise Foreman::FingerprintException.new(
|
||
N_("The remote system presented a public key with hash %s but we're expecting a different hash. If you are sure the remote system is authentic, go to the compute resource edit page, press the 'Test Connection' or 'Load Datacenters' button and submit"), $1)
|
||
else
|
||
raise e
|
||
end
|
||
end
|
||
|
||
def unused_vnc_port ip
|
||
... | ... | |
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
fixes #2656 error connecting to vsphere after upgrade to ruby 1.9.3
(cherry picked from commit 617ee75f8c0f8d239564f3fd48d92a2d772eeb8b)