haze 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +55 -0
- data/bin/haze +8 -0
- data/haze.yml +20 -0
- data/imgs/generic.img +0 -0
- data/lib/haze.rb +70 -0
- data/lib/haze/server.rb +44 -0
- data/lib/haze/version.rb +3 -0
- data/lib/haze/vm.rb +89 -0
- data/spec/haze_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +89 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (0.9.8)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
eventmachine (0.12.10)
|
7
|
+
git (1.2.5)
|
8
|
+
guard (0.8.8)
|
9
|
+
thor (~> 0.14.6)
|
10
|
+
host (0.1.3)
|
11
|
+
jeweler (1.6.4)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
json (1.6.3)
|
16
|
+
little-plugger (1.1.3)
|
17
|
+
logging (1.6.1)
|
18
|
+
little-plugger (>= 1.1.2)
|
19
|
+
method_source (0.6.7)
|
20
|
+
ruby_parser (>= 2.3.1)
|
21
|
+
pokan (0.2.6)
|
22
|
+
eventmachine
|
23
|
+
json
|
24
|
+
redis
|
25
|
+
pokan-cluster (0.1.10)
|
26
|
+
host
|
27
|
+
logging
|
28
|
+
pokan
|
29
|
+
yagni
|
30
|
+
pry (0.9.7.4)
|
31
|
+
coderay (~> 0.9.8)
|
32
|
+
method_source (~> 0.6.7)
|
33
|
+
ruby_parser (>= 2.3.1)
|
34
|
+
slop (~> 2.1.0)
|
35
|
+
rake (0.9.2.2)
|
36
|
+
redis (2.2.2)
|
37
|
+
rspec (2.7.0)
|
38
|
+
rspec-core (~> 2.7.0)
|
39
|
+
rspec-expectations (~> 2.7.0)
|
40
|
+
rspec-mocks (~> 2.7.0)
|
41
|
+
rspec-core (2.7.1)
|
42
|
+
rspec-expectations (2.7.0)
|
43
|
+
diff-lcs (~> 1.1.2)
|
44
|
+
rspec-mocks (2.7.0)
|
45
|
+
ruby-libvirt (0.4.0)
|
46
|
+
ruby_parser (2.3.1)
|
47
|
+
sexp_processor (~> 3.0)
|
48
|
+
sexp_processor (3.0.8)
|
49
|
+
slop (2.1.0)
|
50
|
+
thor (0.14.6)
|
51
|
+
yagni (1.3)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
bundler
|
58
|
+
guard
|
59
|
+
jeweler
|
60
|
+
pokan-cluster
|
61
|
+
pry
|
62
|
+
rspec
|
63
|
+
ruby-libvirt
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Renato Mascarenhas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= haze
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to haze
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Renato Mascarenhas. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
require_relative 'lib/haze/version.rb'
|
7
|
+
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
$stderr.puts e.message
|
12
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
require 'rake'
|
16
|
+
|
17
|
+
require 'jeweler'
|
18
|
+
Jeweler::Tasks.new do |gem|
|
19
|
+
gem.name = "haze"
|
20
|
+
gem.version = Haze::VERSION
|
21
|
+
gem.homepage = "http://github.com/rmascarenhas/haze"
|
22
|
+
gem.license = "MIT"
|
23
|
+
gem.summary = %Q{Cloud manager}
|
24
|
+
gem.description = %Q{Expect a better description in the future}
|
25
|
+
gem.email = "renato.mascosta@gmail.com"
|
26
|
+
gem.authors = ["Fabio de Lima Pereira", "Rafael Regis do Prado", "Renato Mascarenhas"]
|
27
|
+
|
28
|
+
gem.executables << 'haze'
|
29
|
+
gem.add_dependency 'pokan-cluster'
|
30
|
+
gem.add_dependency 'ruby-libvirt'
|
31
|
+
end
|
32
|
+
Jeweler::RubygemsDotOrgTasks.new
|
33
|
+
|
34
|
+
require 'rspec/core'
|
35
|
+
require 'rspec/core/rake_task'
|
36
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
37
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
38
|
+
end
|
39
|
+
|
40
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
41
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
42
|
+
spec.rcov = true
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "haze #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/bin/haze
ADDED
data/haze.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
pokan:
|
2
|
+
address: "172.27.139.248" # your address here
|
3
|
+
|
4
|
+
connect:
|
5
|
+
udp: 7777
|
6
|
+
tcp: 777
|
7
|
+
epoll: false # set to true if you are on a Linux box
|
8
|
+
|
9
|
+
gossip:
|
10
|
+
every: 3
|
11
|
+
|
12
|
+
# Uncomment the following if the server is not seed
|
13
|
+
# seed
|
14
|
+
# address: "..." # seed address
|
15
|
+
# redis: 6379 # port on which redis is waiting for connections
|
16
|
+
|
17
|
+
log:
|
18
|
+
enabled: true
|
19
|
+
level: info
|
20
|
+
file: "haze.log"
|
data/imgs/generic.img
ADDED
Binary file
|
data/lib/haze.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'pokan-cluster'
|
2
|
+
|
3
|
+
module Haze
|
4
|
+
require_relative 'haze/version'
|
5
|
+
require_relative 'haze/vm'
|
6
|
+
|
7
|
+
def self.init
|
8
|
+
File.open('haze.yml', 'w') { |f| f.write(default_config_file) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.start
|
12
|
+
require 'socket'
|
13
|
+
@thread = Thread.new {
|
14
|
+
s = TCPServer.new('127.0.0.1', 5555)
|
15
|
+
|
16
|
+
begin
|
17
|
+
loop do
|
18
|
+
conn = s.accept
|
19
|
+
request = conn.read
|
20
|
+
json = JSON.parse(request)
|
21
|
+
|
22
|
+
response = case json['action']
|
23
|
+
when 'vm create'
|
24
|
+
VM.create(json['options'])
|
25
|
+
when 'vm remove'
|
26
|
+
VM.remove(json['options'])
|
27
|
+
when 'vm list'
|
28
|
+
VM.list
|
29
|
+
end
|
30
|
+
puts response
|
31
|
+
|
32
|
+
conn.print response
|
33
|
+
conn.close_write
|
34
|
+
conn.close
|
35
|
+
end
|
36
|
+
rescue Exception => e
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
require_relative 'haze/server'
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.default_config_file
|
47
|
+
<<-END
|
48
|
+
pokan:
|
49
|
+
address: "..." # your address here
|
50
|
+
|
51
|
+
connect:
|
52
|
+
udp: 7777
|
53
|
+
tcp: 777
|
54
|
+
epoll: false # set to true if you are on a Linux box
|
55
|
+
|
56
|
+
gossip:
|
57
|
+
every: 3
|
58
|
+
|
59
|
+
# Uncomment the following if the server is not seed
|
60
|
+
# seed
|
61
|
+
# address: "..." # seed address
|
62
|
+
# redis: 6379 # port on which redis is waiting for connections
|
63
|
+
|
64
|
+
log:
|
65
|
+
enabled: true
|
66
|
+
level: info
|
67
|
+
file: "haze.log"
|
68
|
+
END
|
69
|
+
end
|
70
|
+
end
|
data/lib/haze/server.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Haze
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
class Server
|
7
|
+
include Pokan::Cluster
|
8
|
+
|
9
|
+
config { YAML.parse_file('./haze.yml').to_ruby }
|
10
|
+
|
11
|
+
require 'socket'
|
12
|
+
Thread.new {
|
13
|
+
config = YAML.parse_file('./haze.yml').to_ruby
|
14
|
+
address = config['pokan']['address']
|
15
|
+
|
16
|
+
s = TCPServer.new(address, 4444)
|
17
|
+
|
18
|
+
begin
|
19
|
+
loop do
|
20
|
+
conn = s.accept
|
21
|
+
request = conn.read
|
22
|
+
json = JSON.parse(request)
|
23
|
+
|
24
|
+
response = case json['action']
|
25
|
+
when 'vm create'
|
26
|
+
VM.create(json['options'])
|
27
|
+
when 'vm remove'
|
28
|
+
VM.remove(json['options'])
|
29
|
+
when 'vm list'
|
30
|
+
VM.list
|
31
|
+
end
|
32
|
+
puts response
|
33
|
+
|
34
|
+
conn.print response
|
35
|
+
conn.close_write
|
36
|
+
conn.close
|
37
|
+
end
|
38
|
+
rescue Exception => e
|
39
|
+
retry
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/haze/version.rb
ADDED
data/lib/haze/vm.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'libvirt'
|
3
|
+
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
module Haze
|
7
|
+
class VM
|
8
|
+
|
9
|
+
def self.create(options)
|
10
|
+
path = '/tmp/'
|
11
|
+
|
12
|
+
dom_xml = <<-XML
|
13
|
+
<domain type='qemu'>
|
14
|
+
<name>#{options['name']}</name>
|
15
|
+
<memory>#{options['memory']}</memory>
|
16
|
+
<currentMemory>#{options['memory']}</currentMemory>
|
17
|
+
<vcpu>1</vcpu>
|
18
|
+
<os>
|
19
|
+
<type arch='i686' machine='pc'>hvm</type>
|
20
|
+
<boot dev='hd'/>
|
21
|
+
</os>
|
22
|
+
<features>
|
23
|
+
<acpi/>
|
24
|
+
</features>
|
25
|
+
<clock offset='utc'/>
|
26
|
+
<on_poweroff>destroy</on_poweroff>
|
27
|
+
<on_reboot>restart</on_reboot>
|
28
|
+
<on_crash>destroy</on_crash>
|
29
|
+
<devices>
|
30
|
+
<disk type='file' device='disk'>
|
31
|
+
<source file='#{path + options['image'] + '.img'}'/>
|
32
|
+
<target dev='hda'/>
|
33
|
+
</disk>
|
34
|
+
<input type='mouse' bus='ps2'/>
|
35
|
+
#{"<graphics type='vnc' port='#{options['vnc']['port']}' listen='#{options['vnc']['ip']}'/>" if options.has_key?('vnc') }
|
36
|
+
</devices>
|
37
|
+
</domain>
|
38
|
+
XML
|
39
|
+
puts dom_xml
|
40
|
+
begin
|
41
|
+
conn = Libvirt::open('qemu:///system')
|
42
|
+
dom = conn.create_domain_xml(dom_xml)
|
43
|
+
@response = { action: 'vm creation', status: 'OK' }
|
44
|
+
rescue Exception => e
|
45
|
+
puts "#{"<graphics type='vnc' port='#{options['vnc']['port']}' listen='#{options['vnc']['ip']}'/>" if options.has_key?('vnc') }"
|
46
|
+
puts e
|
47
|
+
@response = { action: 'vm creation', status: 'ERROR' }
|
48
|
+
ensure
|
49
|
+
conn.close
|
50
|
+
end
|
51
|
+
|
52
|
+
puts @response
|
53
|
+
@response.to_json
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.remove(options)
|
57
|
+
begin
|
58
|
+
puts options
|
59
|
+
conn = Libvirt::open('qemu:///system')
|
60
|
+
conn.lookup_domain_by_id(options['id']).destroy
|
61
|
+
response = { action: 'vm removal', status: 'OK'}
|
62
|
+
rescue Exception => e
|
63
|
+
puts e
|
64
|
+
response = { action: 'vm removal', status: 'ERROR'}
|
65
|
+
ensure
|
66
|
+
conn.close
|
67
|
+
end
|
68
|
+
|
69
|
+
response.to_json
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.list
|
73
|
+
conn = Libvirt::open('qemu:///system')
|
74
|
+
doms = conn.list_domains.map do |id|
|
75
|
+
dom = conn.lookup_domain_by_id(id)
|
76
|
+
{ id: id,
|
77
|
+
name: dom.name,
|
78
|
+
cpu_time: dom.info.cpu_time,
|
79
|
+
vcpus: dom.get_vcpus.size,
|
80
|
+
status: dom.state ? "running" : "paused",
|
81
|
+
memory: dom.max_memory,
|
82
|
+
type: dom.os_type }
|
83
|
+
end
|
84
|
+
conn.close
|
85
|
+
{ action:'vm listing', data: { vms: doms } }.to_json
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
data/spec/haze_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'haze'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fabio de Lima Pereira
|
9
|
+
- Rafael Regis do Prado
|
10
|
+
- Renato Mascarenhas
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-12-01 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: pokan-cluster
|
18
|
+
requirement: &5205540 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *5205540
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-libvirt
|
29
|
+
requirement: &5202660 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *5202660
|
38
|
+
description: Expect a better description in the future
|
39
|
+
email: renato.mascosta@gmail.com
|
40
|
+
executables:
|
41
|
+
- haze
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .rspec
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- bin/haze
|
53
|
+
- haze.yml
|
54
|
+
- imgs/generic.img
|
55
|
+
- lib/haze.rb
|
56
|
+
- lib/haze/server.rb
|
57
|
+
- lib/haze/version.rb
|
58
|
+
- lib/haze/vm.rb
|
59
|
+
- spec/haze_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: http://github.com/rmascarenhas/haze
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -219330059151159148
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.10
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Cloud manager
|
89
|
+
test_files: []
|