xhyve-ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/vmnet/extconf.rb +2 -21
- data/lib/xhyve.rb +1 -0
- data/lib/xhyve/dhcp.rb +13 -0
- data/lib/xhyve/guest.rb +75 -0
- data/lib/xhyve/vendor/xhyve +0 -0
- data/lib/xhyve/version.rb +1 -1
- metadata +60 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cf9777a8a13a4a049b1b2ec2f0529b1aff1b3fa
|
4
|
+
data.tar.gz: 277e88f650d890e5410e7e47212ffdb72e13b04f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a58cbf6ad1c131fdf8da0616b01159460601584366c185c9c3623f5db3fc3be5ecc4975ec994e0192cb19b1066f1015f7a3bfa849b1085caaed02b5eab9138cb
|
7
|
+
data.tar.gz: 4fc91c59c68b9cb603a4560d296e25ae9c72f2a155316a2471a47e4459d2b370c4f567bbcfb0552ccbd209b66dce22d7dfa1a24d1e3248f1581680b66cb8fb02
|
data/ext/vmnet/extconf.rb
CHANGED
@@ -1,28 +1,9 @@
|
|
1
1
|
require "mkmf"
|
2
|
-
|
3
2
|
require 'rbconfig'
|
4
3
|
|
5
|
-
|
6
|
-
os = RbConfig::CONFIG['host_os']
|
7
|
-
case
|
8
|
-
when os.downcase.include?('linux')
|
9
|
-
'linux'
|
10
|
-
when os.downcase.include?('darwin')
|
11
|
-
'darwin'
|
12
|
-
else
|
13
|
-
puts 'You are not on a supported platform. exiting...'
|
14
|
-
puts 'Mac OS X and Linux are the only supported platforms.'
|
15
|
-
exit
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
4
|
+
abort "Only works on OS X" unless RbConfig::CONFIG['host_os'].downcase.include?('darwin')
|
19
5
|
abort "missing vmnet.h" unless have_header "uuid.h"
|
20
6
|
abort "missing vmnet.h" unless have_header "vmnet/vmnet.h"
|
21
|
-
|
22
|
-
if host_os == 'darwin'
|
23
|
-
abort "missing vmnet" unless have_framework "vmnet"
|
24
|
-
else
|
25
|
-
abort "missing vmnet" unless have_library "vmnet"
|
26
|
-
end
|
7
|
+
abort "missing vmnet" unless have_framework "vmnet"
|
27
8
|
|
28
9
|
create_makefile "vmnet/vmnet"
|
data/lib/xhyve.rb
CHANGED
data/lib/xhyve/dhcp.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Xhyve
|
2
|
+
module DHCP
|
3
|
+
LEASES_FILE='/var/db/dhcpd_leases'
|
4
|
+
def self.get_ip_for_mac(mac)
|
5
|
+
contents = File.read(ENV['LEASES_FILE'] || LEASES_FILE)
|
6
|
+
pattern = contents.match(/ip_address=(\S+)\n\thw_address=\d+,#{mac}/)
|
7
|
+
if pattern
|
8
|
+
addrs = pattern.captures
|
9
|
+
addrs.first if addrs
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/xhyve/guest.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
require 'xhyve/dhcp'
|
4
|
+
|
5
|
+
module Xhyve
|
6
|
+
BINARY_PATH=File.expand_path('../../../lib/xhyve/vendor/xhyve', __FILE__).freeze
|
7
|
+
|
8
|
+
class Guest
|
9
|
+
PCI_STR = '-s 0:0,hostbridge'
|
10
|
+
PCI_BASE = 3
|
11
|
+
NETWORK_STR = "-s #{PCI_BASE-1}:0,virtio-net"
|
12
|
+
|
13
|
+
attr_reader :pid, :uuid
|
14
|
+
|
15
|
+
def initialize(**opts)
|
16
|
+
@kernel = opts.fetch(:kernel)
|
17
|
+
@initrd = opts.fetch(:initrd)
|
18
|
+
@cmdline = opts.fetch(:cmdline)
|
19
|
+
@blockdevs = [ opts[:blockdevs] || [] ].flatten
|
20
|
+
@memory = opts[:memory] || '500M'
|
21
|
+
@processors = opts[:processors] || 1
|
22
|
+
@uuid = opts[:uuid] || SecureRandom.uuid
|
23
|
+
@serial = opts[:serial] || 'com1'
|
24
|
+
@acpi = opts[:acpi] || true
|
25
|
+
@sudo = opts[:sudo] || true
|
26
|
+
@command = build_command
|
27
|
+
end
|
28
|
+
|
29
|
+
def start
|
30
|
+
@pid = spawn(@command)
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop
|
34
|
+
Process.kill('TERM', @pid) if running?
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
Process.kill('KILL', @pid) if running?
|
39
|
+
end
|
40
|
+
|
41
|
+
def running?
|
42
|
+
Process.kill(0, @pid)
|
43
|
+
rescue Errno::ESRCH
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def ip
|
48
|
+
@ip ||= Xhyve::DHCP.get_ip_for_mac(get_mac)
|
49
|
+
end
|
50
|
+
|
51
|
+
def mac
|
52
|
+
@mac ||= VMNet.uuid_to_mac(@uuid)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def build_command
|
57
|
+
[
|
58
|
+
"#{"sudo" if @sudo}",
|
59
|
+
"#{BINARY_PATH}",
|
60
|
+
"#{"-A" if @acpi}",
|
61
|
+
"-U #{@uuid}",
|
62
|
+
"-m #{@memory}",
|
63
|
+
"-c #{@processors}",
|
64
|
+
"#{PCI_STR}",
|
65
|
+
'-s 31,lpc',
|
66
|
+
"-l #{@serial},stdio",
|
67
|
+
"#{NETWORK_STR}",
|
68
|
+
"#{"#{@blockdevs.each_with_index.map{ |p,i| "-s #{PCI_BASE+i},virtio-blk,#{p}" }.join(' ')}" unless @blockdevs.empty? }",
|
69
|
+
"-f kexec,#{@kernel},#{@initrd},'#{@cmdline}'"
|
70
|
+
].join(' ')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#./build/xhyve -U $UUID -m ${MEM}G -c ${PROCS} -s 2:0,virtio-net -s 0:0,hostbridge -s 31,lpc -l com2,stdio -A -f kexec,/Volumes/CDROM\ 1/BOOT/VMLINUZ,/Volumes/CDROM\ 1/BOOT/INITRD,"boot=live root=/dev/ram0 live-media=initramfs earlyprintk=serial console=ttyS1,115200 net.ifnames=0 biosdevname=0"
|
75
|
+
end
|
Binary file
|
data/lib/xhyve/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhyve-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
@@ -10,6 +10,62 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simplecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sshkit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net-ping
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.8
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: rake
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -49,6 +105,9 @@ files:
|
|
49
105
|
- ext/vmnet/uuid.h
|
50
106
|
- ext/vmnet/vmnet.c
|
51
107
|
- lib/xhyve.rb
|
108
|
+
- lib/xhyve/dhcp.rb
|
109
|
+
- lib/xhyve/guest.rb
|
110
|
+
- lib/xhyve/vendor/xhyve
|
52
111
|
- lib/xhyve/version.rb
|
53
112
|
- lib/xhyve/vmnet/vmnet.bundle
|
54
113
|
homepage: http://rubygems.org/gems/ruby-xhyve
|