Class: Virt::Guest
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#boot_device ⇒ Object
readonly
Returns the value of attribute boot_device.
-
#current_memory ⇒ Object
readonly
Returns the value of attribute current_memory.
-
#interface ⇒ Object
Returns the value of attribute interface.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#vcpu ⇒ Object
Returns the value of attribute vcpu.
-
#volume ⇒ Object
Returns the value of attribute volume.
-
#xml_desc ⇒ Object
readonly
Returns the value of attribute xml_desc.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Guest
constructor
A new instance of Guest.
- #new? ⇒ Boolean
- #poweroff ⇒ Object
- #reboot ⇒ Object
- #running? ⇒ Boolean
- #save ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #stop(force = false) ⇒ Object
- #to_s ⇒ Object
- #uuid ⇒ Object
Methods included from Util
Constructor Details
#initialize(options = {}) ⇒ Guest
Returns a new instance of Guest.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/virt/guest.rb', line 7 def initialize = {} @connection = Virt.connection @name = [:name] || raise("Must provide a name") # If our domain exists, we ignore the provided options and defaults fetch_guest @memory ||= [:memory] || default_memory_size @vcpu ||= [:vcpu] || default_vcpu_count @arch ||= [:arch] || default_arch @template_path = [:template_path] || default_template_path end |
Instance Attribute Details
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def arch @arch end |
#boot_device ⇒ Object (readonly)
Returns the value of attribute boot_device.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def boot_device @boot_device end |
#current_memory ⇒ Object (readonly)
Returns the value of attribute current_memory.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def current_memory @current_memory end |
#interface ⇒ Object
Returns the value of attribute interface.
5 6 7 |
# File 'lib/virt/guest.rb', line 5 def interface @interface end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def machine @machine end |
#memory ⇒ Object
Returns the value of attribute memory.
5 6 7 |
# File 'lib/virt/guest.rb', line 5 def memory @memory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def name @name end |
#template_path ⇒ Object
Returns the value of attribute template_path.
5 6 7 |
# File 'lib/virt/guest.rb', line 5 def template_path @template_path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def type @type end |
#vcpu ⇒ Object
Returns the value of attribute vcpu.
5 6 7 |
# File 'lib/virt/guest.rb', line 5 def vcpu @vcpu end |
#volume ⇒ Object
Returns the value of attribute volume.
5 6 7 |
# File 'lib/virt/guest.rb', line 5 def volume @volume end |
#xml_desc ⇒ Object (readonly)
Returns the value of attribute xml_desc.
4 5 6 |
# File 'lib/virt/guest.rb', line 4 def xml_desc @xml_desc end |
Instance Method Details
#<=>(other) ⇒ Object
84 85 86 |
# File 'lib/virt/guest.rb', line 84 def <=> other self.name <=> other.name end |
#destroy ⇒ Object
64 65 66 67 68 69 |
# File 'lib/virt/guest.rb', line 64 def destroy return true if new? stop(true) if running? @domain = @domain.undefine new? end |
#new? ⇒ Boolean
20 21 22 |
# File 'lib/virt/guest.rb', line 20 def new? @domain.nil? end |
#poweroff ⇒ Object
60 61 62 |
# File 'lib/virt/guest.rb', line 60 def poweroff stop(true) end |
#reboot ⇒ Object
71 72 73 74 |
# File 'lib/virt/guest.rb', line 71 def reboot raise "Guest not running, can't reboot" if new? or !running? @domain.reboot end |
#running? ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/virt/guest.rb', line 36 def running? return false if new? @domain.active? rescue # some versions of libvirt do not support checking for active state @connection.connection.list_domains.each do |did| return true if @connection.connection.lookup_domain_by_id(did).name == name end false end |
#save ⇒ Object
24 25 26 27 28 |
# File 'lib/virt/guest.rb', line 24 def save @domain = @connection.connection.define_domain_xml(xml) fetch_info !new? end |
#shutdown ⇒ Object
56 57 58 |
# File 'lib/virt/guest.rb', line 56 def shutdown stop end |
#start ⇒ Object
30 31 32 33 34 |
# File 'lib/virt/guest.rb', line 30 def start raise "Guest not created, can't start" if new? @domain.create unless running? running? end |
#stop(force = false) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/virt/guest.rb', line 47 def stop(force=false) raise "Guest not created, can't stop" if new? force ? @domain.destroy : @domain.shutdown !running? rescue Libvirt::Error # domain is not running true end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/virt/guest.rb', line 80 def to_s name.to_s end |
#uuid ⇒ Object
76 77 78 |
# File 'lib/virt/guest.rb', line 76 def uuid @domain.uuid unless new? end |