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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf9777a8a13a4a049b1b2ec2f0529b1aff1b3fa
4
- data.tar.gz: 277e88f650d890e5410e7e47212ffdb72e13b04f
3
+ metadata.gz: ba6d16639d9f006d9eb0ab93ac6d9e0f021fd56b
4
+ data.tar.gz: 55a094bea177b871630409572dbdc99875a0007d
5
5
  SHA512:
6
- metadata.gz: a58cbf6ad1c131fdf8da0616b01159460601584366c185c9c3623f5db3fc3be5ecc4975ec994e0192cb19b1066f1015f7a3bfa849b1085caaed02b5eab9138cb
7
- data.tar.gz: 4fc91c59c68b9cb603a4560d296e25ae9c72f2a155316a2471a47e4459d2b370c4f567bbcfb0552ccbd209b66dce22d7dfa1a24d1e3248f1581680b66cb8fb02
6
+ metadata.gz: b03d16d068d6b5201d0d9402d362d0361f2036f2ddc9820eff6351c308439942cd89cae4ca9c1f77d635cf6b0117e5d65224b1df7d92e1cd8e31f88c93238b26
7
+ data.tar.gz: eade397da6b782fe3fe932f4a30bee66fb6a614d86793ce627c582e4bd3b1e2be84db135c1fece003592f36a81bd125d512034e4236df9723051ddfd65a24024
@@ -1,9 +1,9 @@
1
- require "mkmf"
1
+ require 'mkmf'
2
2
  require 'rbconfig'
3
3
 
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"
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 "vmnet/vmnet"
9
+ create_makefile 'vmnet/vmnet'
@@ -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
- contents = File.read(ENV['LEASES_FILE'] || LEASES_FILE)
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
@@ -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 = [ opts[:blockdevs] || [] ].flatten
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 = spawn(@command)
33
+ @r, @w, @pid = PTY.getpty(@command.join(' '))
31
34
  end
32
35
 
33
36
  def stop
34
- Process.kill('TERM', @pid) if running?
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
- Process.kill(0, @pid)
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(get_mac)
45
+ @ip ||= Xhyve::DHCP.get_ip_for_mac(@mac)
49
46
  end
50
47
 
51
- def mac
52
- @mac ||= VMNet.uuid_to_mac(@uuid)
53
- end
48
+ private
54
49
 
55
- private
56
50
  def build_command
57
51
  [
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(' ')
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
- #./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"
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
@@ -1,3 +1,4 @@
1
+ # Common Xhyve functionality nampesace
1
2
  module Xhyve
2
- VERSION='0.0.2'
3
+ VERSION = '0.0.3'
3
4
  end
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.2
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: sshkit
42
+ name: net-ssh
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.7.1
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: 1.7.1
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: []