xhyve-ruby 0.0.2 → 0.0.3
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 +6 -6
- data/lib/xhyve/dhcp.rb +18 -2
- data/lib/xhyve/guest.rb +29 -35
- data/lib/xhyve/version.rb +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba6d16639d9f006d9eb0ab93ac6d9e0f021fd56b
|
4
|
+
data.tar.gz: 55a094bea177b871630409572dbdc99875a0007d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b03d16d068d6b5201d0d9402d362d0361f2036f2ddc9820eff6351c308439942cd89cae4ca9c1f77d635cf6b0117e5d65224b1df7d92e1cd8e31f88c93238b26
|
7
|
+
data.tar.gz: eade397da6b782fe3fe932f4a30bee66fb6a614d86793ce627c582e4bd3b1e2be84db135c1fece003592f36a81bd125d512034e4236df9723051ddfd65a24024
|
data/ext/vmnet/extconf.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'mkmf'
|
2
2
|
require 'rbconfig'
|
3
3
|
|
4
|
-
abort
|
5
|
-
abort
|
6
|
-
abort
|
7
|
-
abort
|
4
|
+
abort 'Only works on OS X' unless RbConfig::CONFIG['host_os'].downcase.include?('darwin')
|
5
|
+
abort 'missing vmnet.h' unless have_header 'uuid.h'
|
6
|
+
abort 'missing vmnet.h' unless have_header 'vmnet/vmnet.h'
|
7
|
+
abort 'missing vmnet' unless have_framework 'vmnet'
|
8
8
|
|
9
|
-
create_makefile
|
9
|
+
create_makefile 'vmnet/vmnet'
|
data/lib/xhyve/dhcp.rb
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
module Xhyve
|
2
|
+
# Parse DHCP leases file for a MAC address, and get its ip.
|
2
3
|
module DHCP
|
3
|
-
LEASES_FILE='/var/db/dhcpd_leases'
|
4
|
+
LEASES_FILE = '/var/db/dhcpd_leases'
|
5
|
+
WAIT_TIME = 1
|
6
|
+
MAX_ATTEMPTS = 60
|
7
|
+
|
4
8
|
def self.get_ip_for_mac(mac)
|
5
|
-
|
9
|
+
attempts = 0
|
10
|
+
max_attempts = ENV.key?('MAX_IP_WAIT') ? ENV['MAX_IP_WAIT'].to_i : MAX_ATTEMPTS
|
11
|
+
while attempts < max_attempts
|
12
|
+
attempts += 1
|
13
|
+
ip = parse_lease_file_for_mac(mac)
|
14
|
+
return ip if ip
|
15
|
+
sleep(WAIT_TIME)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse_lease_file_for_mac(mac)
|
20
|
+
lease_file = (ENV['LEASES_FILE'] || LEASES_FILE)
|
21
|
+
contents = File.read(lease_file)
|
6
22
|
pattern = contents.match(/ip_address=(\S+)\n\thw_address=\d+,#{mac}/)
|
7
23
|
if pattern
|
8
24
|
addrs = pattern.captures
|
data/lib/xhyve/guest.rb
CHANGED
@@ -1,75 +1,69 @@
|
|
1
1
|
require 'securerandom'
|
2
|
+
require 'pty'
|
2
3
|
|
3
4
|
require 'xhyve/dhcp'
|
4
5
|
|
5
6
|
module Xhyve
|
6
|
-
BINARY_PATH=File.expand_path('../../../lib/xhyve/vendor/xhyve', __FILE__).freeze
|
7
|
+
BINARY_PATH = File.expand_path('../../../lib/xhyve/vendor/xhyve', __FILE__).freeze
|
7
8
|
|
9
|
+
# An object to represent a guest that we can start and stop
|
10
|
+
# Effectively, it's a command wrapper around xhyve to provide an
|
11
|
+
# object oriented interface to a hypervisor guest
|
8
12
|
class Guest
|
9
|
-
PCI_STR = '-s 0:0,hostbridge'
|
10
13
|
PCI_BASE = 3
|
11
|
-
NETWORK_STR = "-s #{PCI_BASE-1}:0,virtio-net"
|
12
14
|
|
13
|
-
attr_reader :pid, :uuid
|
15
|
+
attr_reader :pid, :uuid, :mac
|
14
16
|
|
15
17
|
def initialize(**opts)
|
16
18
|
@kernel = opts.fetch(:kernel)
|
17
19
|
@initrd = opts.fetch(:initrd)
|
18
20
|
@cmdline = opts.fetch(:cmdline)
|
19
|
-
@blockdevs = [
|
21
|
+
@blockdevs = [opts[:blockdevs] || []].flatten
|
20
22
|
@memory = opts[:memory] || '500M'
|
21
|
-
@processors = opts[:processors] || 1
|
23
|
+
@processors = opts[:processors] || '1'
|
22
24
|
@uuid = opts[:uuid] || SecureRandom.uuid
|
23
25
|
@serial = opts[:serial] || 'com1'
|
24
26
|
@acpi = opts[:acpi] || true
|
25
27
|
@sudo = opts[:sudo] || true
|
26
28
|
@command = build_command
|
29
|
+
@mac = VMNet.uuid_to_mac(@uuid)
|
27
30
|
end
|
28
31
|
|
29
32
|
def start
|
30
|
-
@pid =
|
33
|
+
@r, @w, @pid = PTY.getpty(@command.join(' '))
|
31
34
|
end
|
32
35
|
|
33
36
|
def stop
|
34
|
-
Process.kill('
|
35
|
-
end
|
36
|
-
|
37
|
-
def destroy
|
38
|
-
Process.kill('KILL', @pid) if running?
|
37
|
+
Process.kill('KILL', @pid)
|
39
38
|
end
|
40
39
|
|
41
40
|
def running?
|
42
|
-
|
43
|
-
rescue Errno::ESRCH
|
44
|
-
false
|
41
|
+
PTY.check(@pid).nil?
|
45
42
|
end
|
46
|
-
|
43
|
+
|
47
44
|
def ip
|
48
|
-
@ip ||= Xhyve::DHCP.get_ip_for_mac(
|
45
|
+
@ip ||= Xhyve::DHCP.get_ip_for_mac(@mac)
|
49
46
|
end
|
50
47
|
|
51
|
-
|
52
|
-
@mac ||= VMNet.uuid_to_mac(@uuid)
|
53
|
-
end
|
48
|
+
private
|
54
49
|
|
55
|
-
private
|
56
50
|
def build_command
|
57
51
|
[
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
].
|
52
|
+
"#{'sudo' if @sudo}",
|
53
|
+
"#{BINARY_PATH}",
|
54
|
+
"#{'-A' if @acpi}",
|
55
|
+
'-U', @uuid,
|
56
|
+
'-m', @memory,
|
57
|
+
'-c', @processors,
|
58
|
+
'-s', '0:0,hostbridge',
|
59
|
+
'-s', '31,lpc',
|
60
|
+
'-l', "#{@serial},stdio",
|
61
|
+
'-s', "#{PCI_BASE - 1}:0,virtio-net",
|
62
|
+
"#{"#{@blockdevs.each_with_index.map { |p, i| "-s #{PCI_BASE + i},virtio-blk,#{p}" }.join(' ')}" unless @blockdevs.empty? }",
|
63
|
+
'-f' "kexec,#{@kernel},#{@initrd},'#{@cmdline}'"
|
64
|
+
].compact
|
71
65
|
end
|
72
66
|
end
|
73
67
|
|
74
|
-
|
68
|
+
# ./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
69
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: net-ssh
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: net-ping
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.9.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: childprocess
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.8
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.5.8
|
97
111
|
description: Provides a means of interacting with xhyve from ruby
|
98
112
|
email: dale.hamel@srvthe.net
|
99
113
|
executables: []
|