简体   繁体   English

Rails-使用雾连接到KVM

[英]Rails - Using fog to connect to KVM

We are currently trying to connect with our rails app to a remote KVM server with gem 'fog' + 'ruby-libvirt' 我们目前正在尝试将rails应用程序连接到带有gem'fog'+'ruby-libvirt'的远程KVM服务器

Following this good documentation : libvirt-fog-provider 遵循以下良好文档: libvirt-fog-provider

require 'fog'
require 'net/ssh'
require 'net/scp'
require 'pp'

client = Fog::Compute.new({
                     :provider => "libvirt" ,
                     :libvirt_uri => "qemu+ssh://root@perceval.boap.net/system?socket=/var/run/libvirt/libvirt-sock"
                   })

s1 = client.servers.all(:name => "demo2")

This code is working properly with a standard ruby file, we made the connection to KVM server But when we put this same code in rails controller like this : 这段代码与标准的ruby文件一起正常工作,我们与KVM服务器建立了连接,但是当我们将相同的代码放在rails控制器中时,如下所示:

require 'fog'
require 'net/ssh'
require 'net/scp'

class VirtualMachinesController < ApplicationController

  before_action :connect_kvm
  def index
    head :no_content
  end

  private
  def connect_kvm
    client = Fog::Compute.new({
                                  :provider => "libvirt" ,
                                  :libvirt_uri => "qemu+ssh://root@perceval.boap.net/system?socket=/var/run/libvirt/libvirt-sock"
                              })
  end
end

Rails app display this error : Rails应用程序显示此错误:

Call to virConnectOpen failed: internal error: received hangup / error event on socket):
  app/controllers/virtual_machines_controller.rb:28:in `connect_kvm'

Is rails appropriate to hold ssh sessions ? Rails适合举行ssh会话吗? Am i missing something from rails purpose 我是否出于Rails目的缺少某些东西

We found out why it wasn't working properly. 我们发现了为什么它无法正常工作。

Don't forget to add in your Gemfile: 不要忘记在您的Gemfile中添加:

gem 'net-ssh'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM