Module: Haze

Defined in:
lib/haze.rb,
lib/haze/vm.rb,
lib/haze/server.rb,
lib/haze/version.rb

Defined Under Namespace

Classes: Server, VM

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.initObject



7
8
9
# File 'lib/haze.rb', line 7

def self.init
  File.open('haze.yml', 'w') { |f| f.write(default_config_file) }
end

.startObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/haze.rb', line 11

def self.start
  require 'socket'
  @thread = Thread.new {
    s = TCPServer.new('127.0.0.1', 5555)

    begin
    loop do
      conn = s.accept
      request = conn.read
      json = JSON.parse(request)

      response = case json['action']
        when 'vm create'
          VM.create(json['options'])
        when 'vm remove'
          VM.remove(json['options'])
        when 'vm list'
          VM.list
      end
      puts response

      conn.print response
      conn.close_write
      conn.close
    end
    rescue Exception => e
      retry
    end
  }

  require_relative 'haze/server'
end