Class: Xhyve::Guest
- Inherits:
-
Object
- Object
- Xhyve::Guest
- Defined in:
- lib/xhyve/guest.rb
Constant Summary collapse
- PCI_STR =
'-s 0:0,hostbridge'
- PCI_BASE =
3
- NETWORK_STR =
"-s #{PCI_BASE-1}:0,virtio-net"
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(**opts) ⇒ Guest
constructor
A new instance of Guest.
- #ip ⇒ Object
- #mac ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Guest
Returns a new instance of Guest.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/xhyve/guest.rb', line 15 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 @sudo = opts[:sudo] || true @command = build_command end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
13 14 15 |
# File 'lib/xhyve/guest.rb', line 13 def pid @pid end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
13 14 15 |
# File 'lib/xhyve/guest.rb', line 13 def uuid @uuid end |
Instance Method Details
#destroy ⇒ Object
37 38 39 |
# File 'lib/xhyve/guest.rb', line 37 def destroy Process.kill('KILL', @pid) if running? end |
#ip ⇒ Object
47 48 49 |
# File 'lib/xhyve/guest.rb', line 47 def ip @ip ||= Xhyve::DHCP.get_ip_for_mac(get_mac) end |
#mac ⇒ Object
51 52 53 |
# File 'lib/xhyve/guest.rb', line 51 def mac @mac ||= VMNet.uuid_to_mac(@uuid) end |
#running? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/xhyve/guest.rb', line 41 def running? Process.kill(0, @pid) rescue Errno::ESRCH false end |
#start ⇒ Object
29 30 31 |
# File 'lib/xhyve/guest.rb', line 29 def start @pid = spawn(@command) end |
#stop ⇒ Object
33 34 35 |
# File 'lib/xhyve/guest.rb', line 33 def stop Process.kill('TERM', @pid) if running? end |