Module: Boxcutter::KVM

Defined in:
lib/bluebox-boxcutter/kvm.rb

Class Method Summary collapse

Class Method Details

.extract_jnlp_path(html) ⇒ Object



24
25
26
# File 'lib/bluebox-boxcutter/kvm.rb', line 24

def self.extract_jnlp_path(html)
  Nokogiri::HTML(html).css('a').map { |a| a['href'] }.select { |a| a =~ /spider.jnlp/ }.first
end

.run_jnlp(contents) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/bluebox-boxcutter/kvm.rb', line 28

def self.run_jnlp(contents)
  Tempfile.new('kvm-webstart').tap do |f|
    f.write contents
    f.close
    `javaws #{f.path} &`
  end
end

.start(url, user, password) ⇒ Object

given a kvm url and creds, start the java kvm console thingy.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bluebox-boxcutter/kvm.rb', line 8

def self.start(url, user, password)
  u = URI url
  base, path = [ "#{u.scheme}://#{u.host}", u.path ]
  path = '/auth.asp'  # path is missing from some of the password entries.

  client = Class.new do
    include HTTParty
    base_uri base
  end

  response = client.post(path, :body => {:login => user, :password => password, :action_login => 'Login'})
  cookie = response.request.options[:headers]['Cookie']
  jnlp_contents = client.get(extract_jnlp_path(response.body), :headers => {'Cookie' => cookie}).body
  run_jnlp(jnlp_contents)
end