Browse Source

first very rudimentary access to lxd rest api

master
Georg Hopp 10 years ago
parent
commit
3225dd51fb
  1. 4
      app/controllers/dashboard_controller.rb
  2. 3
      app/models/lxd.rb
  3. 23
      app/models/lxd/server.rb
  4. 5
      app/views/dashboard/index.html.erb

4
app/controllers/dashboard_controller.rb

@ -1,4 +1,8 @@
class DashboardController < ApplicationController class DashboardController < ApplicationController
def index def index
@lxd_host = LxdHost.find(1)
@cert = Certificate.find(1)
@lxd = Lxd::Server.by_host @lxd_host, @cert
end end
end end
# vim: set et ts=2 sw=2:

3
app/models/lxd.rb

@ -0,0 +1,3 @@
module Lxd
end
# vim: set ts=2 sw=2:

23
app/models/lxd/server.rb

@ -0,0 +1,23 @@
class Lxd::Server
include ActiveModel::Model
attr_accessor :api_extensions, :api_status, :api_version, :auth, :config,
:environment, :public
def self.by_host(host, certificate)
all = Array.new;
uri = URI.parse(host.uri + '/1.0')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(certificate.cert)
http.key = OpenSSL::PKey::RSA.new(certificate.key)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
Lxd::Server.new(JSON.parse(response.body)['metadata'])
end
end
# vim: set ts=2 sw=2:

5
app/views/dashboard/index.html.erb

@ -1,2 +1,5 @@
<h1>Dashboard#index</h1> <h1>Dashboard#index</h1>
<p>Find me in app/views/dashboard/index.html.erb</p>
<p><%= @lxd_host.class %></p>
<p><%= @cert.class %></p>
<p><%= @lxd.class %></p>
<p><%= @lxd.auth %></p>
Loading…
Cancel
Save