Class: Xhyve::Guest
- Inherits:
-
Object
- Object
- Xhyve::Guest
- Defined in:
- lib/xhyve/guest.rb
Overview
An object to represent a guest that we can start and stop Effectively, it’s a command wrapper around xhyve to provide an object oriented interface to a hypervisor guest
Constant Summary collapse
- PCI_BASE =
3
- NULLDEV =
'/dev/null'
Instance Attribute Summary collapse
-
#mac ⇒ Object
readonly
Returns the value of attribute mac.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#initialize(**opts) ⇒ Guest
constructor
A new instance of Guest.
- #ip ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Guest
Returns a new instance of Guest.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xhyve/guest.rb', line 18 def initialize(**opts) @kernel = opts.fetch(:kernel) @initrd = opts.fetch(:initrd) @cmdline = opts.fetch(:cmdline) @blockdevs = [opts[:blockdevs] || []].flatten @memory = opts[:memory] || '500M' @processors = opts[:processors] || '1' @uuid = opts[:uuid] || SecureRandom.uuid @serial = opts[:serial] || 'com1' @acpi = opts[:acpi] || true @networking = opts[:networking] || true @foreground = opts[:foreground] || false @command = build_command @mac = find_mac end |
Instance Attribute Details
#mac ⇒ Object (readonly)
Returns the value of attribute mac.
16 17 18 |
# File 'lib/xhyve/guest.rb', line 16 def mac @mac end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
16 17 18 |
# File 'lib/xhyve/guest.rb', line 16 def pid @pid end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
16 17 18 |
# File 'lib/xhyve/guest.rb', line 16 def uuid @uuid end |
Instance Method Details
#ip ⇒ Object
53 54 55 |
# File 'lib/xhyve/guest.rb', line 53 def ip @ip ||= Xhyve::DHCP.get_ip_for_mac(@mac) end |
#running? ⇒ Boolean
49 50 51 |
# File 'lib/xhyve/guest.rb', line 49 def running? (true if Process.kill(0, @pid) rescue false) end |
#start ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xhyve/guest.rb', line 34 def start outfile, infile = redirection @pid = spawn(@command, [:out, :err] => outfile, in: infile) if @foreground Process.wait(@pid) outfile.cooked! infile.cooked! end @pid end |
#stop ⇒ Object
45 46 47 |
# File 'lib/xhyve/guest.rb', line 45 def stop Process.kill('KILL', @pid) end |