Commit 3225dd51fbbf059851e80b380f9b62907b42ed61

Authored by Georg Hopp
1 parent f3a845b0

first very rudimentary access to lxd rest api

1 1 class DashboardController < ApplicationController
2 2 def index
  3 + @lxd_host = LxdHost.find(1)
  4 + @cert = Certificate.find(1)
  5 + @lxd = Lxd::Server.by_host @lxd_host, @cert
3 6 end
4 7 end
  8 +# vim: set et ts=2 sw=2:
... ...
  1 +module Lxd
  2 +end
  3 +# vim: set ts=2 sw=2:
... ...
  1 +class Lxd::Server
  2 + include ActiveModel::Model
  3 +
  4 + attr_accessor :api_extensions, :api_status, :api_version, :auth, :config,
  5 + :environment, :public
  6 +
  7 + def self.by_host(host, certificate)
  8 + all = Array.new;
  9 +
  10 + uri = URI.parse(host.uri + '/1.0')
  11 + http = Net::HTTP.new(uri.host, uri.port)
  12 + http.use_ssl = true
  13 + http.cert = OpenSSL::X509::Certificate.new(certificate.cert)
  14 + http.key = OpenSSL::PKey::RSA.new(certificate.key)
  15 + http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  16 +
  17 + request = Net::HTTP::Get.new(uri.request_uri)
  18 + response = http.request(request)
  19 +
  20 + Lxd::Server.new(JSON.parse(response.body)['metadata'])
  21 + end
  22 +end
  23 +# vim: set ts=2 sw=2:
... ...
1 1 <h1>Dashboard#index</h1>
2   -<p>Find me in app/views/dashboard/index.html.erb</p>
  2 +<p><%= @lxd_host.class %></p>
  3 +<p><%= @cert.class %></p>
  4 +<p><%= @lxd.class %></p>
  5 +<p><%= @lxd.auth %></p>
... ...
Please register or login to post a comment